This is a modular monolithic starter template for FastAPI, designed to provide a robust foundation for your projects with async capabilities and flexible deployment options.
- Fully async FastAPI setup
- PostgreSQL database with SQLAlchemy (async)
- JWT authentication
- Modular structure for easy expansion
- Docker support with hot-reload
- Environment variable configuration
- Logging and centralized error handling
- Unit and integration tests with pytest
- Ruff for linting and formatting
- Alembic migrations with async support
- Python 3.12+
- Poetry
- Docker and Docker Compose (for containerized setup)
-
Clone the repository:
git clone https://github.com/yourusername/fastapi-starter.git cd fastapi-starter
-
Copy the example environment file:
cp .env.example .env
-
Start the services:
docker compose up --build
-
Visit
http://localhost:8000/docs
to see the API documentation.
-
Install dependencies:
poetry install
-
Set up your environment variables:
cp .env.example .env
-
Start PostgreSQL:
docker compose up -d db
-
Run migrations:
poetry run alembic upgrade head
-
Start the application:
poetry run uvicorn src.main:app --reload
With Docker:
docker compose exec web alembic upgrade head
Locally:
poetry run alembic upgrade head
poetry run alembic revision --autogenerate -m "Description of changes"
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
poetry run pytest
For test coverage:
poetry run pytest --cov=src
Linting:
poetry run ruff check .
Formatting:
poetry run ruff format .
fastapi-starter/
├── src/ # Application source code
│ ├── auth/ # Authentication module
│ │ ├── models.py # User model
│ │ ├── router.py # Auth routes
│ │ └── jwt.py # JWT handling
│ ├── items/ # Items module
│ │ ├── models.py # Item model
│ │ ├── router.py # Item routes
│ │ └── schemas.py # Pydantic schemas
│ ├── core/ # Core functionality
│ │ ├── config.py # Configuration
│ │ ├── exceptions.py # Exception handling
│ │ └── logging.py # Logging setup
│ ├── database/ # Database setup
│ │ ├── database.py # Database configuration
│ │ └── models.py # Base models
│ └── main.py # Application entry point
├── tests/ # Test suite
├── alembic/ # Database migrations
├── claudeDev_docs/ # Development documentation
├── docker-compose.yml # Docker services configuration
├── Dockerfile # Application container definition
├── pyproject.toml # Project dependencies and config
└── README.md # Project documentation
Key environment variables:
DATABASE_URL
: PostgreSQL connection stringJWT_SECRET_KEY
: Secret key for JWT tokensJWT_ALGORITHM
: Algorithm for JWT (default: HS256)HOST
: Application host (default: 0.0.0.0)PORT
: Application port (default: 8000)
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.