A production-ready REST API for task management, built with FastAPI, PostgreSQL, JWT authentication, and Docker. Designed with clean architecture, service layer separation, and full test coverage.
Features • Tech Stack • Getting Started • API Docs • Project Structure • Running Tests
- 🔐 JWT Authentication — Secure register/login with Bearer token auth
- ✅ Full Task CRUD — Create, list, filter, update, and delete tasks
- 👤 User Ownership — Each user only accesses their own tasks
- 🏷️ Priority & Status — Tasks support
low/medium/highpriority andtodo/in_progress/donestatus - 🔍 Filtering & Pagination — Query tasks by status, priority, skip & limit
- 🐳 Docker Ready — One command to spin up the full stack
- 🧪 Test Suite — Auth and task tests using Pytest + SQLite in-memory DB
- 📄 Auto Docs — Swagger UI and ReDoc auto-generated by FastAPI
| Layer | Technology |
|---|---|
| Framework | FastAPI 0.111 |
| Language | Python 3.12 |
| Database | PostgreSQL 16 |
| ORM | SQLAlchemy 2.0 |
| Migrations | Alembic |
| Auth | JWT (python-jose) + Passlib/bcrypt |
| Validation | Pydantic v2 |
| Testing | Pytest + HTTPX |
| Containerization | Docker + Docker Compose |
- Docker & Docker Compose (recommended)
- Or Python 3.12+ and PostgreSQL installed locally
# 1. Clone the repository
git clone https://github.com/rchintan405/fastapi-task-manager.git
cd fastapi-task-manager
# 2. Set up environment variables
cp .env.example .env
# Edit .env and set a strong SECRET_KEY
# 3. Start the stack
docker compose up --build
# API is live at http://localhost:8000
# Swagger UI at http://localhost:8000/docs# 1. Clone and enter the project
git clone https://github.com/rchintan405/fastapi-task-manager.git
cd fastapi-task-manager
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Set up environment
cp .env.example .env
# Update DATABASE_URL to your local PostgreSQL connection string
# 5. Run database migrations
alembic upgrade head
# 6. Start the server
uvicorn app.main:app --reload
# API is live at http://localhost:8000FastAPI generates interactive docs automatically:
| Doc Type | URL |
|---|---|
| Swagger UI | http://localhost:8000/docs |
| ReDoc | http://localhost:8000/redoc |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/v1/auth/register |
Register a new user | ❌ |
POST |
/api/v1/auth/login |
Login and receive JWT token | ❌ |
GET |
/api/v1/auth/me |
Get current user profile | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/v1/tasks/ |
Create a new task | ✅ |
GET |
/api/v1/tasks/ |
List all tasks (with filters) | ✅ |
GET |
/api/v1/tasks/{id} |
Get a specific task | ✅ |
PATCH |
/api/v1/tasks/{id} |
Update a task | ✅ |
DELETE |
/api/v1/tasks/{id} |
Delete a task | ✅ |
POST /api/v1/tasks/
Authorization: Bearer <token>
{
"title": "Complete project proposal",
"description": "Draft the Q3 project proposal doc",
"priority": "high",
"status": "in_progress",
"due_date": "2025-07-01T18:00:00"
}GET /api/v1/tasks/?status=in_progress&priority=high&skip=0&limit=10
fastapi-task-manager/
├── app/
│ ├── main.py # App entry point, middleware, router registration
│ ├── config.py # Pydantic settings (env vars)
│ ├── database.py # SQLAlchemy engine & session
│ ├── models/ # ORM models (User, Task)
│ ├── schemas/ # Pydantic request/response schemas
│ ├── routers/ # API route handlers (auth, tasks)
│ ├── services/ # Business logic layer
│ └── utils/ # JWT helpers
├── tests/
│ ├── conftest.py # Pytest fixtures (test client, DB)
│ ├── test_auth.py # Auth endpoint tests
│ └── test_tasks.py # Task CRUD tests
├── alembic/ # Database migrations
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── .env.example
Tests use SQLite in-memory so no PostgreSQL needed:
# Install deps (if not already)
pip install -r requirements.txt
# Run all tests
pytest
# With coverage report
pytest --cov=app --cov-report=term-missing
# Run specific test file
pytest tests/test_auth.py -v- Passwords are hashed with bcrypt via Passlib
- JWTs are signed with HS256 and expire in 30 minutes (configurable)
- Each user can only read/modify their own tasks — enforced at the service layer
.envis gitignored; use.env.exampleas a template
Pull requests are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feat/your-feature - Commit your changes:
git commit -m "feat: add your feature" - Push to the branch:
git push origin feat/your-feature - Open a Pull Request
Note: Direct pushes to
mainanddevelopare protected. All changes must go through a PR.
This project is licensed under the MIT License.
Built with ❤️ by Karan Prajapati