FastAPI backend service with SQLAlchemy 2.0 ORM, PostgreSQL, and Alembic migrations.
- FastAPI
- SQLAlchemy 2.0 (
Mapped[],mapped_column,DeclarativeBase) - PostgreSQL (
psycopg2-binary) - Alembic (schema migrations + seed migration)
- Pydantic Settings (
.envbased config)
fastapi-be/
├── app/
│ ├── main.py
│ ├── core/
│ │ ├── config.py
│ │ └── database.py
│ ├── routes/
│ │ └── health.py
│ ├── controllers/
│ ├── services/
│ ├── models/
│ └── schemas/
|
├── .env
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── README.md
The project reads settings from .env via app/core/config.py.
Required variables:
APP_NAME
APP_VERSION
DATABASE_URL# create a new migration from model changes
alembic revision --autogenerate -m "describe changes"
# apply all migrations
alembic upgrade head
# rollback one revision
alembic downgrade -1
# show current revision
alembic current
# show migration history
alembic historydocker compose up -dpython3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtalembic upgrade headuvicorn app.main:app --reload