A production-ready FastAPI application for membership management, deployed to Azure Container Apps with PostgreSQL database. Features Infrastructure as Code (IaC) with Terraform and streamlined deployment via Azure Developer CLI.
- RESTful API: FastAPI-based membership management system with full CRUD operations
- Database: Azure Database for PostgreSQL Flexible Server with SSL support
- Container Orchestration: Azure Container Apps with auto-scaling capabilities
- Secrets Management: Azure Key Vault for secure credential storage
- Infrastructure as Code: Terraform modules for reproducible infrastructure
- Interactive Documentation: Auto-generated Swagger UI and ReDoc endpoints
- Local Development: Docker Compose setup for offline development
- Azure Container Apps: Hosts the FastAPI application with auto-scaling (1-10 replicas)
- Azure PostgreSQL Flexible Server: Managed database with automated backups
- Azure Key Vault: Secure storage for database connection strings
- Azure Container Registry: Private registry for Docker images
src/app/
├── main.py # FastAPI app with API endpoints
├── database.py # SQLAlchemy engine with Azure SSL support
├── models.py # ORM models (Member table)
├── schemas.py # Pydantic validation schemas
└── crud.py # Database operations layer
infra/
├── main.tf # Root Terraform module
└── modules/
├── postgres/ # PostgreSQL Flexible Server
├── keyvault/ # Key Vault with access policies
└── containerapp/# Container Apps environment
Architecture Pattern: Layered architecture with clear separation:
This template will create infrastructure and deploy code to Azure. If you don't have an Azure Subscription, you can sign up for a free account here. Make sure you have contributor role to the Azure subscription.
- Azure Developer CLI (v1.5.0+)
- Python 3.11+
- Terraform CLI (v1.5.0+)
- Azure CLI
- Docker
The fastest way to get started is using Azure Developer CLI:
# Clone the repository
git clone <repository-url>
cd fastapi-postgres-aca
# Login to Azure
azd auth login
# Provision infrastructure and deploy application
azd upThis command will:
- Prompt for environment name, subscription, and Azure region
- Create all required Azure resources via Terraform
- Build and push the Docker image to Azure Container Registry
- Deploy the container to Azure Container Apps
Once complete, you'll see the provisioned resources and the application URL:
# Navigate to source directory
cd src
# Start application with PostgreSQL database
docker-compose up
# Application runs at http://localhost:8000
# API documentation at http://localhost:8000/docsThe application automatically generates interactive API documentation:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Health check endpoint |
| POST | /members/ |
Create a new member |
| GET | /members/ |
List all members (supports pagination) |
| GET | /members/{id} |
Get member by ID |
| PUT | /members/{id} |
Update member details |
# Remove all Azure resources
azd down- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- FastAPI Documentation
- Azure Container Apps Documentation
- Azure PostgreSQL Flexible Server
- Terraform Azure Provider
This project is licensed under the MIT License - see the LICENSE file for details.



