# subhash307/springboot-bitsandbytes architecture

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

- Interactive diagram: https://gitdiagram.com/subhash307/springboot-bitsandbytes
- Repository: https://github.com/subhash307/springboot-bitsandbytes

## Overview

##### Main Components
a. Client & API Layer
- External Clients (Postman, Swagger UI, Web Frontend)
- HTTP Endpoints (REST controllers: ProductController, CategoryController, UserController, CustomEndpoint)
b. Security Layer
- JwtRequestFilter (intercepts requests)
- SecurityConfig (configures HTTP security rules)
- JwtUtil + UserPrincipal + MyUserDetailsService (handles token creation & validation)
c. Service Layer
- ProductService, CategoryService, MyUserDetailsService
d. Data Access Layer
- Repositories (ProductRepository, CategoryRepository, UserRepository)
- Entities (Product, Category, User)
- Mappers (ProductMapper, CategoryMapper)
e. Persistence
- MySQL Database
f. Cross-Cutting Concerns
- DTOs (ProductDTO, CategoryDTO, UserDTO, ExceptionResponseDTO)
- GlobalExceptionHandler
- Logging (logback-spring.xml)
- Configuration (application.properties)

##### Relationships & Data Flow
1. Client → HTTP Request → Controllers
2. Controllers → call Services → (DTOs ↔ Entities mapped by Mappers)
3. Services → Repositories → Database
4. Repositories → return Entities → Services → Controllers → Response DTO
5. JwtRequestFilter intercepts incoming requests before Controllers; JwtUtil & UserPrincipal validate tokens against MyUserDetailsService.
6. GlobalExceptionHandler catches and formats exceptions into ExceptionResponseDTO.

##### Architectural Patterns
- Layered Architecture (Controller → Service → Repository → DB)
- DTO Pattern (separate data transfer objects vs. persistence entities)
- Spring Security Filter Chain (JWT authentication)
- Spring Data JPA (repository abstractions)

- All components (controllers, services, repos, entities, DTOs, mappers, security classes) clearly labeled
- External dependencies (MySQL, Swagger, Postman) shown as separate nodes
- Cross-cutting elements (GlobalExceptionHandler, logging config) noted on the side

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        direction TB
        Postman["Postman"] 
        SwaggerUI["Swagger UI"]
        WebFrontend["Web Frontend"]
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        ProductController["ProductController"]:::api
        CategoryController["CategoryController"]:::api
        UserController["UserController"]:::api
        CustomEndpoint["CustomEndpoint"]:::api
    end

    %% Security Layer
    subgraph "Security Layer"
        direction TB
        JwtRequestFilter["JwtRequestFilter"]:::security
        SecurityConfig["SecurityConfig"]:::security
        JwtUtil["JwtUtil"]:::security
        UserPrincipal["UserPrincipal"]:::security
        AuthUserDetailsService["MyUserDetailsService"]:::security
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        ProductService["ProductService"]:::service
        CategoryService["CategoryService"]:::service
        MyUserDetailsService["MyUserDetailsService"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        subgraph Repositories
            direction TB
            ProductRepository["ProductRepository"]:::data
            CategoryRepository["CategoryRepository"]:::data
            UserRepository["UserRepository"]:::data
        end
        subgraph Mappers
            direction TB
            ProductMapper["ProductMapper"]:::data
            CategoryMapper["CategoryMapper"]:::data
        end
        subgraph Entities
            direction TB
            ProductEntity["Product"]:::data
            CategoryEntity["Category"]:::data
            UserEntity["User"]:::data
        end
    end

    %% Database
    MySQLDB["MySQL Database"]:::db

    %% Cross-Cutting Concerns
    subgraph "Cross-Cutting"
        direction TB
        ProductDTO["ProductDTO"]:::cross
        CategoryDTO["CategoryDTO"]:::cross
        UserDTO["UserDTO"]:::cross
        ExceptionResponseDTO["ExceptionResponseDTO"]:::cross
        GlobalExceptionHandler["GlobalExceptionHandler"]:::cross
        LoggingConfig["logback-spring.xml"]:::cross
        AppConfig["application.properties"]:::cross
    end

    %% Connections
    Postman -->|HTTP Request| ProductController
    SwaggerUI -->|HTTP Request| ProductController
    WebFrontend -->|HTTP Request| ProductController
    ProductController -->|calls| ProductService
    CategoryController -->|calls| CategoryService
    UserController -->|calls| MyUserDetailsService
    CustomEndpoint -->|calls| ProductService

    JwtRequestFilter -->|JWT validation| JwtUtil
    JwtRequestFilter -->|loads user| AuthUserDetailsService
    JwtUtil -->|uses| UserPrincipal
    JwtRequestFilter -->|passes to| ProductController

    ProductService -->|uses| ProductRepository
    CategoryService -->|uses| CategoryRepository
    MyUserDetailsService -->|uses| UserRepository

    ProductService -->|maps| ProductMapper
    CategoryService -->|maps| CategoryMapper
    ProductMapper -->|entity↔dto| ProductEntity
    CategoryMapper -->|entity↔dto| CategoryEntity
    ProductMapper -->|entity↔dto| ProductDTO
    CategoryMapper -->|entity↔dto| CategoryDTO

    ProductRepository -->|SQL queries| MySQLDB
    CategoryRepository -->|SQL queries| MySQLDB
    UserRepository -->|SQL queries| MySQLDB

    ProductController -->|handles errors| GlobalExceptionHandler
    CategoryController -->|handles errors| GlobalExceptionHandler
    UserController -->|handles errors| GlobalExceptionHandler

    %% Click Events
    click ProductController "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/controller/ProductController.java"
    click CategoryController "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/controller/CategoryController.java"
    click UserController "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/controller/UserController.java"
    click CustomEndpoint "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/controller/CustomEndpoint.java"
    click JwtRequestFilter "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/security/JwtRequestFilter.java"
    click SecurityConfig "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/security/SecurityConfig.java"
    click JwtUtil "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/security/JwtUtil.java"
    click UserPrincipal "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/security/UserPrincipal.java"
    click AuthUserDetailsService "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/service/MyUserDetailsService.java"
    click ProductService "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/service/ProductService.java"
    click CategoryService "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/service/CategoryService.java"
    click ProductRepository "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/repository/ProductRepository.java"
    click CategoryRepository "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/repository/CategoryRepository.java"
    click UserRepository "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/repository/UserRepository.java"
    click ProductEntity "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/entity/Product.java"
    click CategoryEntity "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/entity/Category.java"
    click UserEntity "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/entity/User.java"
    click ProductMapper "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/mapper/ProductMapper.java"
    click CategoryMapper "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/mapper/CategoryMapper.java"
    click ProductDTO "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/dto/ProductDTO.java"
    click CategoryDTO "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/dto/CategoryDTO.java"
    click UserDTO "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/dto/UserDTO.java"
    click ExceptionResponseDTO "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/dto/ExceptionResponseDTO.java"
    click GlobalExceptionHandler "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/java/com/bitsnbytes/product/exception/GlobalExceptionHandler.java"
    click LoggingConfig "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/resources/logback-spring.xml"
    click AppConfig "https://github.com/subhash307/springboot-bitsandbytes/blob/main/productlist/src/main/resources/application.properties"

    %% Styles
    classDef api fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef service fill:#DFF2BF,stroke:#333,stroke-width:1px
    classDef data fill:#FFE7BA,stroke:#333,stroke-width:1px
    classDef security fill:#E2D5F7,stroke:#333,stroke-width:1px
    classDef db fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef cross fill:#F0F0F0,stroke:#333,stroke-width:1px
```
