# mohitnamdev22/shelfsmart-backend architecture

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

- Interactive diagram: https://gitdiagram.com/mohitnamdev22/shelfsmart-backend
- Repository: https://github.com/mohitnamdev22/shelfsmart-backend

## Overview

##### Main Components
- REST API Layer (Controllers): Include components like UserController, InventoryController, AlertsController, ReportsController, SupplierController, and UserActivityController.
- Service Layer: Represent business logic with components such as InventoryService, UserService, SupplierService, UserActivityService, GeminiService (for AI suggestions), and InventoryTrendService.
- Data Access Layer: Illustrate the repositories (InventoryRepository, StockMovementRepository, SupplierRepository, UserActivityRepository, UserRepository) that manage database operations.
- Model Layer: Include key entities (InventoryItem, StockMovement, Supplier, User, UserActivity) that define the data models of the application.
- Security Layer: Show security configuration (SecurityConfig) and JWT-related components (JwtFilter, JwtUtil) ensuring the authentication and authorization aspects.
- Database: PostgreSQL (NeonDB) visualized as a separate component receiving data from the repositories.

##### Relationships and Data Flow
- Services, in turn, interact with the Repositories to perform CRUD operations on the PostgreSQL database.
- Also, indicate that certain service components (e.g., GeminiService) interface with the external Gemini API to get AI-driven suggestions.
- The Security components (SecurityConfig, JwtFilter, JwtUtil) intercept incoming requests to validate JWT tokens before controllers are invoked.
- A configuration block representing properties from application.properties.

##### Architectural Patterns & Design Principles
- Layered Architecture: Separate presentation (controllers), business logic (services), and persistence (repositories).
- Security Best Practices: Incorporate JWT-based authentication and authorization.
- RESTful API Design: Note the clearly defined endpoints with standardized HTTP methods for resource management.
- External API Integration: Emphasize the decoupling for AI suggestions via a service component that abstracts Gemini API calls.

##### Relevant Technologies
- Spring Boot (as the primary framework)
- Java 17
- Spring Security & JWT for authentication
- Spring Data JPA for ORM
- PostgreSQL for the database
- Maven for build management
- Gemini API for external integration

- Labels are legible and each component’s role is clear.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Nodes
    client("Client"):::client

    %% Security Layer
    sc("SecurityConfig"):::security
    jf("JwtFilter"):::security
    ju("JwtUtil"):::security

    %% REST API Layer (Controllers)
    subgraph "REST API Layer (Controllers)"
        uc("UserController"):::controller
        ic("InventoryController"):::controller
        ac("AlertsController"):::controller
        rc("ReportsController"):::controller
        supc("SupplierController"):::controller
        uac("UserActivityController"):::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        is("InventoryService"):::service
        us("UserService"):::service
        ss("SupplierService"):::service
        uas("UserActivityService"):::service
        gs("GeminiService"):::service
        its("InventoryTrendService"):::service
        cust("CustomUserDetailsService"):::service
    end

    %% Repository Layer
    subgraph "Data Access Layer (Repositories)"
        ir("InventoryRepository"):::repository
        smr("StockMovementRepository"):::repository
        sr("SupplierRepository"):::repository
        uar("UserActivityRepository"):::repository
        ur("UserRepository"):::repository
    end

    %% Model Layer
    subgraph "Model Layer"
        item("InventoryItem"):::model
        sm("StockMovement"):::model
        sup("Supplier"):::model
        user("User"):::model
        ua("UserActivity"):::model
    end

    %% Configuration & External Nodes
    conf("application.properties"):::config
    gem_ext("Gemini API"):::external
    db("PostgreSQL (NeonDB)"):::database

    %% Connections - Request Flow and Security
    client -->|"HTTP_Request"| jf
    jf -->|"Token_Validation"| ju
    jf -->|"Forward_Request"| uc
    jf -->|"Forward_Request"| ic
    jf -->|"Forward_Request"| ac
    jf -->|"Forward_Request"| rc
    jf -->|"Forward_Request"| supc
    jf -->|"Forward_Request"| uac

    %% Security Configuration
    sc -->|"configures"| jf
    sc -->|"configures"| ju
    sc -->|"uses"| cust

    %% Controllers to Services
    uc -->|"calls"| us
    ic -->|"calls"| is
    ac -->|"calls"| its
    rc -->|"calls"| is
    supc -->|"calls"| ss
    uac -->|"calls"| uas

    %% Configuration influences
    conf -->|"configures"| sc
    conf -->|"configures"| gs

    %% Services to Repositories
    is -->|"DB_Query"| ir
    us -->|"DB_Query"| ur
    ss -->|"DB_Query"| sr
    uas -->|"DB_Query"| uar
    its -->|"DB_Query"| smr

    %% GeminiService external integration
    gs -->|"ExternalCall"| gem_ext

    %% Repositories to Database
    ir -->|"CRUD"| db
    ur -->|"CRUD"| db
    sr -->|"CRUD"| db
    uar -->|"CRUD"| db
    smr -->|"CRUD"| db

    %% Class Definitions for Styles
    classDef client fill:#F0E68C,stroke:#000,stroke-width:1px;
    classDef controller fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef repository fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef model fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef security fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef config fill:#E6E6FA,stroke:#000,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef database fill:#E0FFFF,stroke:#000,stroke-width:1px;

    %% Click Events for Controllers
    click ac "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/controller/AlertsController.java"
    click ic "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/controller/InventoryController.java"
    click rc "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/controller/ReportsController.java"
    click supc "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/controller/SupplierController.java"
    click uac "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/controller/UserActivityController.java"
    click uc "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/controller/UserController.java"

    %% Click Events for Services
    click is "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/InventoryService.java"
    click us "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/UserService.java"
    click ss "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/SupplierService.java"
    click uas "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/UserActivityService.java"
    click gs "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/GeminiService.java"
    click its "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/InventoryTrendService.java"
    click cust "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/service/CustomUserDetailsService.java"

    %% Click Events for Repositories
    click ir "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/repository/InventoryRepository.java"
    click smr "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/repository/StockMovementRepository.java"
    click sr "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/repository/SupplierRepository.java"
    click uar "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/repository/UserActivityRepository.java"
    click ur "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/repository/UserRepository.java"

    %% Click Events for Models
    click item "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/model/InventoryItem.java"
    click sm "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/model/StockMovement.java"
    click sup "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/model/Supplier.java"
    click user "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/model/User.java"
    click ua "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/model/UserActivity.java"

    %% Click Events for Security Components
    click sc "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/config/SecurityConfig.java"
    click jf "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/security/JwtFilter.java"
    click ju "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/java/com/shelfsmart/shelfsmart_backend/security/JwtUtil.java"

    %% Click Event for Configuration
    click conf "https://github.com/mohitnamdev22/shelfsmart-backend/blob/main/src/main/resources/application.properties.sample"
```
