| title | description | tags | ||||
|---|---|---|---|---|---|---|
FastAPI |
A FastAPI server |
|
A production-ready FastAPI template with PostgreSQL, fully async, and modern Python tooling.
CHANGELOG — See what's changed between versions.
- FastAPI with ORJSONResponse for fast serialization
- Fully async — endpoints, CRUD, and database layer
- SQLAlchemy 2.0 with async engine and
select()style queries - Pydantic v2 for request/response validation and settings management
- Pure ASGI middleware for doc protection (no
BaseHTTPMiddlewareoverhead) - Typed lifespan state with proper startup/shutdown lifecycle
- uvloop + httptools for maximum ASGI performance
- GZIP compression for responses > 1KB
- Session-based auth protecting
/docsand/redoc - uv for fast, reproducible dependency management
- Locust load testing included
- Docker multi-stage build ready
├── src/
│ ├── backend/
│ │ ├── main.py # FastAPI app entry point
│ │ ├── api/v1/endpoints/ # Route handlers
│ │ ├── core/ # Config, lifespan, middleware, routers
│ │ ├── crud/ # Service layer (async CRUD)
│ │ ├── dependencies/ # Database setup, DI
│ │ ├── models/ # SQLAlchemy ORM models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── security/ # Authentication
│ │ └── data/ # Seed data
│ └── frontend/
│ └── login/ # Login page templates & static files
├── tests/ # Async test suite
├── pyproject.toml # Dependencies & project config
├── Dockerfile # Multi-stage build with uv
├── locustfile.py # Load testing
└── .env.example # Environment variable template
- Python 3.12+
- uv package manager
# Clone the repository
git clone https://github.com/yuting1214/Fullstack-FastAPI.git
cd Fullstack-FastAPI
# Install dependencies
uv sync
# Copy environment template
cp .env.example .env
# Edit .env with your values
# Run in development mode (SQLite)
uv run python -m src.backend.main --mode dev
# Run in production mode (PostgreSQL)
uv run python -m src.backend.main --mode prod --host 0.0.0.0uv sync --extra dev
uv run pytestNote: Tests use
httpx.AsyncClientviaASGITransport, which does not trigger FastAPI's lifespan events. The sharedtests/conftest.pyhandles DB table creation and teardown automatically. If you add new tests, thesetup_dbfixture runs viaautouse— no manual setup needed.
uv run locust
# Open http://localhost:8089docker build -t fullstack-fastapi .
docker run -p 5000:5000 fullstack-fastapi| Method | Path | Description |
|---|---|---|
GET |
/ |
Health check |
GET |
/login |
Login page |
POST |
/login |
Authenticate |
GET |
/logout |
Clear session |
POST |
/api/v1/messages/ |
Create message |
GET |
/api/v1/messages/ |
List messages |
GET |
/api/v1/messages/{id} |
Get message |
PUT |
/api/v1/messages/{id} |
Update message |
DELETE |
/api/v1/messages/{id} |
Delete message |
See .env.example for all available configuration options.