# namnguyen1409/sp25-swp391-group2-se1889vj architecture

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

- Interactive diagram: https://gitdiagram.com/namnguyen1409/sp25-swp391-group2-se1889vj
- Repository: https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj

## Overview

##### Project type and purpose
- This is a monolithic, full-stack Spring Boot web application (“Rice Sales Management System”) that uses Thymeleaf for server-side rendering, exposes REST endpoints for AJAX/clients, and integrates with WebSocket for real-time notifications. Its purpose is to allow rice dealers to manage products, warehouses, invoices, customers, and users through a browser UI, backed by a Microsoft SQL Server database.

##### File structure
- Top-level: `pom.xml` (Maven build), `src/main/java` (all Java code), `src/main/resources` (static assets and Thymeleaf templates), `uploads` (file store).
- Packages under `java/com/group2/...`:
- `config` – Spring configuration (MVC, security, WebSocket, DataInitializer)
- `controller` – MVC + REST controllers
- `dto` – Data Transfer Objects for API payloads
- `entity` – JPA entities
- `repository` – Spring Data JPA repositories
- `service` & `service/impl` – Business logic layer
- `security` & `filter` – JWT auth, user details, Recaptcha
- `scheduler` – Scheduled tasks (balance, invoice)
- `mapper` – MapStruct or manual mapping between entities and DTOs
- `exception`, `handler` – Custom exceptions and global handlers
- `validation` – Custom validation annotations and validators
- `message` – Domain-specific messaging (e.g., invoice status)
- Other helpers: `util`, `specification` (dynamic query builders)
- Static/UI: `resources/static` (JS/CSS/images), `resources/templates` (Thymeleaf HTML), organized by functional modules (auth, customer, product, invoice, warehouse, etc.).

##### README for additional insights
- Confirms core modules: product, warehouse (with zones), invoice (import/export, sales/purchase), customer, user.
- Tech stack: Spring Boot (Web, Data JPA, Security, Validation, Thymeleaf), Microsoft SQL Server, Lombok, Maven, Java 21.
- Integration: SMTP mail service, Google reCAPTCHA, file storage for uploads.

