# chiennguye/doantotnghiep architecture

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

- Interactive diagram: https://gitdiagram.com/chiennguye/doantotnghiep
- Repository: https://github.com/chiennguye/doantotnghiep

## Overview

##### Project type and purpose
- This is a full-stack web application for a milk-tea ordering business, consisting of:
- A customer-facing React/Redux SPA ("hhtlmilkteauser")
- An admin React/Redux SPA ("hhtlmilkteaadmin")
- A Spring Boot REST + WebSocket monolith ("hhtlmilkteaapi")
- A relational database (configured via JPA/Hibernate)
- External payment & media services (Momo, VNPay, Cloudinary, Google Maps)

##### File structure
- Two parallel React apps under `/hhtlmilkteauser` and `/hhtlmilkteaadmin` each with:
- Public folder (index.html, assets)
- `src/components`, `src/services` (API wrappers), `src/store` (Redux actions & reducers)
- Common utilities (APIClient.js, Notification.js, Constant.js)
- Backend under `/hhtlmilkteaapi` with:
- `controller` layer (REST & WebSocket endpoints)
- `service` layer (business logic, Cloudinary upload, URL shortener)
- `repository` layer (Spring Data JPA interfaces)
- `entity` + `payload` DTOs for requests/responses
- `security` config (JWT filter, entry point, user details)
- Database seeding under `seed`
- `application.properties`, Dockerfile, Procfile for cloud deployment

##### README for insights
- Contains login/test credentials for EmailJS, Momo sandbox, bank details
- Build hints (`--openssl-legacy-provider`) and peer-dep fixes
- Cloudinary and third-party integrations

##### Main components & interactions
a. Frontends (User SPA, Admin SPA)
– Host static assets (Docker/Nginx)
– Use React Router for navigation, Redux for client state
– Call backend via REST (Axios/APIClient) and WebSocket for real-time updates
b. Backend monolith
– Exposes REST endpoints (Auth, Product, Order, ChatBot, Notification, etc.)
– JWT-based authentication & authorization (roles via ERole)
– WebSocket channel for group orders/chat
– Business services (order processing, payment callbacks, URL shortening)
– Persists to relational DB via JPA repositories
c. Database
– Tables for users, roles, products, orders, add-options, sale-offs, etc.
– Seed data on startup
d. External services
– Momo & VNPay (payment gateways)
– Cloudinary (image upload)
– Google Maps (address autocomplete/geo)
– EmailJS (notifications)

##### Architectural patterns & design principles
- Frontends: component-driven UI, container/presentation, DRY common modules
- State management: Redux (actions → reducers → store)
- Backend: layered architecture (Controller → Service → Repository)
- Security: JWT filter, role-based access, CORS config
- Real-time: WebSocket for live events
- Deployment: Docker containers, Procfile for Heroku/GCP

