# juliorbk/visco-sg architecture

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

- Interactive diagram: https://gitdiagram.com/juliorbk/visco-sg
- Repository: https://github.com/juliorbk/visco-sg

## Overview

1. **System shape**
   - This is a single Spring Boot 3 backend, not a multi-service system.
   - It follows a classic layered architecture: **controllers → services → repositories → PostgreSQL**.
   - The main application entry point is `SystemApplication`, with most business logic concentrated in service classes and persistence in Spring Data JPA repositories.

2. **Core runtime and persistence**
   - The app runs on **Java 21**, uses **Hibernate/JPA** for ORM, and persists business state in **PostgreSQL**.
   - Domain state is modeled as JPA entities under `models/entities`, while transport contracts are kept separate in `models/dtos`.
   - This DTO/entity split is important: controllers should not be drawing directly from entities as API payloads.

3. **Security boundary**
   - Authentication is **stateless JWT-based**, with the token stored in an **HttpOnly cookie**.
   - Request authentication is enforced by `JwtAuthFilter`, while `SecurityConfig` defines authorization rules by role.
   - `CustomUserDetailsService` and `UserPrincipal` bridge persisted users into Spring Security’s auth model.

4. **Cross-cutting request protection**
   - `RateLimitFilter` adds per-IP throttling on sensitive endpoints such as login, registration, inventory, procurement, and dashboard access.
   - `GlobalExceptionHandler` centralizes error translation for the API, so controller failures are converted into consistent HTTP responses.
   - `JpaAuditingConfig` suggests created/updated metadata is managed automatically on entities.

5. **Main business domains**
   - The repository is organized around enterprise procurement and inventory workflows:
     - **Auth / Users / Admin**
     - **Suppliers**
     - **Products / Inventory**
     - **Warehouses / Locations / Stock movements**
     - **Requisitions**
     - **Procurement / Purchase orders**
     - **Invoices**
     - **Dashboard / Stats**
     - **Cost centers, employees, management, general management**
   - Each domain has its own controller and service layer, with repositories tied to the corresponding entity set.

6. **Primary workflow chain**
   - The most important data flow is the purchasing lifecycle:
     - a **requisition** is created and approved,
     - it can be **converted into a purchase order**,
     - the order is approved and sent,
     - goods are **received in warehouse**,
     - inventory is updated through **stock movements**,
     - and **invoices** are matched against ordered and received quantities.
   - This flow ties together requisitions, procurement, warehouse, inventory, and invoices into one business process.

7. **Inventory and warehouse boundary**
   - Inventory is not just a product catalog; it includes operational stock state.
   - Entities like `StockLevel`, `InventoryMovement`, `GoodReceipt`, `DispatchNote`, and `Warehouse` indicate the system tracks:
     - current stock by warehouse/location,
     - movement history,
     - receiving and dispatch operations,
     - manual adjustments and transfers.
   - Controllers and services in `WarehouseController` and `WarehouseService` are the main boundary for these operations.

8. **Master data and administrative modules**
   - `Product`, `Supplier`, `Category`, `Uom`, `Location`, `CostCenter`, `Employee`, and `Management` are master-data style domains.
   - These modules support the transactional flows above by providing reference data used in requisitions, purchasing, and inventory allocation.
   - `UserController` and `AdminController` likely handle account lifecycle, role assignment, and administrative operations.

9. **Reporting subsystem**
   - There is a distinct reporting package under `com.visco.backend.reports`, which behaves like a submodule inside the same application.
   - It has its own controllers, entities, repositories, services, DTOs, enums, and utilities.
   - This subsystem generates reports in multiple formats, including **Excel and PDF**, and includes scheduled reporting support (`ScheduledReportService`).
   - Utilities such as chart generation and formatting suggest reports are assembled from business data, then exported and/or emailed.

10. **Operational integrations**
   - The app integrates with **SMTP email** for notifications and scheduled report delivery.
   - `WeeklyReportService` and the README’s scheduled report description imply a time-based job sends reports automatically.
   - `Dockerfile`, `docker-compose.yml`, and Render deployment notes show it is intended to run containerized in production.

11. **API documentation and developer experience**
   - `OpenApiConfig` and the Swagger/OpenAPI setup expose the REST surface for interactive exploration.
   - The repository also includes `HealthController` for operational checking and `ANALISIS_BRECHAS.md` for security/gap analysis.
   - This is a backend-first repo with strong emphasis on API contracts and operational visibility.

