FASTAPI / 10. FULL PROJECT — TASKFLOW
Full Project — TaskFlow API
All concepts combined: Auth + DB + CRUD + Routers + Tests
EXPLANATION
TaskFlow is a complete task management API that uses every concept covered. This is the project you've been building in your head — all the pieces assembled into a real, deployable backend.
Architecture:
• FastAPI app with APIRouter — routes split into auth.py and tasks.py
• SQLModel — User and Task tables with a foreign key relationship
• JWT Authentication — signup, login, protected endpoints
• Full CRUD for tasks — scoped to the authenticated user (users only see their own tasks)
• Pydantic models — separate Create/Read/Update models for each resource
• Dependency chain — get_db → get_current_user → route
• CORS — configured for the Next.js frontend
The User → Task relationship:
• A User has many Tasks (one-to-many)
• Task has owner_id (FK → user.id)
• All task queries are filtered by owner_id = current_user.id
• Users cannot see or modify other users' tasks
Project structure (what a real FastAPI project looks like):
taskflow/
├── main.py ← app setup, lifespan, include routers, CORS
├── database.py ← engine, get_db
├── models.py ← User, Task SQLModel classes
├── schemas.py ← Pydantic Create/Read/Update models
├── auth.py ← password hashing, JWT, get_current_user
├── routers/
│ ├── auth.py ← /auth/signup, /auth/token
│ └── tasks.py ← /tasks/ CRUD (protected)
└── tests/
├── conftest.py
└── test_tasks.py
This is what you'd actually deploy on a server, connect to a PostgreSQL database, and point your Next.js frontend at. The entire TaskFlow project (FastAPI + SQLModel + Next.js) is the pattern for your personal project.ARCHITECTURE
API ENDPOINTS:
POST /auth/signup → create user
POST /auth/token → login → JWT token
GET /me → current user (protected)
GET /tasks/ → list my tasks (protected)
POST /tasks/ → create task (protected)
GET /tasks/{id} → get one task (protected)
PATCH /tasks/{id} → update task (protected)
DELETE /tasks/{id} → delete task (protected)
DATABASE SCHEMA:
┌──────────────┐ ┌─────────────────────┐
│ user │ │ task │
├──────────────┤ ├─────────────────────┤
│ id (PK) │←──┐ │ id (PK) │
│ username │ └───│ owner_id (FK) │
│ email │ │ title │
│ hashed_pw │ │ description │
└──────────────┘ │ done │
│ created_at │
└─────────────────────┘CODE