A comprehensive boilerplate for building microservices using Azure Functions and FastAPI with Docker Compose support.
This project consists of two main microservices with shared components:
- Auth Service (Port 8001) - Authentication and authorization with API versioning
- Organization Service (Port 8002) - Organization management with Service Bus integration
- API Gateway (Port 8003) - Centralized documentation and service aggregation
- Shared Components - Common utilities, authentication, and core functionality
- Infrastructure - Azure Bicep templates for cloud deployment
- Nginx Proxy - Reverse proxy for service routing and load balancing
- Docker and Docker Compose installed
- Git (for cloning the repository)
-
Clone the repository (if not already done):
git clone <repository-url> cd azure_functions_fastapi_microservices_boilerplate
-
Build and start all services:
docker-compose up --build
-
Start services in detached mode:
docker-compose up -d --build
-
View logs:
# All services docker-compose logs -f # Specific service docker-compose logs -f auth-service
-
Stop services:
docker-compose down
-
Auth Service: http://localhost:8001
- Health: http://localhost:8001/health
- API Docs: http://localhost:8001/docs
- API v1: http://localhost:8001/v1/api/
- API v2: http://localhost:8001/v2/api/
-
Organization Service: http://localhost:8002
- Health: http://localhost:8002/health
- API Docs: http://localhost:8002/docs
- API: http://localhost:8002/api/
- Gateway: http://localhost
- Auth Service: http://localhost/auth/
- Organization Service: http://localhost/organization/
- Overall Health: http://localhost/health
The Docker Compose setup includes volume mounts for hot reloading during development:
# Start in development mode
docker-compose up --build
# Make changes to your code - the services will automatically reloadYou can also run individual services:
# Build and run only auth service
docker-compose up --build auth-service
# Run specific services
docker-compose up auth-service organization-serviceCreate .env files for each service to customize configuration:
# services/auth-service/.env
DEBUG=true
LOG_LEVEL=debug
JWT_SECRET_KEY=your-secret-key-change-in-production
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
# services/organization-service/.env
DEBUG=true
COSMOS_DB_ENDPOINT=your-cosmos-endpoint
AZURE_SERVICE_BUS_CONNECTION_STRING=your-service-bus-connection-string# Build without cache
docker-compose build --no-cache
# View running containers
docker-compose ps
# Execute commands in running containers
docker-compose exec auth-service bash
# View resource usage
docker-compose top
# Remove all containers and networks
docker-compose down --remove-orphans
# Remove containers, networks, and volumes
docker-compose down -v# Build individual service
docker build -t auth-service ./services/auth-service
# Run individual container
docker run -p 8001:8000 auth-serviceThis project includes a Makefile for common operations:
# View all available commands
make help
# Build all Docker images
make build
# Start all services in detached mode
make up
# Stop all services
make down
# Restart all services
make restart
# View logs from all services
make logs
# Clean up everything (containers, networks, volumes)
make clean
# Run health checks on all services
make test
# Check health status
make health
# Development mode (with logs)
make dev- Port conflicts: Make sure ports 8001, 8002, 8003, and 80 are available
- Build failures: Try
docker-compose build --no-cache - Permission issues: Ensure Docker has proper permissions
All services include health checks. Monitor service health:
# Check health status
docker-compose ps
# View health check logs
docker-compose logs nginx# Access service logs
docker-compose logs -f [service-name]
# Access service shell
docker-compose exec [service-name] bash
# Inspect service configuration
docker-compose configThis project includes Azure Bicep templates for cloud deployment:
- Azure Functions - Serverless compute for microservices
- Azure Cosmos DB - NoSQL database for data storage
- Azure Service Bus - Message queuing for service communication
- Azure API Management - API gateway and management
-
Prerequisites:
# Install Azure CLI az login az account set --subscription "your-subscription-id"
-
Deploy Infrastructure:
# Deploy using Bicep templates az deployment group create \ --resource-group your-rg \ --template-file infrastructure/main.bicep \ --parameters @infrastructure/parameters.json -
Deploy Functions:
# Deploy auth service cd services/auth-service func azure functionapp publish your-auth-function-app # Deploy organization service cd ../organization-service func azure functionapp publish your-org-function-app
- Environment-specific configurations
- Azure Key Vault for secrets management
- Application Insights for monitoring
- Azure Front Door for load balancing
- Security hardening and compliance
Access all microservices APIs in one place: http://localhost/docs
The new API Gateway provides:
- Centralized Swagger UI with all microservices APIs
- Service switching between individual and unified views
- Real-time API aggregation from all running services
- Health monitoring and service discovery
- Professional documentation interface with service tagging
Each service also provides its own interactive API documentation:
- Auth Service: http://localhost:8001/docs
- Supports API versioning (v1 and v2)
- JWT-based authentication
- User management endpoints
- Organization Service: http://localhost:8002/docs
- Organization CRUD operations
- Service Bus integration
- API Gateway: http://localhost:8003/docs
- Documentation aggregation service
- Health monitoring endpoints
π‘ Tip: Use the unified documentation at http://localhost/docs for the best experience!
azure_functions_fastapi_microservices_boilerplate/
βββ services/ # Microservices
β βββ auth-service/ # Authentication service
β β βββ src/ # Source code
β β βββ HttpTrigger/ # Azure Functions trigger
β β βββ Dockerfile # Container configuration
β β βββ requirements.txt # Python dependencies
β βββ organization-service/ # Organization management service
β β βββ src/ # Source code
β β βββ HttpTrigger/ # Azure Functions HTTP trigger
β β βββ ServiceBusListener/ # Service Bus trigger
β β βββ Dockerfile # Container configuration
β β βββ requirements.txt # Python dependencies
β βββ shared/ # Shared components
β βββ authentication/ # Auth utilities
β βββ core/ # Core utilities
β βββ utils/ # Common utilities
βββ infrastructure/ # Infrastructure as Code
β βββ main.bicep # Main Bicep template
β βββ modules/ # Bicep modules
β βββ apim.bicep # API Management
β βββ cosmos.bicep # Cosmos DB
β βββ servicebus.bicep # Service Bus
βββ docs/ # Documentation
β βββ architecture.md # Architecture overview
β βββ adr/ # Architecture Decision Records
βββ docker-compose.yml # Docker Compose configuration
βββ nginx.conf # Nginx reverse proxy config
βββ Makefile # Development commands
- API Versioning - Support for v1 and v2 APIs
- JWT Authentication - Secure token-based auth
- User Management - Registration, login, profile management
- Password Security - Hashing, reset, change functionality
- Role-based Access Control - Admin and user roles
- CRUD Operations - Full organization management
- Service Bus Integration - Asynchronous message processing
- Event-driven Architecture - Reactive service design
- Common Authentication - Reusable auth utilities
- Core Utilities - Shared business logic
- Standardized Responses - Consistent API responses
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following the project structure
- Add tests for new functionality
- Test with Docker Compose (
make test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Submit a pull request
- Follow the established project structure
- Use type hints in Python code
- Write comprehensive tests
- Update documentation for new features
- Follow PEP 8 coding standards
- Use meaningful commit messages
- FastAPI Documentation
- Azure Functions Python Developer Guide
- Docker Compose Documentation
- Azure Bicep Documentation
Built with β€οΈ using FastAPI, Azure Functions, and Docker