BackAnt CLI is a powerful command-line interface designed to streamline the development of Flask-based REST APIs. It automates the generation of a complete and scalable project structure, allowing developers to focus on business logic rather than boilerplate code.
- Automated Project Scaffolding: Generate a new Flask API with a single command, including a well-organized directory structure.
- Layered Architecture: The generated project follows a clean, layered architecture (Models, Repositories, Services, Routes) to promote separation of concerns and maintainability.
- Database-Ready: Includes SQLAlchemy for database modeling and interaction, with a pre-configured
DBSessionfor easy database access. - Dockerized Environment: Comes with
Dockerfileanddocker-compose.ymlfiles for a consistent development and production environment. - Extensible by Design: Easily add new routes, services, and models using the provided CLI commands.
- Pre-configured for Deployment: Includes a GitHub Actions workflow for building and pushing Docker images to Amazon ECR.
Install the Backant CLI using the .deb package for Ubuntu/Debian systems:
# Download and install the .deb package
sudo dpkg -i backant-cli.debYou can also install using pip:
pip install backant-cliTo create a new Flask API project, use the generate api command:
ant generate api <your_project_name>This will create a new directory named <your_project_name> with the complete project structure.
You can generate a complete API with routes and subroutes from a JSON specification using the --json option:
ant generate api my-project --json '{"routes": {"products": {"type": "GET", "subroutes": {"create": {"type": "POST"}}}}}'ant generate api ecommerce --json api-spec.json--verboseor-v: Show detailed generation progress--dry-run: Validate JSON specification without generating files
# Generate API with verbose output
ant generate api shop --json api-spec.json --verbose
# Validate JSON specification without creating files
ant generate api test --json api.json --dry-runThe JSON specification should follow this structure:
{
"routes": {
"route_name": {
"type": "GET|POST|PUT|DELETE",
"mock": {},
"subroutes": {
"subroute_name": {
"type": "GET|POST|PUT|DELETE",
"mock": {}
}
}
}
}
}Once you have a project, you can easily add new routes and their corresponding components (service, repository, model) with the generate route command:
ant generate route <your_route_name>This command will automatically create:
- A new route in
api/routes/ - A new service in
api/services/ - A new repository in
api/repositories/ - A new model in
api/models/
You can also generate a route with mock data for testing and development purposes. Use the --mock option with a JSON string or a path to a JSON file.
ant generate route <your_route_name> --mock '{"key": "value", "another_key": "another_value"}'ant generate route <your_route_name> --mock /path/to/your/mock_data.jsonThis will generate the same files as the standard generate route command, but the service will return the provided JSON data.
The generated project follows a structured and scalable architecture:
<your_project_name>/
├── api/
│ ├── apis/ # For third-party API integrations
│ ├── decorators/ # Custom decorators (e.g., for authentication)
│ ├── helper/ # Helper functions and utilities
│ ├── models/ # SQLAlchemy database models
│ ├── repositories/ # Data access layer
│ ├── routes/ # API endpoints (controllers)
│ ├── schemas/ # Data validation schemas
│ ├── services/ # Business logic layer
│ └── startup/ # Application startup and configuration
├── .github/
│ └── workflows/ # CI/CD workflows
├── .gitignore
├── docker-compose.yml
├── Dockerfile
└── requirements.txt
BackAnt CLI includes opt-in anonymous telemetry to help us improve the tool. On first run, you'll be asked if you want to participate.
# Environment variable (permanent)
export DO_NOT_TRACK=1
# Per-command flag
ant --no-telemetry generate api my-project
# View telemetry settings
ant --privacyWe never collect file paths, project names, usernames, or any personally identifiable information. See docs/telemetry.md for full details.
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.
- Clone the repository:
git clone https://github.com/backant-io/backant-cli.git
- Create a virtual environment:
python3 -m venv venv source venv/bin/activate - Install the dependencies:
pip install -r requirements.txt
- Install the CLI in editable mode:
pip install -e .
Now you can run the CLI locally using the ant command.
This project is licensed under the MIT License - see the LICENSE file for details.