# briansilent/mejorarecibocaducidades architecture

> Architecture diagram of the GitHub repository briansilent/mejorarecibocaducidades, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/briansilent/mejorarecibocaducidades
- Repository: https://github.com/briansilent/mejorarecibocaducidades

## Overview

1. **Overall shape**
   - This is a two-tier system: a **Spring Boot 3.5 backend** and a **React/Vite frontend**.
   - The backend exposes a REST API under `/api`; the frontend is a separate client that consumes those endpoints.
   - Persistent state lives in **PostgreSQL**.

2. **Backend architecture style**
   - The backend follows a classic layered design:
     **Controller → Service → Repository → Database**
   - Domain logic is concentrated in services, while controllers are thin HTTP adapters.
   - Data passed across the API boundary is mostly shaped with **DTOs**, not entities.

3. **Main business domains**
   - The codebase is organized around several warehouse/logistics domains:
     - **Producto**: master product catalog
     - **Inventario**: stock, alerts, movements, expiry handling
     - **Recepción**: warehouse receiving workflow
     - **Recepción CEDIS**: inbound truck/CEDIS receiving with discrepancies
     - **RPC**: transport cycle control for delivery/return tracking
     - **Orden Compra**: purchase orders
     - **Surtido / Auditoría / Discrepancias**: picking, audit, and mismatch tracking
     - **Dashboard**: aggregated operational KPIs

4. **Primary request flow**
   - A frontend screen calls a controller endpoint.
   - The controller delegates to a domain service.
   - The service reads/writes through Spring Data repositories.
   - Repositories persist JPA entities to PostgreSQL.
   - Responses are returned as DTOs or wrapped API responses, keeping entity internals out of the API.

5. **Security boundary**
   - Authentication is JWT-based.
   - `AuthController`, `JwtService`, `CustomUserDetailsService`, `JwtAuthFilter`, and `SecurityConfig` form the security subsystem.
   - The JWT filter sits in the request path before business controllers, so authenticated and role-protected endpoints are enforced centrally.
   - `Usuario` and `Role` are part of the identity model.

6. **Inventory and expiry intelligence**
   - Inventory is not just stock counting; it includes **expiry-aware alerting** and movement tracking.
   - `AlertaService`, `AlertaCaducidadSheduler`, and inventory-related DTOs/repositories indicate automated detection of near-expiry or expired goods.
   - Inventory updates likely cascade into movement records via `MovimientoInventarioService` and `MovimientoInventarioRepository`.

7. **Receiving and discrepancy processing**
   - The receiving flow is split between regular recepciones and CEDIS-specific recepciones.
   - CEDIS receiving appears to validate physical receipt against expected shipment data, generating **discrepancies** when counts or conditions differ.
   - `DiscrepanciaService`, `DiscrepanciaRecepcion`, and related controllers/repositories form the audit trail for mismatches.

8. **RPC logistics module**
   - The RPC subsystem is a separate operational track for transport control.
   - It has its own controller, service, model, repository, and DTOs, suggesting it is a first-class workflow rather than a small feature.
   - The readme’s endpoints imply lifecycle management: delivery, return, pending closures, and summaries.

9. **Data model boundaries**
   - `Model` contains the JPA entities that map directly to persisted business objects.
   - `DTO` contains API-facing shapes for requests, responses, and summaries.
   - `mapper` classes convert between entity and DTO forms for selected domains such as inventario, producto, and recepcion.

10. **Error handling and API consistency**
   - `GlobalExceptionHandler` and `ErrorResponse` provide centralized exception translation.
   - This means controllers likely return consistent error payloads instead of exposing stack traces or ad hoc failures.

11. **Frontend boundary**
   - The frontend is a Vite-built React app with pages for login, dashboard, inventory, recepciones, discrepancies, and RPC control.
   - It is a client-driven UI that calls the backend API rather than containing core business logic.
   - `PrivateRoute` suggests protected navigation based on authentication state.

12. **Infrastructure and deployment**
   - The backend is containerized with a `Dockerfile`, and the repo includes `docker-compose.yml` for local orchestration.
   - The readme states the backend container connects to a PostgreSQL instance on the host via `host.docker.internal:5432`.
   - This means the DB is an external runtime dependency rather than another service managed inside the backend codebase.

13. **What to show in an architecture diagram**
   - Show the frontend as a separate client.
   - Show JWT auth as a cross-cutting gate in front of all protected backend endpoints.
   - Show the backend split into domain modules, each with controller/service/repository layers.
   - Show PostgreSQL as the single system of record.
   - Show the scheduler as a background actor feeding inventory alert logic.

