# brandonbrandon-alt/optiplant-prueba-tecnica architecture

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

- Interactive diagram: https://gitdiagram.com/brandonbrandon-alt/optiplant-prueba-tecnica
- Repository: https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica

## Overview

1. **Top-level shape**
   - This is a **full-stack inventory ERP** with a **Next.js frontend** and a **Spring Boot backend**.
   - The backend is the architectural center: a **modular monolith** organized by business capability, using **hexagonal architecture** inside each module.

2. **Frontend boundary**
   - `frontend/` is a **Next.js App Router** application with route groups for auth and dashboard flows.
   - Pages are split by business area: login, dashboard, alerts, analytics, branches, catalog, inventory, purchases, sales, returns, transfers, and users.
   - UI logic is concentrated in reusable components and modals under `src/components`, while API access is centralized in `src/api`.
   - The frontend is primarily a **thin presentation layer** over the backend API; it does not appear to own business rules.

3. **Backend application boundary**
   - `backend/` is a **single Spring Boot application** (`InventarioApplication`) exposing REST endpoints and handling security, persistence, and domain logic.
   - Each business module follows the same structure:
     - `application/port/in` for use cases
     - `application/service` for orchestration
     - `application/port/out` for repositories or external dependencies
     - `domain` for models and exceptions
     - `infrastructure/adapter/in/web` for controllers and request/response DTOs
     - `infrastructure/adapter/out/persistence` for JPA entities and repository implementations

4. **Main business modules**
   - The backend is split into these domains: **auth**, **branch**, **catalog**, **inventory**, **purchase**, **sale**, **transfer**, **alert**, **analytics**, and **pricelist**.
   - This separation is important for the diagram: each module is independently shaped, but all live in the same runtime and database.
   - The modules are not just technical layers; they represent actual business subsystems of the ERP.

5. **Core transactional flows**
   - **Sales** create sale records and reduce local inventory; returns create return requests and can restore stock.
   - **Purchases** create purchase orders and, on reception, update inventory and cost-related data.
   - **Transfers** manage inter-branch stock movement with a state machine-like lifecycle: request, prepare, dispatch, receive, and follow-up on exceptions.
   - **Inventory** is the operational ledger underneath these flows, storing movements and local stock state.
   - These flows are the main write paths and are the most important arrows in an architecture diagram.

6. **Inventory as the shared backbone**
   - Inventory has its own domain entities for **local stock** and **movement history**.
   - It also defines domain events such as stock drops/restorations, which likely drive alerting and operational feedback.
   - Several other modules depend on inventory behavior indirectly:
     - sales consume stock
     - purchases replenish stock
     - transfers reserve/move stock between branches
   - This makes inventory the central consistency boundary of the system.

7. **Alerts and event-driven behavior**
   - The `alert` module contains a web controller plus an event listener for stock alerts.
   - This suggests a mixed model: alerts are stored and retrieved like normal data, but at least some are created from inventory-related events rather than only from direct API calls.
   - In the diagram, alerts should be shown as a consumer of inventory signal/events, not only as an isolated CRUD feature.

8. **Authentication and authorization**
   - `auth` contains login, users, roles, JWT support, and role-based access control.
   - The shared security package includes a **JWT authentication filter**, a JWT service, and Spring Security configuration.
   - The frontend login page interacts with auth endpoints, and the resulting token is then used to secure the rest of the API.
   - Roles listed in the README (`ADMIN`, `MANAGER`, `OPERATOR`, `CASHIER`) are central to access boundaries across the system.

9. **Catalog, branches, and pricing as reference data**
   - `catalog` manages products, suppliers, and units of measure, including product-supplier and product-unit relationships.
   - `branch` manages store/warehouse locations.
   - `pricelist` provides price list and product price structures used by sales and POS screens.
   - These modules are mostly supporting/master-data subsystems, but they feed nearly every transaction flow.