[User SPA]   [Admin SPA]
↘         ↙
[API Server (Spring Boot)]
↓
[Database]
- Rectangle (blue) for frontends
- Rectangle (green) for API Server
d. Annotations:
- “Seed data” under Database

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontends"
        direction TB
        UserSPA["User SPA\nReact, Redux"]:::frontend
        AdminSPA["Admin SPA\nReact, Redux"]:::frontend
    end

    %% Backend Monolith
    subgraph "API Server (Spring Boot)" 
        direction TB
        APIInfo["Spring Boot\nJWT, WebSocket\nDockerized, Procfile"]:::backend
        subgraph "Controller Layer"
            Controllers["REST Controllers"]:::backend
            WebSocketConfig["WebSocket Config"]:::backend
        end
        subgraph "Service Layer"
            OrderService["OrderService"]:::backend
            CloudinaryService["CloudinaryService"]:::backend
            UrlShorterService["UrlShorterService"]:::backend
            NotificationService["NotificationService"]:::backend
        end
        subgraph "Repository Layer"
            Repositories["JPA Repositories"]:::backend
        end
        subgraph "Models & DTOs"
            Entities["Entities (JPA)"]:::backend
            DTOReq["Payload Requests"]:::backend
            DTORes["Payload Responses"]:::backend
        end
        subgraph "Security & Config"
            WebSecurityConfig["WebSecurityConfig"]:::backend
            AuthTokenFilter["AuthTokenFilter"]:::backend
            AuthEntryPointJwt["AuthEntryPointJwt"]:::backend
            JwtUtils["JwtUtils"]:::backend
            CustomizeUserService["CustomizeUserService"]:::backend
            JpaConfig["JpaConfig"]:::backend
            AppProps["application.properties"]:::backend
            Utils["Utility Classes"]:::backend
        end
        subgraph "Seed & Deployment"
            Seed["Database Seeding"]:::backend
            RootDockerfile["Root Dockerfile"]:::backend
            APIDockerfile["API Dockerfile"]:::backend
            Procfile["Procfile"]:::backend
            SystemProps["system.properties"]:::backend
        end
    end

    %% Database
    DB[(Database\nJPA/Hibernate\nSeed Data)]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        Momo["Momo"]:::external
        VNPay["VNPay"]:::external
        Cloudinary["Cloudinary"]:::external
        GoogleMaps["Google Maps"]:::external
        EmailJS["EmailJS"]:::external
    end

    %% Connections
    UserSPA -->|"REST API\nAxios/APIClient"| APIInfo
    AdminSPA -->|"REST API\nAxios/APIClient"| APIInfo
    UserSPA -.->|"WebSocket"| APIInfo
    AdminSPA -.->|"WebSocket"| APIInfo

    APIInfo -->|"JPA/Hibernate"| DB

    APIInfo -->|"REST/Callbacks"| Momo
    APIInfo -->|"REST/Callbacks"| VNPay
    APIInfo -->|"SDK/API"| Cloudinary
    APIInfo -->|"HTTP"| GoogleMaps
    APIInfo -->|"SMTP/API"| EmailJS

    %% Click Events
    click UserSPA "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteauser/"
    click AdminSPA "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaadmin/"
    click APIInfo "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/"
    click Controllers "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/controller/"
    click WebSocketConfig "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/config/WebSocketConfig.java"
    click WebSecurityConfig "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/config/WebSecurityConfig.java"
    click AuthTokenFilter "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/security/jwt/AuthTokenFilter.java"
    click AuthEntryPointJwt "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/security/jwt/AuthEntryPointJwt.java"
    click JwtUtils "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/security/jwt/JwtUtils.java"
    click CustomizeUserService "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/security/service/CustomizeUserService.java"
    click OrderService "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/service/OrderService.java"
    click CloudinaryService "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/service/CloudinaryService.java"
    click UrlShorterService "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/service/UrlShorterService.java"
    click NotificationService "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/service/NotificationService.java"
    click Repositories "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/repository/"
    click Entities "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/entity/"
    click DTOReq "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/payload/request/"
    click DTORes "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/payload/response/"
    click Seed "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/seed/"
    click AppProps "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/resources/application.properties"
    click JpaConfig "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/config/JpaConfig.java"
    click Utils "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/src/main/java/com/fpt/hhtlmilkteaapi/utility/Utils.java"
    click RootDockerfile "https://github.com/chiennguye/doantotnghiep/tree/main/Dockerfile"
    click APIDockerfile "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/Dockerfile"
    click Procfile "https://github.com/chiennguye/doantotnghiep/tree/main/hhtlmilkteaapi/Procfile"
    click SystemProps "https://github.com/chiennguye/doantotnghiep/blob/main/hhtlmilkteaapi/system.properties"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#D0FFD8,stroke:#28a745,color:#28a745;
    classDef database fill:#FFE8A0,stroke:#db9e00,color:#db9e00;
    classDef external fill:#FDE2E4,stroke:#d73a49,color:#d73a49;
```
