Infrastructure Overview
Sistema de Ventas uses Spring Cloud infrastructure components to provide service discovery, API gateway, and centralized configuration management.API Gateway
Spring Cloud Gateway for routing and authentication
Service Registry
Eureka Server for service discovery
Config Server
Centralized configuration management
API Gateway (jea-gateway-server)
Overview
Spring Cloud Gateway serves as the single entry point for all client requests, providing routing, load balancing, and security.Technical Configuration
CORS Configuration
Configured to allow requests from the Angular frontend:Route Configuration
The gateway defines explicit routes for each microservice:Authentication Routes (No Filter)
Catalogo Service Routes
Cliente Service Routes
Pagos Service Routes
Venta Service Routes
Pedido Service Routes
Compra Service Routes
Proveedor Service Routes
Gateway Features
Load Balancing
- Uses Eureka service discovery
- Client-side load balancing
lb://URI scheme for service lookup- Automatic failover
Authentication Filter
- JWT token validation
- Applied to all routes except
/auth/** - Custom AuthFilter implementation
- Unauthorized request rejection
Service Discovery
- Dynamic route resolution
- No hardcoded service endpoints
- Automatic service detection
- Health-based routing
Path-Based Routing
- Routes based on URL patterns
- RESTful path matching
- Wildcard support (
/**) - Multiple paths per service
Request Flow
Gateway Benefits
- Single Entry Point: Simplifies client configuration
- Security: Centralized authentication enforcement
- Abstraction: Hides internal service structure
- Flexibility: Easy to add/remove services
- Monitoring: Single point for request logging
- Rate Limiting: Can add rate limiting filters
Service Registry (jea-registry-server)
Overview
Netflix Eureka Server provides service discovery, enabling microservices to find and communicate with each other dynamically.Technical Configuration
Service Registration
All microservices register with Eureka on startup:Registered Services
Business Services
jea-auth-servicejea-catalogo-servicejea-cliente-servicejea-venta-servicejea-compra-servicejea-pedido-servicejea-pagos-servicejea-proveedor-service
Infrastructure Services
jea-gateway-server- Config Server (if registered)
Service Discovery Flow
Instance Identification
Each service instance has a unique ID:jea-venta-service:8f3a2b1c
Eureka Dashboard
Access the Eureka dashboard at:- Registered services
- Instance count per service
- Health status
- Service metadata
- Recent registrations/cancellations
High Availability
For production environments:- Deploy multiple Eureka servers
- Configure peer-to-peer replication
- Update
defaultZonewith all Eureka instances
Service Registry Benefits
Dynamic Discovery
- No hardcoded service URLs
- Automatic service detection
- Supports multiple instances
- Zero-downtime deployments
Health Management
- Automatic health checks
- Failed instance removal
- Self-healing architecture
- Service availability tracking
Load Balancing
- Client-side load balancing
- Round-robin by default
- Instance selection strategies
- Weighted routing support
Resilience
- Handles service failures
- Quick failure detection
- Instance eviction
- Self-preservation mode
Config Server (jea-config-server)
Overview
Spring Cloud Config Server provides centralized external configuration management for all microservices.Configuration Repository
All service configurations are stored in YAML files:Configuration Structure
Each service configuration includes:Server Configuration
Database Configuration
Service Discovery Configuration
Database Configuration by Service
- MySQL Services
- PostgreSQL Services
- Auth:
auth-jea - Catalogo:
catalogo-ms - Venta:
venta-jea - Compra:
compra-jea - Pedido:
pedido-jea - Pagos:
pagos-ms
Environment-Specific Configuration
Supports multiple environments:- Development (local)
- Testing
- Production
jea-venta-service.yml(default)jea-venta-service-dev.yml(development)jea-venta-service-prod.yml(production)
Dynamic Port Assignment
All services use dynamic ports by default:0= random available port- Set
PORTorSERVER_PORTenvironment variable for fixed port - Gateway uses fixed port
8085 - Registry uses fixed port
8090
Config Server Benefits
Centralization
- Single source of truth
- All configs in one place
- Easy to manage and update
- Version control friendly
Environment Management
- Profile-based configuration
- Environment-specific settings
- Easy environment promotion
- Consistent configuration structure
Dynamic Updates
- Configuration refresh without restart
- Spring Cloud Bus integration
- Webhook support
- Immediate propagation
Security
- Encrypted properties support
- Secret management
- Access control
- Audit trail
Infrastructure Architecture
Deployment Considerations
Local Development
- Start Eureka Server (Port 8090)
- Start Config Server
- Start API Gateway (Port 8085)
- Start Business Services (dynamic ports)
- Start Frontend (Port 4200)
Docker Deployment
Environment Variables
- Required Variables
- Database Variables
- Security Variables
EUREKA_URI: Eureka server URLPORTorSERVER_PORT: Service port (optional)
Monitoring and Management
Health Endpoints
All services expose Spring Boot Actuator endpoints:/actuator/health: Service health/actuator/info: Service information/actuator/metrics: Service metrics
Circuit Breaker Monitoring
Resilience4j health indicators:- Circuit breaker states
- Failure rates
- Call statistics
API Documentation
Each service provides Swagger UI:- Path:
/doc/swagger-ui.html - Accessible via Gateway
Next Steps
Database Design
Explore database schemas and initialization
Microservices
Review all business microservices