AI-powered CLI tool that generates production-ready FastAPI projects with clean architecture
Project description
๐ FastAPI Boilerplate Generator
An AI-powered CLI tool that generates production-ready FastAPI projects with clean architecture, interactive prompts, and customizable configurations. Built with LangChain and LangGraph.
โก Quick Install
pip install fastapi-boilerplate-generator
export OPENAI_API_KEY="your-key"
fastapi-boilerplate
โจ Features
๐ฏ Interactive CLI
- User-friendly prompts like
create-react-app - Smart defaults for quick setup
- Configuration preview before generation
- No command-line flags to remember
๐๏ธ Clean Architecture
- Repository pattern for data access
- Service layer for business logic
- Dependency injection with FastAPI
- Domain-driven structure (one module per project)
๐๏ธ Database Support
- PostgreSQL with advanced connection pooling
- SQLite for development/testing
- Abstract base class for easy extension
- Singleton pattern for connection management
๐ณ DevOps Ready
- Docker support with multi-stage builds
- docker-compose with database services
- GitHub Actions or GitLab CI pipelines
- Makefile for common tasks
๐ Well Documented
- Comprehensive constants for API documentation
- Pydantic models for validation
- Example tests with pytest
- README for each generated project
๐ฆ Installation
Prerequisites
- Python 3.11+
- OpenAI API Key (for LLM-powered generation)
Option 1: Install from PyPI (Recommended)
# Install the package
pip install fastapi-boilerplate-generator
# Set up environment variable
export OPENAI_API_KEY="your-openai-api-key"
# On Windows: set OPENAI_API_KEY=your-openai-api-key
Option 2: Install from source (for development)
# Clone the repository
git clone https://github.com/martialo12/fastapi-boilerplate-agent.git
cd fastapi-boilerplate-agent
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
# Set up environment variables
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
๐ Quick Start
1. Run the interactive CLI
If installed from PyPI:
fastapi-boilerplate
If installed from source:
python -m fastapi_boilerplate_agent.cli
2. Answer the prompts
The CLI will guide you through the configuration:
- Project name: Choose your project name (e.g.,
MyAwesomeAPI) - Database: PostgreSQL or SQLite
- Docker: Include Docker support?
- CI/CD: GitHub Actions, GitLab CI, or none
3. Review and confirm
Check the configuration summary and confirm generation.
4. Start developing!
cd my_awesome_api # Your project directory
make install # Install dependencies
make run # Start the server
Your API is now running at http://localhost:8000 ๐
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Interactive CLI
The CLI will guide you through the project setup with interactive prompts:
๐ FastAPI Boilerplate Generator
==================================================
Project name [my_fastapi_app]: ticket_system
Database options:
1. PostgreSQL (recommended for production)
2. SQLite (good for development)
Choose database [1/2]: 1
Include Docker support? [Y/n]: y
CI/CD options:
1. GitHub Actions
2. GitLab CI
3. None
Choose CI/CD [1/2/3]: 1
==================================================
๐ Configuration Summary:
โข Project: ticket_system
โข Database: PostgreSQL
โข Docker: Yes
โข CI/CD: GitHub Actions
==================================================
Generate project with these settings? [Y/n]: y
โณ Generating project...
โ
Successfully generated project in: /path/to/ticket_system
๐ Next steps:
1. cd ticket_system
2. make install
3. make run
๐ก See README.md for more details!
Note: The project is generated in a directory named after your project (in snake_case format):
MyAwesomeAPIโmy_awesome_api/BrainROIโbrain_roi/InvestWithMeโinvest_with_me/
๐ Generated Project Structure
my_awesome_api/ # Your project directory
โโโ app/
โ โโโ __init__.py
โ โโโ main.py # FastAPI application entry point
โ โโโ core/
โ โ โโโ __init__.py
โ โ โโโ constants.py # Global constants
โ โ โโโ database.py # Database connection (SQLite/PostgreSQL)
โ โโโ my_awesome_api/ # Domain module (named after your project)
โ โโโ __init__.py
โ โโโ constants.py # Module-specific constants
โ โโโ dependencies.py # FastAPI dependencies
โ โโโ exceptions.py # Custom exceptions
โ โโโ models.py # SQLAlchemy models
โ โโโ repositories.py # Data access layer
โ โโโ router.py # API endpoints
โ โโโ schemas.py # Pydantic schemas
โ โโโ services.py # Business logic
โโโ tests/
โ โโโ __init__.py
โ โโโ conftest.py # Pytest configuration
โ โโโ test_api.py # API endpoint tests
โ โโโ test_services.py # Service layer tests
โโโ .github/workflows/
โ โโโ ci.yml # GitHub Actions (if selected)
โโโ Dockerfile # Docker configuration (if selected)
โโโ docker-compose.yml # Docker Compose (if selected)
โโโ Makefile # Common tasks
โโโ pyproject.toml # Project metadata
โโโ README.md # Project documentation
โโโ requirements.txt # Python dependencies
๐ ๏ธ Technologies Used
Generator
- LangChain - LLM orchestration framework
- LangGraph - Agent workflow management
- OpenAI GPT-4 - AI-powered code generation
- Python 3.11+ - Programming language
Generated Projects
- FastAPI - Modern web framework
- SQLAlchemy - SQL toolkit and ORM
- Pydantic - Data validation
- Pytest - Testing framework
- Uvicorn - ASGI server
- Docker - Containerization (optional)
๐ก Examples
Example 1: Simple API with SQLite
$ python -m fastapi_boilerplate_agent.cli
Project name: TodoAPI
Database: 2 (SQLite)
Docker: n
CI/CD: 3 (None)
โ
Successfully generated project in: /path/to/todo_api
$ cd todo_api
$ make install
$ make run
# API running at http://localhost:8000
Example 2: Production-Ready API
$ python -m fastapi_boilerplate_agent.cli
Project name: EcommerceAPI
Database: 1 (PostgreSQL)
Docker: y
CI/CD: 1 (GitHub Actions)
โ
Successfully generated project in: /path/to/ecommerce_api
$ cd ecommerce_api
$ docker-compose up -d # Start PostgreSQL
$ make install
$ make test # Run tests
$ make run # Start API
๐ฏ Use Cases
- ๐ Rapid Prototyping: Start a new FastAPI project in seconds
- ๐ Learning: Study clean architecture patterns
- ๐ผ Enterprise: Generate production-ready boilerplate
- ๐ฌ Experimentation: Try different tech stacks quickly
- ๐ฆ Microservices: Quickly scaffold multiple services
๐ค Contributing
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
Development Setup
# Clone the repo
git clone https://github.com/martialo12/fastapi-boilerplate-agent.git
cd fastapi-boilerplate-agent
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies (including dev)
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black src tests
# Lint
flake8 src tests
Ways to Contribute
- ๐ Report bugs
- โจ Suggest new features
- ๐ Improve documentation
- ๐ง Submit pull requests
- โญ Star the project
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- FastAPI community for the amazing framework
- LangChain team for the LLM orchestration tools
- All contributors who help improve this project
๐ฎ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: martialo218@gmail.com
๐บ๏ธ Roadmap
- PyPI package distribution
- Support for more databases (MySQL, MongoDB)
- Authentication templates (JWT, OAuth2)
- GraphQL support
- WebSocket examples
- Celery task queue integration
- Admin panel generation
- API versioning templates
- Multi-tenancy support
- Kubernetes deployment configs
โ FAQ
Q: Do I need an OpenAI API key?
A: Yes, the generator uses GPT-4 to intelligently create your project structure.
Q: Can I customize the generated code?
A: Absolutely! The generated code is yours to modify as needed.
Q: Is the generated code production-ready?
A: Yes, it follows best practices, but you should review and adjust for your specific needs.
Q: What Python version is required?
A: Python 3.11 or higher for the generator. Generated projects use Python 3.11+.
Q: Can I add more features to the generated project?
A: Yes! The generated structure is designed to be easily extended.
Q: Is this free to use?
A: Yes, the generator is MIT licensed. You only pay for OpenAI API usage.
Made with โค๏ธ by the FastAPI community
โญ Star us on GitHub if you find this project useful!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_boilerplate_generator-0.2.7.tar.gz.
File metadata
- Download URL: fastapi_boilerplate_generator-0.2.7.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9292019161b78736106bc324a59ead7b69120dfe4eb20c6c49e6d0e2d172e6c5
|
|
| MD5 |
fcf08eda67abea2f733c359dbe40ad37
|
|
| BLAKE2b-256 |
413ff38aaee4561d9d993ec6e9e76753f6d306382dcecba64d4e873be9aa19c5
|
File details
Details for the file fastapi_boilerplate_generator-0.2.7-py3-none-any.whl.
File metadata
- Download URL: fastapi_boilerplate_generator-0.2.7-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
524e3d14bc766fa7b42eb3643c44ae80678b6b9358e95a1e57d75c74155df134
|
|
| MD5 |
76826b78065fc40d79338250ed40a99e
|
|
| BLAKE2b-256 |
9e19d3c42849a8a161c9023bcdc28f6f9200e737793e0f70117b81d2645c501d
|