10. **Analytics as a read-only aggregation layer**
   - `analytics` is separate from the transactional modules and exposes dashboard-oriented models like summary KPIs, sales trends, top-selling products, branch performance, valuation, and replenishment insights.
   - Its shape implies read-optimized queries or projections over persisted transactional data.
   - In the diagram, analytics should be treated as a **read side** rather than a transaction source.

11. **Persistence and storage**
   - Persistence is implemented with **Spring Data JPA/Hibernate** behind repository ports.
   - Each module has its own JPA entities and repository adapters, but they all target the same relational database.
   - Database schema is managed through **Flyway migrations** in `src/main/resources/db/migration`, with additional backup migration history preserved under `@backup_migrations`.
   - The architecture is therefore a **single DB, multi-module application**, not a microservice landscape.

12. **Shared infrastructure**
   - `shared/infrastructure/web` contains cross-cutting HTTP concerns like the **global exception handler** and error response model.
   - `shared/infrastructure/config` includes OpenAPI setup.
   - This indicates a central platform layer for consistent API behavior across modules.

13. **Runtime/deployment shape**
   - The repo includes Dockerfiles for both backend and frontend, plus a top-level `docker-compose.yml`.
   - That points to a containerized local deployment with at least three meaningful runtime boundaries: frontend, backend, and database.
   - The README also references pgAdmin, which is part of the operational/developer environment rather than the domain architecture.

14. **Testing structure**
   - Tests are organized by the same module boundaries as production code, with controller tests, service tests, and some persistence mapper tests.
   - This reinforces that the codebase is intended to be diagrammed as a set of cohesive bounded modules, not as a flat CRUD app.

15. **How to draw the system**
   - A good architecture diagram would show:
     - **Users/browser** → **Next.js frontend**
     - **Frontend** → **Spring Boot REST API**
     - **API controllers/security** → **application services/use cases**
     - **services** → **domain models and ports**
     - **ports** → **JPA persistence adapters** → **PostgreSQL**
     - **inventory events** → **alerts**
     - **transactional modules** → **analytics/read models**
   - The strongest structural idea is: **one frontend, one backend monolith, many business modules, one shared relational database, with inventory at the center of operational flows**.

Main entry points: [`backend/src/main/java/co/com/zenvory/inventario/InventarioApplication.java`](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/blob/master/backend/src/main/java/co/com/zenvory/inventario/InventarioApplication.java) (InventarioApp), [`backend/src/main/java/co/com/zenvory/inventario/inventory`](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/inventory) (Inventory), [`frontend/app`](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/app) (Next.js App), [`docker-compose.yml`](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/blob/master/docker-compose.yml) (Docker Compose)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_nextjs["Next.js App<br/>frontend shell"]
  node_ui_components["UI Components<br/>presentation components"]
  node_api_client["API Client<br/>frontend api layer"]
end

subgraph group_backend["Backend"]
  node_inventario_app["InventarioApp<br/>spring boot app"]
  node_auth["Auth<br/>identity module"]
  node_catalog["Catalog<br/>master data module"]
  node_branch["Branches<br/>location module"]
  node_inventory["Inventory<br/>stock backbone"]
  node_purchase["Purchases<br/>procurement module"]
  node_sale["Sales<br/>transaction module"]
  node_transfer["Transfers<br/>logistics module"]
  node_pricelist["Price Lists<br/>pricing module"]
  node_alert["Alerts<br/>alert module"]
  node_analytics["Analytics<br/>read model"]
  node_persistence[("JPA Persistence<br/>adapter layer")]
end

subgraph group_shared["Shared infra"]
  node_security["Security"]
  node_flyway["Flyway Migrations<br/>schema evolution"]
end

subgraph group_runtime["Runtime"]
  node_browser(("Users<br/>client"))
  node_postgres[("PostgreSQL<br/>relational database")]
  node_docker{{"Docker Compose<br/>deployment<br/>[docker-compose.yml]"}}
end

