# prodip-shadow/learnx architecture

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

- Interactive diagram: https://gitdiagram.com/prodip-shadow/learnx
- Repository: https://github.com/prodip-shadow/learnx

## Overview

#### Purpose and Runtime
This is a Next.js App Router learning/exam platform with public marketing/auth pages and role-specific dashboards for students, teachers, and administrators. It runs as a Node/Next.js application and exposes backend functionality through App Router route handlers under `src/app/api`. The root application entry and shared providers are `src/app/layout.jsx` and `src/providers/AuthProvider.jsx`.

#### Route and Layout Boundaries
Two route groups separate public/common UI from authenticated dashboard UI:
- Common-site pages and shell: `src/app/(withCommonLayout)/layout.jsx`, `src/app/(withCommonLayout)/page.jsx`, and pages such as `src/app/(withCommonLayout)/exams/page.jsx`.
- Dashboard shell and role areas: `src/app/(withDashboardLayout)/dashboard/layout.jsx`, with student, teacher, and admin subtrees.
Shared navigation and dashboard presentation live in `src/components/shared/Navbar.jsx` and `src/components/shared/DashboardSidebar.jsx`.

#### Authentication and Authorization
Firebase is the authentication integration, initialized in `src/lib/firebase.init.js`, exposed through `src/providers/AuthProvider.jsx`, and consumed via `src/hooks/useAuth.js`. Client-side role gates partition dashboard access through `src/components/StudentRoute.jsx`, `src/components/TeacherRoute.jsx`, and `src/components/AdminRoute.jsx`. This makes identity/session state a frontend-provider boundary, while API handlers must enforce their own data access rules.

#### Role-Based Learning Workflows
Students discover/join exams, submit work, track progress, and access resources through `src/app/(withDashboardLayout)/dashboard/student/my-exams/page.jsx`, `src/app/(withDashboardLayout)/dashboard/student/progress/page.jsx`, and `src/app/(withDashboardLayout)/dashboard/student/resources/page.jsx`.
Teachers create exams, review their exams/results, manage students, and publish resources from `src/app/(withDashboardLayout)/dashboard/teacher/create-exam/page.jsx`, `src/app/(withDashboardLayout)/dashboard/teacher/my-exams/page.jsx`, and `src/app/(withDashboardLayout)/dashboard/teacher/addResource/page.jsx`.
Administrators oversee users, exams, and aggregate results in `src/app/(withDashboardLayout)/dashboard/admin/users/page.jsx`, `src/app/(withDashboardLayout)/dashboard/admin/all-exams/page.jsx`, and `src/app/(withDashboardLayout)/dashboard/admin/all-exams-results/page.jsx`.

#### Exams Pipeline
Public exam discovery and participation UI is centered on `src/app/(withCommonLayout)/exams/page.jsx` with interactive units in `src/app/(withCommonLayout)/exams/_components/ExamHall.jsx` and `src/app/(withCommonLayout)/exams/_components/JoinModal.jsx`. Teachers create exams through `src/app/api/exams/create/route.js`; student completion posts to `src/app/api/exams/submit/route.js`. Result and management screens then consume the persisted exam/submission domain in their role-specific dashboard views.

#### Resources and Persistence Services
MongoDB is the application data-store integration via `src/lib/mongodb.js`. Resource operations are a distinct API boundary: creation/deletion/listing at `src/app/api/resources/create/route.js`, `src/app/api/resources/delete/route.js`, and `src/app/api/resources/get/route.js`; file access is mediated by parameterized open/download handlers at `src/app/api/resources/open/[resourceId]/route.js` and `src/app/api/resources/download/[resourceId]/route.js`. UI counterparts are consolidated in `src/components/ResourceComponents/`.

#### Supporting Services
User administration is handled by `src/app/api/users/route.js` and `src/app/api/users/update/route.js`. Student application/request handling is isolated in `src/app/api/become-student/route.js` and `src/app/api/become-student/manage/route.js`. A chatbot service is independently exposed through `src/app/api/chatbot/route.js`, with a diagnostic endpoint at `src/app/api/chatbot/diagnostic/route.js`, and rendered by `src/components/ChatBot/ChatBot.jsx`.

