- Add m2-setup-backend-prompt.md with structured documentation for FastAPI backend setup - Add m2-setup-backend-scoring.md with acceptance criteria scoring table - Update README.md with M2 milestone links
5.3 KiB
M2: Setup Backend
Prompt
Create the backend infrastructure for newzy news web application using Python FastAPI. Follow these steps:
-
Set up project structure:
newzy/ ├── api/ │ └── v1/ │ └── __init__.py ├── core/ │ └── __init__.py ├── db/ │ └── session.py ├── models/ │ └── __init__.py ├── schemas/ │ └── __init__.py ├── main.py ├── config.py └── requirements.txt -
Create FastAPI application in
main.pywith:- Health check endpoint (
GET /health) - Version endpoint (
GET /api/v1/version)
- Health check endpoint (
-
Set up SQLAlchemy database session using SQLite (configured for Docker volume persistence)
-
Define Pydantic schemas for basic models (Article, Author, Category)
-
Configure
requirements.txtwith:- FastAPI
- uvicorn
- SQLAlchemy
- pydantic
- python-multipart
-
Create initial database models for:
- Article (title, content, author_id, category_id, created_at, published)
- Author (name, email, bio)
- Category (name, slug)
-
Add proper exception handling and error responses
-
Document API endpoints in README.md with examples
Remember: Focus ONLY on backend infrastructure. No frontend implementation required.
Description
This milestone sets up the FastAPI backend for newzy news application using Python. The scope includes database configuration, API structure, core models, and basic endpoints—no complex business logic or integration with other services.
Purpose: Create a functional REST API backbone ready for feature development in subsequent milestones.
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.
Acceptance Criteria
- FastAPI application created in
main.py - SQLAlchemy session configured with SQLite backend
- Database models defined: Article, Author, Category
- Pydantic schemas implemented for all models
- Health check endpoint (
GET /health) returns 200 OK - Version endpoint (
GET /api/v1/version) returns application version requirements.txtlists all Python dependencies- Proper error handling with standardized response format
- README.md documents API endpoints with examples
- Code follows FastAPI and SQLAlchemy best practices
Technical Details
Project 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
Database Schema
Article Model:
id: Integer, primary keytitle: String(200), uniquecontent: Textauthor_id: Integer, foreign key to Authorcategory_id: Integer, foreign key to Categorycreated_at: DateTimepublished: Boolean, default False
Author Model:
id: Integer, primary keyname: String(100), uniqueemail: String(255), uniquebio: Text (nullable)
Category Model:
id: Integer, primary keyname: String(100), uniqueslug: String(100), unique
API Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /health | Health check endpoint |
| GET | /api/v1/version | Returns application version |
| GET | /api/v1/health | Alternative health check path |
Configuration
- Environment variables for database URL
- Docker volume configuration:
/data/dbmapped to SQLite file - CORS enabled for frontend development
QA Notes
Testing Checklist
- Application starts without errors
- Health endpoint returns 200 OK
- Version endpoint returns correct format
- Database connection successful
- Models can be instantiated and committed
- Error responses follow standardized format
- No unhandled exceptions in basic operations
Performance Considerations
- Single-threaded async mode for development (uvicorn workers = 1)
- SQLite file-based storage (no connection pool needed yet)
- Lazy database session management
Security Notes
- Password hashing to be implemented in future milestones
- Authentication mechanism TBD
- CORS configuration should be validated before production
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
Success Metrics
- Application starts in under 10 seconds
- Health check responds within 100ms
- All models query successfully without errors
- README examples work as documented