node_browser -->|"use UI"| node_nextjs
node_nextjs -->|"call API"| node_api_client
node_nextjs -->|"compose UI"| node_ui_components
node_nextjs -->|"REST requests"| node_inventario_app
node_inventario_app -->|"protects"| node_security
node_inventario_app -->|"hosts"| node_auth
node_inventario_app -->|"hosts"| node_catalog
node_inventario_app -->|"hosts"| node_branch
node_inventario_app -->|"hosts"| node_inventory
node_inventario_app -->|"hosts"| node_purchase
node_inventario_app -->|"hosts"| node_sale
node_inventario_app -->|"hosts"| node_transfer
node_inventario_app -->|"hosts"| node_pricelist
node_inventario_app -->|"hosts"| node_alert
node_inventario_app -->|"hosts"| node_analytics
node_auth -->|"stores"| node_persistence
node_catalog -->|"stores"| node_persistence
node_branch -->|"stores"| node_persistence
node_inventory -->|"stores"| node_persistence
node_purchase -->|"replenishes"| node_inventory
node_sale -->|"consumes"| node_inventory
node_transfer -->|"moves stock"| node_inventory
node_inventory -->|"emits events"| node_alert
node_analytics -->|"reads data"| node_persistence
node_persistence -->|"writes"| node_postgres
node_flyway -->|"migrates"| node_postgres
node_docker -.->|"runs"| node_nextjs
node_docker -.->|"runs"| node_inventario_app
node_docker -.->|"runs"| node_postgres

