FastAPI Starter Template (Scalable)
Overview This repository provides a clean, scalable starter template for building a FastAPI backend service.
Key features
- FastAPI app factory with lifespan events
- Environment-based configuration via Pydantic Settings
- Structured logging
- Versioned API router (v1)
- Health and readiness endpoints
- CORS configuration
- Placeholders for DB session and models (SQLAlchemy ready)
Project structure
- app/
- main.py
- core/
- config.py
- logging.py
- api/
- router.py
- v1/
- endpoints/
- health.py
- endpoints/
- dependencies/
- common.py
- db/
- session.py
- models/
- init.py
- schemas/
- common.py
Getting started
-
Create a virtual environment and install dependencies: python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Configure environment variables (optional): cp .env.example .env
-
Run the app: uvicorn app.main:app --reload
-
Test endpoints:
Environment variables (.env)
- PROJECT_NAME: Service name
- ENV: Environment (development|staging|production)
- DEBUG: true/false
- API_V1_PREFIX: API prefix (default: /api/v1)
- CORS_ORIGINS: Comma-separated origins
Docker (optional) Build and run with Docker:
- docker build -t fastapi-starter .
- docker run -p 8000:8000 --env-file .env fastapi-starter
Notes
- Extend app/api/v1/endpoints with your own routers.
- Implement DB connection logic in app/db/session.py when needed.
- Configure logging levels and formats in app/core/logging.py.