Main entry points: [`Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller`](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller) (REST API), [`Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Service`](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Service) (Services), [`Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/InventarioController.java`](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/InventarioController.java) (Inventario), [`Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionController.java`](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionController.java) (Recepción)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui["React app<br/>client<br/>[App.jsx]"]
  node_login["Login<br/>page<br/>[Login.jsx]"]
  node_dash["Dashboard<br/>page<br/>[Dashboard.jsx]"]
  node_invpage["Inventario<br/>page<br/>[Inventario.jsx]"]
  node_recvpage["Recepción<br/>page<br/>[Recepcion.jsx]"]
  node_cedispage["Recepción CEDIS<br/>page<br/>[RecepcionCedis.jsx]"]
  node_rpcpage["RPC Control<br/>page<br/>[RpcControl.jsx]"]
end

subgraph group_backend["Backend"]
  node_api["REST API<br/>spring api"]
  node_auth{{"Auth<br/>security"}}
  node_producto["Producto<br/>domain module"]
  node_inventario["Inventario<br/>domain module"]
  node_recepcion["Recepción<br/>domain module"]
  node_cedis["Recepción CEDIS<br/>domain module"]
  node_rpc["RPC<br/>domain module<br/>[RpcController.java]"]
  node_ordensurt["Orden/Surtido<br/>domain module"]
  node_dashboard["Dashboard<br/>domain module"]
  node_dto["DTOs<br/>api models"]
  node_services["Services<br/>business logic"]
  node_repos[("Repositories<br/>persistence")]
  node_models["Entities<br/>jpa model"]
  node_scheduler(("Expiry job<br/>background job"))
  node_errors{{"Errors<br/>exception handling"}}
end

subgraph group_infra["Infrastructure"]
  node_db[("PostgreSQL<br/>database")]
end

node_ui -->|"login"| node_auth
node_ui -->|"calls"| node_api
node_login -->|"auth flow"| node_auth
node_dash -->|"data"| node_dashboard
node_invpage -->|"data"| node_inventario
node_recvpage -->|"data"| node_recepcion
node_cedispage -->|"data"| node_cedis
node_rpcpage -->|"data"| node_rpc
node_api -->|"secured by"| node_auth
node_api -->|"routes"| node_producto
node_api -->|"routes"| node_inventario
node_api -->|"routes"| node_recepcion
node_api -->|"routes"| node_cedis
node_api -->|"routes"| node_rpc
node_api -->|"routes"| node_ordensurt
node_api -->|"routes"| node_dashboard
node_producto -->|"delegates"| node_services
node_inventario -->|"delegates"| node_services
node_recepcion -->|"delegates"| node_services
node_cedis -->|"delegates"| node_services
node_rpc -->|"delegates"| node_services
node_services -->|"reads/writes"| node_repos
node_repos -->|"maps"| node_models
node_models -->|"persists"| node_db
node_services -->|"shapes"| node_dto
node_scheduler -->|"triggers"| node_inventario
node_scheduler -->|"runs"| node_services
node_api -->|"handles"| node_errors

