# 2k4pxthanh/fe_school_manager architecture

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

- Interactive diagram: https://gitdiagram.com/2k4pxthanh/fe_school_manager
- Repository: https://github.com/2k4pxthanh/fe_school_manager

## Overview

##### Project Type and Purpose
- The project is a single-page application (SPA) built with React.
- It focuses on managing school-related data such as classes, grades, teachers, and students, and contains various pages for CRUD operations (e.g., CreateClass, EditStudent, Dashboard).
- There is state management via Redux (for authentication and more) and specialized services for API interactions.
- The overall purpose is to provide an intuitive interface where different school management tasks are performed.

##### Main Components
- User Interface Layer:
- Components: Reusable UI elements, e.g., Alert, BoxModel, BtnScroll, Pagination, and Select2.
- Pages: Distinct views such as Login, Dashboard, Classes, Grades, Teachers, Students, Create/Edit pages, and a NotFound404.
- Layouts: DefaultLayout that encapsulates common components like Navbar and Sidebar (as found under src/layouts and src/layouts/components).

- State and Business Logic:
- Redux Store: Highlight the AuthReducer and overall state management defined in src/redux. Show how the components and pages interact with the Redux store.
- Hooks: For example, AuthContext (for authentication-related flows) that ensures the correct management of user state.
- Middlewares: The PrivateRoute component is used for route protection, ensuring only authenticated users access specific pages.

- Services and API Interaction:
- API Layer: Use services found in src/services (Api.js and Http.js) to represent the interface to external back-end services (even if the back-end isn’t part of this repository, the services are meant to communicate with it).

- Utilities and Assets:
- Utilities: Several helper functions (e.g., handleAlert, getAvatar, etc.) that support data formatting and UI handling.
- Assets: CSS and images under src/assets enhance the UI.

- Routing and Navigation:
- Routes: Defined in src/routes; outline how different pages are linked via the router.
- Public directory: Contains static files such as index.html and manifest configuration that kick off the application.

##### Relationships and Data Flow
- The UI components and pages then render according to the routes defined in src/routes.
- Layout components (DefaultLayout with Navbar and Sidebar) wrap around the views to provide a consistent UI.
- Pages communicate with the Redux store (e.g., updating or retrieving state managed by AuthReducer) as well as call out to API services (src/services/Api.js and Http.js) to fetch or submit data.
- Middleware (PrivateRoute) is used at routing level to control access to protected routes.
- Utility modules provide common functions used by components – these can be rendered as supporting blocks off the main UI nodes.

