# stephismily/electiveportal architecture

> Architecture diagram of the GitHub repository stephismily/electiveportal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stephismily/electiveportal
- Repository: https://github.com/stephismily/electiveportal

## Overview

PSG Tech Elective Portal supports student registration and constrained elective submission, admin faculty onboarding, and faculty review, search, and Excel export. Browser pages call role-specific API routes; controllers validate requests and read or update MongoDB-backed account and selection records. JWT middleware authenticates protected routes. The README documents the frontend capabilities and API surface; source excerpts establish server, route, controller, model, and database wiring. Frontend request-level wiring was not excerpted, so those API links are documented rather than source-verified.

Main entry points: [`backend/middleware/auth.js`](https://github.com/stephismily/electiveportal/blob/master/backend/middleware/auth.js) (JWT role access), [`backend/server.js`](https://github.com/stephismily/electiveportal/blob/master/backend/server.js) (Express server), [`backend/controllers/authController.js`](https://github.com/stephismily/electiveportal/blob/master/backend/controllers/authController.js) (Account access), [`backend/routes/auth.js`](https://github.com/stephismily/electiveportal/blob/master/backend/routes/auth.js) (Authentication routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_web["Portal shell<br/>[index.html]"]
  node_client_app["Routing and theme<br/>[app.js]"]
  node_client_api["API and token helper<br/>[api.js]"]
  node_client_auth["Login and registration<br/>[auth.js]"]
  node_client_admin["Admin dashboard<br/>[admin.js]"]
  node_client_faculty["Faculty dashboard<br/>[faculty.js]"]
  node_client_student["Elective selection<br/>[student.js]"]
end

subgraph group_api["API and access"]
  node_server["Express server<br/>[server.js]"]
  node_auth_routes["Authentication routes<br/>[auth.js]"]
  node_admin_routes["Admin routes<br/>[admin.js]"]
  node_faculty_routes["Faculty routes<br/>[faculty.js]"]
  node_student_routes["Student routes<br/>[student.js]"]
  node_jwt_access["JWT role access<br/>[auth.js]"]
end

subgraph group_workflows["Portal workflows"]
  node_auth_workflow["Account access<br/>[authController.js]"]
  node_admin_workflow["Faculty onboarding<br/>[adminController.js]"]
  node_faculty_workflow["Faculty reporting"]
  node_student_workflow["Elective submission"]
end

subgraph group_data["Persistence"]
  node_admin_model["Admin account<br/>[Admin.js]"]
  node_faculty_model["Faculty account<br/>[Faculty.js]"]
  node_student_model["Student and electives<br/>[Student.js]"]
  node_db_connect["MongoDB connection<br/>[db.js]"]
end

node_browser(("Student, faculty, admin"))
node_mongodb[("MongoDB")]

node_browser -->|"opens portal"| node_web
node_web -->|"loads client"| node_client_app
node_client_auth -->|"uses auth API"| node_auth_routes
node_client_admin -->|"uses admin API"| node_admin_routes
node_client_faculty -->|"uses faculty API"| node_faculty_routes
node_client_student -->|"uses student API"| node_student_routes
node_server -->|"connects database"| node_db_connect
node_server -->|"mounts routes"| node_auth_routes
node_server -->|"mounts routes"| node_admin_routes
node_server -->|"mounts routes"| node_faculty_routes
node_server -->|"mounts routes"| node_student_routes
node_auth_routes -->|"dispatches to"| node_auth_workflow
node_auth_routes -->|"protects profile"| node_jwt_access
node_admin_routes -->|"dispatches to"| node_admin_workflow
node_admin_routes -->|"protects routes"| node_jwt_access
node_faculty_routes -->|"dispatches to"| node_faculty_workflow
node_faculty_routes -->|"protects routes"| node_jwt_access
node_student_routes -->|"dispatches to"| node_student_workflow
node_student_routes -->|"protects routes"| node_jwt_access
node_auth_workflow -->|"queries accounts"| node_admin_model
node_auth_workflow -->|"queries accounts"| node_faculty_model
node_auth_workflow -->|"creates and queries"| node_student_model
node_admin_workflow -->|"manages faculty"| node_faculty_model
node_faculty_workflow -->|"updates password"| node_faculty_model
node_faculty_workflow -->|"queries selections"| node_student_model
node_student_workflow -->|"reads and updates"| node_student_model
node_jwt_access -->|"loads account"| node_admin_model
node_jwt_access -->|"loads account"| node_faculty_model
node_jwt_access -->|"loads account"| node_student_model
node_db_connect -->|"connects"| node_mongodb

click node_web "https://github.com/stephismily/electiveportal/blob/master/frontend/index.html"
click node_client_app "https://github.com/stephismily/electiveportal/blob/master/frontend/js/app.js"
click node_client_api "https://github.com/stephismily/electiveportal/blob/master/frontend/js/api.js"
click node_client_auth "https://github.com/stephismily/electiveportal/blob/master/frontend/js/auth.js"
click node_client_admin "https://github.com/stephismily/electiveportal/blob/master/frontend/js/admin.js"
click node_client_faculty "https://github.com/stephismily/electiveportal/blob/master/frontend/js/faculty.js"
click node_client_student "https://github.com/stephismily/electiveportal/blob/master/frontend/js/student.js"
click node_server "https://github.com/stephismily/electiveportal/blob/master/backend/server.js"
click node_auth_routes "https://github.com/stephismily/electiveportal/blob/master/backend/routes/auth.js"
click node_admin_routes "https://github.com/stephismily/electiveportal/blob/master/backend/routes/admin.js"
click node_faculty_routes "https://github.com/stephismily/electiveportal/blob/master/backend/routes/faculty.js"
click node_student_routes "https://github.com/stephismily/electiveportal/blob/master/backend/routes/student.js"
click node_jwt_access "https://github.com/stephismily/electiveportal/blob/master/backend/middleware/auth.js"
click node_auth_workflow "https://github.com/stephismily/electiveportal/blob/master/backend/controllers/authController.js"
click node_admin_workflow "https://github.com/stephismily/electiveportal/blob/master/backend/controllers/adminController.js"
click node_faculty_workflow "https://github.com/stephismily/electiveportal/blob/master/backend/controllers/facultyController.js"
click node_student_workflow "https://github.com/stephismily/electiveportal/blob/master/backend/controllers/studentController.js"
click node_admin_model "https://github.com/stephismily/electiveportal/blob/master/backend/models/Admin.js"
click node_faculty_model "https://github.com/stephismily/electiveportal/blob/master/backend/models/Faculty.js"
click node_student_model "https://github.com/stephismily/electiveportal/blob/master/backend/models/Student.js"
click node_db_connect "https://github.com/stephismily/electiveportal/blob/master/backend/config/db.js"

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_web,node_client_app,node_client_api,node_client_auth,node_client_admin,node_client_faculty,node_client_student toneBlue
class node_server,node_auth_routes,node_admin_routes,node_faculty_routes,node_student_routes,node_jwt_access,node_mongodb toneAmber
class node_auth_workflow,node_admin_workflow,node_faculty_workflow,node_student_workflow toneMint
class node_admin_model,node_faculty_model,node_student_model,node_db_connect toneRose
class node_browser toneIndigo
```

## Components

### Web client

- [Portal shell](https://github.com/stephismily/electiveportal/blob/master/frontend/index.html): `frontend/index.html`
- [Routing and theme](https://github.com/stephismily/electiveportal/blob/master/frontend/js/app.js): `frontend/js/app.js`
- [API and token helper](https://github.com/stephismily/electiveportal/blob/master/frontend/js/api.js): `frontend/js/api.js`
- [Login and registration](https://github.com/stephismily/electiveportal/blob/master/frontend/js/auth.js): `frontend/js/auth.js`
- [Admin dashboard](https://github.com/stephismily/electiveportal/blob/master/frontend/js/admin.js): `frontend/js/admin.js`
- [Faculty dashboard](https://github.com/stephismily/electiveportal/blob/master/frontend/js/faculty.js): `frontend/js/faculty.js`
- [Elective selection](https://github.com/stephismily/electiveportal/blob/master/frontend/js/student.js): `frontend/js/student.js`

### API and access

- [Express server](https://github.com/stephismily/electiveportal/blob/master/backend/server.js): `backend/server.js`
- [Authentication routes](https://github.com/stephismily/electiveportal/blob/master/backend/routes/auth.js): `backend/routes/auth.js`
- [Admin routes](https://github.com/stephismily/electiveportal/blob/master/backend/routes/admin.js): `backend/routes/admin.js`
- [Faculty routes](https://github.com/stephismily/electiveportal/blob/master/backend/routes/faculty.js): `backend/routes/faculty.js`
- [Student routes](https://github.com/stephismily/electiveportal/blob/master/backend/routes/student.js): `backend/routes/student.js`
- [JWT role access](https://github.com/stephismily/electiveportal/blob/master/backend/middleware/auth.js): `backend/middleware/auth.js`

### Portal workflows

- [Account access](https://github.com/stephismily/electiveportal/blob/master/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Faculty onboarding](https://github.com/stephismily/electiveportal/blob/master/backend/controllers/adminController.js): `backend/controllers/adminController.js`
- [Faculty reporting](https://github.com/stephismily/electiveportal/blob/master/backend/controllers/facultyController.js): `backend/controllers/facultyController.js`
- [Elective submission](https://github.com/stephismily/electiveportal/blob/master/backend/controllers/studentController.js): `backend/controllers/studentController.js`

### Persistence

- [Admin account](https://github.com/stephismily/electiveportal/blob/master/backend/models/Admin.js): `backend/models/Admin.js`
- [Faculty account](https://github.com/stephismily/electiveportal/blob/master/backend/models/Faculty.js): `backend/models/Faculty.js`
- [Student and electives](https://github.com/stephismily/electiveportal/blob/master/backend/models/Student.js): `backend/models/Student.js`
- [MongoDB connection](https://github.com/stephismily/electiveportal/blob/master/backend/config/db.js): `backend/config/db.js`

### Other components

- **Student, faculty, admin**
- **MongoDB**

## Connections

- Student, faculty, admin → Portal shell: opens portal (evidence: `README.md`)
- Portal shell → Routing and theme: loads client (evidence: `README.md`)
- Login and registration → Authentication routes: uses auth API (evidence: `README.md`)
- Admin dashboard → Admin routes: uses admin API (evidence: `README.md`)
- Faculty dashboard → Faculty routes: uses faculty API (evidence: `README.md`)
- Elective selection → Student routes: uses student API (evidence: `README.md`)
- Express server → MongoDB connection: connects database (evidence: `backend/server.js`)
- Express server → Authentication routes: mounts routes (evidence: `backend/server.js`)
- Express server → Admin routes: mounts routes (evidence: `backend/server.js`)
- Express server → Faculty routes: mounts routes (evidence: `backend/server.js`)
- Express server → Student routes: mounts routes (evidence: `backend/server.js`)
- Authentication routes → Account access: dispatches to (evidence: `backend/routes/auth.js`)
- Authentication routes → JWT role access: protects profile (evidence: `backend/routes/auth.js`)
- Admin routes → Faculty onboarding: dispatches to (evidence: `backend/routes/admin.js`)
- Admin routes → JWT role access: protects routes (evidence: `backend/routes/admin.js`)
- Faculty routes → Faculty reporting: dispatches to (evidence: `backend/routes/faculty.js`)
- Faculty routes → JWT role access: protects routes (evidence: `backend/routes/faculty.js`)
- Student routes → Elective submission: dispatches to (evidence: `backend/routes/student.js`)
- Student routes → JWT role access: protects routes (evidence: `backend/routes/student.js`)
- Account access → Admin account: queries accounts (evidence: `backend/controllers/authController.js`)
- Account access → Faculty account: queries accounts (evidence: `backend/controllers/authController.js`)
- Account access → Student and electives: creates and queries (evidence: `backend/controllers/authController.js`)
- Faculty onboarding → Faculty account: manages faculty (evidence: `backend/controllers/adminController.js`)
- Faculty reporting → Faculty account: updates password (evidence: `backend/controllers/facultyController.js`)
- Faculty reporting → Student and electives: queries selections (evidence: `backend/controllers/facultyController.js`)
- Elective submission → Student and electives: reads and updates (evidence: `backend/controllers/studentController.js`)
- JWT role access → Admin account: loads account (evidence: `backend/middleware/auth.js`)
- JWT role access → Faculty account: loads account (evidence: `backend/middleware/auth.js`)
- JWT role access → Student and electives: loads account (evidence: `backend/middleware/auth.js`)
- MongoDB connection → MongoDB: connects (evidence: `backend/config/db.js`)
