REST API for billing management built with FastAPI, PostgreSQL, Docker Compose, and SQLAlchemy. Allows client registration and invoice creation through clear, automatically documented endpoints.
- ✅ Create and list clients
- ✅ Create and list invoices
- ✅ SQLAlchemy ORM integration
- ✅ Pydantic validation
- ✅ Automatic Swagger/ReDoc documentation
- ✅ Fully containerized with Docker
- ✅ Comprehensive testing with Pytest
- ✅ Database connection waiting with Dockerize
fastapi-billing-api/
├── app/
│ ├── __init__.py
│ ├── crud.py # Database operations
│ ├── database.py # Database configuration
│ ├── main.py # FastAPI application
│ ├── models.py # SQLAlchemy models
│ └── schemas.py # Pydantic schemas
├── tests/
│ └── test_api.py # API tests
├── Dockerfile # Container configuration
├── docker-compose.yml # Multi-service setup
├── requirements.txt # Python dependencies
└── README.md
- Docker and Docker Compose
- Git
git clone https://github.com/yourusername/fastapi-billing-api.git
cd fastapi-billing-apidocker compose up --buildThe API will be available at:
- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- API Base URL: http://localhost:8000
docker compose downPOST /clients/
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}GET /clients/POST /invoices/
Content-Type: application/json
{
"amount": 1250.50,
"client_id": 1
}GET /invoices/Make sure the database is running:
docker compose up -d dbRun the test suite:
docker compose run --rm web pytestRun tests with coverage:
docker compose run --rm web pytest --cov=appThe application uses the following environment variables:
DATABASE_URL: PostgreSQL connection string (automatically set in Docker Compose)
For local development with hot reload:
docker compose up- FastAPI - Modern Python web framework
- PostgreSQL 15 - Relational database
- SQLAlchemy - Python ORM
- Pydantic - Data validation
- Docker - Containerization
- Pytest - Testing framework
- Dockerize - Database connection waiting