Skip to main content

Business Microservices

Sistema de Ventas consists of 8 business microservices, each responsible for a specific domain:

Auth Service

Authentication, authorization, user and role management

Catalogo Service

Product catalog, categories, and inventory management

Cliente Service

Customer information and management

Venta Service

Sales transactions and order processing

Compra Service

Purchase orders and supplier transactions

Pedido Service

Customer orders and order fulfillment

Pagos Service

Payment methods and processing

Proveedor Service

Supplier information and management

Auth Service (jea-auth-service)

Overview

Handles authentication, authorization, user management, and role-based access control.

Technical Details

  • Port: Dynamic (configured via environment)
  • Database: MySQL (auth-jea)
  • API Routes: /auth/**, /usuario/**, /rol/**
  • Authentication: JWT-based with configurable secret

Key Entities

Usuario (User)

@Entity
public class Usuario {
    private Long id;
    private String nombres;
    private String apellidoPaterno;
    private String apellidoMaterno;
    private String dni;
    private String direccion;
    private String telefono;
    private Boolean estado;
    
    @OneToOne
    private AuthUser authUser;
}

AuthUser (Authentication User)

  • Username
  • Password (encrypted)
  • Email
  • Active status

Rol (Role)

  • Role name
  • Description
  • Permissions

Acceso (Access/Permission)

  • Access name
  • Resource
  • Action

Relationships

  • UsuarioAuthUser: One-to-One
  • UsuarioRol: Many-to-Many (via UsuarioRol)
  • RolAcceso: Many-to-Many (via AccesoRol)

Responsibilities

  • User registration and profile management
  • Login and JWT token generation
  • Role and permission management
  • Access control validation
  • User authentication and authorization

Catalogo Service (jea-catalogo-service)

Overview

Manages product catalog, categories, and inventory levels.

Technical Details

  • Port: Dynamic
  • Database: MySQL (catalogo-ms)
  • API Routes: /categoria/**, /producto/**, /imagenes/**
  • Protected: Requires authentication (AuthFilter)

Key Entities

Producto (Product)

@Entity
public class Producto {
    private Long id;
    private String codigo;          // Unique product code
    private String nombre;          // Product name (unique)
    private String descripcion;
    private Integer cantidad;       // Stock quantity
    private Double precioVenta;     // Sale price
    private Double costoCompra;     // Purchase cost
    private boolean estado;         // Active status
    private LocalDateTime fechaCreacion;
    private LocalDateTime fechaActualizacion;
    private String imagen;          // Image path
    
    @ManyToOne
    private Categoria categoria;
}

Categoria (Category)

@Entity
public class Categoria {
    private Long id;
    private String nombre;          // Unique category name
    private String descripcion;
    private boolean estado;
    private LocalDateTime fechaCreacion;
}

Responsibilities

  • Product CRUD operations
  • Category management
  • Inventory tracking
  • Product search and filtering
  • Product image management
  • Stock level updates

Business Rules

  • Product codes and names must be unique
  • Default quantity is 0 for new products
  • Timestamps are automatically managed
  • Products are associated with a single category

Cliente Service (jea-cliente-service)

Overview

Manages customer information and profiles.

Technical Details

  • Port: Dynamic
  • Database: PostgreSQL (cliente-jea)
  • API Routes: /cliente/**
  • Protected: Requires authentication

Key Entities

Cliente (Customer)

@Entity
public class Cliente {
    private Long id;
    private String dni;             // Unique identifier
    private String nombre;
    private String apellido;
    private String direccion;
    private String telefono;
    private String email;           // Unique
    private LocalDateTime fechaRegistro;
    private Boolean activo;
}

Responsibilities

  • Customer registration
  • Customer profile management
  • Customer search and listing
  • Customer status management (active/inactive)

Business Rules

  • DNI must be unique
  • Email must be unique
  • Registration date is automatically set
  • Customers are active by default

Venta Service (jea-venta-service)

Overview

Handles sales transactions and manages the complete sales workflow.

Technical Details

  • Port: Dynamic
  • Database: MySQL (venta-jea)
  • API Routes: /venta/**
  • Protected: Requires authentication
  • Circuit Breaker: Configured for Cliente and Pedido services

Key Entities

Venta (Sale)

@Entity
public class Venta {
    private Integer id;
    private String serie;           // Auto-generated (3 letters)
    private String numero;          // Auto-generated (6 digits)
    private String descripcion;
    private Long clienteId;
    
    @Transient
    private Cliente cliente;        // From Cliente Service
    
    @OneToMany(cascade = CascadeType.ALL)
    private List<VentaDetalle> detalle;
    
    private LocalDateTime fechaVenta;
    private Double baseImponible;   // Taxable base
    private Double igv;             // 18% tax
    private Double total;
    private Long formapagoId;
    
    @Transient
    private FormaPago formaPago;    // From Pagos Service
}

VentaDetalle (Sale Detail)

@Entity
public class VentaDetalle {
    private Integer id;
    private Double cantidad;
    private Double precio;
    private Double baseImponible;
    private Double igv;
    private Double total;
    private Long productoId;
    
    @Transient
    private Producto producto;      // From Catalogo Service
}

Service Integration (Feign Clients)

  • ClienteFeign: Fetches customer information
  • ProductoFeign: Fetches product details and updates stock
  • FormaPagoFeign: Fetches payment method information
  • CategoriaFeign: Fetches category information

Responsibilities

  • Create and manage sales
  • Calculate tax and totals (18% IGV)
  • Generate unique series and numbers
  • Update product inventory
  • Track sales history
  • Sales reporting and analytics

Business Rules

  • Serie and número are auto-generated and unique
  • Tax calculation: Base = Price / 1.18, IGV = Price - Base
  • Totals are automatically calculated from line items
  • Inventory is updated upon sale completion

Compra Service (jea-compra-service)

Overview

Manages purchase orders from suppliers.

Technical Details

  • Port: Dynamic
  • Database: MySQL (compra-jea)
  • API Routes: /compra/**
  • Protected: Requires authentication
  • Circuit Breaker: Configured for external services

Key Entities

Compra (Purchase)

@Entity
public class Compra {
    private Long id;
    private String serie;           // Auto-generated
    private String numero;          // Auto-generated
    private String descripcion;
    private Long proveedorId;
    
    @Transient
    private Proveedor proveedor;    // From Proveedor Service
    
    @OneToMany(cascade = CascadeType.ALL)
    private List<CompraDetalle> detalle;
    
    private LocalDateTime fechaCompra;
    private Double baseImponible;
    private Double igv;             // 18% tax
    private Double total;
    private Long formapagoId;
    
    @Transient
    private FormaPago formaPago;    // From Pagos Service
}

CompraDetalle (Purchase Detail)

@Entity
public class CompraDetalle {
    private Integer id;
    private Double cantidad;
    private Double precio;
    private Double baseImponible;
    private Double igv;
    private Double total;
    private Long productoId;
    
    @Transient
    private Producto producto;      // From Catalogo Service
}

Service Integration

  • ProveedorFeign: Fetches supplier information
  • ProductoFeign: Updates product stock and cost
  • FormaPagoFeign: Fetches payment method

Responsibilities

  • Create and manage purchase orders
  • Calculate costs and taxes
  • Update product inventory upon receipt
  • Track purchase history
  • Supplier order management

Pedido Service (jea-pedido-service)

Overview

Manages customer orders and order fulfillment workflow.

Technical Details

  • Port: Dynamic
  • Database: MySQL (pedido-jea)
  • API Routes: /pedido/**
  • Protected: Requires authentication
  • Circuit Breaker: Configured

Key Entities

Pedido (Order)

@Entity
public class Pedido {
    private Integer id;
    private String codigo;
    private String serie;
    private String descripcion;
    private String estado;          // PENDIENTE, EN_PROCESO, COMPLETADO, etc.
    private Long clienteId;
    
    @Transient
    private Cliente cliente;
    
    @OneToMany(cascade = CascadeType.ALL)
    private List<PedidoDetalle> detalle;
    
    private LocalDateTime fechaPedido;
    private LocalDate fechaEntrega; // Delivery date (default: 1 week)
    private Double baseImponible;
    private Double igv;
    private Double total;
    private Long formapagoId;
    
    @Transient
    private FormaPago formaPago;
}

PedidoDetalle (Order Detail)

  • Similar structure to VentaDetalle and CompraDetalle
  • Links to products via productoId

Responsibilities

  • Create and manage customer orders
  • Track order status (pending, processing, completed)
  • Schedule delivery dates
  • Calculate order totals
  • Order fulfillment workflow

Business Rules

  • Default estado is “PENDIENTE”
  • Delivery date defaults to 1 week after order date
  • Tax calculations follow same rules as Venta

Pagos Service (jea-pagos-service)

Overview

Manages payment methods and processing.

Technical Details

  • Port: Dynamic
  • Database: MySQL (pagos-ms)
  • API Routes: /pagos/**
  • Protected: Requires authentication

Key Entities

FormaPago (Payment Method)

@Entity
public class FormaPago {
    private Long id;
    private String nombre;          // Payment method name
}

Supported Payment Methods

  • Efectivo (Cash)
  • Transferencia Bancaria (Bank Transfer)
  • Cheque (Check)
  • Tarjeta de Crédito (Credit Card)
  • Tarjeta de Débito (Debit Card)
  • Depósito Bancario (Bank Deposit)
  • Letra de Cambio (Bill of Exchange)
  • Pagaré (Promissory Note)

Responsibilities

  • Manage payment method catalog
  • Provide payment method information to other services
  • Payment method CRUD operations

Proveedor Service (jea-proveedor-service)

Overview

Manages supplier information and relationships.

Technical Details

  • Port: Dynamic
  • Database: PostgreSQL (proveedor-jea)
  • API Routes: /proveedor/**
  • Protected: Requires authentication

Key Entities

Proveedor (Supplier)

@Entity
public class Proveedor {
    private Long id;
    private String ruc;             // Tax ID
    private String nombre;          // Company name
    private String telefono;
    private String direccion;
    private String correo;          // Email
    private Boolean estado;         // Active status
}

Responsibilities

  • Supplier registration and management
  • Supplier information lookup
  • Supplier status management
  • Supplier contact information

Business Rules

  • Suppliers are active by default
  • RUC serves as unique identifier

Inter-Service Communication

Service Dependencies

Circuit Breaker Configuration

All transaction services (Venta, Compra, Pedido) implement Resilience4j circuit breakers:
resilience4j.circuitbreaker:
  instances:
    orderByIdCB:
      registerHealthIndicator: true
      slidingWindowSize: 10
      permittedNumberOfCallsInHalfOpenState: 3
      slidingWindowType: TIME_BASED
      minimumNumberOfCalls: 4
      waitDurationInOpenState: 5s
      failureRateThreshold: 50
      eventConsumerBufferSize: 10

Fallback Mechanisms

Each Feign client provides fallback methods for graceful degradation:
  • Returns default/placeholder data when service is unavailable
  • Logs errors for monitoring
  • Maintains system availability despite partial failures

API Documentation

All services expose OpenAPI/Swagger documentation:
  • Swagger UI Path: /doc/swagger-ui.html
  • API Docs: SpringDoc OpenAPI enabled
  • Access via Gateway: http://localhost:8085/{service-path}/doc/swagger-ui.html

Next Steps

Infrastructure

Learn about Gateway, Registry, and Config Server

Database Design

Explore database schemas and structure

Build docs developers (and LLMs) love