click node_ui "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/App.jsx"
click node_login "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Login.jsx"
click node_dash "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Dashboard.jsx"
click node_invpage "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Inventario.jsx"
click node_recvpage "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Recepcion.jsx"
click node_cedispage "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/RecepcionCedis.jsx"
click node_rpcpage "https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/RpcControl.jsx"
click node_api "https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller"
click node_auth "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Config/SecurityConfig.java"
click node_producto "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/ProductoController.java"
click node_inventario "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/InventarioController.java"
click node_recepcion "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionController.java"
click node_cedis "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionCedisController.java"
click node_rpc "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RpcController.java"
click node_ordensurt "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/OrdenCompraController.java"
click node_dashboard "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/DashboardController.java"
click node_dto "https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/DTO"
click node_services "https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Service"
click node_repos "https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Repository"
click node_models "https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Model"
click node_scheduler "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Sheduler/AlertaCaducidadSheduler.java"
click node_errors "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/exception/GlobalExceptionHandler.java"
click node_db "https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/resources/application.properties"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui,node_login,node_dash,node_invpage,node_recvpage,node_cedispage,node_rpcpage toneBlue
class node_api,node_auth,node_producto,node_inventario,node_recepcion,node_cedis,node_rpc,node_ordensurt,node_dashboard,node_dto,node_services,node_repos,node_models,node_scheduler,node_errors toneAmber
class node_db toneMint
```

## Components

### Frontend

React/Vite client UI

- [React app](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/App.jsx): client · Vite-built frontend that consumes the API · `frontend-vite/src/App.jsx`
- [Login](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Login.jsx): page · Authentication entry point · `frontend-vite/src/pages/Login.jsx`
- [Dashboard](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Dashboard.jsx): page · Operational KPI overview · `frontend-vite/src/pages/Dashboard.jsx`
- [Inventario](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Inventario.jsx): page · Inventory browsing and actions · `frontend-vite/src/pages/Inventario.jsx`
- [Recepción](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/Recepcion.jsx): page · Standard receiving workflow · `frontend-vite/src/pages/Recepcion.jsx`
- [Recepción CEDIS](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/RecepcionCedis.jsx): page · Inbound CEDIS receiving workflow · `frontend-vite/src/pages/RecepcionCedis.jsx`
- [RPC Control](https://github.com/briansilent/mejorarecibocaducidades/blob/main/frontend-vite/src/pages/RpcControl.jsx): page · Transport cycle control UI · `frontend-vite/src/pages/RpcControl.jsx`

### Backend

Spring Boot API and domain services

- [REST API](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller): spring api · HTTP boundary for all business domains · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller`
- [Auth](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Config/SecurityConfig.java): security · JWT authentication and authorization · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Config/SecurityConfig.java`
- [Producto](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/ProductoController.java): domain module · Product catalog management · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/ProductoController.java`
- [Inventario](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/InventarioController.java): domain module · Stock, movements, alerts, and expiry handling · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/InventarioController.java`
- [Recepción](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionController.java): domain module · Warehouse receiving workflow · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionController.java`
- [Recepción CEDIS](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionCedisController.java): domain module · CEDIS receiving and discrepancy capture · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RecepcionCedisController.java`
- [RPC](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RpcController.java): domain module · Delivery and return cycle tracking · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/RpcController.java`
- [Orden/Surtido](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/OrdenCompraController.java): domain module · Purchase orders, picking, and audit flows · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/OrdenCompraController.java`
- [Dashboard](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/DashboardController.java): domain module · Aggregated operational reporting · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Controller/DashboardController.java`
- [DTOs](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/DTO): api models · Request, response, and summary shapes · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/DTO`
- [Services](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Service): business logic · Domain rules and orchestration · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Service`
- [Repositories](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Repository): persistence · Spring Data access layer · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Repository`
- [Entities](https://github.com/briansilent/mejorarecibocaducidades/tree/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Model): jpa model · Persisted domain entities · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Model`
- [Expiry job](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Sheduler/AlertaCaducidadSheduler.java): background job · Periodic inventory expiry alert generation · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/Sheduler/AlertaCaducidadSheduler.java`
- [Errors](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/java/com/bodegaaurrera/perecederos_demo/exception/GlobalExceptionHandler.java): exception handling · Centralized API error translation · `Backend/src/main/java/com/bodegaaurrera/perecederos_demo/exception/GlobalExceptionHandler.java`

### Infrastructure

Runtime, database, and deployment support

- [PostgreSQL](https://github.com/briansilent/mejorarecibocaducidades/blob/main/Backend/src/main/resources/application.properties): database · System of record · `Backend/src/main/resources/application.properties`

## Connections

- React app → Auth: login · Frontend sends credentials and receives JWT
- React app → REST API: calls · React screens consume backend endpoints
- Login → Auth: auth flow · Login page uses authentication subsystem
- Dashboard → Dashboard: data · Dashboard page reads KPI endpoints
- Inventario → Inventario: data · Inventory page drives stock and alert queries
- Recepción → Recepción: data · Receiving page uses receiving endpoints
- Recepción CEDIS → Recepción CEDIS: data · CEDIS page uses inbound discrepancy workflow
- RPC Control → RPC: data · RPC control page uses transport lifecycle endpoints
- REST API → Auth: secured by · JWT filter and security config guard protected routes
- REST API → Producto: routes · API exposes product management controller
- REST API → Inventario: routes · API exposes inventory controller
- REST API → Recepción: routes · API exposes receiving controller
- REST API → Recepción CEDIS: routes · API exposes CEDIS receiving controller
- REST API → RPC: routes · API exposes RPC controller
- REST API → Orden/Surtido: routes · API exposes order, picking, and audit controllers
- REST API → Dashboard: routes · API exposes dashboard endpoints
- Producto → Services: delegates · Controllers delegate domain work to services
- Inventario → Services: delegates · Inventory controller uses service layer
- Recepción → Services: delegates · Receiving controller uses service layer
- Recepción CEDIS → Services: delegates · CEDIS controller uses service layer
- RPC → Services: delegates · RPC controller uses service layer
- Services → Repositories: reads/writes · Business logic persists through repositories
- Repositories → Entities: maps · Repositories manage JPA entities
- Entities → PostgreSQL: persists · Entities are stored in PostgreSQL
- Services → DTOs: shapes · Services and controllers exchange DTOs
- Expiry job → Inventario: triggers · Background job feeds expiry alert logic
- Expiry job → Services: runs · Scheduled job invokes alert service
- REST API → Errors: handles · Central exception handler standardizes failures
