# richxrd22/venta-productos-electronicos-back architecture

> Architecture diagram of the GitHub repository richxrd22/venta-productos-electronicos-back, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/richxrd22/venta-productos-electronicos-back
- Repository: https://github.com/richxrd22/venta-productos-electronicos-back

## Overview

##### Project Type and Purpose
- This is a monolithic backend service for a “Sistema de Venta de Productos Electrónicos.”
- It’s built with Spring Boot (Maven), exposes a REST API, secures endpoints with Spring Security + JWT, and persists data via JPA/Hibernate with Flyway migrations.

##### Main Architectural Layers and Components
a. API Layer (Web/MVC)
- Controllers under `com.neon.sve.controller.*`
- DTO classes under `com.neon.sve.dto.*` (request/response objects)
- Exception handler (`GlobalExceptionHandler`)
b. Security Layer
- `JwtAuthenticationFilter`, `JwtService`
- `SecurityConfig`, `JwtAccessDeniedHandler`, `JwtAuthenticationEntryPoint`
c. Service Layer (Business Logic)
- Interfaces in `com.neon.sve.service.*` and implementations in `*.impl` packages
- AuthService, EmailService, plus domain services for producto, usuario, venta, etc.
d. Data Access Layer
- Spring Data JPA repositories under `com.neon.sve.repository.*`
e. Persistence / Database
- Entities under `com.neon.sve.model.*`
- Flyway migration scripts in `src/main/resources/db/migration`
f. External Services
- SMTP/email server (EmailService)
- JWT token issuer/validator (self-hosted via JwtService)

##### Relationships and Data Flow
- Client (Web or Mobile) → HTTP(S) → Spring Security filter chain (JwtAuthenticationFilter)
- Upon successful auth, request forwarded to the appropriate Controller
- Controller calls Service layer methods
- Service methods orchestrate business rules and call Repository interfaces
- Repository uses JPA/Hibernate to read/write to the relational database
- On certain events (e.g., user registration), Service calls EmailService to send emails

##### Architectural Patterns and Principles
- Layered (Onion/Clean) architecture: clear separation of concerns
- Dependency Injection (Spring) decouples components
- DTOs isolate API contracts from internal models
- Flyway ensures versioned, repeatable database migrations
- JWT-based stateless authentication

##### Technologies and Frameworks to Highlight
- Spring Boot (embedded Tomcat)
- Spring MVC, Spring Data JPA, Hibernate
- Spring Security + JWT
- Flyway for DB migrations
- Maven for build & dependency management
- Java 11+ (assumed)

##### Final Checklist
- Clear labels on every component.
- Layers logically (API, Security, Business, Data, External).
- Call out key frameworks (Spring Boot, JWT, Flyway, JPA).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client\n(Web/Mobile)"]:::client

    %% Security Layer
    JwtFilter["JwtAuthenticationFilter"]:::security
    JwtService["JwtService"]:::security

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Controllers["Controllers"]:::controller
        AuthController["AuthController"]:::controller
        ProductoControllers["Producto Controllers"]:::controller
        UsuarioControllers["Usuario Controllers"]:::controller
        VentaControllers["Venta Controllers"]:::controller
        DTOs["DTOs"]:::dto
        ExceptionHandler["GlobalExceptionHandler"]:::exception
    end

    %% Service Layer
    subgraph "Service Layer" 
        direction TB
        AuthService["AuthService"]:::service
        EmailService["EmailService"]:::service
        DomainServices["Domain Services\n(categoria, empleado,\ningresoStock, marca,\nproducto, proveedor,\nrol, subCategoria,\nusuario, usuarioEmpleado)"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        Repositories["Repositories"]:::repository
    end

    %% Persistence / Database
    Database[(Relational Database)]:::database

    %% External Services
    SMTP["SMTP Server"]:::external

    %% Configuration
    subgraph "Configuration"
        direction TB
        SecurityConfig["SecurityConfig"]:::config
        JwtAccessDeniedHandler["JwtAccessDeniedHandler"]:::config
        JwtEntryPoint["JwtAuthenticationEntryPoint"]:::config
        ApplicationConfig["ApplicationConfig"]:::config
        UserInitializer["User Initializer Services"]:::config
    end

    %% Flyway Migration
    Flyway["Flyway Migrations"]:::flyway

    %% Application Entry
    SveApp["SveApplication"]:::app

    %% Flows
    Client -->|JWT Auth| JwtFilter
    JwtFilter -->|REST API call| Controllers
    Controllers -->|uses DTOs| DTOs
    Controllers -->|"handles exceptions"| ExceptionHandler
    Controllers -->|business logic| AuthService
    Controllers -->|business logic| DomainServices
    AuthService -->|CRUD operations| Repositories
    DomainServices -->|CRUD operations| Repositories
    Repositories -->|JPA/Hibernate| Database
    DomainServices -.->|send email| SMTP
    SveApp -->|starts| Flyway
    Flyway -->|migrations| Database

    %% Configuration dependencies
    SveApp --> SecurityConfig
    SveApp --> ApplicationConfig
    SecurityConfig --> JwtFilter
    SecurityConfig --> JwtService
    SecurityConfig --> JwtAccessDeniedHandler
    SecurityConfig --> JwtEntryPoint
    ApplicationConfig --> UserInitializer

    %% Click Events
    click Controllers "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/java/com/neon/sve/controller"
    click AuthController "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/controller/auth/AuthController.java"
    click ProductoControllers "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/java/com/neon/sve/controller/producto"
    click UsuarioControllers "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/java/com/neon/sve/controller/usuario"
    click VentaControllers "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/controller/venta/IngresoStockController.java"
    click DTOs "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/java/com/neon/sve/dto"
    click ExceptionHandler "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/exception/GlobalExceptionHandler.java"
    click JwtFilter "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/jwt/JwtAuthenticationFilter.java"
    click JwtService "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/jwt/JwtService.java"
    click SecurityConfig "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/config/SecurityConfig.java"
    click JwtAccessDeniedHandler "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/config/JwtAccessDeniedHandler.java"
    click JwtEntryPoint "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/config/JwtAuthenticationEntryPoint.java"
    click ApplicationConfig "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/config/ApplicationConfig.java"
    click UserInitializer "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/java/com/neon/sve/config/userInitializer"
    click AuthService "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/service/AuthService.java"
    click EmailService "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/service/EmailService.java"
    click Repositories "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/java/com/neon/sve/repository"
    click Database "https://github.com/richxrd22/venta-productos-electronicos-back/tree/main/backend/src/main/resources/db/migration"
    click SveApp "https://github.com/richxrd22/venta-productos-electronicos-back/blob/main/backend/src/main/java/com/neon/sve/SveApplication.java"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef security fill:#FFF9C4,stroke:#FBC02D,color:#F57F17;
    classDef controller fill:#E1F5FE,stroke:#0277BD,color:#01579B;
    classDef dto fill:#E3F2FD,stroke:#0288D1,color:#01579B;
    classDef exception fill:#FFEBEE,stroke:#C62828,color:#B71C1C;
    classDef service fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20;
    classDef repository fill:#FFE0B2,stroke:#EF6C00,color:#E65100;
    classDef database fill:#CFD8DC,stroke:#455A64,color:#263238;
    classDef external fill:#FFCDD2,stroke:#E53935,color:#B71C1C;
    classDef config fill:#F3E5F5,stroke:#8E24AA,color:#4A148C;
    classDef flyway fill:#ECEFF1,stroke:#607D8B,color:#455A64;
    classDef app fill:#E0E0E0,stroke:#9E9E9E,color:#424242;
```
