A microservice framework based on FastAPI, Traefik and Consul, featuring complete service discovery, API gateway and authentication mechanisms, with one-click deployment via Docker Compose.
- Service Discovery: Service registration and health checks using Consul
- API Gateway: Request routing, load balancing and authentication middleware via Traefik
- Authentication & Authorization: JWT-based unified authentication service
- Containerized Deployment: All components are Dockerized, with one-click startup via docker-compose
- Scalability: Easily add new microservices that automatically integrate into the existing framework
- Consul: Service registration and discovery center
- Traefik: API gateway responsible for routing and load balancing
- Auth Service: Handles user authentication and JWT token issuance
- User Service: APIs for user management
- Product Service: APIs for product management (example service)
- Frontend Service: Vue.js-based user interface providing visual operations
- Docker
- Docker Compose
# Clone the repository
git clone <repository-url>
cd fastapi-microservice-framework
# Start all services
docker-compose up -d
# Check service status
docker-compose ps- Traefik management dashboard: http://localhost:8080
- Consul management interface: http://localhost:8500
- API gateway entry: http://localhost
- Frontend service: http://localhost (accessed through API gateway)
# Get access token
curl -X POST "http://localhost/api/auth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin&password=secret"
# Access user service with token
curl "http://localhost/api/users" \
-H "Authorization: Bearer <your_token>"
# Access product service with token
curl "http://localhost/api/products" \
-H "Authorization: Bearer <your_token>".
├── docker-compose.yml # Service orchestration configuration
├── traefik/ # Traefik gateway configuration
│ └── traefik.yml
├── services/
│ ├── auth/ # Authentication service
│ ├── frontend/ # Frontend service
│ ├── user/ # User service
│ └── product/ # Product service
├── .env.example # Environment variables example
└── README.md
To add a new microservice, simply follow these steps:
- Create a new service folder under the
servicesdirectory - Implement the FastAPI application with Consul service registration logic
- Add service configuration in
docker-compose.yml - Configure Traefik routing rules
- Replace all default secrets and passwords
- Configure HTTPS certificates
- Add persistent data storage
- Configure appropriate resource limits
- Add monitoring and log collection
Release Date: Please refer to base-v1.0.0 tag for details
Note: This version corresponds to the
base-stablebranch. For long-term maintenance, please develop based on this branch.
This is the first basic starter version with the following key features:
- Complete microservice architecture based on FastAPI, Traefik and Consul
- Implemented auth service, user service and product service
- Integrated frontend service providing visual operation interface
- Support service discovery, load balancing and API gateway routing
- Provided Docker Compose configuration for easy deployment