Main entry points: [`src/app/api/exams/create/route.js`](https://github.com/prodip-shadow/learnx/blob/main/src/app/api/exams/create/route.js) (Exam create and submit), [`src/lib/mongodb.js`](https://github.com/prodip-shadow/learnx/blob/main/src/lib/mongodb.js) (MongoDB), [`src/components/StudentRoute.jsx`](https://github.com/prodip-shadow/learnx/blob/main/src/components/StudentRoute.jsx) (Role route gates), [`src/app/(withCommonLayout)/exams/page.jsx`](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/page.jsx) (Exam discovery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js application"]
  node_root["Root layout<br/>app entry<br/>[layout.jsx]"]
  node_common["Public site shell<br/>route layout<br/>[layout.jsx]"]
  node_exam_discovery["Exam discovery<br/>public page<br/>[page.jsx]"]
  node_exam_hall["Exam hall<br/>interactive UI<br/>[ExamHall.jsx]"]
  node_join_modal["Join modal<br/>interactive UI<br/>[JoinModal.jsx]"]
  node_resources_ui["Resource components<br/>shared UI"]
end

subgraph group_auth["Identity and access"]
  node_route_gates{{"Role route gates<br/>client authorization<br/>[StudentRoute.jsx]"}}
  node_auth_provider["Auth provider<br/>session provider<br/>[AuthProvider.jsx]"]
  node_firebase{{"Firebase Auth<br/>authentication service<br/>[firebase.init.js]"}}
end

subgraph group_roles["Role dashboards"]
  node_dashboard["Dashboard shell<br/>route layout<br/>[layout.jsx]"]
  node_student["Student learning<br/>dashboard pages<br/>[page.jsx]"]
  node_teacher["Teacher exam management<br/>dashboard pages<br/>[page.jsx]"]
  node_admin["Admin oversight<br/>dashboard pages<br/>[page.jsx]"]
end

subgraph group_api["Backend route handlers"]
  node_exam_api["Exam create and submit<br/>exam API<br/>[route.js]"]
  node_resource_api["Resource API<br/>[route.js]"]
  node_users_api["User administration API<br/>user API<br/>[route.js]"]
  node_student_request_api["Student request API<br/>[route.js]"]
  node_chatbot["Chatbot service<br/>chat API and UI<br/>[route.js]"]
end

subgraph group_data["Persistence"]
  node_mongodb[("MongoDB<br/>application datastore<br/>[mongodb.js]")]
end

node_root -->|"installs"| node_auth_provider
node_auth_provider -->|"initializes session with"| node_firebase
node_common -->|"hosts"| node_exam_discovery
node_exam_discovery -->|"renders"| node_exam_hall
node_exam_hall -->|"opens"| node_join_modal
node_dashboard -->|"applies"| node_route_gates
node_route_gates -->|"permits student role"| node_student
node_route_gates -->|"permits teacher role"| node_teacher
node_route_gates -->|"permits admin role"| node_admin
node_exam_discovery -->|"joins and submits via"| node_exam_api
node_teacher -->|"creates and manages exams"| node_exam_api
node_student -->|"reads results and progress"| node_exam_api
node_admin -->|"oversees exams and results"| node_exam_api
node_teacher -->|"publishes resources"| node_resource_api
node_student -->|"accesses"| node_resources_ui
node_resources_ui -->|"retrieves files through"| node_resource_api
node_admin -->|"administers users"| node_users_api
node_student_request_api -->|"persists requests"| node_mongodb
node_exam_api -->|"persists exams and submissions"| node_mongodb
node_resource_api -->|"persists resource records"| node_mongodb
node_users_api -->|"updates users"| node_mongodb
node_chatbot -.->|"uses application data"| node_mongodb

click node_root "https://github.com/prodip-shadow/learnx/blob/main/src/app/layout.jsx"
click node_common "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/layout.jsx"
click node_exam_discovery "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/page.jsx"
click node_exam_hall "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/_components/ExamHall.jsx"
click node_join_modal "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/_components/JoinModal.jsx"
click node_dashboard "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/layout.jsx"
click node_student "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/student/my-exams/page.jsx"
click node_teacher "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/teacher/create-exam/page.jsx"
click node_admin "https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/admin/all-exams/page.jsx"
click node_route_gates "https://github.com/prodip-shadow/learnx/blob/main/src/components/StudentRoute.jsx"
click node_auth_provider "https://github.com/prodip-shadow/learnx/blob/main/src/providers/AuthProvider.jsx"
click node_firebase "https://github.com/prodip-shadow/learnx/blob/main/src/lib/firebase.init.js"
click node_exam_api "https://github.com/prodip-shadow/learnx/blob/main/src/app/api/exams/create/route.js"
click node_resource_api "https://github.com/prodip-shadow/learnx/blob/main/src/app/api/resources/create/route.js"
click node_users_api "https://github.com/prodip-shadow/learnx/blob/main/src/app/api/users/route.js"
click node_student_request_api "https://github.com/prodip-shadow/learnx/blob/main/src/app/api/become-student/route.js"
click node_chatbot "https://github.com/prodip-shadow/learnx/blob/main/src/app/api/chatbot/route.js"
click node_mongodb "https://github.com/prodip-shadow/learnx/blob/main/src/lib/mongodb.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_root,node_common,node_exam_discovery,node_exam_hall,node_join_modal,node_resources_ui toneBlue
class node_route_gates,node_auth_provider,node_firebase toneAmber
class node_dashboard,node_student,node_teacher,node_admin toneMint
class node_exam_api,node_resource_api,node_users_api,node_student_request_api,node_chatbot toneRose
class node_mongodb toneIndigo
```

## Components

### Next.js application

- [Root layout](https://github.com/prodip-shadow/learnx/blob/main/src/app/layout.jsx): app entry · Installs shared application providers. · `src/app/layout.jsx`
- [Public site shell](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/layout.jsx): route layout · Hosts marketing and public exam pages. · `src/app/(withCommonLayout)/layout.jsx`
- [Exam discovery](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/page.jsx): public page · Discovery and participation interface. · `src/app/(withCommonLayout)/exams/page.jsx`
- [Exam hall](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/_components/ExamHall.jsx): interactive UI · `src/app/(withCommonLayout)/exams/_components/ExamHall.jsx`
- [Join modal](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withCommonLayout)/exams/_components/JoinModal.jsx): interactive UI · `src/app/(withCommonLayout)/exams/_components/JoinModal.jsx`
- **Resource components**: shared UI

### Identity and access

- [Role route gates](https://github.com/prodip-shadow/learnx/blob/main/src/components/StudentRoute.jsx): client authorization · Student, teacher, and admin dashboard guards. · `src/components/StudentRoute.jsx`
- [Auth provider](https://github.com/prodip-shadow/learnx/blob/main/src/providers/AuthProvider.jsx): session provider · Exposes client identity and session state. · `src/providers/AuthProvider.jsx`
- [Firebase Auth](https://github.com/prodip-shadow/learnx/blob/main/src/lib/firebase.init.js): authentication service · `src/lib/firebase.init.js`

### Role dashboards

- [Dashboard shell](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/layout.jsx): route layout · Shared authenticated dashboard boundary. · `src/app/(withDashboardLayout)/dashboard/layout.jsx`
- [Student learning](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/student/my-exams/page.jsx): dashboard pages · My exams, progress, and resources. · `src/app/(withDashboardLayout)/dashboard/student/my-exams/page.jsx`
- [Teacher exam management](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/teacher/create-exam/page.jsx): dashboard pages · Exam creation, review, students, and resources. · `src/app/(withDashboardLayout)/dashboard/teacher/create-exam/page.jsx`
- [Admin oversight](https://github.com/prodip-shadow/learnx/blob/main/src/app/(withDashboardLayout)/dashboard/admin/all-exams/page.jsx): dashboard pages · Users, all exams, and aggregate results. · `src/app/(withDashboardLayout)/dashboard/admin/all-exams/page.jsx`

### Backend route handlers

- [Exam create and submit](https://github.com/prodip-shadow/learnx/blob/main/src/app/api/exams/create/route.js): exam API · Persists teacher-created exams and student submissions. · `src/app/api/exams/create/route.js`
- [Resource API](https://github.com/prodip-shadow/learnx/blob/main/src/app/api/resources/create/route.js): resource API · Creates, lists, deletes, opens, and downloads resources. · `src/app/api/resources/create/route.js`
- [User administration API](https://github.com/prodip-shadow/learnx/blob/main/src/app/api/users/route.js): user API · Lists and updates user records. · `src/app/api/users/route.js`
- [Student request API](https://github.com/prodip-shadow/learnx/blob/main/src/app/api/become-student/route.js): request API · Handles student applications and management. · `src/app/api/become-student/route.js`
- [Chatbot service](https://github.com/prodip-shadow/learnx/blob/main/src/app/api/chatbot/route.js): chat API and UI · Independent chatbot endpoint with client rendering. · `src/app/api/chatbot/route.js`

### Persistence

- [MongoDB](https://github.com/prodip-shadow/learnx/blob/main/src/lib/mongodb.js): application datastore · Stores exam, submission, user, request, and resource domains. · `src/lib/mongodb.js`

## Connections

- Root layout → Auth provider: installs
- Auth provider → Firebase Auth: initializes session with
- Public site shell → Exam discovery: hosts
- Exam discovery → Exam hall: renders
- Exam hall → Join modal: opens
- Dashboard shell → Role route gates: applies
- Role route gates → Student learning: permits student role
- Role route gates → Teacher exam management: permits teacher role
- Role route gates → Admin oversight: permits admin role
- Exam discovery → Exam create and submit: joins and submits via
- Teacher exam management → Exam create and submit: creates and manages exams
- Student learning → Exam create and submit: reads results and progress
- Admin oversight → Exam create and submit: oversees exams and results
- Teacher exam management → Resource API: publishes resources
- Student learning → Resource components: accesses
- Resource components → Resource API: retrieves files through
- Admin oversight → User administration API: administers users
- Student request API → MongoDB: persists requests
- Exam create and submit → MongoDB: persists exams and submissions
- Resource API → MongoDB: persists resource records
- User administration API → MongoDB: updates users
- Chatbot service → MongoDB: uses application data
