Phase 1: Project Setup & Architecture

The Stack: Why FastAPI + PostgreSQL + Docker

3 min read

What We're Building

Welcome to TaskFlow — a production-grade task management REST API. By the end of this course, you'll have built a fully functional API that handles:

  • User management — Registration, login, JWT authentication
  • Projects — Create and manage project workspaces
  • Tasks — Full CRUD with status tracking, priorities, and assignments
  • Role-based access — Owners, admins, and members with different permissions

This isn't a toy project. TaskFlow uses the same architecture patterns you'll find at companies shipping real software.

Why This Stack in 2026

Technology Version Why It Wins
FastAPI 0.128.x Async-first, automatic OpenAPI docs, Pydantic validation built-in. One of the fastest-growing Python frameworks with a massive ecosystem.
PostgreSQL 18.2 The industry standard for relational data. Version 18.2 (released Feb 12, 2026) brings continued performance improvements and reliability.
SQLAlchemy 2.0.46 The 2.0 API is fully mature — modern typed queries, async support, and the most battle-tested ORM in Python.
Alembic 1.18.4 Database migrations done right. Tracks schema changes in version control so your database evolves alongside your code.
Pydantic 2.12.x Data validation at the speed of Rust. Pydantic v2's core is written in Rust, making it orders of magnitude faster than v1.
Docker Compose v2 v2 Container orchestration built into Docker CLI. Compose v1 reached end-of-life in July 2023 — v2 is the standard.
Redis 7.x (redis-py 7.1.1) In-memory caching and rate limiting. We'll use it to cache frequent queries and throttle API abuse.
Python 3.12+ Performance improvements, better error messages, and type statement support.

Why Not Django REST Framework?

Django REST Framework is excellent, but FastAPI gives us:

  • Native async support — handle thousands of concurrent connections
  • Automatic API documentation — Swagger UI and ReDoc generated from your code
  • Type-first validation — Pydantic models enforce data contracts at every boundary
  • Lower overhead — no ORM opinions, no admin panel, no template engine — just the API layer

For a focused REST API project, FastAPI lets you build exactly what you need without carrying what you don't.

Project Structure

Here's the directory layout we'll build throughout this course:

taskflow/
├── docker-compose.yml          # Services: app, postgres, redis
├── Dockerfile                  # Multi-stage build for the API
├── requirements.txt            # Pinned dependencies
├── .env                        # Environment variables (never commit)
├── alembic.ini                 # Alembic configuration
├── alembic/                    # Migration scripts
│   └── versions/
├── app/
│   ├── __init__.py
│   ├── main.py                 # FastAPI application entry point
│   ├── core/
│   │   ├── __init__.py
│   │   ├── config.py           # Settings via Pydantic
│   │   ├── database.py         # SQLAlchemy engine & session
│   │   ├── security.py         # JWT & password hashing
│   │   └── redis.py            # Redis connection
│   ├── api/
│   │   ├── __init__.py
│   │   ├── deps.py             # Dependency injection
│   │   └── v1/
│   │       ├── __init__.py
│   │       ├── auth.py         # Login & registration
│   │       ├── users.py        # User endpoints
│   │       ├── projects.py     # Project endpoints
│   │       └── tasks.py        # Task endpoints
│   ├── models/
│   │   ├── __init__.py
│   │   ├── user.py             # User SQLAlchemy model
│   │   ├── project.py          # Project model
│   │   └── task.py             # Task model
│   ├── schemas/
│   │   ├── __init__.py
│   │   ├── user.py             # User Pydantic schemas
│   │   ├── project.py          # Project schemas
│   │   └── task.py             # Task schemas
│   └── tests/
│       ├── __init__.py
│       ├── conftest.py         # Fixtures & test database
│       ├── test_auth.py
│       ├── test_users.py
│       ├── test_projects.py
│       └── test_tasks.py

Each directory has a clear responsibility:

  • core/ — Configuration, database connections, security utilities
  • api/ — Route handlers organized by version
  • models/ — SQLAlchemy ORM models (database tables)
  • schemas/ — Pydantic models (request/response validation)
  • tests/ — pytest test suite

What You'll Have After This Module

  1. A running Docker Compose stack with FastAPI, PostgreSQL 18, and Redis
  2. A health check endpoint at GET /health that confirms all services are connected
  3. A clean project structure ready for the database models, auth system, and API routes we'll build in the next modules
  4. Pinned dependencies so your environment is reproducible anywhere

This is the foundation everything else builds on. Let's get started.

Next: Hands-on lab — Initialize the TaskFlow project :::

Quiz

Module 1 Quiz: Project Setup & Architecture

Take Quiz