# xheenkhalil/zyntra_ architecture

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

- Interactive diagram: https://gitdiagram.com/xheenkhalil/zyntra_
- Repository: https://github.com/xheenkhalil/zyntra_

## Overview

#### Purpose and deployable entry points
Zyntra Exams is a full-stack platform for organization-managed exams, guest quizzes, automated grading, candidate workflows, and AI-assisted proctoring. The browser application starts at `frontend/src/main.tsx` and composes routing/UI in `frontend/src/App.tsx`. The API process starts at `backend/src/index.ts`; TypeScript source is compiled into the committed runtime output under `backend/dist/index.js`.

#### Frontend application shell and access control
React/Vite provides distinct student, course-admin, central-admin, and super-admin experiences. Role-specific layouts frame pages, while authentication state and protected navigation are centralized in:
- `frontend/src/context/AuthProvider.tsx`
- `frontend/src/components/ProtectedRoute.tsx`
- `frontend/src/layouts/StudentLayout.tsx`
- `frontend/src/layouts/CentralAdminLayout.tsx`
- `frontend/src/layouts/SuperAdminLayout.tsx`

Frontend services form the API boundary for authentication, exam lifecycle, administration, analytics, guest quizzes, and proctoring.

#### Exam authoring, delivery, and grading
Course/admin workflows build question banks and exams; students run assigned exams and receive submission/results views. Core UI stages are represented by:
- `frontend/src/pages/ExamBankPage.tsx`
- `frontend/src/pages/ExamBuilderPage.tsx`
- `frontend/src/pages/ExamRunnerPage.tsx`
- `frontend/src/pages/ResultsPage.tsx`

Requests flow through `frontend/src/services/examService.ts` to the backend exam and question domains:
- `backend/src/routes/examRoutes.ts`
- `backend/src/controllers/examController.ts`
- `backend/src/controllers/questionController.ts`

The backend owns persistence-backed exam status, submissions, automatic evaluation, and grade-scale behavior.

#### Identity and multi-role administration
JWT authentication, Argon2 password handling, and role/permission enforcement gate all protected API domains. The boundary is implemented through:
- `backend/src/routes/authRoutes.ts`
- `backend/src/controllers/authController.ts`
- `backend/src/middleware/authMiddleware.ts`

Administrative domains are separated by central/course/super-admin route-controller pairs, allowing organization, user, course, dashboard, system, and guest-quiz operations without exposing them directly to candidate flows:
- `backend/src/routes/centralAdminRoutes.ts`
- `backend/src/routes/courseAdminRoutes.ts`
- `backend/src/routes/superAdminRoutes.ts`

#### Proctoring and AI analysis pipeline
Candidate proctoring includes face-enrollment, webcam-monitoring, and behavioral/browser-violation capture. The frontend captures and presents these flows via:
- `frontend/src/components/ProctoringEnrollment.tsx`
- `frontend/src/pages/EnrollmentTestPage.tsx`
- `frontend/src/pages/ProctoringDashboard.tsx`

It calls proctoring endpoints handled by `backend/src/routes/proctoringRoutes.ts` and `backend/src/controllers/proctoringController.ts`. AI-related API work is isolated in `backend/src/controllers/aiController.ts` and `backend/src/services/zyntraAiService.ts`, integrating Google Generative AI/Gemini for integrity analysis.

#### API composition, persistence, and asynchronous work
Express routes dispatch to controllers; middleware provides authentication and centralized error handling:
- `backend/src/index.ts`
- `backend/src/middleware/errorMiddleware.ts`
- `backend/src/utils/AppError.ts`

PostgreSQL is the authoritative database behind `backend/src/services/db.ts`. Redis supports caching and BullMQ-backed email/background work through:
- `backend/src/services/cacheService.ts`
- `backend/src/queues/emailQueue.ts`
- `backend/src/services/emailService.ts`

