Crushing the Command Line: How I Used Amazon Q to Build a Smarter FastAPI Scaffolder


This is a submission for the Amazon Q Developer "Quack The Code" Challenge: Crushing the Command Line.
What I Built
I created the FastAPI Scaffolder CLI β a zero-config generator for production-ready FastAPI apps. It solves common pain points:
π Saves over an hour per project setup.
π‘οΈ Bakes in best practices (async DB pools, retry logic, secure defaults).
βοΈ Generates Infrastructure as Code (Terraform/Docker for AWS/Local).
With one command, you get:
fastapi-scaffold create myapp \
--db=postgresql \
--broker=redis \
--prod=aws
This generates a directory with all the files you need to get started, including a Dockerfile, docker-compose.yaml, and Terraform files for AWS deployment.
Key Benefits
β Simplifies database and configuration setup with auto-generated async SQLAlchemy/Motor integrations.
β Production-ready: Includes Terraform, Docker Compose, and monitoring tools.
β Flexible and fast: Designed to be less opinionated while still providing a solid foundation.
Existing scaffolding tools like the official FastAPI template often lack production readiness or are too rigid. This tool is built to be both flexible and easy to use.
Demo
The scaffolder supports:
π’οΈ Multiple databases: PostgreSQL, MongoDB, SQLite.
π¬ Message brokers: Redis, RabbitMQ.
π¦ Deployment options: Minimal, Full (AWS ECS), Serverless.
Let me walk you through a typical workflow:
Install the CLI:
uv pip install scaffold-fastapi
Run the scaffolder command:
scaffold-fastapi customer-api --db=postgresql --broker=redis --stack=full
OR just pass the name of the app to see the default options:
scaffold-fastapi customer-api
- Generated files: The tool generates a complete project structure:
βββ app/
β βββ api/
β β βββ v1/
β βββ core/
β βββ db/
β βββ models/
β βββ main.py
βββ tasks/
β βββ celery_app.py
β βββ sample_tasks.py
βββ infra/
β βββ docker/
β βββ terraform/
β βββ helm/
βββ Dockerfile
βββ docker-compose.yml
Run the app:
cd customer-api docker-compose up
Access the API: Open your browser and navigate to
http://localhost:8000/docs
to see the auto-generated API documentation.Run the Celery worker:
docker-compose run --rm worker
Your FastAPI application is now running with:
PostgreSQL database with async connection pool
Redis for caching and message brokering
Celery worker for background tasks
Health check endpoints
API documentation at /api/v1/docs
When you're ready to deploy:
cd infra/terraform
terraform init
terraform apply
Project Structure
The scaffolder itself is organized into modular generators:
scaffold-fastapi/
βββ scaffold_fastapi/
β βββ generators/
β β βββ app.py # FastAPI application files
β β βββ celery.py # Celery task configuration
β β βββ docker.py # Docker and docker-compose files
β β βββ env.py # Environment variable files
β β βββ terraform.py # AWS deployment files
β βββ __init__.py
βββ cli.py # CLI entrypoint
βββ pyproject.toml
βββ README.md
βββ LICENSE
Code Repository
The complete code is available on GitHub: scaffold-fastapi. The repository includes detailed instructions and examples of the generated code.
The package is also available on PyPI: scaffold-fastapi.
How I Used Amazon Q Developer
Amazon Q Developer was the secret weapon that made this project possible. Here's how it helped:
Initial Concept and Planning
Defining the scope: Amazon Q helped identify the most valuable features for a FastAPI scaffolder, such as database support, message broker integration, and deployment options.
Designing the CLI interface: It suggested using Typer for a clean, intuitive command-line experience.
Planning the project structure: Amazon Q provided best practices for organizing FastAPI projects, including separating concerns and using async database connections.
Generating code snippets: It created boilerplate code for components like async database setup, Celery configuration, and Docker files.
Rapid Prototyping
Amazon Q accelerated development by:
Implementing the CLI: It generated the core CLI logic with proper argument handling and validation.
Creating generator modules: Each component had its own generator function, producing well-structured, idiomatic code.
Debugging and Refinement
Amazon Q was invaluable for:
Troubleshooting: It helped resolve Docker Compose networking issues.
Code optimization: Suggestions improved efficiency and maintainability.
Feature expansion: New features were implemented cleanly with its guidance.
Packaging and Distribution
Amazon Q assisted in:
Creating the
pyproject.toml
file: It generated a well-structured configuration for packaging and dependencies.Setting up the CLI entry point: It provided the necessary boilerplate for Typer to work seamlessly with the package.
Writing documentation: It helped draft the README and usage instructions, ensuring clarity for users.
Creating a license file: It suggested using the MIT license, which is widely accepted and easy to understand.
Creating Github Actions CI/CD workflows: It generated a basic CI/CD pipeline for testing and deploying the scaffolder.
Creating a Dockerfile: It generated a Dockerfile for the CLI tool, making it easy to run in a containerized environment.
Find more about the packaging process in the packaging guide.md and packaging-and-dist.md
Lessons Learned
Start with clear requirements: The more specific your initial prompt, the better the results.
Iterative development: Break complex tasks into smaller chunks and refine incrementally.
Collaborative problem-solving: Treat Amazon Q as a pair programming partner, not just a code generator.
Impact and Future Plans
This scaffolder has already saved me countless hours. What used to take a full day now takes minutes. The generated code is robust and follows best practices.
Future Enhancements
Support for more databases like CockroachDB and DynamoDB.
Authentication templates for OAuth, JWT, and API keys.
Testing frameworks with pytest fixtures and example tests.
CI/CD templates for GitHub Actions and AWS CodePipeline.
Conclusion
Amazon Q Developer has transformed how I approach development. It's not just about writing code fasterβit's about writing better code with fewer bugs and better architecture. This FastAPI scaffolder is just one example of how Amazon Q can help developers build smarter tools.
If you're building CLI tools or automation scripts, I highly recommend leveraging Amazon Q Developer. Start with a clear vision, break down the problem, and let Amazon Q help you implement the solution.
I hope you have enjoyed this article. If you have any questions, please feel free to reach out to me on Twitter. or LinkedIn. You can also check out my other articles on Dev.to. Thanks for reading!
Subscribe to my newsletter
Read articles from KEN MWAURA directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

KEN MWAURA
KEN MWAURA
Nairobi, Kenya