# davidd23b/notmess-backend architecture

> Architecture diagram of the GitHub repository davidd23b/notmess-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davidd23b/notmess-backend
- Repository: https://github.com/davidd23b/notmess-backend

## Overview

##### Project Type and Purpose
- This is a Spring Boot–based REST API backend (no UI layer in this repo).
- It exposes HTTP endpoints to manage “NotMess” domain entities (Albaran, Appcc*, Producto, Usuario, etc.) and handles authentication via JWT.
- It persists data in a PostgreSQL database using Spring Data JPA and provides auxiliary services for CSV import and image handling.

##### High-Level Architecture Components
a. Entry Point
- NotMessBackendApplication.java: boots the Spring context and embedded Tomcat.
b. API Layer (Controllers)
- Packages under controller/ (e.g., AuthController, ProductoController, AppccController, etc.).
- Exposes REST endpoints, input DTOs → output DTOs, orchestrates service calls.
c. Security Layer
- SecurityConfig, JwtAuthFilter, JwtUtil, CustomUserDetailsService, AuthenticationEntryPoint.
- Intercepts HTTP calls, authenticates via JWT, authorizes roles.
d. Service Layer
- service/ + impl/ (e.g., ProductoServiceImpl, AuthServiceImpl): business rules, transaction management.
- CsvService, ImagenService for file operations.
e. Repository/Data Access
- repository/ interfaces extending JpaRepository for CRUD.
- model/ JPA entities correspond to SQL scripts in resources/SQL.
f. Persistence
- PostgreSQL database, schema defined in SQL/*.sql files.
g. External Actors
- Clients (frontend UI, mobile apps, Postman) that call the REST API.
- Possibly external file storage if images are offloaded.

##### Component Relationships and Data Flows
- Client → HTTP(S) → JwtAuthFilter → Controller
- Controller → Service → Repository → PostgreSQL
- Service may call CsvService or ImagenService for filesystem or S3 operations.
- SecurityConfig wires JwtAuthFilter before controllers.
- DTO mappers convert between entities and DTOs.

##### Architectural Patterns and Principles
- Layered Architecture (Controller → Service → Repository).
- Dependency Injection via Spring.
- JWT-based stateless authentication.
- DTO + Mapper pattern to decouple API models from persistence models.
- Exception handling via GlobalExceptionHandler.

2. “Client” actor outside.
- Controllers layer at top.
- Security component (JwtAuthFilter) between Client and Controllers.
- Service layer below Controllers.
- Repository layer below Services.
5. Notes on SQL scripts under resources/SQL as deployment artifacts.
- Controllers (blue), Services (green), Repositories (orange), Security (red), Database (brown).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    Client((Client)):::actor

    %% System Boundary
    subgraph "NotMess Backend"
        direction TB

        %% Entry Point
        EntryPoint["NotMessBackendApplication"]:::app

        %% Security Layer
        subgraph "Security Layer"
            direction TB
            SecurityConfig["SecurityConfig"]:::security
            JwtAuthFilter["JwtAuthFilter"]:::security
            JwtUtil["JwtUtil"]:::security
            CustomUserDetailsService["CustomUserDetailsService"]:::security
            JwtAuthenticationEntryPoint["JwtAuthenticationEntryPoint"]:::security
        end

        %% API Controllers
        subgraph "API Controllers"
            direction TB
            AuthController["AuthController"]:::controller
            ProductoController["ProductoController"]:::controller
            AppccController["AppccController"]:::controller
            AlbaranController["AlbaranController"]:::controller
            UsuarioController["UsuarioController"]:::controller
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            AuthService["AuthService"]:::service
            ProductoService["ProductoService"]:::service
            CsvService["CsvService"]:::service
            ImagenService["ImagenService"]:::service
        end

        %% Repository Layer
        subgraph "Repository Layer"
            direction TB
            ProductoRepository["ProductoRepository"]:::repo
            AlbaranRepository["AlbaranRepository"]:::repo
            UsuarioRepository["UsuarioRepository"]:::repo
        end

        %% Utilities
        subgraph "Utilities"
            direction TB
            CsvUtil["CsvUtil"]:::util
        end
    end

    %% External Systems
    PostgreSQL[(PostgreSQL Database)]:::db
    S3[(External Storage)]:::external

    %% Data Flows
    Client -->|"HTTP Request"| JwtAuthFilter
    JwtAuthFilter -->|"JWT Validation"| AuthController
    AuthController -->|"login() / register()"| AuthService
    AuthService --> JwtUtil
    AuthController -->|"protected endpoints"| ProductoController
    ProductoController -->|"calls"| ProductoService
    ProductoService -->|"JPA Query"| ProductoRepository
    ProductoRepository --> PostgreSQL
    AlbaranController -->|"calls"| AuthService
    AlbaranController --> AlbaranRepository
    AlbaranRepository --> PostgreSQL
    UsuarioController --> UsuarioRepository
    UsuarioRepository --> PostgreSQL
    CsvService --> CsvUtil
    CsvService --> ProductoRepository
    ImagenService --> S3

    %% Click Events
    click EntryPoint "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/NotMessBackendApplication.java"
    click AuthController "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/controller/AuthController.java"
    click ProductoController "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/controller/ProductoController.java"
    click AppccController "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/controller/AppccController.java"
    click AlbaranController "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/controller/AlbaranController.java"
    click UsuarioController "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/controller/UsuarioController.java"
    click SecurityConfig "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/config/SecurityConfig.java"
    click JwtAuthFilter "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/security/JwtAuthFilter.java"
    click JwtUtil "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/security/JwtUtil.java"
    click CustomUserDetailsService "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/security/CustomUserDetailsService.java"
    click JwtAuthenticationEntryPoint "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/security/JwtAuthenticationEntryPoint.java"
    click AuthService "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/service/AuthService.java"
    click ProductoService "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/service/ProductoService.java"
    click CsvService "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/service/CsvService.java"
    click ImagenService "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/service/ImagenService.java"
    click ProductoRepository "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/repository/ProductoRepository.java"
    click AlbaranRepository "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/repository/AlbaranRepository.java"
    click UsuarioRepository "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/repository/UsuarioRepository.java"
    click CsvUtil "https://github.com/davidd23b/notmess-backend/blob/main/src/main/java/backend/util/CsvUtil.java"
    click PostgreSQL "https://github.com/davidd23b/notmess-backend/tree/main/src/main/resources/SQL/"

    %% Styles
    classDef actor fill:#f9f,stroke:#333,stroke-width:2px;
    classDef app fill:#bbf,stroke:#333,stroke-width:1px;
    classDef security fill:#f88,stroke:#900,stroke-width:1px;
    classDef controller fill:#88f,stroke:#333,stroke-width:1px;
    classDef service fill:#8f8,stroke:#070,stroke-width:1px;
    classDef repo fill:#f8c,stroke:#a60,stroke-width:1px;
    classDef util fill:#fc8,stroke:#aa5500,stroke-width:1px;
    classDef db fill:#a52,stroke:#732,stroke-width:2px;
    classDef external fill:#ccc,stroke:#666,stroke-width:1px;
```
