A CLI for generating modular FastAPI projects with environment and dependency management
Project description
FasCraft ๐
FasCraft is a powerful CLI tool designed to streamline the creation and management of modular FastAPI projects. It eliminates boilerplate code and enforces best practices from the start, allowing developers to focus on business logic.
โจ Features
- ๐ Project Generation - Create new FastAPI projects with domain-driven architecture
- ๐ง Module Management - Generate, list, update, and remove domain modules
- ๐๏ธ Domain-Driven Design - Self-contained modules with models, schemas, services, and routers
- โ๏ธ Smart Configuration - Automatic project detection and configuration management
- ๐ก๏ธ Safety First - Confirmations, backups, and rollback capabilities
- ๐จ Rich CLI - Beautiful tables, color coding, and progress indicators
- ๐งช Production Ready - Comprehensive testing and error handling
- ๐ Environment Management - Complete .env templates with database configurations
- ๐ฆ Dependency Management - Production-ready requirements files for development and production
- ๐๏ธ Database Support - MongoDB, PostgreSQL, MySQL, and SQLite configurations
- โก Service Integration - Redis, Celery, JWT, and CORS configurations
๐ Quick Start
Installation
# Install from PyPI
pip install fascraft
# Or install from source
git clone https://github.com/LexxLuey/fascraft.git
cd fascraft
poetry install
Note: FasCraft itself uses Poetry for development, but the projects it generates support both Poetry and pip!
Create Your First Project
# Generate a new FastAPI project
fascraft new my-awesome-api
# Navigate to your project
cd my-awesome-api
# Install dependencies (choose your preferred method)
# Option 1: Using Poetry (recommended)
poetry install
# Option 2: Using pip
pip install -r requirements.txt
# Start the development server
uvicorn main:app --reload
๐ก Pro Tip: Your generated project includes both Poetry and pip configurations, so you can use whichever dependency manager you prefer!
โ ๏ธ Important: You must install dependencies before running the FastAPI server. The generated project structure is ready, but dependencies need to be installed first.
Add Domain Modules
# Generate a customers module
fascraft generate customers
# Generate a products module
fascraft generate products
# Your project now has:
# โโโ customers/
# โ โโโ models.py
# โ โโโ schemas.py
# โ โโโ services.py
# โ โโโ routers.py
# โ โโโ tests/
# โโโ products/
# โโโ models.py
# โโโ schemas.py
# โโโ services.py
# โโโ routers.py
# โโโ tests/
๐ Complete Workflow Example
Here's the complete workflow from project creation to running your API:
# 1. Create new project
fascraft new my-ecommerce-api
# 2. Navigate to project directory
cd my-ecommerce-api
# 3. Install dependencies (choose one)
poetry install # Poetry (recommended)
# OR
pip install -r requirements.txt # pip
# 4. Start development server
uvicorn main:app --reload
# 5. Add domain modules as needed
fascraft generate products
fascraft generate orders
๐ Available Commands
Project Management
fascraft new <project_name> # Create new FastAPI project
fascraft generate <module_name> # Add new domain module
Module Management
fascraft list # List all modules with health status
fascraft remove <module_name> # Remove module with safety confirmations
fascraft update <module_name> # Update module templates with backups
Utility Commands
fascraft hello [name] # Say hello
fascraft version # Show version
fascraft --help # Show all available commands
๐๏ธ Project Structure
FasCraft generates projects with a clean, domain-driven architecture:
my-awesome-api/
โโโ config/ # Configuration and shared utilities
โ โโโ __init__.py
โ โโโ settings.py # Pydantic settings with environment support
โ โโโ database.py # SQLAlchemy configuration
โ โโโ exceptions.py # Custom HTTP exceptions
โ โโโ middleware.py # CORS and timing middleware
โโโ customers/ # Domain module (self-contained)
โ โโโ __init__.py
โ โโโ models.py # SQLAlchemy models
โ โโโ schemas.py # Pydantic schemas
โ โโโ services.py # Business logic
โ โโโ routers.py # FastAPI routes
โ โโโ tests/ # Module-specific tests
โโโ products/ # Another domain module
โ โโโ __init__.py
โ โโโ models.py
โ โโโ schemas.py
โ โโโ services.py
โ โโโ routers.py
โ โโโ tests/
โโโ main.py # FastAPI application entry point
โโโ pyproject.toml # Poetry configuration with all dependencies
โโโ .env # Environment configuration (database, Redis, etc.)
โโโ .env.sample # Sample environment file
โโโ requirements.txt # Core dependencies (pip)
โโโ requirements.dev.txt # Development dependencies (pip)
โโโ requirements.prod.txt # Production dependencies (pip)
โโโ README.md # Project documentation
๐ Environment & Dependency Management
FasCraft generates comprehensive environment and dependency files for production-ready applications:
Environment Configuration
.env- Configure your environment like a true 12 factor app that it is..env.sample- Template for team collaboration. Complete environment configuration with database connections- Database Support - MongoDB, PostgreSQL, MySQL, SQLite configurations
- Service Integration - Redis, Celery, JWT, CORS settings
- Production Ready - Optimized for different deployment environments
Dependency Management
FasCraft generates projects with dual dependency management - you can use either Poetry or pip!
pyproject.toml- Complete Poetry configuration with all dependencies and development toolsrequirements.txt- Core production dependencies for pip usersrequirements.dev.txt- Development tools and testing frameworks for pip usersrequirements.prod.txt- Production-optimized dependencies with Gunicorn for pip users
Quick Setup
Option 1: Using Poetry (Recommended)
# Install all dependencies (production + development)
poetry install
# Install only production dependencies
poetry install --only main
# Install with specific groups
poetry install --with dev,prod
Option 2: Using pip
# Install production dependencies
pip install -r requirements.txt
# Install development dependencies
pip install -r requirements.dev.txt
# Install production dependencies
pip install -r requirements.prod.txt
๐ฆ Dual Dependency Management
FasCraft generates projects with both Poetry and pip support, giving you the flexibility to choose your preferred dependency manager:
๐ฏ Poetry Configuration (pyproject.toml)
- Complete dependency management with version pinning
- Development tools (pytest, black, ruff, mypy, etc.)
- Production dependencies (Gunicorn, database drivers, etc.)
- Group-based installation (main, dev, prod)
- Lock file for reproducible builds
๐ง pip Configuration (requirements files)
requirements.txt- Core production dependenciesrequirements.dev.txt- Development and testing toolsrequirements.prod.txt- Production-optimized with Gunicorn- Simple installation with standard pip commands
- Easy deployment to environments without Poetry
๐ Why Both?
- Team flexibility - Some developers prefer Poetry, others prefer pip
- Deployment options - CI/CD pipelines often work better with requirements files
- Learning curve - New developers can start with pip, graduate to Poetry
- Production ready - Both approaches are production-tested
๐ง Module Management
List Modules
fascraft list
Shows a beautiful table with:
- Module health status (โ Healthy / โ ๏ธ Incomplete)
- File counts and test coverage
- Module size and last modified date
Remove Modules
fascraft remove customers
- Shows removal preview with file counts and size
- Asks for confirmation (use
--forceto skip) - Automatically cleans up main.py references
- Cannot be undone (safety first!)
Update Modules
fascraft update customers
- Creates automatic backups before updating
- Refreshes all module templates
- Rollback capability if update fails
- Preserves your custom business logic
๐ก Practical Examples
Getting Started with Poetry
# Create and navigate to your project
fascraft new my-api
cd my-api
# Install all dependencies (recommended for development)
poetry install
# Run your FastAPI app
poetry run uvicorn main:app --reload
# Add new dependencies
poetry add redis
poetry add --group dev pytest-cov
Getting Started with pip
# Create and navigate to your project
fascraft new my-api
cd my-api
# Install core dependencies
pip install -r requirements.txt
# Install development tools (optional, for testing and development)
pip install -r requirements.dev.txt
# Run your FastAPI app
uvicorn main:app --reload
# Add new dependencies
pip install redis
pip install pytest-cov
Production Deployment
# Using Poetry
poetry install --only main,prod
poetry run gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
# Using pip
pip install -r requirements.prod.txt
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
๐ฏ Use Cases
- ๐ Rapid Prototyping - Get a production-ready API structure in seconds
- ๐ข Enterprise Applications - Consistent architecture across teams
- ๐ Learning FastAPI - Best practices built into every template
- ๐ Legacy Migration - Convert existing projects to domain-driven design
- ๐ฅ Team Onboarding - Standardized project structure for new developers
๐ ๏ธ Development
Prerequisites
- Python 3.8+
- Poetry (for dependency management) - Optional for generated projects
- FastAPI knowledge (for customizing generated code)
Setup Development Environment
git clone https://github.com/LexxLuey/fascraft.git
cd fascraft
poetry install
poetry run pytest # Run all tests
Running Tests
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=fascraft
# Run specific test file
poetry run pytest tests/test_generate_command.py
๐ Documentation
- ROADMAP.md - Development phases and current status (Phase 3: Advanced Project Detection next)
- CONTRIBUTING.md - How to contribute to FasCraft
- CHANGELOG.md - Version history and changes
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details on:
- Code style and standards
- Testing requirements
- Pull request process
- Development setup
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- FastAPI - The amazing web framework that makes this possible
- Typer - Beautiful CLI framework
- Rich - Rich text and beautiful formatting
- Jinja2 - Powerful templating engine
Made with โค๏ธ for the FastAPI community
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 fascraft-0.3.1.tar.gz.
File metadata
- Download URL: fascraft-0.3.1.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.3 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d38a247a537ad04d040ce51bea883a8a1805f328db33beffa945a7702c9e6982
|
|
| MD5 |
5d489255ae10458c5719e0985befd1cd
|
|
| BLAKE2b-256 |
5f7a260aa3c54a4c85b3d6fdd03d3af511b2fb45cde3a432176738480fd9c454
|
File details
Details for the file fascraft-0.3.1-py3-none-any.whl.
File metadata
- Download URL: fascraft-0.3.1-py3-none-any.whl
- Upload date:
- Size: 38.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.3 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71064e49c12543607b8822feb35a9c856efd1b51c35ea052e214000046e46bb5
|
|
| MD5 |
9134418a305274858fb2dcfbfe3691f4
|
|
| BLAKE2b-256 |
3659a6f04a1535508552f4bd1a8c86a2cf2be103b3f5d5a878a5590c11a9ac06
|