A distributed Todo application built using Spring Boot, designed to explore microservices architecture, container orchestration, and service communication patterns.
This project emphasizes:
- Service decomposition
- API Gateway routing
- Service discovery (Eureka)
- JWT-based authentication
- Isolated databases per service
- Containerized deployment with Docker Compose
The system follows a classic microservices architecture:
Client
↓
Gateway Service (8080)
↓
Auth Service (8081)
Todo Service (8082)
↓
PostgreSQL (isolated per service)
All services register with a Discovery Server (Eureka) and communicate over a shared Docker bridge network.
-
Port:
8761 -
Technology: Spring Cloud Netflix Eureka
-
Responsibility:
- Service registry
- Service health monitoring
-
Health endpoint:
http://localhost:8761/actuator/health
All services register themselves on startup.
-
Port:
8081 -
Responsibilities:
- User authentication
- JWT generation
- Credential validation
-
Database:
postgres-auth -
Environment variables:
JWT_SECRETSPRING_DATASOURCE_URLSPRING_DATASOURCE_USERNAMESPRING_DATASOURCE_PASSWORD
-
Port:
8082 -
Responsibilities:
- Todo CRUD operations
- Business logic enforcement
-
Database:
postgres-todo -
Isolated database per service (microservices best practice)
-
Port:
8080 -
Responsibilities:
- Entry point for all client requests
- Route forwarding
- JWT validation
- Service discovery integration
All client requests should go through:
http://localhost:8080/api/{service}
Example:
http://localhost:8080/api/auth/login
http://localhost:8080/api/todos
Each microservice owns its database.
| Service | Database Container | Volume |
|---|---|---|
| Auth | postgres-auth | auth_data |
| Todo | postgres-todo | todo_data |
- Image:
postgres:15-alpine - Persistent storage via Docker volumes
- No shared database between services
All services are defined in docker-compose.yml.
All containers run inside:
todo-net (bridge network)
Internal service communication uses container names:
http://discovery-server:8761
jdbc:postgresql://postgres-auth:5432/...
jdbc:postgresql://postgres-todo:5432/...
Service dependencies are controlled using depends_on.
-
auth-servicewaits for:- discovery-server (healthy)
- postgres-auth (started)
-
todo-servicewaits for:- discovery-server (healthy)
- postgres-todo (started)
-
gateway-servicewaits for:- discovery-server (healthy)
The discovery server includes a health check:
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8761/actuator/health"]
interval: 10s
retries: 5
start_period: 30s- Docker
- Java 21
From project root:
docker compose -f compose.dev.yml up -dThis will:
- Build all modules
- Create Docker images
- Start all services
- Attach databases
- Register services with Eureka
docker compose -f compose.dev.yml up {service-name} -dExample:
docker compose -f compose.dev.yml up auth-service -dCreate a .env file in the project root:
# Auth Database
AUTH_POSTGRES_DB_NAME=authdb
AUTH_POSTGRES_USERNAME=authuser
AUTH_POSTGRES_PASSWORD=authpass
AUTH_POSTGRES_PORT=5433
# Todo Database
TODO_POSTGRES_DB_NAME=tododb
TODO_POSTGRES_USERNAME=todouser
TODO_POSTGRES_PASSWORD=todopass
TODO_POSTGRES_PORT=5434
# Security
JWT_SECRET=your-super-secret-key
root/
├── discovery-server/
├── auth-service/
├── todo-service/
├── gateway-service/
├── docker-compose.yml
├── pom.xml
└── .env
- Enable hot reloading inside Docker
- Implement Role-Based Access Control (RBAC)
- Add attachment uploads (SFTP + async processing)
- Introduce automated tests (move toward TDD)
- Add OpenAPI documentation
- Centralized logging & tracing
- Follow outbox pattern
- CI/CD pipeline
- Database per service
- Externalized configuration
- Service discovery
- API gateway pattern
- Containerized deployment
- Fault-aware startup order