Skip to content

Build a production-shaped Todo API

This tutorial builds a complete FastAPI application with Ormdantic. You will use SQLite while developing, review real migration artifacts in the Playground, and run the same application against PostgreSQL with Docker Compose.

The final application is not a toy script. Configuration, persistence models, request schemas, services, routes, migrations, and tests have separate modules. Every source file shown here is executed by the repository test suite.

FastAPI OpenAPI page listing the Todo project and item endpoints

The running application exposes health, project, and todo operations through its generated OpenAPI interface.

What you will build

%% architecture
flowchart LR
    Client[HTTP client] --> API[FastAPI routes]
    API --> Service[TodoService]
    Service --> ORM[Ormdantic tables]
    ORM --> Dev[(SQLite development)]
    ORM --> Prod[(PostgreSQL production)]
    Models[Pydantic models] --> ORM
    Models --> Migrations[Dialect migration tracks]
    Migrations --> Dev
    Migrations --> Prod

The layers have deliberately narrow jobs:

  • config.py validates environment variables and redacts database credentials.
  • models.py declares the persisted Project and Todo tables.
  • schemas.py owns the HTTP request and response contract.
  • service.py owns transactions, typed filters, and relationship loading.
  • routes.py translates HTTP operations into service calls.
  • main.py initializes Ormdantic in FastAPI's application lifespan.
  • migrations/ contains checked and reversible SQLite and PostgreSQL histories.

Follow the tutorial

  1. Set up the example.
  2. Configure development and production.
  3. Understand the persisted models.
  4. Build CRUD operations and typed queries.
  5. Review and run migrations.
  6. Start PostgreSQL with Compose.
  7. Test the application.
  8. Use the production checklist.

For the underlying concepts, keep Database and tables, Relationships, and Migrations and reflection nearby.