Skip to main content

AI-powered CLI tool that generates production-ready FastAPI projects with clean architecture

Project description

๐Ÿš€ FastAPI Boilerplate Generator

PyPI version Python 3.11+ License: MIT Code style: black Downloads

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 ๐ŸŽ‰

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

Generated Projects

๐Ÿ’ก 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

๐Ÿ—บ๏ธ 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

fastapi_boilerplate_generator-0.2.2.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_boilerplate_generator-0.2.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_boilerplate_generator-0.2.2.tar.gz.

File metadata

File hashes

Hashes for fastapi_boilerplate_generator-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4b3d5ec0bd71d55063340bd81b687eed7e34e5d4d16b05bf48cbd78247489a7f
MD5 916f98b2146c6696c48ba7a9ea7da026
BLAKE2b-256 e7a602163c4d5458b5a753a6b2f608c5d63851cb5322f519065f340c17725476

See more details on using hashes here.

File details

Details for the file fastapi_boilerplate_generator-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_boilerplate_generator-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 904e99a65bb3390bd4bb2461301303ac7a0828fd48914cd117a6dedb5edb8577
MD5 41932e50175e0fcc382a346ad0af4f8a
BLAKE2b-256 da672a71e84cb2ffadc04e173ae78c1068d8a5cca9971605f17d7a7f0c78703f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page