Overview
A production-ready backend boilerplate for building high-performance RESTful APIs using FastAPI and Motor, an asynchronous driver for MongoDB. This template includes health checks, CRUD operations, automatic API documentation, Docker support, and uses Cookiecutter for rapid project generation.
⚠️ Getting Started - Required First Step
Before using this template, you must execute the following command. This is not just a quick start guide—it's the mandatory first step to create your project.
cookiecutter gh:klee1611/cookiecutter-fastapi-mongo
After project creation, all dependencies will be automatically installed. All subsequent commands must be run inside the newly created project directory.
System Requirements
- Python 3.10 or higher
- Poetry 2.x - Python dependency management tool
- Cookiecutter - Project templating tool
- Docker - For containerization
- GNU Make - For running build commands
Key Features
High Performance
- Asynchronous FastAPI framework
- Motor async MongoDB driver
- Non-blocking I/O operations
- High concurrency support
Developer Experience
- Auto-generated Swagger documentation
- Pytest with async support
- Poetry 2.x for dependency management
- Type hints with MyPy
Production Ready
- Dockerfile included
- Docker Compose configuration
- Multi-stage builds
- Health check endpoints
Modern Stack
- FastAPI 0.115+
- Motor 3.6+
- MongoDB 4.4+
- Python 3.10+
Usage Guide
Running Tests
make test
Development Server
make dev
This command starts a MongoDB container and launches the FastAPI development server with hot-reload enabled.
Building Docker Image
make docker-build
Docker Compose
make docker-compose-up
make docker-compose-down
Accessing API Documentation
Once the server is running, access the interactive API documentation at: http://localhost:8888/docs
Project Structure
your-project/
├── app/
│ ├── api/ # API endpoints
│ ├── dao/ # Data access layer
│ ├── db/ # Database connection
│ ├── models/ # Pydantic models
│ └── conf/ # Configuration
├── tests/ # Test cases
├── docker-compose.yml
├── Dockerfile
├── pyproject.toml
└── Makefile
Contributing
We welcome contributions! For major changes, please open an issue first to discuss what you would like to change. Pull requests are always appreciated.
License
This project is licensed under the MIT License. See the LICENSE file for details.