A scalable, production-ready FastAPI backend boilerplate that standardizes authentication, asynchronous processing, event-driven workflows, real-time communication, and email services. Designed to accelerate the development of robust APIs and microservices.
- Authentication & Security: JWT-based authentication with secure password hashing
- Asynchronous Processing: Celery integration for background task processing
- Event-Driven Architecture: Built-in support for event-driven workflows
- Real-Time Communication: WebSocket support for real-time features
- Email Services: Integrated email functionality for notifications and user communication
- Database Management: SQLAlchemy with Alembic migrations for robust data handling
- API Documentation: Auto-generated Swagger/OpenAPI documentation
- Validation: Pydantic models for request/response validation
- CI/CD Ready: Jenkins pipeline configuration included
- Docker Support: Containerization ready with .dockerignore
- OTP System: Built-in OTP (One-Time Password) functionality
- Framework: FastAPI
- Database: PostgreSQL / SQLite (configurable)
- ORM: SQLAlchemy
- Migrations: Alembic
- Task Queue: Celery + Redis
- Validation: Pydantic
- Authentication: JWT (JSON Web Tokens)
- Email: SMTP integration
- Testing: Pytest (ready for integration)
- CI/CD: Jenkins
- Containerization: Docker
fastapi_boilerplate/
├── alembic/ # Database migrations
├── api/ # API routes and endpoints
├── core/ # Core functionality (config, security)
├── db/ # Database models and session management
├── pydanticValidators/ # Pydantic validation schemas
├── service/ # Business logic services
├── util/ # Utility functions (email, common helpers)
├── worker/ # Celery worker configuration and tasks
├── main.py # Application entry point
├── Pipfile # Dependency management
├── alembic.ini # Alembic configuration
├── Jenkinsfile # CI/CD pipeline
└── example.env # Environment variables template
- Python 3.8+
- PostgreSQL or SQLite
- Redis (for Celery tasks)
-
Clone the repository
git clone https://github.com/yourusername/fastapi-boilerplate.git cd fastapi-boilerplate -
Install dependencies
pipenv install pipenv shell
-
Environment Setup
cp example.env .env # Edit .env with your configuration -
Database Setup
# Run migrations alembic upgrade head -
Start the application
uvicorn main:app --reload
-
Start Celery Worker (in a separate terminal)
celery -A worker.celery_app worker --loglevel=info
The API will be available at http://localhost:8000
API documentation at http://localhost:8000/docs
Key environment variables:
DATABASE_URL: Database connection stringSECRET_KEY: JWT secret keyREDIS_URL: Redis connection URLSMTP_SERVER: Email server configurationJWT_ACCESS_TOKEN_EXPIRE_MINUTES: Token expiration time
# Build the image
docker build -t fastapi-boilerplate .
# Run the container
docker run -p 8000:8000 fastapi-boilerplateUse a production ASGI server like Gunicorn:
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Dhruv - Your GitHub
⭐ If you found this project helpful, please give it a star!