##### Architectural Patterns and Design Principles
- Component-based Architecture: The project clearly divides functionality into reusable components, pages, hooks, and layouts.
- Separation of Concerns: UI elements, state management, API interaction, and routing are clearly separated.
- Use of Modern State Management: Redux is employed for handling complex state (especially authentication data).
- Modular Design: Each directory serves a specific purpose (e.g., components, pages, services), enabling scalability and ease-of-maintenance.
- Integration of Route Protection via Middleware: The PrivateRoute component ensures certain routes require authentication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry & Bootstrapping Layer
    subgraph "Entry & Bootstrapping"
        entry1["public/index.html"]:::entry
        entry2["src/index.js"]:::entry
    end
    entry1 --> entry2

    %% User Interface Layer
    subgraph "User Interface"
        %% Reusable Components
        subgraph "Reusable Components"
            compAlert["Alert"]:::ui
            compBox["BoxModel"]:::ui
            compBtn["BtnScroll"]:::ui
            compGlobal["GlobalStyles"]:::ui
            compPagination["Pagination"]:::ui
            compSelect["Select2"]:::ui
        end

        %% Pages
        subgraph "Pages"
            pageLogin["Login"]:::ui
            pageDashboard["Dashboard"]:::ui
            pageClasses["Classes"]:::ui
            pageCreateClass["CreateClass"]:::ui
            pageEditClass["EditClass"]:::ui
            pageGrades["Grades"]:::ui
            pageCreateGrade["CreateGrade"]:::ui
            pageEditGrade["EditGrade"]:::ui
            pageTeachers["Teachers"]:::ui
            pageCreateTeacher["CreateTeacher"]:::ui
            pageEditTeacher["EditTeacher"]:::ui
            pageStudents["Students"]:::ui
            pageCreateStudent["CreateStudent"]:::ui
            pageEditStudent["EditStudent"]:::ui
            pageNotFound["NotFound404"]:::ui
        end

        %% Layouts
        subgraph "Layouts"
            layoutDefault["DefaultLayout"]:::ui
            layoutNavbar["Navbar"]:::ui
            layoutSidebar["Sidebar"]:::ui
        end
    end

    %% State Management Layer
    subgraph "State Management"
        reduxStore["Redux Store"]:::state
        authReducer["AuthReducer"]:::state
        authContext["Auth Context"]:::state
    end

    %% Routing & Middleware Layer
    subgraph "Routing & Middleware"
        routesConfig["Routes Configuration"]:::route
        privateRoute["PrivateRoute"]:::route
    end

    %% Services Layer
    subgraph "Services"
        apiService["API Service"]:::service
        httpService["HTTP Service"]:::service
    end

    %% Utilities Layer
    subgraph "Utilities"
        utilAvatar["getAvatar"]:::util
        utilAlert["handleAlert"]:::util
        utilActive["handleActiveWeb"]:::util
        utilDataTable["handleAddDataTableJquery"]:::util
        utilBirthday["handleBirthday"]:::util
        utilCallApi["handleCallSelectApi"]:::util
        utilIdValue["handleIdEqualValue"]:::util
        utilUpperCase["handleListUpperCase"]:::util
    end

    %% Assets Layer
    subgraph "Assets"
        assetsCSS["CSS"]:::asset
        assetsImages["Images"]:::asset
    end

    %% Relationships and Data Flow
    entry2 --> routesConfig
    routesConfig --> pageLogin
    routesConfig --> pageDashboard
    routesConfig --> pageClasses
    routesConfig --> pageGrades
    routesConfig --> pageTeachers
    routesConfig --> pageStudents
    routesConfig --> pageNotFound
    routesConfig --> privateRoute
    privateRoute --> pageCreateClass
    privateRoute --> pageEditClass
    privateRoute --> pageCreateGrade
    privateRoute --> pageEditGrade
    privateRoute --> pageCreateTeacher
    privateRoute --> pageEditTeacher
    privateRoute --> pageCreateStudent
    privateRoute --> pageEditStudent

    layoutDefault --> pageDashboard
    layoutDefault --> pageClasses
    layoutDefault --> pageGrades
    layoutDefault --> pageTeachers
    layoutDefault --> pageStudents
    layoutDefault --> pageNotFound
    layoutDefault --> layoutNavbar
    layoutDefault --> layoutSidebar
    layoutDefault --> routesConfig

    %% Pages utilizing Reusable Components
    pageDashboard --> compAlert
    pageClasses --> compBox
    pageGrades --> compBtn
    pageTeachers --> compPagination
    pageStudents --> compSelect
    pageLogin --> compGlobal

    %% Pages interacting with State Management
    pageDashboard --> reduxStore
    pageClasses --> reduxStore
    pageGrades --> reduxStore
    pageTeachers --> reduxStore
    pageStudents --> reduxStore
    reduxStore --> authReducer
    reduxStore --> authContext
    authContext --> reduxStore

    %% Pages interacting with Services
    pageDashboard --> apiService
    pageClasses --> apiService
    pageGrades --> apiService
    pageTeachers --> apiService
    pageStudents --> apiService
    pageDashboard --> httpService

    %% Components utilizing Utilities and Assets
    compAlert --> utilAlert
    compBox --> utilAvatar
    compGlobal --> assetsCSS
    compGlobal --> assetsImages

    %% Pages using additional Utilities
    pageDashboard --> utilActive
    pageDashboard --> utilDataTable
    pageDashboard --> utilBirthday
    pageDashboard --> utilCallApi
    pageDashboard --> utilIdValue
    pageDashboard --> utilUpperCase

    %% Click Events for Components and Files
    click compAlert "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/components/Alert/index.js"
    click compBox "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/components/BoxModel/index.js"
    click compBtn "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/components/BtnScroll/index.js"
    click compGlobal "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/components/GlobalStyles/index.js"
    click compPagination "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/components/Pagination/index.js"
    click compSelect "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/components/Select2/index.js"
    click pageLogin "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/Login/index.js"
    click pageDashboard "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/Dashboard/index.js"
    click pageClasses "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/Classes/index.js"
    click pageCreateClass "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/CreateClass/index.js"
    click pageEditClass "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/EditClass/index.js"
    click pageGrades "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/Grades/index.js"
    click pageCreateGrade "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/CreateGrade/index.js"
    click pageEditGrade "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/EditGrade/index.js"
    click pageTeachers "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/Teachers/index.js"
    click pageCreateTeacher "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/CreateTeacher/index.js"
    click pageEditTeacher "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/EditTeacher/index.js"
    click pageStudents "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/Students/index.js"
    click pageCreateStudent "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/CreateStudent/index.js"
    click pageEditStudent "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/EditStudent/index.js"
    click pageNotFound "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/pages/NotFound404/index.js"
    click layoutDefault "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/layouts/DefaultLayout/index.js"
    click layoutNavbar "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/layouts/components/Navbar/index.js"
    click layoutSidebar "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/layouts/components/Sidebar/index.js"
    click reduxStore "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/redux/store.js"
    click authReducer "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/redux/reducers/AuthReducer.js"
    click authContext "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/hooks/AuthContext.js"
    click routesConfig "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/routes/index.js"
    click privateRoute "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/middlewares/PrivateRoute.js"
    click apiService "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/services/Api.js"
    click httpService "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/services/Http.js"
    click utilAvatar "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/getAvatar.js"
    click utilAlert "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleAlert.js"
    click utilActive "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleActiveWeb.js"
    click utilDataTable "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleAddDataTableJquery.js"
    click utilBirthday "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleBirthday.js"
    click utilCallApi "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleCallSelectApi.js"
    click utilIdValue "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleIdEqualValue.js"
    click utilUpperCase "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/utils/handleListUpperCase.js"
    click entry2 "https://github.com/2k4pxthanh/fe_school_manager/blob/main/src/index.js"
    click entry1 "https://github.com/2k4pxthanh/fe_school_manager/blob/main/public/index.html"

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px;
    classDef ui fill:#bbf,stroke:#333,stroke-width:2px;
    classDef state fill:#bfb,stroke:#333,stroke-width:2px;
    classDef route fill:#fbf,stroke:#333,stroke-width:2px;
    classDef service fill:#ffb,stroke:#333,stroke-width:2px;
    classDef util fill:#aff,stroke:#333,stroke-width:2px;
    classDef asset fill:#fea,stroke:#333,stroke-width:2px;
```
