# jomaroto/tani-back architecture

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

- Interactive diagram: https://gitdiagram.com/jomaroto/tani-back
- Repository: https://github.com/jomaroto/tani-back

## Overview

##### Project Type and Purpose
- This is a Java Spring‑Boot RESTful backend service (“TANI”) deployed via Google App Engine (see app.yaml, gcloudignore).
- It exposes endpoints for user management, products, orders, notifications, image handling, and email. Authentication is JWT‑based with Firebase integration.

##### File Structure Analysis
Top‑Level
- build.gradle, gradlew wrapper → Gradle‑based build and dependency management
- app.yaml → GAE deployment descriptor
- src/main/java/tani → Spring‑Boot code organized by layer
Layers under “tani”:
- config → security filters (FiltroToken), JWT utilities, Firebase initialization
- controllers → REST controllers (AutenticacionController, UsuarioController, ProductoController, PedidoController, NotificacionController)
- dto → request/response objects, organized by feature (usuario, producto, pedido, detallepedido, notificacion, otros)
- exceptions → global exception handler
- model → JPA entities and enums
- repositories → Spring Data JPA interfaces for each entity
- services/interfaces and services/impl → business‑logic interfaces and their implementations (e.g., UsuarioServicioImpl, ProductoServicioImpl, EmailServicioImpl, ImagenesServicioImpl)
Tests under src/test/java/tani/test → unit/integration tests per feature

1. Clients
– Web or Mobile frontend
– Third‑party cron/jobs (if any) for batch notifications or email
2. API Layer
– Spring MVC Controllers (HTTP endpoints)
– JWT Authentication Filter → intercepts requests, validates token via JWTUtils + FirebaseConfig
3. Service Layer
– Business services (UsuarioServicio, ProductoServicio, PedidoServicio, DetallePedidoServicio, NotificacionServicio, EmailServicio, ImagenesServicio)
– Orchestrate workflows across entities, handle validation, trigger external calls (email, Firebase notifications, image storage)
4. Data Access Layer
– Spring Data Repositories → CRUD against relational database (e.g., Cloud SQL)
5. Persistence
– SQL Database (MySQL/Postgres) storing tables: Usuario, Producto, ProductoTalla, Pedido, DetallePedido, Notificacion
6. External Services
– Firebase Cloud Messaging → push notifications
– SMTP or email‑relay service → EmailServicioImpl
– Cloud Storage or CDN → ImagenesServicioImpl

##### Relationships and Data Flow
– Controllers → Service Layer calls (business methods)
– Services → Repositories → Database
– Services → External Services (Email, Firebase, Image Storage)
– Controllers ← Exception Handler (global) for uniform error responses
– Config components (JWT filter) applied at the HTTP ingress to secure controller methods

##### Architectural Patterns & Principles
– Layered (Controller → Service → Repository → Database)
– Separation of Concerns: DTOs isolate API contract; Entities represent persistence; Services contain business logic
– Dependency Injection via Spring to wire config, repos, services
– Filter Chain for security (JWT, Firebase token validation)
– Externalization of cross‑cutting concerns: email, image storage, notifications

##### Detailed Capture of Essential Elements
– Illustrate entity flow: Repositories map Entities ↔ Database
– Highlight configurations (FirebaseConfig) that integrate external services
– Ensure test suite is represented as a separate bubble for “Automated Tests” interfacing at the controller and service layers

## Diagram (Mermaid)

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

    %% Security & Config
    subgraph "Security & Configuration" 
        direction TB
        FiltroToken["FiltroToken\n(JWT + Firebase Filter)"]:::config
        JWTUtils["JWTUtils"]:::config
        FirebaseConfig["FirebaseConfig"]:::config
    end

    %% Controllers
    subgraph "API Layer\n(Spring MVC Controllers)" 
        direction TB
        AutenticacionController["AutenticacionController"]:::controller
        UsuarioController["UsuarioController"]:::controller
        ProductoController["ProductoController"]:::controller
        PedidoController["PedidoController"]:::controller
        NotificacionController["NotificacionController"]:::controller
        ExcepcionesGlobales["ExcepcionesGlobales\n(Global Exception Handler)"]:::exception
    end

    %% DTOs
    DTOs["DTOs\n(request/response objects)"]:::dto

    %% Services
    subgraph "Service Layer" 
        direction TB
        UsuarioServicioImpl["UsuarioServicioImpl"]:::service
        ProductoServicioImpl["ProductoServicioImpl"]:::service
        PedidoServicioImpl["PedidoServicioImpl"]:::service
        DetallePedidoServicioImpl["DetallePedidoServicioImpl"]:::service
        EmailServicioImpl["EmailServicioImpl"]:::service
        ImagenesServicioImpl["ImagenesServicioImpl"]:::service
        NotificacionServicioImpl["NotificacionServicioImpl"]:::service
    end

    %% Repositories
    subgraph "Data Access Layer\n(Spring Data JPA Repositories)"
        direction TB
        UsuarioRepo["UsuarioRepo"]:::repository
        ProductoRepo["ProductoRepo"]:::repository
        ProductoTallaRepo["ProductoTallaRepo"]:::repository
        PedidoRepo["PedidoRepo"]:::repository
        DetallePedidoRepo["DetallePedidoRepo"]:::repository
        NotificacionRepo["NotificacionRepo"]:::repository
    end

    %% Persistence
    Database[(SQL Database)]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        FirebaseFCM["Firebase Cloud Messaging"]:::external
        SMTP["SMTP / Email Relay"]:::external
        CloudStorage["Cloud Storage / CDN"]:::external
    end

    %% Project Artifacts
    subgraph "Project Artifacts"
        direction TB
        TANIApplication["TANIApplication\n(Spring Boot Entry)"]:::artifact
        AppYaml["app.yaml"]:::artifact
        Gradle["build.gradle"]:::artifact
    end

    %% Tests
    Tests["Automated Tests\n(unit & integration)"]:::test

    %% Connections
    Client -->|"Authorization: Bearer <token>"| FiltroToken
    FiltroToken -->|passes to| AutenticacionController
    FiltroToken -->|passes to| UsuarioController
    FiltroToken -->|passes to| ProductoController
    FiltroToken -->|passes to| PedidoController
    FiltroToken -->|passes to| NotificacionController

    AutenticacionController -->|uses DTOs| DTOs
    UsuarioController -->|uses DTOs| DTOs
    ProductoController -->|uses DTOs| DTOs
    PedidoController -->|uses DTOs| DTOs
    NotificacionController -->|uses DTOs| DTOs

    AutenticacionController -->|calls| UsuarioServicioImpl
    UsuarioController -->|calls| UsuarioServicioImpl
    ProductoController -->|calls| ProductoServicioImpl
    PedidoController -->|calls| PedidoServicioImpl
    PedidoController -->|calls| DetallePedidoServicioImpl
    NotificacionController -->|calls| NotificacionServicioImpl

    UsuarioServicioImpl -->|CRUD| UsuarioRepo
    ProductoServicioImpl -->|CRUD| ProductoRepo
    ProductoServicioImpl -->|CRUD| ProductoTallaRepo
    PedidoServicioImpl -->|CRUD| PedidoRepo
    DetallePedidoServicioImpl -->|CRUD| DetallePedidoRepo
    NotificacionServicioImpl -->|CRUD| NotificacionRepo

    UsuarioRepo -->|reads/writes| Database
    ProductoRepo -->|reads/writes| Database
    ProductoTallaRepo -->|reads/writes| Database
    PedidoRepo -->|reads/writes| Database
    DetallePedidoRepo -->|reads/writes| Database
    NotificacionRepo -->|reads/writes| Database

    EmailServicioImpl -->|sends email via| SMTP
    ImagenesServicioImpl -->|stores images on| CloudStorage
    NotificacionServicioImpl -->|push via| FirebaseFCM

    Controllers -->|errors to| ExcepcionesGlobales

    TANIApplication -->|bootstraps| AutenticacionController
    TANIApplication -->|bootstraps| UsuarioController
    TANIApplication -->|bootstraps| ProductoController
    TANIApplication -->|bootstraps| PedidoController
    TANIApplication -->|bootstraps| NotificacionController

    Tests -->|validate| AutenticacionController
    Tests -->|validate| UsuarioServicioImpl
    Tests -->|validate| ProductoServicioImpl

    %% Click Events
    click TANIApplication "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/TANIApplication.java"
    click AppYaml "https://github.com/jomaroto/tani-back/blob/master/app.yaml"
    click Gradle "https://github.com/jomaroto/tani-back/blob/master/build.gradle"
    click FiltroToken "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/config/FiltroToken.java"
    click JWTUtils "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/config/JWTUtils.java"
    click FirebaseConfig "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/config/FirebaseConfig.java"
    click ExcepcionesGlobales "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/exceptions/ExcepcionesGlobales.java"
    click AutenticacionController "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/controllers/AutenticacionController.java"
    click UsuarioController "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/controllers/UsuarioController.java"
    click ProductoController "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/controllers/ProductoController.java"
    click PedidoController "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/controllers/PedidoController.java"
    click NotificacionController "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/controllers/NotificacionController.java"
    click DTOs "https://github.com/jomaroto/tani-back/tree/master/src/main/java/tani/dto"
    click UsuarioServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/UsuarioServicioImpl.java"
    click ProductoServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/ProductoServicioImpl.java"
    click PedidoServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/PedidoServicioImpl.java"
    click DetallePedidoServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/DetallePedidoServicioImpl.java"
    click EmailServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/EmailServicioImpl.java"
    click ImagenesServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/ImagenesServicioImpl.java"
    click NotificacionServicioImpl "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/services/impl/NotificacionServicioImpl.java"
    click UsuarioRepo "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/repositories/UsuarioRepo.java"
    click ProductoRepo "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/repositories/ProductoRepo.java"
    click ProductoTallaRepo "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/repositories/ProductoTallaRepo.java"
    click PedidoRepo "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/repositories/PedidoRepo.java"
    click DetallePedidoRepo "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/repositories/DetallePedidoRepo.java"
    click NotificacionRepo "https://github.com/jomaroto/tani-back/blob/master/src/main/java/tani/repositories/NotificacionRepo.java"
    click Tests "https://github.com/jomaroto/tani-back/tree/master/src/test/java/tani/test"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef config fill:#FFF4C1,stroke:#333,stroke-width:1px
    classDef controller fill:#C1E1FF,stroke:#333,stroke-width:1px
    classDef service fill:#D1FFD6,stroke:#333,stroke-width:1px
    classDef repository fill:#FFD8B1,stroke:#333,stroke-width:1px
    classDef database fill:#FFFFFF,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#E8D0FF,stroke:#333,stroke-width:1px
    classDef exception fill:#FFCCCC,stroke:#333,stroke-width:1px
    classDef dto fill:#EEEEEE,stroke:#333,stroke-width:1px
    classDef artifact fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef test fill:#FFD1DC,stroke:#333,stroke-width:1px
```