##### Final advice
- Be as detailed as possible: break down the monolith into its logical modules (Security, Web/MVC, REST API, Services, Repositories, Scheduling, Storage, Messaging).
- External dependencies (DB, SMTP, Recaptcha).
- Avoid over-complicating: focus on essential flows (user login, CRUD operations, scheduled tasks, notifications).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        StaticAssets["Static Assets"]:::frontend
        Templates["Thymeleaf Templates"]:::frontend
    end

    %% Application Monolith
    subgraph "Spring Boot Application" 
        direction TB

        %% Web Layer
        subgraph "Web Layer" 
            direction TB
            Controllers["Controllers\n(MVC + REST)"]:::web
            MvcConfig["MvcConfig.java"]:::config
            WebSecurityConfig["WebSecurityConfig.java"]:::config
            JwtFilter["JwtAuthenticationFilter.java"]:::config
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            ServiceDir["Service Interfaces"]:::service
            ServiceImplDir["Service Implementations"]:::service
        end

        %% Data Access Layer
        subgraph "Data Access Layer"
            direction TB
            RepoDir["Repositories"]:::data
            SpecDir["Specifications"]:::data
        end

        %% Persistence
        subgraph "Persistence"
            direction TB
            EntityDir["JPA Entities"]:::data
            Database["SQL Server"]:::database
        end

        %% Scheduling
        subgraph "Scheduling Module"
            direction TB
            BalanceScheduler["BalanceScheduler"]:::scheduler
            InvoiceScheduler["InvoiceScheduler"]:::scheduler
        end

        %% File Storage
        subgraph "File Storage"
            direction TB
            Uploads["uploads/"]:::storage
            StorageProps["StorageProperties.java"]:::config
            StorageService["StorageService"]:::service
            FileSystemStorage["FileSystemStorageServiceImpl.java"]:::service
        end

        %% Messaging & WebSocket
        subgraph "Messaging & WebSocket"
            direction TB
            WebSocketConfig["WebSocketConfig.java"]:::config
            WebSocketController["WebSocketController"]:::web
            InvoiceStatusMsg["InvoiceStatusMessage.java"]:::message
        end

        %% Security & Authentication
        subgraph "Security & Authentication"
            direction TB
            SecurityDir["security package"]:::security
            JwtAuthFilter["JwtAuthenticationFilter.java"]:::security
            RecaptchaInterceptor["RecaptchaInterceptor.java"]:::security
        end

        %% External Integrations
        subgraph "External Integrations"
            direction TB
            EmailService["EmailService.java"]:::service
            EmailServiceImpl["EmailServiceImpl.java"]:::service
            RecaptchaService["RecaptchaService.java"]:::security
        end

        %% DTOs & Mappers
        subgraph "DTOs & Mappers"
            direction TB
            DtoDir["DTO package"]:::data
            MapperDir["Mapper package"]:::data
        end

        %% Validation & Exception Handling
        subgraph "Validation & Exception"
            direction TB
            ValidationDir["validation package"]:::data
            ExceptionDir["exception & handler"]:::data
        end

    end

    %% External Services
    SMTP["SMTP Mail Server"]:::cloud
    RecapAPI["Google reCAPTCHA API"]:::cloud

    %% Connections
    StaticAssets -->|loads| Controllers
    Templates -->|renders| Controllers
    Controllers -->|calls| ServiceDir
    MvcConfig --> Controllers
    WebSecurityConfig --> Controllers
    JwtFilter --> Controllers
    ServiceDir -->|uses| RepoDir
    ServiceImplDir --> RepoDir
    RepoDir --> Database
    SpecDir --> RepoDir
    EntityDir --> RepoDir
    BalanceScheduler --> ServiceDir
    InvoiceScheduler --> ServiceDir
    Uploads --> FileSystemStorage
    StorageProps --> FileSystemStorage
    StorageService --> FileSystemStorage
    FileSystemStorage --> Uploads
    Controllers --> FileSystemStorage
    Controllers --> WebSocketController
    WebSocketController --> WebSocketConfig
    WebSocketController --> StaticAssets
    ServiceDir --> EmailService
    EmailServiceImpl --> SMTP
    RecaptchaInterceptor --> RecapAPI
    Controllers --> RecaptchaInterceptor
    SecurityDir --> JwtAuthFilter
    RecaptchaService --> RecapAPI
    DtoDir --> MapperDir
    Controllers --> DtoDir
    ServiceDir --> MapperDir

    %% Click Events
    click StaticAssets "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/resources/static"
    click Templates "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/resources/templates"
    click Controllers "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/controller"
    click MvcConfig "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/config/MvcConfig.java"
    click WebSecurityConfig "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/config/WebSecurityConfig.java"
    click JwtFilter "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/filter/JwtAuthenticationFilter.java"
    click ServiceDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/service"
    click ServiceImplDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/service/impl"
    click RepoDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/repository"
    click SpecDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/specification"
    click EntityDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/entity"
    click Uploads "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/uploads/"
    click StorageProps "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/config/StorageProperties.java"
    click StorageService "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/service/StorageService.java"
    click FileSystemStorage "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/service/impl/FileSystemStorageServiceImpl.java"
    click WebSocketConfig "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/config/WebSocketConfig.java"
    click WebSocketController "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/controller/WebSocketController.java"
    click InvoiceStatusMsg "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/message/InvoiceStatusMessage.java"
    click SecurityDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/security"
    click JwtAuthFilter "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/filter/JwtAuthenticationFilter.java"
    click RecaptchaInterceptor "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/handler/RecaptchaInterceptor.java"
    click EmailService "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/service/EmailService.java"
    click EmailServiceImpl "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/service/impl/EmailServiceImpl.java"
    click RecaptchaService "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/blob/master/src/main/java/com/group2/sp25swp391group2se1889vj/security/RecaptchaService.java"
    click DtoDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/dto"
    click MapperDir "https://github.com/namnguyen1409/sp25-swp391-group2-se1889vj/tree/master/src/main/java/com/group2/sp25swp391group2se1889vj/mapper"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px
    classDef web fill:#bbf,stroke:#333,stroke-width:2px
    classDef config fill:#ddf,stroke:#333,stroke-width:2px
    classDef service fill:#bfb,stroke:#333,stroke-width:2px
    classDef data fill:#fea,stroke:#333,stroke-width:2px
    classDef database fill:#cff,stroke:#333,stroke-width:2px
    classDef scheduler fill:#fdd,stroke:#333,stroke-width:2px
    classDef storage fill:#fcf,stroke:#333,stroke-width:2px
    classDef message fill:#ffd,stroke:#333,stroke-width:2px
    classDef security fill:#fbb,stroke:#333,stroke-width:2px
    classDef cloud fill:#def,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
```
