# longnt08/nhom6-financial-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/longnt08/nhom6-financial-management-system
- Repository: https://github.com/longnt08/nhom6-financial-management-system

## Overview

##### Project Overview and Type
- This is a full-stack enterprise application designed for financial management (accounting, auditing, budget, investment). The backend is built with Java EE using EJB for business logic and deployed on WildFly, while the frontend is a modern JavaScript client (built with React/Vite). The application also integrates with MongoDB as its primary data store.

##### Main Components
a. Frontend Client:
- Located in the “client” directory.
- Built using React with Vite configuration. It includes components/pages (e.g., AccountingPage, AuditPage) and service modules (AccountingService, AuditService) to interact with backend APIs.
- It handles user interactions and displays views (including forms and reports).

b. Backend Server:
- The core server-side code is under the “src” directory.
- Organized using Java EE conventions with layered patterns. Key packages include:
- Controller: Handles incoming API requests (e.g., AccountingController, AuditController).
- Service / Business Logic: Contains EJB components and local business services (e.g., AccountingRecordService, AuditServiceLocal).
- Repository/Data Access: Provides interfaces to MongoDB (e.g., AccountingRecordRepository, AuditRepository).
- Model: Defines domain entities (e.g., AccountingRecord, Audit, User).
- API & Utils: Contains shared interfaces, utilities for parsing JSON, JWT authentication, and MongoDB connections.
- Servlet and Web Layers: Handles legacy or JSP-based presentation (e.g., AccountingRecordServlet, various JSP pages under src/main/webapp) which may be used alongside RESTful API endpoints.
- Configuration files such as pom.xml, MongoDBConfig, ApplicationConfig help set up the environment and dependencies.

c. Infrastructure & External Services:
- WildFly: The Java EE application server used to run the backend services.
- MongoDB: The NoSQL database where financial data, user data, and other entities are stored.
- Maven: Build and dependency management tool ensuring proper packaging and deployment of the application.
- RESTful API Layer: Acts as the communication bridge between the frontend client and backend services.

##### Relationships and Interactions
- The backend interacts with MongoDB using specially configured utilities (MongoDBUtil, MongoDBConfig) and repository classes. Mark this connection clearly.
- Deployment process on WildFly, showing how the packaged application (WAR/EAR) is deployed, and how WildFly manages the application lifecycle.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separate presentation (both web and REST), business logic (EJB services), and data access (repositories).
- MVC-ish for the web part: Controllers/Servlets as “C”, JSP pages as “V”, and business services as “M” (with additional separation in the service layer).
- RESTful API: The client’s service calls are routed to the backend controllers.
- Dependency Injection and modular design provided by Java EE and EJB.

