This repository provides a simple Python script to scaffold a FastAPI project following a Domain-Driven Design (DDD) folder structure.
It also sets up essential tools such as Ruff, pytest, pre-commit, Bandit, pip-audit, and Import Linter to ensure high code quality from the start.
- ✅ FastAPI with DDD structure (
src/api,src/application,src/domain,src/infrastructure) - ✅ Dockerfile & docker-compose setup
- ✅ Linting and formatting with Ruff
- ✅ Testing with pytest and coverage reports
- ✅ Security checks with bandit and pip-audit
- ✅ Import contracts with import-linter
- ✅ Pre-commit hooks (black, ruff, trailing whitespace, etc.)
git clone https://github.com/fabianfalon/fastapi-ddd-scaffolder.git
cd fastapi-ddd-scaffolderpython scaffold.py --path ./projects --name my-serviceThis will generate the project under ./projects/my-service.
my-service/
├── infra/
│ └── docker-compose.yml
├── src/
│ ├── api/
│ │ └── v1/
│ │ ├── endpoints/
│ │ │ └── health.py
│ │ ├── dependencies.py
│ │ └── schemas.py
│ ├── application/
│ ├── domain/
│ ├── infrastructure/
│ └── main.py
├── tests/
│ └── api/
│ └── test_health.py
├── .importlinter
├── .pre-commit-config.yaml
├── .gitignore
├── .env.example
├── Dockerfile
├── Makefile
├── pyproject.toml
├── requirements.txt
├── requirements-tests.txt
├── ruff.toml
└── pytest.ini
make run # Run the FastAPI app with uvicorn
make test # Run tests
make test-cov # Run tests with coverage
make lint # Run Ruff lint
make format # Format code
make sec # Run security checks (bandit + pip-audit)
make contracts # Run Import Linter contracts
make build # Build docker image
make up # Start docker-compose
make down # Stop docker-compose- Python >=3.11
- Docker & Docker Compose (optional, for containerized runs)
This project is licensed under the MIT License. See the LICENSE file for more details.