Documentation Index
Fetch the complete documentation index at: https://mintlify.com/stevenrq/sgivu/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SGIVU is designed for deployment on AWS infrastructure with a microservices architecture orchestrated by Docker Compose. The recommended production setup uses a private VPC with publicly exposed services behind an Application Load Balancer (ALB) and Nginx reverse proxy.Infrastructure Components
Suggested AWS Architecture
- VPC: Private network with public and private subnets
- EC2/ECS/EKS: Container orchestration (EC2 with Docker Compose is the baseline)
- RDS: Managed PostgreSQL and MySQL instances
- S3: Static frontend hosting and vehicle image storage
- ALB: Application Load Balancer for HTTPS termination and traffic distribution
- Nginx: Reverse proxy for routing and service isolation
Service Ports
Development (docker-compose.dev.yml)
| Service | Port | Public Access |
|---|---|---|
| sgivu-gateway | 8080 | Yes (via Nginx) |
| sgivu-auth | 9000 | Yes (via Nginx) |
| sgivu-config | 8888 | No |
| sgivu-discovery (Eureka) | 8761 | Debug only |
| sgivu-user | 8081 | No |
| sgivu-client | 8082 | No |
| sgivu-vehicle | 8083 | No |
| sgivu-purchase-sale | 8084 | No |
| sgivu-ml | 8000 | No |
| sgivu-zipkin | 9411 | Debug only |
| PostgreSQL | 5432 | No |
| MySQL | 3306 | No |
| Redis | 6379 | No |
Production (docker-compose.yml)
In production, only Gateway (8080) and Auth (9000) are exposed via Nginx on port 80/443. All other services have no port mappings and are accessible only within thesgivu-network Docker bridge network.
Deployment Patterns
Nginx as Single Entry Point
Nginx acts as the sole public entry point (configured ininfra/nginx/sites-available/default.conf):
- Auth Server (port 9000): Routes
/login,/oauth2/*,/.well-known/*for OIDC flows - Gateway (port 8080): Routes
/v1/*for business APIs and/auth/sessionfor BFF session management - Frontend: S3 bucket serves as catch-all fallback for Angular SPA
- Independent scaling of Auth and Gateway services
- Simplified firewall rules (only 80/443 exposed)
- Isolation of authentication lifecycle from business APIs
BFF Pattern (Backend For Frontend)
The Gateway implements the BFF pattern:- Stores
access_tokenandrefresh_tokenin server-side sessions (backed by Redis) - Frontend never handles tokens directly (XSS protection)
- Session cookie is
HttpOnly,SameSite=Lax
~/workspace/source/README.md:49-61 for Redis configuration details.
Network Architecture
Docker Networking
All services communicate through thesgivu-network bridge network:
Service Discovery
Eureka Discovery Service (sgivu-discovery:8761) provides service registration and discovery:
- Gateway uses
lb://service-namerouting via Eureka - Services register themselves on startup
- Health checks prevent routing to unhealthy instances
Internal Communication
Service-to-service calls use:- JWT Bearer tokens (relayed by Gateway for user-initiated requests)
X-Internal-Service-Keyheader for internal service calls without user context
Environment Configuration
Configuration Profiles
- Development:
.env.dev→docker-compose.dev.yml - Production:
.env→docker-compose.yml
SPRING_PROFILES_ACTIVE selects the appropriate YAML overlay from Config Server:
dev→ loads{service}-dev.ymlprod→ loads{service}-prod.yml
Config Server
Centralized configuration viasgivu-config (port 8888):
Development mode (native profile):
Critical Environment Variables
See Environment Reference for complete details. Key variables:| Variable | Purpose | Impact if Misconfigured |
|---|---|---|
ISSUER_URL ↔ SGIVU_AUTH_URL | JWT issuer validation | All JWT tokens rejected (total auth failure) |
REDIS_PASSWORD | Gateway session storage | No sessions = no authentication |
SERVICE_INTERNAL_SECRET_KEY | Internal service calls | Service-to-service calls fail (401/403) |
SGIVU_GATEWAY_SECRET | OAuth2 client secret | Authorization code exchange fails |
Data Persistence
Volume Mounts
sgivu_auth_db(OAuth2 clients, authorizations, sessions)sgivu_user_db(users, roles, permissions)sgivu_client_db(clients/customers data)sgivu_vehicle_db(vehicle inventory)sgivu_purchase_sale_db(transactions)sgivu_ml_db(ML model artifacts, predictions)
Deployment Steps
Initial Setup
-
Prepare environment file:
-
Configure AWS resources:
- Create RDS instances for PostgreSQL and MySQL
- Set up S3 buckets for frontend and vehicle images
- Configure ALB and security groups
- Update
.envwith AWS endpoints and credentials
-
Build and push images (if not using pre-built
stevenrq/*images): -
Deploy to EC2:
Zero-Downtime Updates
Update a single service without downtime:- Rebuilds/pulls the service image
- Recreates only that container
- Leaves other services running
Scaling Horizontally
To scale a service (e.g., Gateway for high traffic):Gateway can scale horizontally because sessions are stored in Redis (shared state). Other services can also scale if made stateless.
Security Considerations
Secrets Management
- Store
.envsecurely on deployment server - Use
chmod 400for SSH keys (clave.pem) - Rotate
JWT_KEYSTORE_PASSWORDandSERVICE_INTERNAL_SECRET_KEYregularly - Use AWS IAM roles instead of hardcoded
AWS_ACCESS_KEY/AWS_SECRET_KEYwhen possible
Network Security
- Place EC2 instances in private subnets
- Only ALB should be in public subnet
- Configure security groups to allow:
- Inbound: ALB → EC2 (80/443)
- Outbound: EC2 → RDS, S3, VPC endpoints
- Internal: Services within
sgivu-network
Service Hardening
- Expose Eureka (
/eureka/) and Zipkin (/zipkin/) only via VPN or IP whitelist - Enable HTTPS/TLS termination at ALB
- Use AWS WAF for rate limiting and DDoS protection
- Restrict actuator endpoints (
/actuator/*) to internal network
Monitoring Deployment Health
Service Startup Order
Services havedepends_on relationships ensuring correct startup:
- Databases:
sgivu-postgres,sgivu-mysql,sgivu-redis - Infrastructure:
sgivu-config,sgivu-discovery - Auth:
sgivu-auth - Services:
sgivu-user,sgivu-client,sgivu-vehicle,sgivu-purchase-sale - Gateway:
sgivu-gateway(depends on auth + redis) - ML:
sgivu-ml(depends on all services)
Verify Deployment
Troubleshooting
Port Conflicts
Problem:Error: port 8080 is already allocated
Solution:
Config Server Unreachable
Problem: Services fail to start with config errors Solution:- Verify
SPRING_CLOUD_CONFIG_URIpoints tohttp://sgivu-config:8888 - Check Config Server logs:
docker compose logs sgivu-config - For Git profile, verify repository URL and credentials
- For native profile, verify volume mount:
../../../../sgivu-config-repo:/config-repo
Service Not Registering with Eureka
Problem: Gateway returns 503 for API calls Solution:- Check
EUREKA_URL=http://sgivu-discovery:8761/eureka - Verify service can reach Eureka:
docker compose exec sgivu-user curl sgivu-discovery:8761 - Check Eureka UI for registered instances
JWT Validation Failures
Problem: All API calls return 401 Unauthorized Solution:- Ensure
ISSUER_URLandSGIVU_AUTH_URLare identical - In production, both should be
http://your-ec2-hostname(not internal Docker hostnames) - Verify
extra_hostsin docker-compose maps EC2 hostname tohost-gateway - Check Auth Server is reachable at
/.well-known/openid-configuration
Redis Connection Failures
Problem: Gateway fails to start with “Unable to connect to Redis” Solution:- Verify
REDIS_PASSWORDmatches between Redis container and Gateway config - Check Redis is running:
docker compose ps sgivu-redis - Test connection:
docker compose exec sgivu-redis redis-cli -a "$REDIS_PASSWORD" ping
Rollback Procedures
Rollback Single Service
Full Stack Rollback
Database Rollback
Flyway migrations are versioned. To rollback:- Restore database from backup
- Deploy service version matching database schema
Next Steps
- Docker Compose Configuration: Detailed compose file reference
- Nginx Configuration: Reverse proxy setup and routing rules
- Monitoring Setup: Observability and distributed tracing