# ruhul-amin33/edu-web architecture

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

- Interactive diagram: https://gitdiagram.com/ruhul-amin33/edu-web
- Repository: https://github.com/ruhul-amin33/edu-web

## Overview

1. **Overall shape**
   - This is a single Node.js/Express monolith for an education platform, with server-side rendered pages rather than a separate SPA.
   - The main entrypoint is `server.js`, which wires HTTP routing, middleware, static assets, uploads, and database access.

2. **Presentation layer**
   - The UI is built with **EJS templates** under `views/`.
   - Shared page chrome lives in `views/partials/` (`layout`, `footer`, `sidebar`, social icons), while feature pages are split by domain: auth, student, exam, materials, courses, admin, teacher, admission.
   - Static frontend assets are in `public/css/style.css` and `public/js/main.js`, which support the bilingual UI, dark mode, animations, and responsive navigation.

3. **Route boundaries / application modules**
   - The app is organized by domain routes in `routes/`: `auth`, `student`, `exam`, `materials`, `courses`, `teacher`, `admin`, and `admission`.
   - Each route file corresponds to a functional subsystem and its pages, making the app closer to a modular MVC style than a thin REST API.

4. **Authentication and access control**
   - `middleware/auth.js` is the shared boundary for login/session enforcement and role-based authorization.
   - Roles matter structurally: students, teachers, and admins see different dashboards, navigation, and capabilities, and the middleware gates those paths.

5. **Data persistence**
   - Primary persistence is **MySQL**, configured through `config/db.js`.
   - `database.sql` is the base schema plus seed data, while the `migration_*.sql` files indicate incremental schema evolution for admissions, folder hierarchy, and year/board handling.
   - The data model supports users, questions, exams, materials, courses, purchases, reviews, reports, team members, and admin moderation state.

6. **File and content storage**
   - Uploaded content is stored under `uploads/`, split into `uploads/pdfs` for study materials and `uploads/avatars` for team/user images.
   - The README also describes optional **Cloudinary** storage for durable file hosting; when configured, it becomes the external asset store and avoids losing uploads on ephemeral disks.

7. **Student workflow**
   - Students authenticate, set up their stream/level, and then move through dashboard → materials browsing → course purchase → exam setup → exam taking → result/history.
   - Exam pages include timed question delivery, navigation, submission, results, and wrong-question reporting, all backed by server-side state and database records.

8. **Teacher workflow**
   - Teachers can create MCQ questions, bulk upload them, edit rejected items, and view question approval status.
   - Their submissions flow into an admin moderation queue, so teacher content is not directly published without review.

9. **Admin as the control plane**
   - The admin area is the operational center of the system: dashboard analytics, user/role management, course and material management, team/content management, review moderation, purchase verification, and question approval/rejection.
   - This subsystem also manages nested content organization, reflected by the folder-system migration and the materials/admin pages.

10. **External integrations**
   - Password reset relies on email delivery via Gmail credentials from `.env`.
   - Course payments are handled operationally through local business workflows for bKash/Nagad/Rocket rather than a visible payment API integration in this repo.
   - The app is designed to run locally or behind a process manager/reverse proxy in production, but the architecture remains a classic server-rendered web app with MySQL and file storage.

11. **Key data flows to diagram**
   - Browser request → Express route → auth middleware (if protected) → MySQL query / file access → EJS render → browser response.
   - Upload flows go from admin/teacher forms to filesystem or Cloudinary, then metadata is stored in MySQL.
   - Email reset flows go from auth routes to the mail provider.
   - Content moderation flows go from teacher/student submissions into admin review, then back into published content or rejection comments.

