A powerful CLI tool for generating production-ready FastAPI projects with best practices, integrated authentication, and flexible ORM options.
- π Production Ready: Pre-configured with security, logging, and deployment best practices
- π Integrated Authentication: FastAPI-Users integration with JWT authentication
- ποΈ Flexible ORM: Choose between SQLAlchemy (PostgreSQL) or Beanie (MongoDB)
- π³ Docker Support: Complete Docker setup with docker-compose
- π¦ Celery Integration: Background task processing
- π§ͺ Testing Ready: Pre-configured testing setup
- π API Documentation: Auto-generated OpenAPI/Swagger documentation
- π― CLI Driven: Simple command-line interface for project generation
pip install fastapi-template-cli# Create an API-only project with SQLAlchemy
fastapi-template-cli new my-api --orm sqlalchemy --type api
# Create a modular project with MongoDB
fastapi-template-cli new my-app --orm beanie --type modular
# Create with project description
fastapi-template-cli new my-project --orm sqlalchemy --type modular \
--description "My awesome FastAPI project" --author "Your Name"- Lightweight FastAPI backend
- Database integration (SQLAlchemy or Beanie)
- FastAPI-Users authentication
- No frontend or background tasks
- Complete backend with FastAPI
- Database integration
- FastAPI-Users authentication
- Celery for background tasks
- Redis for caching and task queue
- Docker setup with docker-compose
- Database: PostgreSQL
- ORM: SQLAlchemy 2.0 with async support
- Migrations: Alembic
- Connection: asyncpg driver
- Database: MongoDB
- ODM: Beanie (async MongoDB ODM)
- Driver: Motor
- Schema: Pydantic-based documents
# List available templates
fastapi-template-cli list-templates
# Create a new project
fastapi-template-cli new myproject
# Show version
fastapi-template-cli versionGenerated projects follow a clean architecture:
myproject/
βββ app/
β βββ api/
β β βββ v1/
β β βββ api.py
β β βββ endpoints/
β β βββ users.py
β βββ core/
β β βββ config.py
β β βββ security.py
β βββ db/
β β βββ session.py (SQLAlchemy) or mongo.py (Beanie)
β β βββ base_class.py (SQLAlchemy)
β βββ models/
β β βββ user.py
β βββ schemas/
β β βββ user.py
β βββ users.py (FastAPI-Users config)
β βββ main.py
βββ docker/
β βββ Dockerfile
β βββ docker-compose.yml (modular only)
βββ alembic/ (SQLAlchemy only)
βββ workers/ (modular only)
βββ pyproject.toml
βββ .env
βββ .gitignore
- Includes Redis as Celery broker and result backend
- Separate Celery worker for long-running tasks
- Celery Beat for scheduled tasks
- Complete frontend integration
- Production-ready Docker setup
- Lightweight FastAPI core
- Database-only backend
- Minimal dependencies
- Optimized for microservices
- Simplified Docker setup
e-commerce/
βββ app/
β βββ api/v1/
β β βββ api.py # Main API router
β β βββ endpoints/
β β βββ users.py # User endpoints
β βββ core/
β β βββ config.py # Application configuration
β β βββ security.py # Security utilities
β β βββ users.py # User management
β βββ database/
β β βββ base.py # Database base setup
β β βββ base_class.py # Base model class
β β βββ session.py # Database session
β βββ models/
β β βββ users.py # User models
β βββ schemas/
β β βββ user.py # Pydantic schemas
β βββ users/
β β βββ dependencies.py # User dependencies
β β βββ manager.py # User manager
β βββ main.py # FastAPI application
βββ alembic/ # Database migrations
βββ docker/ # Docker configuration
βββ tests/ # Test files
βββ .env.dev # Development environment
βββ .env.prod # Production environment
βββ pyproject.toml # Project dependencies
full-erp/
βββ app/
β βββ core/
β β βββ config.py # Application configuration
β β βββ security.py # Security utilities
β β βββ users.py # User management
β βββ database/
β β βββ base.py # Database base setup
β β βββ base_class.py # Base model class
β β βββ session.py # Database session
β βββ models/
β β βββ users.py # User models
β βββ routers/
β β βββ test.py # Test endpoints
β βββ schemas/
β β βββ user.py # Pydantic schemas
β βββ services/ # Business logic services
β βββ users/
β β βββ dependencies.py # User dependencies
β β βββ manager.py # User manager
β βββ utils/ # Utility functions
β βββ workers/
β β βββ celery_app.py # Celery configuration
β β βββ tasks.py # Background tasks
β βββ main.py # FastAPI application
βββ alembic/ # Database migrations
βββ docker/ # Docker configuration
βββ tests/ # Test files
βββ .env.dev # Development environment
βββ .env.prod # Production environment
βββ docker-compose.dev.yml # Development Docker setup
βββ docker-compose.prod.yml # Production Docker setup
βββ pyproject.toml # Project dependencies
-
Setup Database
cd myproject pip install -e . alembic upgrade head
-
Run Development Server
uvicorn app.main:app --reload
-
Create Database Migration
alembic revision --autogenerate -m "Add new table"
-
Setup MongoDB
cd myproject pip install -e . # MongoDB will auto-initialize on first connection
-
Run Development Server
uvicorn app.main:app --reload
-
Start All Services
cd myproject docker-compose up -d -
Access Services
- API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- MongoDB: localhost:27017 (Beanie)
- PostgreSQL: localhost:5432 (SQLAlchemy)
- Redis: localhost:6379
Create a .env file in your project root:
# Database
DATABASE_URL=postgresql+asyncpg://user:pass@localhost/dbname # SQLAlchemy
MONGODB_URL=mongodb://localhost:27017/myproject # Beanie
# Security
SECRET_KEY=your-secret-key-here
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Redis (modular)
REDIS_URL=redis://localhost:6379/0
# Email (optional)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-password# Install PostgreSQL
# Create database
createdb myproject
# Set DATABASE_URL
export DATABASE_URL=postgresql+asyncpg://user:password@localhost/myproject# Install MongoDB
# MongoDB will create database on first connection
export MONGODB_URL=mongodb://localhost:27017/myprojectFor modular projects:
# Build and run
docker-compose -f docker-compose.dev.yaml up -d --build
# Stop services
docker-compose -f docker-compose.dev.yaml down-
Environment Variables
export SECRET_KEY=your-production-secret export DATABASE_URL=your-production-db-url
-
Gunicorn/Uvicorn
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
-
Traefik Reverse Proxy Includes Traefik configuration in
docker-compose.prod.yml:services: traefik: image: traefik:v3.0 command: - --api.dashboard=true - --providers.docker=true - --entrypoints.web.address=:80 - --entrypoints.websecure.address=:443 - --certificatesresolvers.letsencrypt.acme.tlschallenge=true - --certificatesresolvers.letsencrypt.acme.email=your-email@domain.com - --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Add tests for new functionality
- Run tests:
pytest - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- π Documentation
- π Issue Tracker
- π¬ Discussions
