Overview
The Customer Service (jea-cliente) manages customer master data including personal information, contact details, and customer lifecycle. It provides customer information to Sales and Orders services. Database: PostgreSQL (cliente-db)
Port: Dynamic (configured via Eureka)
Core Entities
Cliente
Customer master data. Location:jea-cliente/src/main/java/com/example/mscliente/entity/Cliente.java:12
Fields:
id(Long) - Primary keydni(String) - National identification number (unique, required)nombre(String) - First name (required)apellido(String) - Last namedireccion(String) - Addresstelefono(String) - Phone numberemail(String) - Email address (unique, required)fechaRegistro(LocalDateTime) - Registration timestamp (auto-generated)activo(Boolean) - Active status (default: true)
cliente
Unique Constraints:
dni- Each customer must have unique identificationemail- Each customer must have unique email
@PrePersist- SetsfechaRegistroto current timestamp andactivoto true
Key Components
Controllers
ClienteController
Location:jea-cliente/src/main/java/com/example/mscliente/controller/ClienteController.java:13
Endpoints:
POST /cliente- Create new customerGET /cliente/{id}- Get customer by IDGET /cliente/dni/{dni}- Get customer by DNIGET /cliente- List all customersPUT /cliente/{id}- Update customerDELETE /cliente/{id}- Delete customer
- DNI-based customer lookup
- Full CRUD operations
- Standard REST conventions
Services
ClienteService
Location:jea-cliente/src/main/java/com/example/mscliente/service/ClienteService.java
Implementation: ClienteServiceImpl.java
Key Methods:
guardarCliente()- Create new customerobtenerClientePorId()- Find by IDobtenerClientePorDni()- Find by DNIobtenerTodosLosClientes()- List all customersactualizarCliente()- Update customer informationeliminarCliente()- Delete customer
Repositories
ClienteRepository
Location:jea-cliente/src/main/java/com/example/mscliente/repository/ClienteRepository.java
Extends JpaRepository<Cliente, Long>
Provides custom query methods:
findByDni()- Lookup customer by DNIfindByEmail()- Lookup customer by email
Dependencies
Spring Boot Version: 3.1.3 Spring Cloud Version: 2022.0.2 Key Dependencies:spring-boot-starter-data-jpa- JPA/Hibernatespring-boot-starter-web- REST APIspring-boot-starter-validation- Bean validationspring-cloud-starter-netflix-eureka-client:4.0.3- Service discoveryspring-cloud-starter-config:4.0.4- Centralized configurationspringdoc-openapi-starter-webmvc-ui:2.0.2- OpenAPI/Swagger UIpostgresql- PostgreSQL driverlombok- Code generation
Configuration
Config File:config-data/jea-cliente-service.yml
Key Settings:
Database Schema
Main Tables:cliente- Customer master data- Primary key:
id - Unique constraints:
dni,email - Indexes: On
dniandemailfor fast lookups
- Primary key:
Key Features
- Customer master data management
- Unique identification by DNI and email
- Active/inactive status tracking
- Registration timestamp tracking
- DNI-based customer search
- Email uniqueness validation
- PostgreSQL database (vs MySQL in other services)
- OpenAPI/Swagger documentation
- Eureka service discovery integration
- Centralized configuration via Config Server
Integration Points
Consumed by:
- Sales Service - Fetches customer data for sales transactions via
ClienteFeign - Orders Service - Retrieves customer information for orders via
ClienteFeign
APIs Exposed:
- Customer CRUD operations
- Customer lookup by ID
- Customer search by DNI
- Customer listing
Usage Pattern
Other services reference customers by ID:Validation Rules
DNI (National ID)
- Must be unique across all customers
- Required field
- Used for customer identification and lookup
- Must be unique across all customers
- Required field
- Used for customer communication
Customer Status
activo = true- Customer can make purchases and ordersactivo = false- Customer is deactivated (soft delete)
Data Privacy Considerations
Personal Information
The Customer service stores sensitive personal data:- National identification (DNI)
- Contact information (phone, email, address)
- Must comply with data protection regulations
Best Practices
- Implement access control at API Gateway level
- Log access to customer data for audit trails
- Consider encryption for sensitive fields (DNI)
- Implement data retention policies
- Support GDPR/data privacy requests (right to be forgotten)
Database Choice: PostgreSQL
Why PostgreSQL?
- Data Integrity - Strong ACID compliance for customer data
- Advanced Features - Better support for complex queries if needed
- JSON Support - Can store additional customer metadata
- Polyglot Persistence - Demonstrates flexibility in microservices
Comparison with Other Services
| Service | Database | Reason |
|---|---|---|
| Customer | PostgreSQL | Strong data integrity, personal data |
| Supplier | PostgreSQL | Similar to customer requirements |
| Others | MySQL | Transactional data, lighter weight |
Future Enhancements
Potential additions:- Customer segmentation (VIP, regular, etc.)
- Customer credit limits
- Multiple addresses (billing, shipping)
- Customer notes or comments
- Purchase history summary (from Sales service)
- Customer loyalty points
- Marketing preferences (newsletter opt-in)
- Customer groups or classifications