Main entry points: [`server.js`](https://github.com/ruhul-amin33/edu-web/blob/main/server.js) (server.js), [`config/db.js`](https://github.com/ruhul-amin33/edu-web/blob/main/config/db.js) (MySQL Config), [`routes/admin.js`](https://github.com/ruhul-amin33/edu-web/blob/main/routes/admin.js) (Admin), [`routes/teacher.js`](https://github.com/ruhul-amin33/edu-web/blob/main/routes/teacher.js) (Teacher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Presentation"]
  node_n11["Views<br/>ejs templates"]
  node_n12["Home & Pages<br/>public pages<br/>[home.ejs]"]
  node_n13["Admin Views<br/>admin pages"]
  node_n14["Domain Views<br/>feature pages"]
  node_n15["UI Assets<br/>frontend assets"]
end

subgraph group_g2["App Modules"]
  node_n1["server.js<br/>express entrypoint<br/>[server.js]"]
  node_n2["Auth<br/>route module<br/>[auth.js]"]
  node_n3["Student<br/>route module<br/>[student.js]"]
  node_n4["Teacher<br/>route module<br/>[teacher.js]"]
  node_n5["Admin<br/>route module<br/>[admin.js]"]
  node_n6["Exam<br/>route module<br/>[exam.js]"]
  node_n7["Materials<br/>route module<br/>[materials.js]"]
  node_n8["Courses<br/>route module<br/>[courses.js]"]
  node_n9["Admission<br/>route module<br/>[admission.js]"]
  node_n10["Auth Guard<br/>middleware<br/>[auth.js]"]
end

subgraph group_g3["Data Layer"]
  node_n16[("MySQL Config<br/>db config<br/>[db.js]")]
  node_n17["Schema<br/>[database.sql]"]
end

subgraph group_g4["Storage & Integrations"]
  node_n18["Uploads<br/>file storage"]
  node_n19(("Cloudinary<br/>external storage"))
  node_n20(("Email Reset<br/>email service"))
end

node_n1 -->|"protects"| node_n10
node_n1 -->|"mounts"| node_n2
node_n1 -->|"mounts"| node_n3
node_n1 -->|"mounts"| node_n4
node_n1 -->|"mounts"| node_n5
node_n1 -->|"mounts"| node_n6
node_n1 -->|"mounts"| node_n7
node_n1 -->|"mounts"| node_n8
node_n1 -->|"mounts"| node_n9
node_n1 -->|"renders"| node_n11
node_n1 -->|"serves"| node_n15
node_n1 -->|"queries"| node_n16
node_n16 -->|"uses"| node_n17
node_n2 -->|"sends"| node_n20
node_n4 -->|"uploads"| node_n18
node_n5 -->|"manages"| node_n18
node_n5 -.->|"optional"| node_n19
node_n3 -->|"submits to"| node_n5
node_n4 -->|"submits to"| node_n5
node_n6 -->|"records"| node_n16
node_n7 -->|"reads"| node_n16
node_n8 -->|"reads"| node_n16
node_n13 -->|"administers"| node_n16
node_n14 -->|"included in"| node_n11
node_n12 -->|"styled by"| node_n15

click node_n1 "https://github.com/ruhul-amin33/edu-web/blob/main/server.js"
click node_n2 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/auth.js"
click node_n3 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/student.js"
click node_n4 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/teacher.js"
click node_n5 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/admin.js"
click node_n6 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/exam.js"
click node_n7 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/materials.js"
click node_n8 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/courses.js"
click node_n9 "https://github.com/ruhul-amin33/edu-web/blob/main/routes/admission.js"
click node_n10 "https://github.com/ruhul-amin33/edu-web/blob/main/middleware/auth.js"
click node_n11 "https://github.com/ruhul-amin33/edu-web/tree/main/views"
click node_n12 "https://github.com/ruhul-amin33/edu-web/blob/main/views/home.ejs"
click node_n13 "https://github.com/ruhul-amin33/edu-web/tree/main/views/admin"
click node_n14 "https://github.com/ruhul-amin33/edu-web/tree/main/views/student"
click node_n15 "https://github.com/ruhul-amin33/edu-web/tree/main/public"
click node_n16 "https://github.com/ruhul-amin33/edu-web/blob/main/config/db.js"
click node_n17 "https://github.com/ruhul-amin33/edu-web/blob/main/database.sql"
click node_n18 "https://github.com/ruhul-amin33/edu-web/tree/main/uploads"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n11,node_n12,node_n13,node_n14,node_n15 toneBlue
class node_n1,node_n2,node_n3,node_n4,node_n5,node_n6,node_n7,node_n8,node_n9,node_n10 toneAmber
class node_n16,node_n17 toneMint
class node_n18,node_n19,node_n20 toneRose
```

## Components

### Presentation

Server-rendered pages and static assets

- [Views](https://github.com/ruhul-amin33/edu-web/tree/main/views): ejs templates · Server-side rendered pages and shared layout partials · `views`
- [Home & Pages](https://github.com/ruhul-amin33/edu-web/blob/main/views/home.ejs): public pages · Landing pages, auth screens, student and domain views · `views/home.ejs`
- [Admin Views](https://github.com/ruhul-amin33/edu-web/tree/main/views/admin): admin pages · Admin dashboards, moderation, users, courses, materials, and reports · `views/admin`
- [Domain Views](https://github.com/ruhul-amin33/edu-web/tree/main/views/student): feature pages · Student, teacher, exam, courses, materials, and admission pages · `views/student`
- [UI Assets](https://github.com/ruhul-amin33/edu-web/tree/main/public): frontend assets · Shared stylesheet and client-side behavior for navigation, theme, and responsiveness · `public`

### App Modules

Express routes and shared middleware

- [server.js](https://github.com/ruhul-amin33/edu-web/blob/main/server.js): express entrypoint · Wires middleware, routes, static assets, uploads, and rendering · `server.js`
- [Auth](https://github.com/ruhul-amin33/edu-web/blob/main/routes/auth.js): route module · Login, registration, password reset, and session flows · `routes/auth.js`
- [Student](https://github.com/ruhul-amin33/edu-web/blob/main/routes/student.js): route module · Student dashboard, profile, and setup pages · `routes/student.js`
- [Teacher](https://github.com/ruhul-amin33/edu-web/blob/main/routes/teacher.js): route module · Question creation, bulk upload, editing, and exam setup · `routes/teacher.js`
- [Admin](https://github.com/ruhul-amin33/edu-web/blob/main/routes/admin.js): route module · Operational control plane for users, content, moderation, and analytics · `routes/admin.js`
- [Exam](https://github.com/ruhul-amin33/edu-web/blob/main/routes/exam.js): route module · Exam browsing, setup, taking, results, and history · `routes/exam.js`
- [Materials](https://github.com/ruhul-amin33/edu-web/blob/main/routes/materials.js): route module · Material browsing, search, and access pages · `routes/materials.js`
- [Courses](https://github.com/ruhul-amin33/edu-web/blob/main/routes/courses.js): route module · Course catalog and detail pages · `routes/courses.js`
- [Admission](https://github.com/ruhul-amin33/edu-web/blob/main/routes/admission.js): route module · Admission landing and related flow · `routes/admission.js`
- [Auth Guard](https://github.com/ruhul-amin33/edu-web/blob/main/middleware/auth.js): middleware · Shared login, session, and role-based access control · `middleware/auth.js`

### Data Layer

Database schema and persistence config

- [MySQL Config](https://github.com/ruhul-amin33/edu-web/blob/main/config/db.js): db config · Database connection and query setup · `config/db.js`
- [Schema](https://github.com/ruhul-amin33/edu-web/blob/main/database.sql): sql schema · Base schema, seed data, and incremental migrations · `database.sql`

### Storage & Integrations

Uploaded content and external services

- [Uploads](https://github.com/ruhul-amin33/edu-web/tree/main/uploads): file storage · Local storage for PDFs and avatars · `uploads`
- **Cloudinary**: external storage · Optional hosted file storage for durable uploads
- **Email Reset**: email service · Password reset delivery through Gmail credentials

## Connections

- server.js → Auth Guard: protects · Applies access control to protected routes
- server.js → Auth: mounts · Registers auth endpoints
- server.js → Student: mounts · Registers student endpoints
- server.js → Teacher: mounts · Registers teacher endpoints
- server.js → Admin: mounts · Registers admin endpoints
- server.js → Exam: mounts · Registers exam endpoints
- server.js → Materials: mounts · Registers materials endpoints
- server.js → Courses: mounts · Registers course endpoints
- server.js → Admission: mounts · Registers admission endpoints
- server.js → Views: renders · Serves EJS pages for responses
- server.js → UI Assets: serves · Exposes static CSS, JS, and images
- server.js → MySQL Config: queries · Reads and writes application data
- MySQL Config → Schema: uses · Connects the app to schema and migrations
- Auth → Email Reset: sends · Triggers password reset email delivery
- Teacher → Uploads: uploads · Stores teacher-uploaded question assets where needed
- Admin → Uploads: manages · Admin content operations may create or organize stored files
- Admin → Cloudinary: optional · Can publish uploads to hosted storage when configured
- Student → Admin: submits to · Student activity and admin-managed state flow to moderation or review
- Teacher → Admin: submits to · Teacher questions enter the admin approval queue
- Exam → MySQL Config: records · Persists exam setup, attempts, results, and history
- Materials → MySQL Config: reads · Loads materials and purchase-related records
- Courses → MySQL Config: reads · Loads course catalog and detail data
- Admin Views → MySQL Config: administers · Moderation and management pages operate on database records
- Domain Views → Views: included in · Domain pages are rendered through the shared view system
- Home & Pages → UI Assets: styled by · Landing and public pages depend on shared UI assets
