FastAPI training API with Postgres, SQLAlchemy, Alembic, and user/chat modules.
.
├── api/ # FastAPI app, Alembic, tests, Python dependencies
│ ├── app/ # Backend application package
│ ├── alembic/ # Database migrations
│ ├── tests/ # API tests
│ └── pyproject.toml
└── docker-compose.yml # db + api local stack
- Docker Desktop
uvfor running the API outside Docker
Docker Compose is the recommended local setup because it runs the API and database with the right network and env wiring.
Create the API env file:
cp api/.env.example api/.envThen configure it:
DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/fastapi_db
ENVIRONMENT=development
OPENAI_API_KEY=your_api_key_hereStart services:
docker compose up --buildOr run in the background:
docker compose up -d --buildOpen:
- API docs:
http://127.0.0.1:8000/docs - Postgres:
localhost:5432
Stop the stack:
docker compose stopRemove containers and volumes when you want a clean database:
docker compose down -vcd api
uv sync
uv run uvicorn app.main:app --reloadWhen running manually, make sure Postgres is available and api/.env points to the correct database host.
Run API tests from the API project root:
cd api
uv run pytestThe tests expect Postgres at localhost:5432 with a fastapi_test_db database.