# drekhai123/fall2024-swd392-se1707-group1 architecture

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

- Interactive diagram: https://gitdiagram.com/drekhai123/fall2024-swd392-se1707-group1
- Repository: https://github.com/drekhai123/fall2024-swd392-se1707-group1

## Overview

##### Main Components
- Backend (Web API):
- API Controllers (e.g., AccountController, CustomerController, etc.) that expose RESTful endpoints.
- Data Access Layer including Entity Framework’s DbContext (KDOSDbContext.cs) and Migrations.
- Domain Models and DTOs: The “Models” directory contains both domain objects and data transfer objects, segregating data concerns.
- Repositories: Both interface definitions (IAccountRepository, ICustomerRepository, etc.) and their SQL-based implementations that encapsulate data access logic.
- Services: Custom business logic components such as MailingService and VNPay integration, along with helpers for things like AutoMapper configuration.
- Configuration Files and Settings: appsettings.json and launchSettings.json for environment configuration.

- Frontend (React Application):
- Application Structure: A “src” folder with main entry point (index.js, App.js) and routing configuration.
- Components: Separated by roles (admin, customer, deliveryStaff, healthcare, staff) which show different views and functionalities.
- API Integration: Dedicated “api” folder with modules responsible for handling AJAX calls to the backend endpoints.
- UI/UX Elements: Components organized into common, form, and provider sections indicate design elements, utility functions, and state management (i.e., notification providers).
- Assets and Styling: Public assets and CSS files support the user interface.

##### Analyzing the Interactions
- Frontend ↔ Backend:
- The frontend makes HTTP requests (using APIs defined in the “api” folder) to the backend endpoints exposed by the controllers.
- API wrappers (for authentication, orders, payments, etc.) ensure the UI communicates with the correct backend services.
- Backend Data Flow:
- Controllers receive requests, map input data to DTOs, and then delegate processing to services.
- Services interact with repositories to perform CRUD operations on the database via KDOSDbContext.
- Mapping (via AutoMapperProfile) converts domain entities to DTOs for transmission back to the client.
- External Services:
- VNPay: Integration for payment processing.
- Mailing Services: To handle email notifications (registration, password reset, order invoices, etc.).

##### Architectural Patterns and Design Principles
- Layered Architecture: The clear separation between Controllers, Services, Repositories, and Data Models demonstrates the layered approach.
- API-First Design: Frontend and backend are decoupled via RESTful APIs.
- Separation of Concerns: Distinct directories for DTOs, domain models, and business logic ensure modularity and testability.
- Configuration Management: Use of environment-specific JSON settings for backend configuration.

To represent the system accurately, include the following elements:
a. A Frontend layer depicting the React application along with routing and UI components (e.g., admin dashboard, customer order pages, etc.).
b. A Backend layer consisting of:
- Controllers that expose API endpoints.
- A Service layer that encapsulates business logic (including VNPay and Mailing Services).
- A Repository layer for data access with interfaces and SQL-based implementations.
- A Database (Entity Framework-managed via migrations) representing persistent data storage.
- Auxiliary components such as AutoMapper for object mapping and configuration files (appsettings).
c. An External Integration section highlight:
- Payment Gateway (VNPay).
- Email/Mailing system.
- HTTP/REST communication from Frontend to Backend.
- Data flow within the backend between Controllers → Services → Repositories → Database.
- Communication with external services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE_Main["React Application (index.js, App.js)"]:::frontend
        FE_Routes["Routing Config (routes.js)"]:::frontend
        FE_Components["React UI Components"]:::frontend
        FE_API["API Integration Modules (AJAX)"]:::frontend
    end

    subgraph "Backend Layer"
        B_Controller["API Controllers"]:::backend
        B_Service["Service Layer"]:::backend
        subgraph "Services"
            MS["Mailing Service"]:::backend
            VN["VNPay Integration"]:::backend
            AutoMapper["AutoMapper Profile"]:::backend
        end
        B_Repo["Repository Layer"]:::backend
        B_Model["Domain Models & DTOs"]:::backend
        B_Db["Data Access Layer (DbContext)"]:::backend
        B_Config["Configuration Files (appsettings, launchSettings)"]:::backend
    end

    subgraph "Database"
        DB["Database (Entity Framework)"]:::database
    end

    subgraph "External Integrations"
        Ext_VN["External Payment Gateway (VNPay)"]:::external
        Ext_Mail["External Mailing System"]:::external
    end

    %% Frontend Relationships
    FE_Main --> FE_Routes
    FE_Main --> FE_Components
    FE_Main --> FE_API

    %% Frontend to Backend Communication
    FE_API -->|"RESTcalls"| B_Controller

    %% Backend Internal Flow
    B_Controller -->|"mapsData"| B_Model
    B_Controller -->|"delegates"| B_Service
    B_Service -->|"calls"| B_Repo
    B_Service -->|"usesMapping"| AutoMapper
    B_Service -->|"triggers"| MS
    B_Service -->|"triggers"| VN
    B_Repo -->|"CRUD"| B_Db
    B_Db --> DB
    B_Controller -->|"readsConfig"| B_Config

    %% External Integrations
    VN -->|"integrates"| Ext_VN
    MS -->|"emailsVia"| Ext_Mail

    %% Click Events
    click B_Controller "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Controllers"
    click B_Db "https://github.com/drekhai123/fall2024-swd392-se1707-group1/blob/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Datas/KDOSDbContext.cs"
    click B_Model "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Models"
    click B_Repo "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Repositories"
    click MS "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Services/MailingService"
    click VN "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Services/VNPay"
    click AutoMapper "https://github.com/drekhai123/fall2024-swd392-se1707-group1/blob/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/Mappings/AutoMapperProfile.cs"
    click B_Config "https://github.com/drekhai123/fall2024-swd392-se1707-group1/blob/main/backend/KDOS_Fall2024_SWD392_Group1_NETAPI/KDOS_Web_API/appsettings.json"
    click FE_Main "https://github.com/drekhai123/fall2024-swd392-se1707-group1/blob/main/frontend/kods/src/index.js"
    click FE_Routes "https://github.com/drekhai123/fall2024-swd392-se1707-group1/blob/main/frontend/kods/src/routes.js"
    click FE_Components "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/frontend/kods/src/components"
    click FE_API "https://github.com/drekhai123/fall2024-swd392-se1707-group1/tree/main/frontend/kods/src/components/api"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px,stroke-dasharray: 5,5;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
