Contributing to FastAPI Admin CLI
First off, thank you for considering contributing to FastAPI Admin CLI! It's people like you that make this tool better for everyone. This document provides guidelines and instructions for contributing to this project.
Table of Contents
- Introduction
- Project Structure
- Development Setup
- Development Workflow
- Adding New Commands
- Testing
- Documentation
- Pull Request Process
- Style Guidelines
- Documentation Guidelines
Introduction
FastAPI Admin CLI is a Django-inspired command-line tool for managing FastAPI applications with a modular structure. It helps developers quickly scaffold and manage FastAPI projects with a clean, organized architecture.
The project aims to simplify common tasks in FastAPI development, such as:
- Creating new projects with a well-structured template
- Adding modular apps within a project
- Managing Docker containers
- Handling database migrations
- Providing easy access to shell and admin operations
Project Structure
Here's an overview of the project's structure:
fastapi-admin-cli/
├── fastapi_admin/ # Main package directory
│ ├── __init__.py # Package initialization with version
│ ├── cli.py # Main CLI entry point
│ ├── commands/ # CLI commands implementation
│ │ ├── __init__.py # Package initialization
│ │ ├── app.py # App creation command
│ │ ├── container.py # Container shell access
│ │ ├── docker.py # Docker management commands
│ │ ├── migrations.py # Database migration commands
│ │ ├── project.py # Project creation command
│ │ └── superuser.py # Superuser management
│ └── utils/ # Utility functions
│ ├── __init__.py # Package initialization
│ ├── docker_utils.py # Docker-related utilities
│ ├── file_utils.py # File operation utilities
│ └── template_utils.py # Template handling utilities
├── pyproject.toml # Project metadata and dependencies
├── README.md # Project documentation
├── record_demo.sh # Demo recording script
└── test_commands.sh # Test script for CLI commands
Key Components:
-
cli.py: The main entry point for the CLI tool. It registers all the command groups.
-
commands/: Each file in this directory implements a specific command group:
-
project.py
: Creates new FastAPI projects app.py
: Creates new apps within a projectdocker.py
: Manages Docker containersmigrations.py
: Handles database migrationscontainer.py
: Provides shell access to containers-
superuser.py
: Manages superuser creation -
utils/: Contains utility functions used across the project:
-
template_utils.py
: Handles fetching and processing templates file_utils.py
: Provides file system operationsdocker_utils.py
: Contains Docker-related utilities
Development Setup
Fork and Clone the Repository
-
Fork the repository on GitHub
-
Clone your fork locally:
- Add the original repository as upstream:
Setting Up Development Environment
- Create a virtual environment:
- Install the package in development mode:
- Install additional development dependencies:
Development Workflow
- Create a branch for your feature or bugfix:
- Make your changes and commit them:
- Keep your branch updated with the upstream:
- Push your changes to your fork:
- Open a pull request on GitHub
Adding New Commands
To add a new command to the CLI:
-
Create a new file in the
fastapi_admin/commands/
directory, e.g.,mycommand.py
. -
Implement your command using
typer
(see existing commands for examples). -
Register your command in
cli.py
by adding:
Example command structure:
import typer
from rich.console import Console
from rich.panel import Panel
app = typer.Typer(help="My new command description")
console = Console()
@app.callback(invoke_without_command=True)
def main(param: str):
"""Main command implementation"""
console.print(Panel(f"Executing command with {param}"))
# Command implementation here
Testing
You can test your changes using the test_commands.sh
script:
If you're adding new commands or features, consider adding tests for them to this script.
For interactive testing, use:
Documentation
When adding new features, please update the documentation:
-
Add your command to the command table in README.md
-
Document your command's usage with examples
-
If your command adds significant functionality, consider adding a section to README.md
Pull Request Process
-
Ensure your code passes all tests and linting checks
-
Update the documentation if needed
-
Make sure your PR title and description clearly describe the changes
-
Link any related issues in your PR description
-
Be responsive to feedback and be willing to make requested changes
Style Guidelines
This project follows these style guidelines:
-
Use Black for code formatting
-
Use isort for import sorting
-
Follow PEP 8 style guidelines
-
Write clear docstrings for functions and classes
-
Use type hints where appropriate
Before submitting a PR, format your code:
Documentation Guidelines
This project uses MkDocs with the Material theme for documentation. When contributing to documentation:
Setting Up Documentation Environment
- Navigate to the documentation directory:
- Install MkDocs and required plugins:
Testing Documentation Changes
- Run the MkDocs development server:
- Open your browser and navigate to
http://127.0.0.1:8000/
to preview changes
Documentation Structure
The documentation is organized as follows:
docs/index.md
: Main landing pagedocs/getting-started/
: Installation and quick start guidesdocs/reference/
: Command reference and detailed usage instructionsdocs/development/
: Contribution and development guidelines
Writing Documentation
-
Use Markdown for all documentation files
-
Follow a clear and consistent style throughout documentation
-
Include code examples where appropriate
-
Organize content with clear headers and subheaders
-
Use admonitions for notes, warnings, and tips:
-
When adding a new command or feature, be sure to:
-
Add it to the appropriate reference page
- Include examples of usage
- Document all options and arguments
- Consider adding it to the navigation in
mkdocs.yml
Building Documentation for Production
To build the documentation for production:
This will generate the static site in the site/
directory.
Thank you for contributing to FastAPI Admin CLI! Your efforts help make this tool better for everyone.