# manhquydev/student-forum-web architecture

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

- Interactive diagram: https://gitdiagram.com/manhquydev/student-forum-web
- Repository: https://github.com/manhquydev/student-forum-web

## Overview

##### Project type and purpose
- This is a full-stack web application called “Diễn Đàn Sinh Viên” (Student Forum).
- Frontend: React SPA that provides UI for students to register, login, create/join forums, post, comment, etc.
- Backend: Node.js + Express REST API with JWT-based authentication, connecting to MongoDB for data persistence.

##### File structure
- Top-level folders:
- frontend/ – React source: components, pages, contexts, services, static assets.
- backend/ – Express API: config, models (Mongoose), controllers, routes, middleware, scripts, server entry, environment files.
- Patterns & conventions:
- Backend: MVC-style layering – routes → middleware → controllers → models → MongoDB.
- Frontend: Component-based UI, React Router for navigation, Context API for auth & DB status, a thin service layer (apiService.js) for HTTP.
- Config & Deployment:
- .env files in both frontend and backend for runtime variables (API URL, DB URI, JWT secret).
- vercel.json indicates deployment on Vercel.

##### README for additional insights
- Tech stack: Node.js 14+, MongoDB 4+, React.
- Features: Auth (student & admin), forum/post/comment CRUD, search, admin scripts (create/reset admin).
- Runtime flow:
- Frontend (http://localhost:3000) → calls → Backend (http://localhost:5001) → queries → MongoDB.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client / Browser"]:::frontend

    %% Frontend Layer
    subgraph "Frontend Layer"
        Pages["Pages"]:::frontend
        Components["Components"]:::frontend
        PrivateRoute["PrivateRoute.js"]:::frontend
        AdminRoute["AdminRoute.js"]:::frontend
        AuthContext["AuthContext.js"]:::frontend
        DBContext["DatabaseContext.js"]:::frontend
        APIService["apiService.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        APIGateway["server.js"]:::backend
        VercelConfig["vercel.json"]:::backend
        Env[".env"]:::backend
        DBConfig["db.js"]:::backend
        Routes["Routes"]:::backend
        AuthMiddleware["authMiddleware.js"]:::backend
        ErrorMiddleware["errorMiddleware.js"]:::backend
        Controllers["Controllers"]:::backend
        Models["Models"]:::backend
        subgraph "Scripts"
            CreateAdmin["createAdmin.js"]:::scripts
            ResetAdmin["resetAdminPassword.js"]:::scripts
        end
    end

    %% Database
    MongoDB["MongoDB"]:::database

    %% Connections
    Client --> Pages
    Pages --> APIService
    Components --> APIService
    PrivateRoute --> APIService
    AdminRoute --> APIService
    AuthContext --> APIService
    DBContext --> APIService
    APIService -->|"HTTP Requests"| APIGateway
    APIGateway -->|"uses routes"| Routes
    Routes -->|"auth check"| AuthMiddleware
    AuthMiddleware --> Controllers
    Routes -->|"error handling"| ErrorMiddleware
    Controllers --> Models
    DBConfig --> MongoDB
    Models --> MongoDB
    Env --> APIGateway
    VercelConfig --> APIGateway
    CreateAdmin --> MongoDB
    ResetAdmin --> MongoDB

    %% Click Events
    click Pages "https://github.com/manhquydev/student-forum-web/tree/main/frontend/src/pages/"
    click Components "https://github.com/manhquydev/student-forum-web/tree/main/frontend/src/components/"
    click PrivateRoute "https://github.com/manhquydev/student-forum-web/blob/main/frontend/src/components/PrivateRoute.js"
    click AdminRoute "https://github.com/manhquydev/student-forum-web/blob/main/frontend/src/components/AdminRoute.js"
    click AuthContext "https://github.com/manhquydev/student-forum-web/blob/main/frontend/src/contexts/AuthContext.js"
    click DBContext "https://github.com/manhquydev/student-forum-web/blob/main/frontend/src/context/DatabaseContext.js"
    click APIService "https://github.com/manhquydev/student-forum-web/blob/main/frontend/src/services/apiService.js"
    click APIGateway "https://github.com/manhquydev/student-forum-web/blob/main/backend/server.js"
    click VercelConfig "https://github.com/manhquydev/student-forum-web/blob/main/backend/vercel.json"
    click Env "https://github.com/manhquydev/student-forum-web/blob/main/backend/.env"
    click DBConfig "https://github.com/manhquydev/student-forum-web/blob/main/backend/config/db.js"
    click Routes "https://github.com/manhquydev/student-forum-web/tree/main/backend/routes/"
    click AuthMiddleware "https://github.com/manhquydev/student-forum-web/blob/main/backend/middleware/authMiddleware.js"
    click ErrorMiddleware "https://github.com/manhquydev/student-forum-web/blob/main/backend/middleware/errorMiddleware.js"
    click Controllers "https://github.com/manhquydev/student-forum-web/tree/main/backend/controllers/"
    click Models "https://github.com/manhquydev/student-forum-web/tree/main/backend/models/"
    click CreateAdmin "https://github.com/manhquydev/student-forum-web/blob/main/backend/scripts/createAdmin.js"
    click ResetAdmin "https://github.com/manhquydev/student-forum-web/blob/main/backend/scripts/resetAdminPassword.js"

    %% Styles
    classDef frontend fill:#e3f2fd,stroke:#2196f3,color:#0d47a1,stroke-width:1px
    classDef backend fill:#e8f5e9,stroke:#4caf50,color:#1b5e20,stroke-width:1px
    classDef database fill:#fff3e0,stroke:#ff9800,color:#e65100,stroke-width:1px
    classDef scripts fill:#eceff1,stroke:#90a4ae,color:#37474f,stroke-width:1px
```
