# ignorancio/backend-java-store architecture

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

- Interactive diagram: https://gitdiagram.com/ignorancio/backend-java-store
- Repository: https://github.com/ignorancio/backend-java-store

## Overview

- API Gateway/Entry Point: Represent the Spring Boot application (StoreApplication) that serves as the entry point.
- Modules (each as their own bounded context):
- Authentication: Includes AuthController and AuthService, handling JWT-based authentication and registration.
- Products: With ProductController, ProductServiceImpl, and distinct handling of caching via Redis.
- Categories: Contains controllers, service interfaces and implementations, and mappers.
- Orders: With order controllers, services, and domain entities representing order details.
- Search: Incorporates integration with Elasticsearch for product searches.
- Users: Manages user accounts, roles, and related operations.
- Shared/Configuration Components:
- Security Configurations: Including JwtService, SecurityConfig, and related filters (JwtAuthFilter).
- Global Exception Handling: ControllerAdvice and ErrorResponse.
- OpenAPI/Swagger Config: For API documentation.
- External Dependencies:
- Database: Postgres for data storage.
- Cache: Redis for caching products.
- Search Engine: Elasticsearch for search functionality.
- Docker/Docker Compose: For containerization and deployment.

##### Data Flows and Interactions
- From the controller layers, show interactions with the service (application) layer.
- The service layers should then call domain logic and use ports (or interfaces) for persistence, triggering repositories in the infrastructure layer.
- External calls are represented where repositories interact with Postgres for CRUD operations, Redis for caching, or Elasticsearch for search capabilities.
- Lines representing calls from security filters (JwtAuthFilter) to JwtService and related configurations in SecurityConfig.

##### Important Architectural Patterns and Technologies
- Hexagonal architecture by grouping the internal business logic (domain+application) inside a “core hexagon” with ports pointing to different adapters.
- Mention design patterns deployed (like dependency inversion, separation of concerns, and possibly adapter or mapper patterns where conversion between entities and DTOs happens).

##### Additional Recommended Elements
- Interactions via filters (JwtAuthFilter) and indicate the role of OpenAPI/Swagger in API documentation.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    Client["Client Request"]:::external

    %% API Gateway/Entry Point
    subgraph "API Gateway"
        SA["StoreApplication"]:::gateway
    end
    Client -->|"HTTP Request"| SA

    %% Authentication Module
    subgraph "Authentication Module"
        AC["AuthController"]:::controller
        AS["AuthService"]:::service
        AC -->|"calls"| AS
    end
    SA --> AC

    %% Products Module
    subgraph "Products Module"
        PC["ProductController"]:::controller
        PS["ProductServiceImpl"]:::service
        RP["RedisProductRepository"]:::adapter
        PC -->|"calls"| PS
        PS -->|"usesCaching"| RP
    end
    SA --> PC

    %% Categories Module
    subgraph "Categories Module"
        CC["CategoryController"]:::controller
        CS["CategoryServiceImpl"]:::service
        CR["CategoryRepository"]:::domain
        CM["CategoryMapper"]:::adapter
        CC -->|"calls"| CS
        CS -->|"persistsVia"| CR
        CS -->|"maps"| CM
    end
    SA --> CC

    %% Orders Module
    subgraph "Orders Module"
        OC["OrderController"]:::controller
        OS["OrderServiceImpl"]:::service
        OD["Order Domain"]:::domain
        OC -->|"calls"| OS
        OS -->|"operatesOn"| OD
    end
    SA --> OC

    %% Search Module
    subgraph "Search Module"
        SS["SearchServiceImpl"]:::service
        EP["ElasticProductRepository"]:::adapter
        SP["SearchProductRepository"]:::adapter
        SS -->|"calls"| EP
        SS -->|"calls"| SP
    end
    %% (Assuming Search is internally invoked via API endpoints)

    %% Users Module
    subgraph "Users Module"
        UC["UserController"]:::controller
        US["UserServiceImpl"]:::service
        UD["User Domain"]:::domain
        UC -->|"calls"| US
        US -->|"operatesOn"| UD
    end
    SA --> UC

    %% Shared / Configuration Components
    subgraph "Shared/Configuration"
        JS["JwtService"]:::config
        SC["SecurityConfig"]:::config
        JF["JwtAuthFilter"]:::config
        CAHandler["CustomAccessDeniedHandler"]:::config
        CAEntry["CustomAuthenticationEntryPoint"]:::config
        SW["SwaggerConfig"]:::config
        SC -->|"configures"| JF
        JF -->|"verifies"| JS
        SC -->|"sets"| CAHandler
        SC -->|"sets"| CAEntry
    end

    %% Global Exception Handling
    subgraph "Global Exception Handling"
        CA["ControllerAdvice"]:::config
        ER["ErrorResponse"]:::domain
        CA -->|"handles"| ER
    end

    %% Deployment Components
    subgraph "Deployment"
        DF["Dockerfile"]:::external
        DC["docker-compose.yml"]:::external
    end

    %% External Systems
    subgraph "External Systems"
        PG["Postgres DB"]:::external
        RD["Redis Cache"]:::external
        ES["Elasticsearch"]:::external
    end

    %% Module to External Systems Connections
    RP -->|"cachesIn"| RD
    EP -->|"queries"| ES
    SP -->|"queries"| ES
    CR -->|"persistsIn"| PG
    OD -->|"storesDataIn"| PG
    UD -->|"persistsIn"| PG

    %% Class Definitions with Colors
    classDef gateway fill:#ffcc00,stroke:#333,stroke-width:2px,color:#000;
    classDef controller fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef domain fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef adapter fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef config fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;

    %% Click Events
    click SA "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/StoreApplication.java"
    click AC "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/auth/infrastructure/AuthController.java"
    click AS "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/auth/application/AuthService.java"

    click PC "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/product/infrastructure/ProductController.java"
    click PS "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/product/application/ProductServiceImpl.java"
    click RP "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/product/infrastructure/repository/implementation/RedisProductRepository.java"

    click CC "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/category/infrastructure/CategoryController.java"
    click CS "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/category/application/CategoryServiceImpl.java"
    click CR "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/category/domain/CategoryRepository.java"
    click CM "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/category/infrastructure/mapper/CategoryMapper.java"

    click OC "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/order/infrastructure/OrderController.java"
    click OS "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/order/application/OrderServiceImpl.java"
    click OD "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/order/domain/Order.java"

    click SS "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/search/application/SearchServiceImpl.java"
    click EP "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/search/infrastructure/repository/ElasticProductRepository.java"
    click SP "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/search/infrastructure/repository/implementation/SearchProductRepository.java"

    click UC "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/user/infrastructure/UserController.java"
    click US "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/user/application/UserServiceImpl.java"
    click UD "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/user/domain/User.java"

    click JS "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/config/application/JwtService.java"
    click SC "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/config/infrastructure/SecurityConfig.java"
    click JF "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/config/infrastructure/filter/JwtAuthFilter.java"
    click CAHandler "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/config/infrastructure/CustomAccessDeniedHandler.java"
    click CAEntry "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/config/infrastructure/CustomAuthenticationEntryPoint.java"
    click SW "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/config/infrastructure/SwaggerConfig.java"

    click CA "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/exception/infrastructure/ControllerAdvice.java"
    click ER "https://github.com/ignorancio/backend-java-store/blob/main/src/main/java/com/example/store/exception/infrastructure/ErrorResponse.java"

    click DF "https://github.com/ignorancio/backend-java-store/tree/main/Dockerfile"
    click DC "https://github.com/ignorancio/backend-java-store/blob/main/docker-compose.yml"
```
