Stop wrestling with project structure. Start building features.
Traditional FastAPI project setup:
mkdir my-api && cd my-api
touch main.py requirements.txt
# ... 30 minutes of boilerplate later ...With Octopus:
octopus init
uv run fastapi dev
uv run pytest
# โจ Production-ready FastAPI app in 2 seconds๐ค AI-First Design - Structure so clean that AI assistants understand it instantly
๐ Zero Config - No manual imports, no router mounting, no configuration hell
๐จ Beautiful DX - Rich CLI with colors, trees, and helpful feedback
โพ๏ธ Infinite Nesting - Features inside features, as deep as you need
๐ง
Onion Architecture - Clean layers: Router โ Service โ Entities/Schemas
๐ Auto-Discovery - Add a feature, it's instantly available in your API
โจ Path Syntax - Create nested features from anywhere: octopus add feature users/profile
๐ฆ Modern Stack - FastAPI + UV + Pydantic + Your choice of DB/Auth
# Create your app
octopus init
cd app
# Add features - they auto-mount to your API
octopus add feature users
octopus add feature products
# Add shared modules - instantly available everywhere
octopus add shared database
octopus add shared auth
# Navigate anywhere, add nested features
cd app/users
octopus add feature profile
octopus add feature settings
# Or use path syntax - no need to navigate!
octopus add feature products/inventory
octopus add feature users/profile/avatar
# Visualize your structure
octopus structureBeautiful visualization:
๐ test_app/
โโโ ๐ app/
โโโ โก products/ (1 route)
โ โโโ GET /status Get status of the products feature.
โ โโโ โก inventory/ (1 route)
โ โโโ GET /status Get status of the inventory feature.
โโโ โก users/ (1 route)
โ โโโ GET /status Get status of the users feature.
โ โโโ โก profile/ (1 route)
โ โโโ GET /status Get status of the profile feature.
โ โโโ โก avatar/ (1 route)
โ โโโ GET /status Get status of the avatar feature.
โโโ ๐ฆ auth/
โโโ ๐ฆ config/
โโโ ๐ฆ database/
โโโ ๐ฆ routing/
๐ Statistics: 5 features โข 4 shared modules โข 5 routers โข 9 services
Run it:
# Run it
uv run fastapi devResult: Fully working API with routes:
GET /users/โGET /users/profile/โGET /users/settings/โGET /products/โ
No manual configuration. No imports. No routing setup. It just works.
Octopus is a production-ready CLI tool that generates well-structured FastAPI applications following a recursive fractal onion architecture.
๐ค AI-Friendly by Design - Created specifically to be understood by AI assistants while maintaining high structural quality. Clear separation of concerns, consistent patterns, and self-documenting structure make it ideal for AI-assisted development with GitHub Copilot, ChatGPT, or any coding assistant.
Every component (app, feature, shared module) can contain nested features and shared modules, creating a self-similar structure at any depth.
โจ Recursive Architecture - Features can contain sub-features infinitely deep
๐ง
Onion Layer Pattern - Clear separation: Router โ Service โ Entities/Schemas
๐ Auto-Discovery - Routers automatically mount without manual configuration
๐ฆ Context-Aware - Commands detect where you are in the project structure
๐ฏ Service Layer Pattern - Business logic isolated from routing and data layers
๐ Cascading Shared Modules - App-level utilities available at any depth
๐ Comprehensive Docs - Every app includes architecture guides and examples
๐ง UV Package Manager - Modern Python dependency management
โก Tab Completion - Shell autocompletion support for all commands
Requirements: Python 3.10+ and UV package manager
git clone https://github.com/Tom-Laurent-TL/octopus.git
cd octopus
uv venv && .venv\Scripts\Activate.ps1
uv pip install -e .octopus init --path your/path/my-project (will create the path if needed)
uv run fastapi dev๐ That's it! Open http://localhost:8000 - your API is live!
# Add user management
octopus add feature users
octopus add shared database
# Add nested features - two ways:
# 1. Navigate into the feature
cd app/users
octopus add feature authentication
octopus add feature profile
# 2. Or use path syntax from anywhere
octopus add feature users/settings
octopus add feature users/profile/avatar
# View your structure
octopus structure --routesEvery generated app includes comprehensive guides:
| Guide | What You'll Learn |
|---|---|
| ARCHITECTURE.md | Complete architecture explanation, fractal structure, auto-discovery |
| BEST_PRACTICES.md | Service patterns, dependency injection, error handling, security |
| EXAMPLES.md | Full CRUD example, nested features, JWT auth, database setup |
cd my-api
cat docs/ARCHITECTURE.md # Start here!๐ Available Commands
# Initialize a new FastAPI application with full architecture
octopus init
# Initialize in a specific directory
octopus init --path my-apiCreates a complete FastAPI project with:
- Main app with config as a shared module
- Comprehensive documentation (ARCHITECTURE.md, BEST_PRACTICES.md, EXAMPLES.md)
- Test structure with example health check test
- Placeholder TODO files for planning
- UV package management setup
- Ready-to-run FastAPI application
# Add a feature module (context-aware)
octopus add feature <NAME>
# Examples
octopus add feature users # In app root - creates app/users/
octopus add feature hello_world # Inside features/users/ - creates nested feature
# Or use path syntax from anywhere (no need to cd!)
octopus add feature users/profile # Creates app/users/features/profile/
octopus add feature users/profile/settings # Deeply nested!Creates:
- Router with automatic mounting
- Service class for business logic
entities.pyfor database modelsschemas.pyfor API models- Auto-imports for sibling shared modules (commented)
- On-demand
features/andshared/subdirectories
# Add a shared module (context-aware)
octopus add shared <NAME>
# Examples
octopus add shared database # Creates shared/database/
octopus add shared auth # Creates shared/auth/Creates:
- Service class pattern
- Automatically updates all sibling features with import comments
- Special handling for
configmodule (includes Settings class)
# Remove a feature (context-aware)
octopus remove feature <NAME>
# Remove a shared module (context-aware)
octopus remove shared <NAME>
# Examples
octopus remove feature users
octopus remove shared databaseSafely removes features or shared modules, including:
- All files and directories
- Nested features and shared modules
- Updates imports in sibling units
# Display a rich tree view of your project structure
octopus structure
# Show full structure with all files
octopus structure --full
# Show API routes
octopus structure --routesVisualizes your Octopus project with:
- Color-coded features and shared modules
- Nesting depth indicators
- Optional route mapping
- File and directory counts
๐๏ธ Generated Project Structure
my-api/
โโโ app/
โ โโโ __init__.py # Auto-discovery: mounts all features & shared
โ โโโ main.py # FastAPI app entry point
โ โโโ router.py # Root API router
โ โโโ users/ # Feature (created with: octopus add feature users)
โ โ โโโ __init__.py # Auto-mounts sub-features & shared modules
โ โ โโโ router.py # Routes: /users/*
โ โ โโโ service.py # Business logic (UsersService class)
โ โ โโโ entities.py # Database models (SQLAlchemy)
โ โ โโโ schemas.py # API models (Pydantic)
โ โ โโโ features/ # Nested features (created on-demand)
โ โ โ โโโ profile/ # Sub-feature: /users/profile/*
โ โ โ โโโ router.py
โ โ โ โโโ service.py
โ โ โ โโโ ...
โ โ โโโ shared/ # Feature-scoped shared modules
โ โ โโโ validation/ # Shared within users feature
โ โโโ shared/ # App-level shared modules
โ โโโ config/ # Configuration (created by default)
โ โ โโโ __init__.py
โ โ โโโ service.py # Settings class + ConfigService
โ โโโ database/ # (created with: octopus add shared database)
โ โ โโโ __init__.py
โ โ โโโ service.py # DatabaseService class
โ โโโ auth/ # (created with: octopus add shared auth)
โ โโโ __init__.py
โ โโโ service.py # AuthService class
โโโ docs/
โ โโโ ARCHITECTURE.md # Complete architecture guide
โ โโโ BEST_PRACTICES.md # Coding standards & patterns
โ โโโ EXAMPLES.md # Real-world implementation examples
โโโ pyproject.toml # UV package configuration
โโโ uv.lock # Locked dependencies
๐ Recursive Structure - Every unit (app, feature) can contain:
features/- Nested features (self-similar structure)shared/- Shared modules for that scope- Standard files:
router.py,service.py,entities.py,schemas.py
๐ง Onion Layers (dependency direction: โ)
Router โ Service โ Entities/Schemas
๐ Auto-Discovery - No manual imports needed:
app/__init__.pyauto-mounts all features- Feature
__init__.pyauto-mounts sub-features - Uses centralized
auto_discover_routers()utility
๐ Cascading Shared Modules - The killer feature:
app/shared/config/ # Automatically available to ALL features
app/shared/database/ # At ANY nesting depth
# Even deeply nested features have access (absolute imports):
# app/features/users/features/profile/features/avatar/__init__.py
# from app.shared.config.service import settings โ
Works!
# from app.shared.database.service import get_db โ
Works!
# No more unreadable relative imports like:
# from ......shared.config import settings โ Avoid this!๐ฆ Service Layer Pattern - All business logic in XxxService classes:
class UsersService:
def get_all(self): ...
def create(self, data): ...๐ ๏ธ Technology Stack
- Typer - Modern CLI framework with beautiful terminal output and Rich integration
- Rich - Beautiful terminal formatting, colors, and progress indicators
- Python 3.10+ - Modern Python features
- FastAPI - High-performance async web framework
- Pydantic - Data validation and settings management
- Pydantic-Settings - Environment-based configuration
- UV - Fast Python package manager
- SQLAlchemy - ORM (in documentation examples)
- Python-Jose - JWT tokens (in auth examples)
- Bcrypt - Password hashing (in auth examples)
โก Shell Autocompletion
Enable tab completion for your shell:
PowerShell:
octopus --install-completion powershell
# Restart your terminalBash:
octopus --install-completion bash
source ~/.bashrcZsh:
octopus --install-completion zsh
source ~/.zshrcFish:
octopus --install-completion fish
# Restart your terminalAfter installation, press TAB to autocomplete commands, subcommands, and options!
- โ Full app scaffolding with recursive structure
- โ Feature generation with Service class pattern
- โ Shared module generation with auto-imports
- โ Context-aware commands (detects current location)
- โ Auto-discovery system (no manual router mounting)
- โ Comprehensive documentation (3 markdown guides per app)
- โ Test structure generation with examples
- โ Remove commands for features and shared modules
- โ Structure visualization with rich tree display
- โ UV package management integration
- โ Shell autocompletion support
- โ On-demand directory creation (no empty folders)
- โ Absolute imports (works at any nesting depth)
- CI/CD templates - GitHub Actions, GitLab CI workflows
- Database migration integration - Alembic setup and templates
- Docker configuration - Dockerfile and docker-compose templates
# General help
octopus --help
# Command-specific help
octopus init --help
octopus add --help
octopus add feature --help
octopus add shared --help
octopus remove --help
octopus structure --helpContributions are welcome! Areas for contribution:
- Enhanced test generation for features
- Additional documentation templates
- Database migration templates
- Docker and CI/CD configurations
- Improved error handling
- Add tests for the CLI itself
- Plugin system development
Built with ๐ค AI-First thinking | Made for developers who โค๏ธ clean architecture
โญ Star us on GitHub if Octopus makes your FastAPI development easier!
Report Bug โข Request Feature โข Contribute
MIT License - See LICENSE file for details
Built with โค๏ธ for FastAPI developers