# tqanh23/course_regsistration_doan architecture

> Architecture diagram of the GitHub repository tqanh23/course_regsistration_doan, 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/tqanh23/course_regsistration_doan
- Repository: https://github.com/tqanh23/course_regsistration_doan

## Overview

##### Project Overview and Identification of Main Components
- Project Purpose: Although the README is brief (“Course_regsistration_doan”), the file structure reveals a course registration system with a full-stack setup. There is clearly a backend “server” component handling routes, controllers, middleware, models, and services for authentication and administration. In addition, there are multiple client interfaces:
– A web frontend (located in the “dkhp” directory) built with Vite and using React (files like App.jsx, main.jsx, index.html signal a React-based approach).
– Mobile applications: Two mobile projects exist (“dkhpmobile” and “thunghiem”) that are set up with Expo (evident from the .expo folders, app.jsons, and TypeScript files). They likely represent either alternative mobile interfaces (or versions/experiments) for accessing the course registration functionality.

##### Analyzing the File Structure for Architectural Clues
- Web Frontend (dkhp):
– Contains standard React files, styles, assets, and configuration (vite.config.js).
– The structure suggests a single-page application that interacts with the backend.
- Mobile Frontends (dkhpmobile, thunghiem):
– Both have assets, screens, and (in thunghiem) a dedicated navigation folder.
– Use Expo and TypeScript for mobile development.
- Server:
– Contains a clear MVC/MVP-like structure:
▪ “config” (db connection details),
▪ “controllers” (admin and auth logic),
▪ “middleware” (includes auth and role checking),
▪ “models” (database schemas for admin and student),
▪ “routes” (defining endpoints for admin, auth, and student functions),
▪ “services” (business logic for authentication).
– The main entry point is server.js, which likely sets up the Express (or similar) framework.
- Additional Directories:
– The presence of both “dkhpmobile” and “thunghiem” suggest that the project supports multiple client types or mobile experiences, which may have different navigational or UI requirements.

##### Key Relationships and Interactions
- All client applications (web and mobile) connect with the backend server via RESTful APIs. The backend—through its controllers, routes, and middleware—handles authentication, course registration logic, and potentially role-based access for admins and students.
- The server interacts with a database (although the exact database isn’t specified, the “db.js” in the config folder hints at setting up the connection) to store data related to users, courses, registrations, etc.
- For mobile applications, additional layers like navigation might be used to manage the flow between screens (as seen in thunghiem’s “navigation/Navigation.tsx”).

##### Architectural Patterns / Principles
- Full-stack separation: clear separation of frontend (web and mobile) and backend.
- MVC-like pattern on the backend: controllers, models, and routes are distinctly managed.
- RESTful API communication with clearly defined endpoints (see multiple route files in “server/src/routes”).
- For mobile apps, using Expo and TypeScript ensures cross-platform compatibility and robust typing.
- Use of middleware on the server (authMiddleware, roleMiddleware) highlights an emphasis on security and request validation.

##### Additional Suggestions for Detail

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        client_web["Web Frontend (React/Vite)"]
        client_mobile1["Mobile Client (Expo - dkhpmobile)"]
        client_mobile2["Mobile Client (Expo - thunghiem)"]
        mobile_nav["Mobile Navigation"]
    end

    %% Backend API Server with detailed subcomponents
    subgraph "Backend API Server"
        api["API Server (Entry Point)"]
        
        subgraph "Routes"
            routes_admin["Admin Routes"]
            routes_auth["Auth Routes"]
            routes_student["Student Routes"]
        end

        subgraph "Middleware"
            auth_middleware_admin["Auth Middleware (Admin)"]
            auth_middleware_nonadmin["Auth Middleware"]
            role_middleware["Role Middleware"]
        end

        subgraph "Controllers"
            controllers_admin["Admin Controllers"]
            controllers_auth["Auth Controllers"]
        end

        subgraph "Data Layer"
            models_admin["Admin Model"]
            models_student["Student Model"]
            service_auth["Auth Service"]
            db_config["DB Configuration"]
        end
    end

    %% Database
    database(("Database"))

    %% Connections from Clients to Backend
    client_web -->|"API_Request"| api
    client_mobile1 -->|"API_Request"| api
    client_mobile2 -- "navigate" --> mobile_nav
    mobile_nav -->|"API_Request"| api

    %% Connections within Backend API Server
    api --> routes_admin
    api --> routes_auth
    api --> routes_student

    %% Routing flows with middleware separation
    routes_admin -->|"auth"| auth_middleware_admin
    routes_auth -->|"auth"| auth_middleware_nonadmin
    routes_student -->|"auth"| auth_middleware_nonadmin

    auth_middleware_admin -->|"role-check"| role_middleware
    role_middleware -->|"process"| controllers_admin

    auth_middleware_nonadmin -->|"process"| controllers_auth

    %% Controllers interactions to Data Layer
    controllers_admin -->|"DB_Operation"| models_admin
    controllers_admin -->|"logic"| service_auth

    controllers_auth -->|"DB_Operation"| models_student
    controllers_auth -->|"logic"| service_auth

    models_admin -->|"connect"| db_config
    models_student -->|"connect"| db_config
    service_auth -->|"connect"| db_config

    db_config -->|"DB_Query"| database

    %% Click Events for Client Layer
    click client_web "https://github.com/tqanh23/course_regsistration_doan/tree/main/dkhp/"
    click client_mobile1 "https://github.com/tqanh23/course_regsistration_doan/tree/main/dkhpmobile/"
    click client_mobile2 "https://github.com/tqanh23/course_regsistration_doan/tree/main/thunghiem/"
    click mobile_nav "https://github.com/tqanh23/course_regsistration_doan/blob/main/thunghiem/navigation/Navigation.tsx"

    %% Click Events for Backend API Server Components
    click api "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/server.js"
    click routes_admin "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/routes/adminRoutes.js"
    click routes_auth "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/routes/authRoutes.js"
    click routes_student "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/routes/studentRoutes.js"
    click auth_middleware_admin "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/middleware/authMiddleware.js"
    click auth_middleware_nonadmin "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/middleware/authMiddleware.js"
    click role_middleware "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/middleware/roleMiddleware.js"
    click controllers_admin "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/controllers/adminControllers.js"
    click controllers_auth "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/controllers/authControllers.js"
    click models_admin "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/models/admin.js"
    click models_student "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/models/student.js"
    click service_auth "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/services/adminAuthService.js"
    click db_config "https://github.com/tqanh23/course_regsistration_doan/blob/main/server/src/config/db.js"

    %% Styling
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef server fill:#F4A460,stroke:#000,stroke-width:1px;
    classDef database fill:#90EE90,stroke:#000,stroke-width:1px;

    class client_web,client_mobile1,client_mobile2,mobile_nav client;
    class api,routes_admin,routes_auth,routes_student,auth_middleware_admin,auth_middleware_nonadmin,role_middleware,controllers_admin,controllers_auth,models_admin,models_student,service_auth,db_config server;
    class database database;
```