12. **Import/export and batch operations**
   - The presence of Apache POI and Apache Commons CSV in the README maps to two important backend capabilities:
     - **Excel report generation**
     - **bulk product import from CSV**
   - These are not core request/response endpoints but batch-oriented side flows that feed into the same product and reporting domains.

13. **Testing boundary**
   - Tests are focused on service-layer behavior, not full end-to-end UI flows.
   - Existing unit tests cover auth, invoice, procurement, requisition, stats, supplier, and warehouse services.
   - That reinforces the architecture: the service layer is the main place where business rules are expected to live and be verified.

14. **What to show in an architecture diagram**
   - A clean diagram for this repo should center on:
     - **Frontend client** calling the Spring Boot API
     - **Security filter chain** in front of controllers
     - **Domain services** grouped by business area
     - **JPA repositories** persisting to PostgreSQL
     - **Reporting/email scheduling** as a side subsystem
     - **External dependencies**: PostgreSQL, SMTP, and deployment/runtime infrastructure on Render.

Main entry points: [`src/main/java/com/visco/backend/config/SecurityConfig.java`](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/SecurityConfig.java) (Security Config), [`src/main/java/com/visco/backend/reports/services/ReportService.java`](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ReportService.java) (Report Service), [`src/main/java/com/visco/backend/repositories`](https://github.com/juliorbk/visco-sg/tree/main/src/main/java/com/visco/backend/repositories) (JPA Repos), [`src/main/java/com/visco/backend/services/AuthService.java`](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/AuthService.java) (Auth Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Core API"]
  node_app(("SystemApplication<br/>boot entrypoint"))
  node_auth_controller["Auth API<br/>controller"]
  node_procurement_controller["Procurement API<br/>controller"]
  node_warehouse_controller["Warehouse API<br/>controller"]
  node_product_controller["Product API<br/>controller"]
  node_dashboard_controller["Dashboard API<br/>controller"]
  node_admin_controller["Admin API<br/>controller"]
  node_auth_service["Auth Service<br/>[AuthService.java]"]
  node_procurement_service["Procurement Service"]
  node_warehouse_service["Warehouse Service"]
  node_stats_service["Stats Service<br/>[StatsService.java]"]
end

subgraph group_group_security["Security"]
  node_jwt_filter["JWT Filter<br/>security filter<br/>[JwtAuthFilter.java]"]
  node_rate_filter["Rate Limit<br/>security filter"]
  node_security_config["Security Config"]
  node_user_details["User Details<br/>security bridge"]
end

subgraph group_group_reporting["Reporting"]
  node_report_controller["Report API<br/>controller"]
  node_report_service["Report Service<br/>[ReportService.java]"]
  node_scheduled_reports["Scheduled Reports<br/>scheduler"]
  node_export_utils["Export Utils<br/>export helpers"]
end

subgraph group_group_infra["Infrastructure"]
  node_exception_handler["API Errors<br/>advice"]
  node_db_entities[("JPA Models<br/>entities")]
  node_db_repos["JPA Repos<br/>repositories"]
  node_postgres[("PostgreSQL<br/>database")]
  node_email_service["Email Service<br/>integration<br/>[EmailService.java]"]
end

node_app -->|"boots with"| node_security_config
node_app -->|"wires"| node_db_repos
node_auth_controller -->|"calls"| node_auth_service
node_admin_controller -->|"uses"| node_auth_service
node_procurement_controller -->|"calls"| node_procurement_service
node_warehouse_controller -->|"calls"| node_warehouse_service
node_product_controller -->|"reads/writes"| node_db_repos
node_dashboard_controller -->|"calls"| node_stats_service
node_auth_service -->|"authenticates via"| node_user_details
node_auth_service -->|"notifies"| node_email_service
node_jwt_filter -->|"enforced by"| node_security_config
node_rate_filter -->|"enforced by"| node_security_config
node_security_config -->|"protects"| node_auth_controller
node_security_config -->|"protects"| node_procurement_controller
node_security_config -->|"protects"| node_warehouse_controller
node_security_config -->|"protects"| node_dashboard_controller
node_user_details -->|"loads users from"| node_db_repos
node_db_repos -->|"maps"| node_db_entities
node_db_entities -->|"persists to"| node_postgres
node_exception_handler -->|"handles errors for"| node_auth_controller
node_exception_handler -->|"handles errors for"| node_procurement_controller
node_exception_handler -->|"handles errors for"| node_warehouse_controller
node_report_controller -->|"calls"| node_report_service
node_report_service -->|"uses"| node_export_utils
node_scheduled_reports -->|"triggers"| node_report_service
node_scheduled_reports -->|"delivers via"| node_email_service
node_report_service -->|"reads data from"| node_db_repos
node_report_service -->|"exports from"| node_postgres

click node_app "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/SystemApplication.java"
click node_auth_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/AuthController.java"
click node_procurement_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/ProcurementController.java"
click node_warehouse_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/WarehouseController.java"
click node_product_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/ProductController.java"
click node_dashboard_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/DashboardController.java"
click node_admin_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/AdminController.java"
click node_auth_service "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/AuthService.java"
click node_procurement_service "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/ProcurementService.java"
click node_warehouse_service "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/WarehouseService.java"
click node_stats_service "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/StatsService.java"
click node_jwt_filter "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/JwtAuthFilter.java"
click node_rate_filter "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/RateLimitFilter.java"
click node_security_config "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/SecurityConfig.java"
click node_user_details "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/CustomUserDetailsService.java"
click node_exception_handler "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/exception/GlobalExceptionHandler.java"
click node_db_entities "https://github.com/juliorbk/visco-sg/tree/main/src/main/java/com/visco/backend/models/entities"
click node_db_repos "https://github.com/juliorbk/visco-sg/tree/main/src/main/java/com/visco/backend/repositories"
click node_report_controller "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/controllers/ReportController.java"
click node_report_service "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ReportService.java"
click node_scheduled_reports "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ScheduledReportService.java"
click node_export_utils "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ExcelExportService.java"
click node_email_service "https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/EmailService.java"

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_app,node_auth_controller,node_procurement_controller,node_warehouse_controller,node_product_controller,node_dashboard_controller,node_admin_controller,node_auth_service,node_procurement_service,node_warehouse_service,node_stats_service toneBlue
class node_jwt_filter,node_rate_filter,node_security_config,node_user_details toneAmber
class node_report_controller,node_report_service,node_scheduled_reports,node_export_utils toneMint
class node_exception_handler,node_db_entities,node_db_repos,node_postgres,node_email_service toneRose
```

## Components

### Core API

Spring Boot entrypoint, controllers, services, and persistence for the main business domains.

- [SystemApplication](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/SystemApplication.java): boot entrypoint · Main Spring Boot application entry point. · `src/main/java/com/visco/backend/SystemApplication.java`
- [Auth API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/AuthController.java): controller · Login, registration, and session-related endpoints. · `src/main/java/com/visco/backend/controllers/AuthController.java`
- [Procurement API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/ProcurementController.java): controller · Requisitions and purchase-order workflow endpoints. · `src/main/java/com/visco/backend/controllers/ProcurementController.java`
- [Warehouse API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/WarehouseController.java): controller · Stock, receiving, dispatch, and transfer endpoints. · `src/main/java/com/visco/backend/controllers/WarehouseController.java`
- [Product API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/ProductController.java): controller · Product master data and import operations. · `src/main/java/com/visco/backend/controllers/ProductController.java`
- [Dashboard API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/DashboardController.java): controller · Operational stats and summary endpoints. · `src/main/java/com/visco/backend/controllers/DashboardController.java`
- [Admin API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/controllers/AdminController.java): controller · Administrative account and role management endpoints. · `src/main/java/com/visco/backend/controllers/AdminController.java`
- [Auth Service](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/AuthService.java): service · Authentication flow, cookie handling, and JWT issuance. · `src/main/java/com/visco/backend/services/AuthService.java`
- [Procurement Service](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/ProcurementService.java): service · Requisition approval and purchase-order lifecycle. · `src/main/java/com/visco/backend/services/ProcurementService.java`
- [Warehouse Service](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/WarehouseService.java): service · Inventory movements, receiving, dispatch, and stock operations. · `src/main/java/com/visco/backend/services/WarehouseService.java`
- [Stats Service](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/StatsService.java): service · Dashboard metrics and business aggregates. · `src/main/java/com/visco/backend/services/StatsService.java`

### Security

Authentication, authorization, and request protection.

- [JWT Filter](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/JwtAuthFilter.java): security filter · Validates stateless JWT authentication from requests. · `src/main/java/com/visco/backend/config/JwtAuthFilter.java`
- [Rate Limit](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/RateLimitFilter.java): security filter · Per-IP throttling for sensitive endpoints. · `src/main/java/com/visco/backend/config/RateLimitFilter.java`
- [Security Config](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/SecurityConfig.java): security config · Authorization rules and security chain configuration. · `src/main/java/com/visco/backend/config/SecurityConfig.java`
- [User Details](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/config/CustomUserDetailsService.java): security bridge · Maps persisted users into Spring Security principals. · `src/main/java/com/visco/backend/config/CustomUserDetailsService.java`

### Reporting

Standalone reporting subsystem within the same application.

- [Report API](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/controllers/ReportController.java): controller · Report creation, export, and scheduling endpoints. · `src/main/java/com/visco/backend/reports/controllers/ReportController.java`
- [Report Service](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ReportService.java): service · Report generation orchestration and export workflow. · `src/main/java/com/visco/backend/reports/services/ReportService.java`
- [Scheduled Reports](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ScheduledReportService.java): scheduler · Time-based report generation and delivery. · `src/main/java/com/visco/backend/reports/services/ScheduledReportService.java`
- [Export Utils](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/reports/services/ExcelExportService.java): export helpers · Excel, PDF, charting, and formatting helpers for reports. · `src/main/java/com/visco/backend/reports/services/ExcelExportService.java`

### Infrastructure

Cross-cutting runtime, persistence, and external integrations.

- [API Errors](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/exception/GlobalExceptionHandler.java): advice · Central exception translation for controller failures. · `src/main/java/com/visco/backend/exception/GlobalExceptionHandler.java`
- [JPA Models](https://github.com/juliorbk/visco-sg/tree/main/src/main/java/com/visco/backend/models/entities): entities · Core domain entities for users, procurement, inventory, and master data. · `src/main/java/com/visco/backend/models/entities`
- [JPA Repos](https://github.com/juliorbk/visco-sg/tree/main/src/main/java/com/visco/backend/repositories): repositories · Spring Data repositories for the main application domain. · `src/main/java/com/visco/backend/repositories`
- **PostgreSQL**: database · Primary persistent store for business state.
- [Email Service](https://github.com/juliorbk/visco-sg/blob/main/src/main/java/com/visco/backend/services/EmailService.java): integration · SMTP-based notification and report delivery. · `src/main/java/com/visco/backend/services/EmailService.java`

## Connections

- SystemApplication → Security Config: boots with · Application initializes the security configuration and request pipeline.
- SystemApplication → JPA Repos: wires · Spring Boot wires repositories and services at startup.
- Auth API → Auth Service: calls · Authentication endpoints delegate login and registration logic.
- Admin API → Auth Service: uses · Administrative account actions rely on auth/user services.
- Procurement API → Procurement Service: calls · Procurement endpoints delegate workflow orchestration.
- Warehouse API → Warehouse Service: calls · Warehouse endpoints delegate operational stock logic.
- Product API → JPA Repos: reads/writes · Product management persists through repositories.
- Dashboard API → Stats Service: calls · Dashboard endpoints query aggregates and KPIs.
- Auth Service → User Details: authenticates via · Auth service integrates with Spring Security user lookup.
- Auth Service → Email Service: notifies · Authentication flows may trigger email notifications.
- JWT Filter → Security Config: enforced by · JWT authentication participates in the security chain.
- Rate Limit → Security Config: enforced by · Rate limiting is applied within the security/request pipeline.
- Security Config → Auth API: protects · Authorization rules gate API endpoints.
- Security Config → Procurement API: protects · Authorization applies to procurement operations.
- Security Config → Warehouse API: protects · Authorization applies to warehouse operations.
- Security Config → Dashboard API: protects · Authorization applies to dashboard access.
- User Details → JPA Repos: loads users from · Security bridge resolves users via repositories.
- JPA Repos → JPA Models: maps · Repositories operate on JPA entities.
- JPA Models → PostgreSQL: persists to · JPA entities are stored in PostgreSQL.
- API Errors → Auth API: handles errors for · Central error handling normalizes API responses.
- API Errors → Procurement API: handles errors for · Central error handling normalizes API responses.
- API Errors → Warehouse API: handles errors for · Central error handling normalizes API responses.
- Report API → Report Service: calls · Report endpoints delegate generation and export.
- Report Service → Export Utils: uses · Report generation uses export and chart helpers.
- Scheduled Reports → Report Service: triggers · Scheduled jobs invoke report generation workflows.
- Scheduled Reports → Email Service: delivers via · Scheduled reports are sent through SMTP email.
- Report Service → JPA Repos: reads data from · Reports aggregate business data through repositories.
- Report Service → PostgreSQL: exports from · Reports ultimately derive from persisted operational data.