click node_nextjs "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/app"
click node_ui_components "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/src/components"
click node_api_client "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/src/api"
click node_inventario_app "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/blob/master/backend/src/main/java/co/com/zenvory/inventario/InventarioApplication.java"
click node_security "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/shared/infrastructure/security"
click node_auth "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/auth"
click node_catalog "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/catalog"
click node_branch "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/branch"
click node_inventory "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/inventory"
click node_purchase "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/purchase"
click node_sale "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/sale"
click node_transfer "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/transfer"
click node_pricelist "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/pricelist"
click node_alert "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/alert"
click node_analytics "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/analytics"
click node_flyway "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/resources/db/migration"
click node_docker "https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/blob/master/docker-compose.yml"

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_nextjs,node_ui_components,node_api_client toneBlue
class node_inventario_app,node_auth,node_catalog,node_branch,node_inventory,node_purchase,node_sale,node_transfer,node_pricelist,node_alert,node_analytics,node_persistence toneAmber
class node_security,node_flyway toneMint
class node_browser,node_postgres,node_docker toneRose
```

## Components

### Frontend

Next.js App Router presentation layer

- [Next.js App](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/app): frontend shell · App Router UI with auth and dashboard flows · `frontend/app`
- [UI Components](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/src/components): presentation components · Reusable page widgets, modals, and layout components · `frontend/src/components`
- [API Client](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/frontend/src/api): frontend api layer · Centralized HTTP access and auth helpers · `frontend/src/api`

### Backend

Spring Boot modular monolith

- [InventarioApp](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/blob/master/backend/src/main/java/co/com/zenvory/inventario/InventarioApplication.java): spring boot app · Single backend runtime entrypoint · `backend/src/main/java/co/com/zenvory/inventario/InventarioApplication.java`
- [Auth](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/auth): identity module · Login, users, roles, and access control · `backend/src/main/java/co/com/zenvory/inventario/auth`
- [Catalog](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/catalog): master data module · Products, suppliers, and units of measure · `backend/src/main/java/co/com/zenvory/inventario/catalog`
- [Branches](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/branch): location module · Branch and warehouse reference data · `backend/src/main/java/co/com/zenvory/inventario/branch`
- [Inventory](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/inventory): stock backbone · Local stock, movements, and stock events · `backend/src/main/java/co/com/zenvory/inventario/inventory`
- [Purchases](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/purchase): procurement module · Purchase orders and receiving flow · `backend/src/main/java/co/com/zenvory/inventario/purchase`
- [Sales](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/sale): transaction module · Sales and return request flow · `backend/src/main/java/co/com/zenvory/inventario/sale`
- [Transfers](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/transfer): logistics module · Inter-branch stock transfer lifecycle · `backend/src/main/java/co/com/zenvory/inventario/transfer`
- [Price Lists](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/pricelist): pricing module · Price lists and product price structures · `backend/src/main/java/co/com/zenvory/inventario/pricelist`
- [Alerts](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/alert): alert module · Stock alerts and resolutions · `backend/src/main/java/co/com/zenvory/inventario/alert`
- [Analytics](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/analytics): read model · Dashboard KPIs and operational aggregates · `backend/src/main/java/co/com/zenvory/inventario/analytics`
- **JPA Persistence**: adapter layer · Module-specific JPA entities and repository adapters

### Shared infra

Cross-cutting backend platform concerns

- [Security](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/java/co/com/zenvory/inventario/shared/infrastructure/security): jwt security · JWT filter, token service, and Spring Security config · `backend/src/main/java/co/com/zenvory/inventario/shared/infrastructure/security`
- [Flyway Migrations](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/tree/master/backend/src/main/resources/db/migration): schema evolution · Versioned database migrations and backup history · `backend/src/main/resources/db/migration`

### Runtime

Containerized deployment boundaries

- **Users**: client · Human operators using the ERP in a browser
- **PostgreSQL**: relational database · Single shared relational datastore
- [Docker Compose](https://github.com/brandonbrandon-alt/optiplant-prueba-tecnica/blob/master/docker-compose.yml): deployment · Containerized local runtime for frontend, backend, and database · `docker-compose.yml`

## Connections

- Users → Next.js App: use UI · Users interact with the ERP through the browser
- Next.js App → API Client: call API · Pages and components use the centralized HTTP client
- Next.js App → UI Components: compose UI · Route pages are built from reusable components
- Next.js App → InventarioApp: REST requests · Frontend screens consume backend endpoints
- InventarioApp → Security: protects · Requests pass through JWT authentication and authorization
- InventarioApp → Auth: hosts · Authentication and user management module
- InventarioApp → Catalog: hosts · Catalog master-data module
- InventarioApp → Branches: hosts · Branch reference-data module
- InventarioApp → Inventory: hosts · Inventory backbone module
- InventarioApp → Purchases: hosts · Purchase lifecycle module
- InventarioApp → Sales: hosts · Sales and returns module
- InventarioApp → Transfers: hosts · Transfer workflow module
- InventarioApp → Price Lists: hosts · Pricing module
- InventarioApp → Alerts: hosts · Alerting module
- InventarioApp → Analytics: hosts · Read-side analytics module
- Auth → JPA Persistence: stores · Users and roles are persisted through JPA adapters
- Catalog → JPA Persistence: stores · Products, suppliers, and units are persisted through JPA adapters
- Branches → JPA Persistence: stores · Branches are persisted through JPA adapters
- Inventory → JPA Persistence: stores · Inventory state and movement history are persisted through JPA adapters
- Purchases → Inventory: replenishes · Receiving updates inventory and cost-related data
- Sales → Inventory: consumes · Sales reduce stock and returns can restore it
- Transfers → Inventory: moves stock · Transfers reserve, dispatch, and receive inventory between branches
- Inventory → Alerts: emits events · Stock drops and restorations trigger alerting behavior
- Analytics → JPA Persistence: reads data · Analytics queries persisted transactional data
- JPA Persistence → PostgreSQL: writes · All modules target the same relational database
- Flyway Migrations → PostgreSQL: migrates · Schema is managed by versioned migrations
- Docker Compose → Next.js App: runs · Frontend is containerized for local deployment
- Docker Compose → InventarioApp: runs · Backend is containerized for local deployment
- Docker Compose → PostgreSQL: runs · Database is part of the composed runtime
