Skip to content

Repository files navigation

⚡ FastAPI Task Manager

FastAPI Python PostgreSQL Docker JWT Pytest License

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.

FeaturesTech StackGetting StartedAPI DocsProject StructureRunning Tests


✨ Features

  • 🔐 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/high priority and todo/in_progress/done status
  • 🔍 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

🛠 Tech Stack

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

🚀 Getting Started

Prerequisites


▶ Option 1: Run with Docker (Recommended)

# 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

▶ Option 2: Run Locally

# 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:8000

📖 API Documentation

FastAPI generates interactive docs automatically:

Doc Type URL
Swagger UI http://localhost:8000/docs
ReDoc http://localhost:8000/redoc

🔑 Auth Endpoints

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

📋 Task Endpoints

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

Example: Create 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"
}

Example: Filter Tasks

GET /api/v1/tasks/?status=in_progress&priority=high&skip=0&limit=10

📁 Project Structure

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

🧪 Running Tests

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

🔒 Security Notes

  • 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
  • .env is gitignored; use .env.example as a template

🤝 Contributing

Pull requests are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feat/your-feature
  3. Commit your changes: git commit -m "feat: add your feature"
  4. Push to the branch: git push origin feat/your-feature
  5. Open a Pull Request

Note: Direct pushes to main and develop are protected. All changes must go through a PR.


📄 License

This project is licensed under the MIT License.


Built with ❤️ by Karan Prajapati

Portfolio LinkedIn Upwork

About

A production-ready Task Management REST API built with FastAPI, PostgreSQL, JWT Auth, Docker & Pytest

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages