# manbeoit18/cnpm_web architecture

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

- Interactive diagram: https://gitdiagram.com/manbeoit18/cnpm_web
- Repository: https://github.com/manbeoit18/cnpm_web

## Overview

##### Project Type and Purpose
- This is a full-stack application that seems designed to manage warehouse operations. The backend is a Spring Boot application (using Maven) and the frontend is implemented in a React-based framework (using Vite). The functionality revolves around managing products, inventory, receipts (both import and export), suppliers, user accounts, and authentication.
- The backend is structured under the “com.example.warehouse” package, featuring controllers, services, repositories, DTOs, entities, models, configuration files (for security, CORS, and JWT), and utility classes. The presence of data.sql indicates that the database is pre-populated or initialized on startup.
- The frontend, located in the “warehouse-frontend” directory, contains components, pages, assets, and utility files that communicate with the backend APIs.

##### Architectural Components
a. Main Components:
- Frontend Client: Represent the React/Vite application with UI components such as Login, Main Dashboard, Products, Inventory, Suppliers etc. Emphasize that these components handle user interaction, authentication (with a ProtectedRoute), and API calls.
- Backend Server: Represent the Spring Boot application, which should be further broken down into its layers:
- Controllers: For handling HTTP requests (e.g., AccountController, AuthController, ProductController, etc.).
- Services: Business logic handlers (e.g., AccountService, InventoryService, ProductService, etc.).
- Repositories: Data access layers (e.g., AccountRepository, ProductRepository, etc.).
- Configurations: Security, CORS, JWT filter configurations.
- Utilities: JWT utilities and any custom deserializers.
- Database: Represent the underlying relational database managed by Spring Data JPA (the initialization script data.sql hints at a SQL database).

b. Relationships and Interactions:
- Within the Backend, illustrate the layered architecture:
Controller → Service → Repository → Database.
- Optionally, include the flow for authentication, highlighting the auth endpoints (AuthController, LoginRequest/Response DTOs) to show how JWT is used to secure endpoints.

##### Important Architectural Patterns and Design Principles
- Layered Architecture/MVC: Separate concerns into controllers (presentation/API layer), services (business logic), and repositories (data access).
- RESTful API Design: Mark the API endpoints as part of the overall REST layout and show clear separation between resources.
- Separation of Frontend and Backend: Stress the decoupled nature of the system, where the frontend (React) is a completely separate project communicating with a Spring Boot backend via RESTful APIs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FEClient("Frontend Client (React/Vite)"):::frontend
        FEComponents("UI Components & Pages"):::frontend
        FE_API1("API Utility (api.js)"):::frontend
        FE_API2("API Utility (api.jsx)"):::frontend
    end

    %% Backend Main Architecture Subgraph
    subgraph "Backend"
        MainApp("Main Application"):::backend
        Controllers("Controllers"):::backend
        Services("Services"):::backend
        Repositories("Repositories"):::backend
        Database("Relational Database"):::database
    end

    %% Backend Data Modeling Subgraph
    subgraph "Backend Data Models"
        DTOs("DTOs"):::backend
        Entities("Entities"):::backend
        Models("Models"):::backend
    end

    %% Security and Configuration Subgraph
    subgraph "Security & Config"
        Configurations("Configurations (Security,CORS,JWT)"):::security
        Utilities("JWT Utility"):::backend
    end

    %% Frontend Relationships
    FEClient -->|"triggers"| FEComponents
    FEComponents -->|"calls API"| FE_API1
    FEComponents -->|"calls API"| FE_API2
    FE_API1 -->|"HTTP Request"| Controllers
    FE_API2 -->|"HTTP Request"| Controllers

    %% Backend Layered Architecture
    MainApp -->|"initializes"| Controllers
    Controllers -->|"delegates to"| Services
    Services -->|"queries via"| Repositories
    Repositories -->|"data operations"| Database

    %% Data Modeling Connections
    Controllers -->|"uses"| DTOs
    Services -->|"maps to"| Models
    Controllers -->|"maps entities"| Entities

    %% Security Connections
    Configurations -->|"secures"| Controllers
    Controllers -->|"validates JWT via"| Utilities

    %% Click Events for Frontend
    click FEClient "https://github.com/manbeoit18/cnpm_web/tree/master/warehouse-frontend"
    click FEComponents "https://github.com/manbeoit18/cnpm_web/tree/master/warehouse-frontend/src/components"
    click FEComponents "https://github.com/manbeoit18/cnpm_web/tree/master/warehouse-frontend/src/pages"
    click FE_API1 "https://github.com/manbeoit18/cnpm_web/blob/master/warehouse-frontend/src/utils/api.js"
    click FE_API2 "https://github.com/manbeoit18/cnpm_web/blob/master/warehouse-frontend/src/api.jsx"

    %% Click Events for Backend
    click MainApp "https://github.com/manbeoit18/cnpm_web/blob/master/backend/src/main/java/com/example/warehouse/BackendApplication.java"
    click Controllers "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/controller"
    click Services "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/service"
    click Repositories "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/repository"
    click DTOs "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/dto"
    click Entities "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/entity"
    click Models "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/model"
    click Configurations "https://github.com/manbeoit18/cnpm_web/tree/master/backend/src/main/java/com/example/warehouse/config"
    click Utilities "https://github.com/manbeoit18/cnpm_web/blob/master/backend/src/main/java/com/example/warehouse/util/JwtUtil.java"
    click Database "https://github.com/manbeoit18/cnpm_web/blob/master/backend/src/main/resources/data.sql"

    %% Class Definitions for Styling
    classDef frontend fill:#a2d9ce,stroke:#1e8449,stroke-width:2px;
    classDef backend fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef security fill:#f1948a,stroke:#c0392b,stroke-width:2px;
    classDef database fill:#edbb99,stroke:#cd6155,stroke-width:2px;
```
