chore: initial project setup with documentation and standards

This commit is contained in:
Daniel Samson committed 2026-10-30 09:42:38 +00:00
1 parent 4c82e4f54c
commit 0824474e70
6 files changed
+803 -106

No files matched your search

+253
View File
@@ -0,0 +1,253 @@
# newzy - API Documentation
This document describes the API endpoints for the newzy news web application.
## Base URL
- Development: `http://localhost:3000/api`
- Production: `<your-domain>/api`
## Authentication
Most endpoints require authentication via Bearer token. Include in headers:
```
Authorization: Bearer <your-jwt-token>
Content-Type: application/json
```
## Common Response Formats
### Success Response
```json
{
"success": true,
"data": {},
"message": "Operation completed successfully"
}
```
### Error Response
```json
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human readable error message"
}
}
```
## Authentication Endpoints
### POST /auth/register
Register a new user.
**Request Body:**
```json
{
"email": "user@example.com",
"password": "securePassword123",
"name": "John Doe"
}
```
**Response:**
```json
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"email": "user@example.com",
"name": "John Doe"
}
},
"message": "User registered successfully"
}
```
### POST /auth/login
Login and get authentication token.
**Request Body:**
```json
{
"email": "user@example.com",
"password": "securePassword123"
}
```
**Response:**
```json
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"email": "user@example.com",
"name": "John Doe"
}
},
"message": "Login successful"
}
```
### POST /auth/logout
Logout and invalidate token.
**Request:** No body required
**Response:**
```json
{
"success": true,
"message": "Logged out successfully"
}
```
## Articles Endpoints
### GET /articles
List all articles with optional filtering.
**Query Parameters:**
- `category`: Filter by category (optional)
- `page`: Page number for pagination (default: 1)
- `limit`: Items per page (default: 10, max: 50)
- `search`: Search keyword (optional)
**Example:**
```bash
GET /articles?category=technology&page=1&limit=20&search=ai
```
**Response:**
```json
{
"success": true,
"data": {
"articles": [
{
"id": 1,
"title": "AI in Modern Technology",
"content": "...",
"author": "Jane Smith",
"category": "technology",
"publishedAt": "2024-01-15T10:30:00Z",
"views": 1523
}
],
"pagination": {
"currentPage": 1,
"totalPages": 5,
"totalItems": 100
}
}
}
```
### GET /articles/:id
Get a single article by ID.
**Response:**
```json
{
"success": true,
"data": {
"article": {
"id": 1,
"title": "AI in Modern Technology",
"content": "...",
"author": "Jane Smith",
"category": "technology",
"publishedAt": "2024-01-15T10:30:00Z",
"views": 1523,
"imageUrl": "https://example.com/image.jpg"
}
}
}
```
### POST /articles
Create a new article (authenticated only).
**Request Body:**
```json
{
"title": "New Article Title",
"content": "Article content here...",
"category": "technology",
"author": "Author Name",
"imageUrl": "https://example.com/image.jpg"
}
```
### PUT /articles/:id
Update an existing article (authenticated only).
**Request Body:**
```json
{
"title": "Updated Title",
"content": "Updated content...",
"category": "technology"
}
```
### DELETE /articles/:id
Delete an article (authenticated with admin role only).
## Categories Endpoints
### GET /categories
List all categories.
**Response:**
```json
{
"success": true,
"data": {
"categories": [
{ "id": 1, "name": "Technology", "slug": "technology" },
{ "id": 2, "name": "Sports", "slug": "sports" }
]
}
}
```
### GET /categories/:id
Get a single category with its articles.
## Error Codes
| Code | Description | HTTP Status |
|------|-------------|-------------|
| `INVALID_CREDENTIALS` | Invalid email or password | 401 |
| `TOKEN_EXPIRED` | JWT token has expired | 401 |
| `UNAUTHORIZED` | Missing or invalid token | 401 |
| `NOT_FOUND` | Resource not found | 404 |
| `INTERNAL_ERROR` | Server-side error | 500 |
## Rate Limiting
API endpoints are rate limited to prevent abuse:
- **100 requests per minute** per IP address
- Headers include remaining quota:
- `X-RateLimit-Limit: 100`
- `X-RateLimit-Remaining: 95`
- `X-RateLimit-Reset: <timestamp>`
+95
View File
@@ -0,0 +1,95 @@
# newzy - System Architecture
This document describes the architecture of the newzy news web application.
## High-Level Architecture
```
┌─────────────────────────────────────────────────────┐
│ Client Layer │
│ (Browser-based Web Application) │
│ ┌─────────────────┬─────────────────┬──────────┐ │
│ │ Frontend │ API Calls │ State │ │
│ │ Framework │ REST/GraphQL │ Mgmt │ │
│ └─────────────────┴─────────────────┴──────────┘ │
└─────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ API Layer │
│ (Node.js/Express Backend) │
│ ┌─────────────────┬─────────────────┬──────────┐ │
│ │ Authentication │ Validation │ Routes │ │
│ │ Middleware │ Error Handling │ Controllers│
│ └─────────────────┴─────────────────┴──────────┘ │
└─────────────────────────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ Data Layer │
│ (Database & Cache) │
│ ┌─────────────────┬─────────────────┬──────────┐ │
│ │ Primary DB │ Caching │ Backup │ │
│ │ Service │ Service │ Service │ │
│ └─────────────────┴─────────────────┴──────────┘ │
└─────────────────────────────────────────────────────┘
```
## Core Components
### Frontend
- **Framework**: React (latest stable version)
- **State Management**: Context API or Redux (as needed)
- **Styling**: CSS Modules / Tailwind CSS
- **Routing**: React Router v6
### Backend
- **Runtime**: Node.js 18 LTS
- **Framework**: Express.js
- **Database ORM**: Sequelize
- **Authentication**: JWT with bcrypt password hashing
### Database
- **Primary**: PostgreSQL (production), SQLite (development)
- **Caching**: Redis (optional for performance)
## File Structure
```
newzy/
├── src/
│ ├── api/ # API routes and controllers
│ │ ├── auth/ # Authentication endpoints
│ │ ├── articles/ # Article management endpoints
│ │ └── categories/ # Category endpoints
│ ├── models/ # Database models
│ ├── utils/ # Utility functions
│ └── config/ # Configuration files
├── docs/ # Documentation (this file)
├── tests/ # Test suite
└── public/ # Static assets
```
## API Endpoints (Planned)
| Method | Endpoint | Description |
|--------|--------------------|----------------------|
| GET | /api/articles | List all articles |
| GET | /api/articles/:id | Get article by ID |
| POST | /api/articles | Create new article |
| PUT | /api/articles/:id | Update article |
| DELETE | /api/articles/:id | Delete article |
## Security Considerations
- HTTPS only in production
- Rate limiting on API endpoints
- Input validation and sanitization
- CORS configuration
- Environment variable management for secrets
## Future Enhancements
- WebSocket support for real-time updates
- GraphQL API implementation
- CDN integration for static assets
- Multi-language support (i18n)
- Admin dashboard