A production-ready FastAPI project template following industry best practices. This template provides a solid foundation for building scalable and maintainable APIs.
- 🎯 Modular Structure: Clear separation of concerns with layered architecture
- 🔐 Authentication & Authorization: JWT-based auth system
- 📝 API Documentation: Automatic Swagger/OpenAPI documentation
- 🔄 Database Integration: SQLAlchemy ORM with migrations
- 🎭 Environment Management: Configuration via environment variables
- 📊 Logging: Structured logging setup
- ✅ Testing: Pytest setup with fixtures and examples
- 🔍 Input Validation: Pydantic models for request/response validation
- 🛠 Dependency Injection: Clean dependency management
- 🚀 Docker Support: Containerization ready
├── app/
│ ├── api/
│ │ ├── v1/
│ │ │ ├── endpoints/
│ │ │ └── dependencies.py
│ │ └── deps.py
│ ├── core/
│ │ ├── config.py
│ │ ├── security.py
│ │ └── logging.py
│ ├── db/
│ │ ├── base.py
│ │ ├── session.py
│ │ └── models/
│ ├── models/
│ ├── schemas/
│ ├── services/
│ └── utils/
├── tests/
│ ├── conftest.py
│ ├── test_api/
│ └── test_services/
├── alembic/
│ ├── env.py
│ └── versions/
├── scripts/
├── .env.example
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── main.py
- Clone the template:
git clone https://github.com/yourusername/fastapi-template.git
cd fastapi-template- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your configurations- Run the application:
uvicorn main:app --reloadVisit http://localhost:8000/docs for the Swagger documentation.
- API Versioning: Place new endpoints under
app/api/v1/endpoints/ - Database Models: Add SQLAlchemy models in
app/db/models/ - Schemas: Define Pydantic models in
app/schemas/ - Business Logic: Implement services in
app/services/ - Configuration: Add new settings in
app/core/config.py - Testing: Write tests in the
tests/directory
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.