Analytics endpoints/controllers aggregate operational and assessment data for dashboard consumers, including `frontend/src/pages/SuperAdminAnalytics.tsx` and `backend/src/controllers/analyticsController.ts`.

#### Runtime and delivery boundaries
The frontend is a React 19 Vite/PWA application, configured for Vercel deployment in `frontend/vercel.json`. The backend is Node.js/Express TypeScript, requiring PostgreSQL, Redis, JWT secrets, and a Gemini API key. CI is split by application boundary in `.github/workflows/frontend.yml` and `.github/workflows/backend.yml`.

Main entry points: [`backend/src/index.ts`](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/index.ts) (Express API process), [`frontend/src/App.tsx`](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/App.tsx) (App routing shell), [`backend/src/services/db.ts`](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/db.ts) (PostgreSQL), [`.github/workflows/frontend.yml`](https://github.com/xheenkhalil/zyntra_/blob/main/.github/workflows/frontend.yml) (Split application CI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React/Vite Frontend"]
  node_web_entry["Browser entry<br/>React entry<br/>[main.tsx]"]
  node_app_shell["App routing shell<br/>React app<br/>[App.tsx]"]
  node_access_control["Auth and protected navigation<br/>frontend access control<br/>[AuthProvider.tsx]"]
  node_exam_ui["Exam authoring and delivery<br/>exam UI<br/>[ExamRunnerPage.tsx]"]
  node_proctor_ui["Proctoring UI"]
  node_analytics_ui["Super-admin analytics<br/>analytics UI"]
  node_exam_api_client["Exam API client<br/>frontend service<br/>[examService.ts]"]
end

subgraph group_backend["Node/Express Backend"]
  node_api_entry{{"Express API process<br/>Node.js entry<br/>[index.ts]"}}
  node_auth_domain["Identity and authorization<br/>auth domain<br/>[authRoutes.ts]"]
  node_auth_middleware["Auth middleware<br/>Express middleware<br/>[authMiddleware.ts]"]
  node_exam_routes["Exam and question routes<br/>API routes<br/>[examRoutes.ts]"]
  node_exam_controller["Exam lifecycle and grading<br/>controller<br/>[examController.ts]"]
  node_admin_domains["Administration domains<br/>admin routes"]
  node_proctoring_domain["Proctoring API<br/>proctoring routes"]
  node_ai_integrity["AI integrity analysis<br/>AI service<br/>[zyntraAiService.ts]"]
  node_analytics_domain["Analytics aggregation<br/>analytics controller"]
end

subgraph group_data["Data &amp; Async Services"]
  node_postgres[("PostgreSQL<br/>authoritative database<br/>[db.ts]")]
  node_redis[("Redis cache and queue backend<br/>cache / queue store<br/>[cacheService.ts]")]
  node_email_queue["Email background work<br/>BullMQ queue<br/>[emailQueue.ts]"]
end

subgraph group_delivery["Delivery"]
  node_backend_runtime["Compiled backend runtime<br/>JavaScript runtime output<br/>[index.js]"]
  node_frontend_deploy["Vercel frontend deployment<br/>deployment config<br/>[vercel.json]"]
  node_ci["Split application CI<br/>GitHub Actions<br/>[frontend.yml]"]
end

node_web_entry -->|"mounts"| node_app_shell
node_app_shell -->|"uses"| node_access_control
node_app_shell -->|"routes to"| node_exam_ui
node_app_shell -->|"routes to"| node_proctor_ui
node_app_shell -->|"routes to"| node_analytics_ui
node_access_control -->|"authenticates via API"| node_auth_domain
node_exam_ui -->|"uses"| node_exam_api_client
node_exam_api_client -->|"API requests"| node_api_entry
node_proctor_ui -->|"proctoring requests"| node_api_entry
node_analytics_ui -->|"dashboard requests"| node_api_entry
node_api_entry -->|"protects routes with"| node_auth_middleware
node_auth_middleware -->|"authorizes"| node_auth_domain
node_api_entry -->|"dispatches"| node_exam_routes
node_api_entry -->|"dispatches"| node_admin_domains
node_api_entry -->|"dispatches"| node_proctoring_domain
node_api_entry -->|"dispatches"| node_analytics_domain
node_exam_routes -->|"invokes"| node_exam_controller
node_exam_controller -->|"persists exams and grades"| node_postgres
node_admin_domains -->|"manages organization data"| node_postgres
node_proctoring_domain -->|"submits integrity signals"| node_ai_integrity
node_ai_integrity -->|"stores analysis"| node_postgres
node_analytics_domain -->|"aggregates"| node_postgres
node_api_entry -->|"uses cache"| node_redis
node_redis -->|"backs"| node_email_queue
node_backend_runtime -.->|"compiled from"| node_api_entry
node_frontend_deploy -.->|"deploys"| node_web_entry
node_ci -.->|"builds frontend"| node_frontend_deploy
node_ci -.->|"builds backend"| node_backend_runtime

click node_web_entry "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/main.tsx"
click node_app_shell "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/App.tsx"
click node_access_control "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/context/AuthProvider.tsx"
click node_exam_ui "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/pages/ExamRunnerPage.tsx"
click node_proctor_ui "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/components/ProctoringEnrollment.tsx"
click node_analytics_ui "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/pages/SuperAdminAnalytics.tsx"
click node_exam_api_client "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/services/examService.ts"
click node_api_entry "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/index.ts"
click node_auth_domain "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/authRoutes.ts"
click node_auth_middleware "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/middleware/authMiddleware.ts"
click node_exam_routes "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/examRoutes.ts"
click node_exam_controller "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/controllers/examController.ts"
click node_admin_domains "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/centralAdminRoutes.ts"
click node_proctoring_domain "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/proctoringRoutes.ts"
click node_ai_integrity "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/zyntraAiService.ts"
click node_analytics_domain "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/controllers/analyticsController.ts"
click node_postgres "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/db.ts"
click node_redis "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/cacheService.ts"
click node_email_queue "https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/queues/emailQueue.ts"
click node_backend_runtime "https://github.com/xheenkhalil/zyntra_/blob/main/backend/dist/index.js"
click node_frontend_deploy "https://github.com/xheenkhalil/zyntra_/blob/main/frontend/vercel.json"
click node_ci "https://github.com/xheenkhalil/zyntra_/blob/main/.github/workflows/frontend.yml"

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_entry,node_app_shell,node_access_control,node_exam_ui,node_proctor_ui,node_analytics_ui,node_exam_api_client toneBlue
class node_api_entry,node_auth_domain,node_auth_middleware,node_exam_routes,node_exam_controller,node_admin_domains,node_proctoring_domain,node_ai_integrity,node_analytics_domain toneAmber
class node_postgres,node_redis,node_email_queue toneMint
class node_backend_runtime,node_frontend_deploy,node_ci toneRose
```

## Components

### React/Vite Frontend

- [Browser entry](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/main.tsx): React entry · `frontend/src/main.tsx`
- [App routing shell](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/App.tsx): React app · `frontend/src/App.tsx`
- [Auth and protected navigation](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/context/AuthProvider.tsx): frontend access control · Role-specific layouts and protected routes gate the application. · `frontend/src/context/AuthProvider.tsx`
- [Exam authoring and delivery](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/pages/ExamRunnerPage.tsx): exam UI · Question banks, exam building, candidate runs, and results. · `frontend/src/pages/ExamRunnerPage.tsx`
- [Proctoring UI](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/components/ProctoringEnrollment.tsx): proctoring UI · Enrollment, webcam monitoring, and dashboard workflows. · `frontend/src/components/ProctoringEnrollment.tsx`
- [Super-admin analytics](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/pages/SuperAdminAnalytics.tsx): analytics UI · `frontend/src/pages/SuperAdminAnalytics.tsx`
- [Exam API client](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/src/services/examService.ts): frontend service · `frontend/src/services/examService.ts`

### Node/Express Backend

- [Express API process](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/index.ts): Node.js entry · Composes routes, middleware, and error handling. · `backend/src/index.ts`
- [Identity and authorization](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/authRoutes.ts): auth domain · JWT, Argon2, and role/permission enforcement. · `backend/src/routes/authRoutes.ts`
- [Auth middleware](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/middleware/authMiddleware.ts): Express middleware · `backend/src/middleware/authMiddleware.ts`
- [Exam and question routes](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/examRoutes.ts): API routes · `backend/src/routes/examRoutes.ts`
- [Exam lifecycle and grading](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/controllers/examController.ts): controller · Owns status, submissions, automatic evaluation, and grade scales. · `backend/src/controllers/examController.ts`
- [Administration domains](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/centralAdminRoutes.ts): admin routes · Separate central, course, and super-admin operations. · `backend/src/routes/centralAdminRoutes.ts`
- [Proctoring API](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/routes/proctoringRoutes.ts): proctoring routes · `backend/src/routes/proctoringRoutes.ts`
- [AI integrity analysis](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/zyntraAiService.ts): AI service · Gemini-backed integrity analysis. · `backend/src/services/zyntraAiService.ts`
- [Analytics aggregation](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/controllers/analyticsController.ts): analytics controller · `backend/src/controllers/analyticsController.ts`

### Data & Async Services

- [PostgreSQL](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/db.ts): authoritative database · Persistence for application and assessment state. · `backend/src/services/db.ts`
- [Redis cache and queue backend](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/services/cacheService.ts): cache / queue store · `backend/src/services/cacheService.ts`
- [Email background work](https://github.com/xheenkhalil/zyntra_/blob/main/backend/src/queues/emailQueue.ts): BullMQ queue · `backend/src/queues/emailQueue.ts`

### Delivery

- [Compiled backend runtime](https://github.com/xheenkhalil/zyntra_/blob/main/backend/dist/index.js): JavaScript runtime output · `backend/dist/index.js`
- [Vercel frontend deployment](https://github.com/xheenkhalil/zyntra_/blob/main/frontend/vercel.json): deployment config · `frontend/vercel.json`
- [Split application CI](https://github.com/xheenkhalil/zyntra_/blob/main/.github/workflows/frontend.yml): GitHub Actions · Independent frontend and backend workflows. · `.github/workflows/frontend.yml`

## Connections

- Browser entry → App routing shell: mounts
- App routing shell → Auth and protected navigation: uses
- App routing shell → Exam authoring and delivery: routes to
- App routing shell → Proctoring UI: routes to
- App routing shell → Super-admin analytics: routes to
- Auth and protected navigation → Identity and authorization: authenticates via API
- Exam authoring and delivery → Exam API client: uses
- Exam API client → Express API process: API requests
- Proctoring UI → Express API process: proctoring requests
- Super-admin analytics → Express API process: dashboard requests
- Express API process → Auth middleware: protects routes with
- Auth middleware → Identity and authorization: authorizes
- Express API process → Exam and question routes: dispatches
- Express API process → Administration domains: dispatches
- Express API process → Proctoring API: dispatches
- Express API process → Analytics aggregation: dispatches
- Exam and question routes → Exam lifecycle and grading: invokes
- Exam lifecycle and grading → PostgreSQL: persists exams and grades
- Administration domains → PostgreSQL: manages organization data
- Proctoring API → AI integrity analysis: submits integrity signals
- AI integrity analysis → PostgreSQL: stores analysis
- Analytics aggregation → PostgreSQL: aggregates
- Express API process → Redis cache and queue backend: uses cache
- Redis cache and queue backend → Email background work: backs
- Compiled backend runtime → Express API process: compiled from
- Vercel frontend deployment → Browser entry: deploys
- Split application CI → Vercel frontend deployment: builds frontend
- Split application CI → Compiled backend runtime: builds backend
