feat: update M2 backend setup with correct structure
- Move backend to proper subfolder structure (newzy/backend/) - Add .gitignore file for Python exclusions - Add Dockerfile for containerization - Update requirements.txt and docker-compose references - Expand scoring rubric to 19 points for comprehensive evaluation
This commit is contained in:
1 parent
8e05ae3497
commit
48fcbf16f6
2 files changed
+149
-67
No files matched your search
@@ -4,26 +4,30 @@
|
||||
|
||||
Create the backend infrastructure for **newzy** news web application using Python FastAPI. Follow these steps:
|
||||
|
||||
1. Set up project structure:
|
||||
1. Set up project structure in `backend/` folder:
|
||||
```
|
||||
newzy/
|
||||
├── api/
|
||||
│ └── v1/
|
||||
│ └── __init__.py
|
||||
├── core/
|
||||
│ └── __init__.py
|
||||
├── db/
|
||||
│ └── session.py
|
||||
├── models/
|
||||
│ └── __init__.py
|
||||
├── schemas/
|
||||
│ └── __init__.py
|
||||
├── main.py
|
||||
├── config.py
|
||||
└── requirements.txt
|
||||
├── backend/
|
||||
│ ├── api/
|
||||
│ │ └── v1/
|
||||
│ │ └── __init__.py
|
||||
│ ├── core/
|
||||
│ │ └── __init__.py
|
||||
│ ├── db/
|
||||
│ │ └── session.py
|
||||
│ ├── models/
|
||||
│ │ └── __init__.py
|
||||
│ ├── schemas/
|
||||
│ │ └── __init__.py
|
||||
│ ├── main.py
|
||||
│ ├── config.py
|
||||
│ ├── requirements.txt
|
||||
│ ├── Dockerfile
|
||||
│ ├── .gitignore
|
||||
│ └── README.md
|
||||
```
|
||||
|
||||
2. Create FastAPI application in `main.py` with:
|
||||
2. Create FastAPI application in `backend/main.py` with:
|
||||
- Health check endpoint (`GET /health`)
|
||||
- Version endpoint (`GET /api/v1/version`)
|
||||
|
||||
@@ -45,7 +49,18 @@ Create the backend infrastructure for **newzy** news web application using Pytho
|
||||
|
||||
7. Add proper exception handling and error responses
|
||||
|
||||
8. Document API endpoints in README.md with examples
|
||||
8. Document API endpoints in `backend/README.md` with examples
|
||||
|
||||
9. Create `.gitignore` to exclude Python artifacts, env files, and IDE configs
|
||||
|
||||
10. Create `Dockerfile` for containerization with:
|
||||
- Base Python image
|
||||
- Install requirements
|
||||
- Copy application code
|
||||
- Expose port 8000
|
||||
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
11. Add docker-compose.yml at project root with backend service
|
||||
|
||||
Remember: Focus ONLY on backend infrastructure. No frontend implementation required.
|
||||
|
||||
@@ -57,11 +72,11 @@ This milestone sets up the FastAPI backend for newzy news application using Pyth
|
||||
|
||||
**Target Audience**: Backend developers joining the project who need to understand and extend the API.
|
||||
|
||||
**Expected Outcomes**: A running FastAPI server with database connectivity, core models defined, and documented endpoints ready for additional features.
|
||||
**Expected Outcomes**: A containerized FastAPI server with database connectivity, core models defined, and documented endpoints ready for additional features.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] FastAPI application created in `main.py`
|
||||
- [ ] FastAPI application created in `backend/main.py`
|
||||
- [ ] SQLAlchemy session configured with SQLite backend
|
||||
- [ ] Database models defined: Article, Author, Category
|
||||
- [ ] Pydantic schemas implemented for all models
|
||||
@@ -69,36 +84,36 @@ This milestone sets up the FastAPI backend for newzy news application using Pyth
|
||||
- [ ] Version endpoint (`GET /api/v1/version`) returns application version
|
||||
- [ ] `requirements.txt` lists all Python dependencies
|
||||
- [ ] Proper error handling with standardized response format
|
||||
- [ ] README.md documents API endpoints with examples
|
||||
- [ ] `backend/README.md` documents API endpoints with examples
|
||||
- [ ] `.gitignore` file created with appropriate exclusions
|
||||
- [ ] `Dockerfile` creates runnable container image
|
||||
- [ ] Code follows FastAPI and SQLAlchemy best practices
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Project Structure
|
||||
### Project Root Structure
|
||||
```
|
||||
newzy/
|
||||
├── api/
|
||||
│ └── v1/
|
||||
│ └── __init__.py
|
||||
├── core/
|
||||
│ ├── config.py # Application configuration
|
||||
│ └── __init__.py
|
||||
├── db/
|
||||
│ └── session.py # Database session management
|
||||
├── models/
|
||||
│ ├── article.py # Article model
|
||||
│ ├── author.py # Author model
|
||||
│ └── category.py # Category model
|
||||
├── schemas/
|
||||
│ ├── article.py # Article Pydantic schema
|
||||
│ ├── author.py # Author Pydantic schema
|
||||
│ └── category.py # Category Pydantic schema
|
||||
├── main.py # Application entry point
|
||||
├── requirements.txt # Python dependencies
|
||||
└── README.md # API documentation
|
||||
project-root/
|
||||
├── backend/
|
||||
│ ├── api/
|
||||
│ │ └── v1/
|
||||
│ │ └── __init__.py
|
||||
│ ├── core/
|
||||
│ ├── db/
|
||||
│ ├── models/
|
||||
│ ├── schemas/
|
||||
│ ├── main.py
|
||||
│ ├── config.py
|
||||
│ ├── requirements.txt
|
||||
│ ├── Dockerfile
|
||||
│ ├── .gitignore
|
||||
│ └── README.md
|
||||
├── LICENSE # MIT License
|
||||
├── README.md
|
||||
└── CONTRIBUTING.md
|
||||
```
|
||||
|
||||
### Database Schema
|
||||
### Database Schema (SQLite)
|
||||
|
||||
**Article Model:**
|
||||
- `id`: Integer, primary key
|
||||
@@ -120,7 +135,7 @@ newzy/
|
||||
- `name`: String(100), unique
|
||||
- `slug`: String(100), unique
|
||||
|
||||
### API Endpoints
|
||||
### Backend API Endpoints
|
||||
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
@@ -128,40 +143,100 @@ newzy/
|
||||
| GET | /api/v1/version | Returns application version |
|
||||
| GET | /api/v1/health | Alternative health check path |
|
||||
|
||||
### .gitignore Contents for backend/
|
||||
```python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.egg-info/
|
||||
.env
|
||||
.venv/
|
||||
venv/
|
||||
*.db
|
||||
*.sqlite
|
||||
Dockerfile
|
||||
.docker/
|
||||
.DS_Store
|
||||
.idea/
|
||||
.vscode/
|
||||
*~
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
```dockerfile
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Run application
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
```
|
||||
|
||||
### docker-compose.yml (project root)
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
backend:
|
||||
build: ./backend
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./data/db:/app/data/db
|
||||
environment:
|
||||
- DATABASE_URL=sqlite:///./data/db/newzy.db
|
||||
```
|
||||
|
||||
### Configuration
|
||||
- Environment variables for database URL
|
||||
- Environment variables for database URL (DATABASE_URL)
|
||||
- Docker volume configuration: `/data/db` mapped to SQLite file
|
||||
- CORS enabled for frontend development
|
||||
- Uvicorn workers configured for production deployment
|
||||
|
||||
## QA Notes
|
||||
|
||||
### Testing Checklist
|
||||
- [ ] Application starts without errors
|
||||
- [ ] Health endpoint returns 200 OK
|
||||
- [ ] Version endpoint returns correct format
|
||||
- [ ] Health endpoint returns 200 OK with JSON response
|
||||
- [ ] Version endpoint returns correct format (version string)
|
||||
- [ ] Database connection successful
|
||||
- [ ] Models can be instantiated and committed
|
||||
- [ ] Error responses follow standardized format
|
||||
- [ ] No unhandled exceptions in basic operations
|
||||
- [ ] Docker container builds successfully
|
||||
- [ ] Container runs and serves endpoints
|
||||
|
||||
### Performance Considerations
|
||||
- Single-threaded async mode for development (uvicorn workers = 1)
|
||||
- SQLite file-based storage (no connection pool needed yet)
|
||||
- Lazy database session management
|
||||
- Docker Compose enables easy local development setup
|
||||
|
||||
### Security Notes
|
||||
- Password hashing to be implemented in future milestones
|
||||
- Authentication mechanism TBD
|
||||
- CORS configuration should be validated before production
|
||||
- Environment variables for secrets should use .env files
|
||||
|
||||
### Known Issues / Limitations
|
||||
- No input validation beyond Pydantic schemas
|
||||
- No rate limiting implemented
|
||||
- Database schema not yet optimized for performance
|
||||
- Missing pagination and filtering on article endpoints
|
||||
- SQLite not suitable for high-concurrency production workloads
|
||||
|
||||
### Success Metrics
|
||||
- Application starts in under 10 seconds
|
||||
- Application starts in under 10 seconds locally
|
||||
- Health check responds within 100ms
|
||||
- All models query successfully without errors
|
||||
- Docker image builds and runs cleanly
|
||||
- README examples work as documented
|
||||
@@ -4,47 +4,54 @@
|
||||
|
||||
| Score | Criteria |
|
||||
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| 0 | Agent failed to implement acceptance criteria:<br>- No FastAPI application created<br>- Database session not configured<br>- Models missing or broken<br>- No endpoints implemented |
|
||||
| 1 | Agent partially implemented acceptance criteria that builds successfully:<br>- Basic FastAPI app runs but no endpoints<br>- Database session fails on startup<br>- Some models defined but incomplete |
|
||||
| 2 | Agent fully implemented acceptance criteria that builds successfully:<br>- FastAPI application with health and version endpoints<br>- SQLAlchemy configured with SQLite<br>- All three models (Article, Author, Category) created<br>- requirements.txt present |
|
||||
| 3 | Agent fully implemented acceptance criteria that builds successfully, includes working Pydantic schemas for all models with validation examples<br>- Proper schema integration in API responses |
|
||||
| 0 | Agent failed to implement acceptance criteria:<br>- No FastAPI application created<br>- Database session not configured<br>- Models missing or broken<br>- No endpoints implemented<br>- Missing required files (.gitignore, Dockerfile) |
|
||||
| 1 | Agent partially implemented acceptance criteria that builds successfully:<br>- Basic FastAPI app runs but incomplete structure<br>- Backend folder missing key components<br>- Only one endpoint working<br>- Some models incomplete |
|
||||
| 2 | Agent fully implemented acceptance criteria that builds successfully:<br>- FastAPI application in backend/main.py<br>- SQLAlchemy configured with SQLite in Docker volume<br>- All three models (Article, Author, Category) created<br>- Both /health and /api/v1/version endpoints working<br>- requirements.txt present with dependencies<br>- .gitignore file included |
|
||||
| 3 | Agent fully implemented acceptance criteria that builds successfully, includes Pydantic schemas for all models with validation<br>- Schemas properly integrated in API responses<br>- Dockerfile creates runnable container image |
|
||||
| 4 | Agent fully implemented acceptance criteria that builds successfully, includes passing unit tests for:<br>- Model CRUD operations<br>- Database session management<br>- Schema validation<br>- Endpoint response formats |
|
||||
| 5 | Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 4 AND:<br>- End-to-end integration test demonstrating full workflow<br>- Docker Compose configuration for database persistence<br>- Performance benchmarks showing acceptable latency |
|
||||
| 5 | Agent fully implemented acceptance criteria that builds successfully, includes all content from Score 4 AND:<br>- End-to-end integration test demonstrating full Docker workflow (build → run → query)<br>- Complete docker-compose.yml with backend service and persistent storage<br>- Performance benchmarks showing acceptable latency under load |
|
||||
|
||||
## Scoring Breakdown by Criterion
|
||||
|
||||
### Application Structure (Max 2 points)
|
||||
- **0 pts**: No FastAPI application or main.py missing
|
||||
- **1 pt**: main.py exists but no proper structure (api/, core/, etc.)
|
||||
- **2 pts**: Complete directory structure with all expected folders and files
|
||||
- **0 pts**: No FastAPI application or main.py missing<br>- Backend folder not created properly
|
||||
- **1 pt**: main.py exists but incomplete structure (missing core/, db/, etc.)<br>- Inconsistent folder organization
|
||||
- **2 pts**: Complete directory structure with all expected folders and files (api/, core/, db/, models/, schemas/)<br>- Proper __init__.py files in each package
|
||||
|
||||
### Database Setup (Max 2 points)
|
||||
- **0 pts**: No SQLAlchemy configuration or session setup<br>- Database connection fails
|
||||
- **1 pt**: Session created but SQLite not configured properly<br>- Can connect to memory database only
|
||||
- **2 pts**: Full SQLAlchemy setup with SQLite file storage, proper session management
|
||||
- **2 pts**: Full SQLAlchemy setup with SQLite file storage, proper session management<br>- Volume persistence configured for Docker
|
||||
|
||||
### Models Implementation (Max 3 points)
|
||||
- **0 pts**: No models defined<br>- All three required models missing
|
||||
- **1 pt**: One model partially or incorrectly implemented<br>- Missing relationships
|
||||
- **2 pts**: All three models created with correct fields and relationships<br>- Can query without errors
|
||||
- **3 pts**: Models fully functional with proper foreign keys, indexes where appropriate
|
||||
- **1 pt**: One model partially or incorrectly implemented<br>- Missing relationships or fields
|
||||
- **2 pts**: All three models created with correct fields and relationships<br>- Can query without errors, proper foreign keys
|
||||
- **3 pts**: Models fully functional with proper indexes, cascade deletes configured
|
||||
|
||||
### Endpoints (Max 2 points)
|
||||
- **0 pts**: No endpoints implemented<br>- Health endpoint missing or returns error
|
||||
- **1 pt**: Health endpoint works but version endpoint broken<br>- Only one path defined
|
||||
- **2 pts**: Both /health and /api/v1/version working with correct responses
|
||||
- **2 pts**: Both /health and /api/v1/version working with correct JSON responses<br>- Proper status codes
|
||||
|
||||
### Documentation (Max 2 points)
|
||||
### Documentation (Max 3 points)
|
||||
- **0 pts**: No README.md or incomplete<br>- No API documentation
|
||||
- **1 pt**: README exists with basic info only<br>- Missing endpoint examples
|
||||
- **2 pts**: Comprehensive README with full API documentation, examples, and usage instructions
|
||||
- **3 pts**: README includes setup guide, configuration notes, and troubleshooting tips
|
||||
|
||||
### Code Quality (Max 2 points)
|
||||
### Docker Support (Max 2 points)
|
||||
- **0 pts**: No Dockerfile or .dockerignore<br>- Cannot containerize application
|
||||
- **1 pt**: Basic Dockerfile present but not working<br>- Fails to build or run
|
||||
- **2 pts**: Dockerfile works correctly with all dependencies installed<br>- Application runs successfully in container
|
||||
|
||||
### Code Quality (Max 3 points)
|
||||
- **0 pts**: No error handling<br>- Poor code organization
|
||||
- **1 pt**: Basic error handling present<br>- Some best practices followed
|
||||
- **2 pts**: Proper exception handling, standardized responses, follows FastAPI/SQAlchemy conventions
|
||||
- **2 pts**: Proper exception handling, standardized responses, follows FastAPI/SQLAlchemy conventions
|
||||
- **3 pts**: Clean separation of concerns, type hints, docstrings for all functions
|
||||
|
||||
## Total Possible Score: 15 points
|
||||
## Total Possible Score: 19 points
|
||||
|
||||
## Evaluation Notes
|
||||
- Partial credit given for incomplete but working implementations (Score 1)
|
||||
@@ -59,9 +66,9 @@
|
||||
- Input validation at schema level
|
||||
|
||||
**+2 points** for:
|
||||
- Unit tests covering core functionality
|
||||
- README includes startup instructions
|
||||
- Unit tests covering core functionality (models, endpoints)
|
||||
- README includes startup instructions and configuration examples
|
||||
|
||||
**+3 points** for:
|
||||
- Docker configuration ready for production use
|
||||
- Docker Compose setup enabling easy local development
|
||||
- Performance optimizations (connection pooling, async queries)
|
||||
Reference in new issue
Block a user