##### Detailed Component Breakdown
- Backend: Detail the “src/main/java/org/example” package segmentation: highlight the “controller”, “service”, “impl”, “repository”, “model”, “servlet”, and “utils” directories. This demonstrates a well-organized layered approach.
- Infrastructure: Mark out WildFly for deployment and MongoDB for persistent storage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client
    subgraph "Frontend Client"
        A["React Client"]:::frontend
        subgraph "Pages"
            A1["Accounting Page"]:::frontend
            A2["Audit Page"]:::frontend
        end
        subgraph "Services"
            A3["AccountingService"]:::frontend
            A4["AuditService"]:::frontend
        end
    end

    %% Backend Server
    subgraph "Backend Server"
        subgraph "Controllers"
            B1["AccountingController"]:::controller
            B2["AuditController"]:::controller
        end
        subgraph "Business Logic (EJB)"
            C1["AccountingRecordService"]:::service
            C2["AuditService (EJB)"]:::service
        end
        subgraph "Data Access"
            D1["AccountingRecordRepository"]:::repository
            D2["AuditRepository"]:::repository
        end
        subgraph "Domain Models"
            E1["AccountingRecord"]:::model
            E2["Audit"]:::model
            E3["User"]:::model
        end
        subgraph "API & Utilities"
            F1["JsonParsable"]:::api
            F2["JWTUtil"]:::api
            F3["MongoDBUtil"]:::api
            F4["Methods"]:::api
        end
        subgraph "Servlet & Web Layers"
            G1["AccountingRecordServlet"]:::api
            G2["JSP: accounting"]:::api
            G3["JSP: user"]:::api
        end
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        H1["WildFly"]:::external
        H2["MongoDB"]:::external
        H3["Maven"]:::config
        subgraph "Configuration"
            I1["pom.xml"]:::config
            I2["MongoDBConfig"]:::config
            I3["ApplicationConfig"]:::config
        end
    end

    %% Data Flow Connections
    %% Frontend to Backend Controllers via REST API calls
    A3 -->|"RESTAPICall"| B1
    A4 -->|"RESTAPICall"| B2

    %% Controllers calling Business Logic (EJB)
    B1 -->|"EJBInvoke"| C1
    B2 -->|"EJBInvoke"| C2

    %% Business Logic accessing Data Access layer
    C1 -->|"DataAccess"| D1
    C2 -->|"DataAccess"| D2

    %% Data Access interacting with Domain Models
    D1 -->|"CRUD"| E1
    D2 -->|"CRUD"| E2

    %% Controllers and Business Logic using API & Utilities
    B1 -->|"Uses"| F1
    B2 -->|"Uses"| F1
    C1 -->|"Utilizes"| F3
    C2 -->|"Utilizes"| F3
    G1 -->|"JWTCheck"| F2

    %% Servlet layer legacy interaction with Domain Models
    G1 -->|"LegacyAccess"| E1

    %% Deployment: Backend deployed on WildFly
    C1 -->|"Deployed_on"| H1
    C2 -->|"Deployed_on"| H1

    %% API & Utilities connecting to MongoDB
    F3 -->|"DB_Connection"| H2

    %% Maven build triggering backend deployment
    H3 -->|"BuildDeploy"| B1
    H3 -->|"BuildDeploy"| B2

    %% Maven linking to configuration files
    H3 -->|"Uses"| I1
    H3 -->|"Uses"| I2
    H3 -->|"Uses"| I3

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef controller fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef service fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef repository fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef model fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef api fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef external fill:#c3e6cb,stroke:#155724,stroke-width:2px;
    classDef config fill:#d6d8db,stroke:#1b1e21,stroke-width:2px;

    %% Click Events for Frontend
    click A "https://github.com/longnt08/nhom6-financial-management-system/tree/main/client"
    click A1 "https://github.com/longnt08/nhom6-financial-management-system/tree/main/client/src/pages/Accounting"
    click A2 "https://github.com/longnt08/nhom6-financial-management-system/tree/main/client/src/pages/Audit"
    click A3 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/client/src/services/AccountingService.js"
    click A4 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/client/src/services/AuditService.js"

    %% Click Events for Backend Controllers
    click B1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/controller/AccountingController.java"
    click B2 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/controller/AuditController.java"

    %% Click Events for Backend Business Logic / EJB Components
    click C1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/impl/AccountingRecordService.java"
    click C2 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/impl/AuditService.java"

    %% Click Events for Backend Data Access / Repositories
    click D1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/repository/AccountingRecordRepository.java"
    click D2 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/repository/AuditRepository.java"

    %% Click Events for Domain Models
    click E1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/model/AccountingRecord.java"
    click E2 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/model/Audit.java"
    click E3 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/model/User.java"

    %% Click Events for API & Utilities
    click F1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/api/JsonParsable.java"
    click F2 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/utils/JWTUtil.java"
    click F3 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/utils/MongoDBUtil.java"
    click F4 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/api/Methods.java"

    %% Click Events for Servlet & Web Layers
    click G1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/servlet/AccountingRecordServlet.java"
    click G2 "https://github.com/longnt08/nhom6-financial-management-system/tree/main/src/main/webapp/WEB-INF/accounting"
    click G3 "https://github.com/longnt08/nhom6-financial-management-system/tree/main/src/main/webapp/WEB-INF/user"

    %% Click Events for Configuration Files
    click I1 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/pom.xml"
    click I2 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/MongoDBConfig.java"
    click I3 "https://github.com/longnt08/nhom6-financial-management-system/blob/main/src/main/java/org/example/config/ApplicationConfig.java"
```
