# luongxuannhat/e_learning_fe architecture

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

- Interactive diagram: https://gitdiagram.com/luongxuannhat/e_learning_fe
- Repository: https://github.com/luongxuannhat/e_learning_fe

## Overview

##### Main Components of the System
- Frontend Application: Built with Next.js, it is composed of multiple route groups (pages) and specialized directories. Examples include pages for “educations”, “students”, “teachers”, “dang-ky-hoc-phan” (course registration), “quan-ly-*” (management modules for classes, courses, faculties, etc.), and more.
- Components & UI Elements: Under the “src/app/components” directory, you see reusable UI components (Alert, Navbar, Login Card, etc.) and other domain-specific widgets (video player, editor, paging).
- Middleware: The “src/middleware” directory contains authentication and authorization modules (Authen.tsx and Author.tsx) which enforce access controls.
- Models: Under “src/models”, there are definitions for key domain entities such as Attendance, Classes, ChatRoom, Document, Enrollment, Feedback, etc. These provide the data structures for the application’s business logic.
- Services: In “src/services”, you have business logic wrappers such as authService.ts and a general service module for backend interactions.

##### Relationships and Interactions
- The Entry Point (Next.js Routes): The “src/app” directory houses various routes (grouped by URL path, e.g., “(head-education)”, “quan-ly-hoc-phan”, “lop-hoc”, “tai-khoan”). Each of these components represents a distinct functional area (education management, course registration, account settings, etc.).
- UI and Reusable Components: Pages rely on components like the Navbar, Login Card, and sidebar built under “src/app/components” to keep the UI consistent and modular.
- Middleware Integration: As an access control layer, middleware (from “src/middleware”) intercepts page requests, checking authentication and authorization before requests hit the page components.
- Data Models and Services: The UI components and pages interact with the services layer (business logic) which in turn uses data models. This layer can be thought of as the “backend” logic even though it resides within the same Next.js project (typical for server-side rendering and API routes in Next.js).

##### Architectural Patterns and Design Principles
- Modular Routing: The extensive use of route folders under “src/app” suggests a deep modular approach where different user roles (secretaries, teachers, students, etc.) have dedicated pages and layouts.
- Separation of Concerns: UI components, middleware, data models, and services are clearly separated into different directories.
- Reusability: The design promotes reusable components (e.g., shared elements like login cards, alerts, navigation bars) which reduce duplication and improve maintainability.
- Next.js Specific Features: Leveraging Next.js’s file-based routing, dynamic routing (e.g., “[id]” folders), and middleware support.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Global Entities
    Browser["Browser (Client)"]:::client

    %% Next.js Frontend Layer
    subgraph "Next.js Frontend"
        direction TB
        %% Route Groups & Pages
        subgraph "Route Groups & Pages"
            headEd["Head-Education Routes"]:::route
            dangky["Dang-Ky-Hoc-Phan"]:::route
            quanly["Quan-Ly-Hoc-Phan"]:::route
            lophoc["Lop-Hoc"]:::route
            taikhoan["Tai-Khoan"]:::route
        end
        %% UI Components & Reusable Elements
        subgraph "UI Components"
            components["Reusable Components"]:::ui
            navbar["Navbar Component"]:::ui
            login["Login Card Component"]:::ui
        end
    end

    %% Middleware Layer
    subgraph "Middleware"
        authen["Authen (Authentication)"]:::middleware
        author["Author (Authorization)"]:::middleware
    end

    %% Business Logic / Services Layer
    subgraph "Business Logic / Services"
        services["Service Modules"]:::service
    end

    %% Data Models Layer
    subgraph "Data Models"
        models["Domain Entities"]:::data
    end

    %% Connections - Flow of Requests and Dependencies
    Browser -->|"Accesses"| headEd
    Browser -->|"Accesses"| dangky
    Browser -->|"Accesses"| quanly
    Browser -->|"Accesses"| lophoc
    Browser -->|"Accesses"| taikhoan

    headEd -->|"Renders"| components
    dangky -->|"Renders"| components
    quanly -->|"Renders"| components
    lophoc -->|"Renders"| components
    taikhoan -->|"Renders"| components

    components -->|"Includes"| navbar
    components -->|"Includes"| login

    %% Securing and Handling Requests
    headEd -->|"SecuredBy"| authen
    dangky -->|"SecuredBy"| authen
    quanly -->|"SecuredBy"| authen
    lophoc -->|"SecuredBy"| authen
    taikhoan -->|"SecuredBy"| authen

    authen -->|"Validates"| author
    author -->|"ForwardsTo"| services
    services -->|"InteractsWith"| models

    %% Click Events for Component Mappings
    click headEd "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/app/(head-education)/"
    click dangky "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/app/dang-ky-hoc-phan"
    click quanly "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/app/quan-ly-hoc-phan"
    click lophoc "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/app/lop-hoc"
    click taikhoan "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/app/tai-khoan"
    click components "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/app/components"
    click navbar "https://github.com/luongxuannhat/e_learning_fe/blob/main/src/app/components/navbar.tsx"
    click login "https://github.com/luongxuannhat/e_learning_fe/blob/main/src/app/components/login_card/login.tsx"
    click authen "https://github.com/luongxuannhat/e_learning_fe/blob/main/src/middleware/Authen.tsx"
    click author "https://github.com/luongxuannhat/e_learning_fe/blob/main/src/middleware/Author.tsx"
    click services "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/services"
    click models "https://github.com/luongxuannhat/e_learning_fe/tree/main/src/models"

    %% Styles
    classDef client fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef route fill:#87CEFA,stroke:#333,stroke-width:2px;
    classDef ui fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef middleware fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef service fill:#AFEEEE,stroke:#333,stroke-width:2px;
    classDef data fill:#FFE4B5,stroke:#333,stroke-width:2px;
```
