# shrouk-saleh/ravenace architecture

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

- Interactive diagram: https://gitdiagram.com/shrouk-saleh/ravenace
- Repository: https://github.com/shrouk-saleh/ravenace

## Overview

#### Purpose and deployable surfaces
RavenACE / EduCert Pro is an AI-assisted examination, certification, and organization-management platform. It has three executable applications: an Express/MongoDB API in `backend/server.js`, a React/Vite browser client rooted at `frontend/src/main.jsx`, and an Electron secure-exam client rooted at `electron-engine/main/main.js`. Container deployment is defined by `Dockerfile`.

#### API composition and persistence
The backend organizes HTTP endpoints by business domain: routes dispatch to controllers, which operate on MongoDB models and services. Core wiring begins in `backend/server.js`; database connectivity is centralized in `backend/config/db.js`. Persistent domain boundaries include identities and organizations (`backend/models/User.js`, `backend/models/Organization.js`), authored exams/questions (`backend/models/Exam.js`, `backend/models/Question.js`), and exam execution/results (`backend/models/Attempt.js`, `backend/models/Certificate.js`).

#### Identity, tenancy, and access boundary
Authentication and authorization are enforced before protected API actions through `backend/middleware/authMiddleware.js` and organization scoping through `backend/middleware/orgMiddleware.js`. Auth lifecycle endpoints are in `backend/routes/authRoutes.js`; organization administration is separated in `backend/routes/organizationRoutes.js`. This establishes role- and tenant-aware access across instructor, student, administrator, and organization workflows.

#### Exam authoring and attempt lifecycle
Exam/question APIs provide the authoring side (`backend/routes/examRoutes.js`, `backend/routes/questionRoutes.js`), while attempts use `backend/routes/attemptRoutes.js` and `backend/controllers/attemptController.js`. A typical flow is: instructor creates an exam and questions; student starts an `Attempt`; answers and integrity events are saved during the session; submission produces grading/results and potentially certificates. Results, rankings, and certificate verification are separate read/reporting domains in `backend/routes/resultRoutes.js`, `backend/routes/leaderboardRoutes.js`, and `backend/routes/certificateRoutes.js`.

#### AI grading, learning, and integrity analysis
AI-facing API endpoints are isolated in `backend/routes/aiRoutes.js` and `backend/controllers/aiController.js`. Services cover Gemini-backed generation/tutoring (`backend/services/geminiService.js`, `backend/services/questionGenService.js`, `backend/services/tutorService.js`), code and written-answer grading (`backend/services/codeGraderService.js`, `backend/services/writtenGraderService.js`), and plagiarism/cheating analysis (`backend/services/plagiarismService.js`, `backend/services/cheatAnalysisService.js`). Their outputs persist as analysis and integrity records, including `backend/models/AiAnalysis.js`, `backend/models/PlagiarismReport.js`, and `backend/models/CheatLog.js`.

#### Browser client and realtime interaction
The standard user interface is a React SPA with routing/application composition in `frontend/src/App.jsx`, authenticated session state in `frontend/src/context/AuthContext.jsx`, and API transport in `frontend/src/api/axios.js`. Socket.IO client connectivity is represented by `frontend/src/api/socket.js`; backend socket support is centralized at `backend/utils/socket.js`. Browser exam interaction is primarily represented by `frontend/src/pages/ExamInterface.jsx`, with anti-cheat behavior in `frontend/src/hooks/useAntiCheat.js`.

#### Secure Electron examination runtime
The Electron application is a distinct controlled-exam boundary, not merely a browser wrapper. `electron-engine/core/ExamEngine.js` coordinates exam execution; `electron-engine/services/ExamService.js`, `electron-engine/services/AutoSaveService.js`, and `electron-engine/services/SubmissionService.js` communicate state and submissions to the backend through `electron-engine/communication/HttpClient.js`. Main/preload/renderer isolation is implemented through `electron-engine/main/main.js`, `electron-engine/preload/preload.js`, and `electron-engine/ipc/IpcHandlers.js`.

#### Proctoring and external integrations
Electron security monitors detect focus loss, display/process/network changes, debugging, VMs, recording, and input anomalies under `electron-engine/core/security/SecurityManager.js` and related monitor modules. Security events feed the session/anti-cheat lifecycle via `electron-engine/services/SessionGuardian.js`. External commercial and enterprise boundaries include Stripe billing (`backend/routes/stripeRoutes.js`, `backend/services/stripeService.js`), integration credentials (`backend/routes/integrationRoutes.js`, `backend/models/IntegrationCredential.js`), and email delivery (`backend/utils/emailService.js`).

Main entry points: [`backend/server.js`](https://github.com/shrouk-saleh/ravenace/blob/main/backend/server.js) (Express API), [`backend/config/db.js`](https://github.com/shrouk-saleh/ravenace/blob/main/backend/config/db.js) (MongoDB), [`backend/middleware/authMiddleware.js`](https://github.com/shrouk-saleh/ravenace/blob/main/backend/middleware/authMiddleware.js) (Access & tenant boundary), [`backend/controllers/aiController.js`](https://github.com/shrouk-saleh/ravenace/blob/main/backend/controllers/aiController.js) (AI grading & analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser client"]
  node_browser_app["React SPA<br/>browser application<br/>[main.jsx]"]
  node_browser_session["Session &amp; API client<br/>client state<br/>[AuthContext.jsx]"]
  node_browser_exam["Browser exam UI<br/>exam interface<br/>[ExamInterface.jsx]"]
  node_browser_socket["Socket client<br/>realtime client<br/>[socket.js]"]
end

subgraph group_api["Backend API"]
  node_api_server["Express API<br/>API application<br/>[server.js]"]
  node_access["Access &amp; tenant boundary<br/>middleware<br/>[authMiddleware.js]"]
  node_identity_org["Identity &amp; organizations<br/>domain API<br/>[authRoutes.js]"]
  node_exam_authoring["Exam authoring<br/>domain API<br/>[examRoutes.js]"]
  node_attempts["Attempt lifecycle<br/>controller"]
  node_reporting["Results &amp; certificates<br/>reporting API<br/>[resultRoutes.js]"]
  node_ai["AI grading &amp; analysis<br/>AI service layer<br/>[aiController.js]"]
  node_realtime["Socket server<br/>realtime gateway<br/>[socket.js]"]
  node_mongo[("MongoDB<br/>database<br/>[db.js]")]
  node_integrations["Billing &amp; integrations<br/>integration API<br/>[stripeRoutes.js]"]
end

subgraph group_electron["Secure exam client"]
  node_electron_main["Electron main &amp; IPC<br/>desktop runtime<br/>[main.js]"]
  node_exam_engine["Controlled exam engine<br/>exam runtime<br/>[ExamEngine.js]"]
  node_electron_transport["Exam sync services<br/>desktop service layer<br/>[ExamService.js]"]
  node_security["Security monitoring<br/>proctoring layer<br/>[SecurityManager.js]"]
  node_guardian["Session guardian<br/>integrity service<br/>[SessionGuardian.js]"]
end

subgraph group_external["External services"]
  node_gemini{{"Gemini AI<br/>AI provider<br/>[geminiService.js]"}}
  node_stripe{{"Stripe<br/>payment provider<br/>[stripeService.js]"}}
end

node_browser_app -->|"uses"| node_browser_session
node_browser_app -->|"renders"| node_browser_exam
node_browser_app -->|"connects"| node_browser_socket
node_browser_session -->|"HTTPS API"| node_api_server
node_browser_exam -->|"attempt actions"| node_api_server
node_browser_socket -->|"Socket.IO"| node_realtime
node_api_server -->|"protects requests"| node_access
node_access -->|"authorizes"| node_identity_org
node_access -->|"scopes"| node_exam_authoring
node_access -->|"scopes"| node_attempts
node_api_server -->|"routes"| node_reporting
node_api_server -->|"routes"| node_ai
node_identity_org -->|"persists"| node_mongo
node_exam_authoring -->|"persists exams/questions"| node_mongo
node_attempts -->|"persists attempts"| node_mongo
node_attempts -->|"grades and analyzes"| node_ai
node_ai -->|"stores analysis"| node_mongo
node_ai -->|"generation/tutoring"| node_gemini
node_reporting -->|"reads results/certificates"| node_mongo
node_api_server -->|"routes"| node_integrations
node_integrations -->|"billing"| node_stripe
node_electron_main -->|"hosts"| node_exam_engine
node_exam_engine -->|"exam state"| node_electron_transport
node_exam_engine -->|"monitors session"| node_security
node_security -->|"security events"| node_guardian
node_guardian -->|"enforces integrity"| node_exam_engine
node_electron_transport -->|"HTTPS sync/submission"| node_api_server

click node_browser_app "https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/main.jsx"
click node_browser_session "https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/context/AuthContext.jsx"
click node_browser_exam "https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/pages/ExamInterface.jsx"
click node_browser_socket "https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/api/socket.js"
click node_api_server "https://github.com/shrouk-saleh/ravenace/blob/main/backend/server.js"
click node_access "https://github.com/shrouk-saleh/ravenace/blob/main/backend/middleware/authMiddleware.js"
click node_identity_org "https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/authRoutes.js"
click node_exam_authoring "https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/examRoutes.js"
click node_attempts "https://github.com/shrouk-saleh/ravenace/blob/main/backend/controllers/attemptController.js"
click node_reporting "https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/resultRoutes.js"
click node_ai "https://github.com/shrouk-saleh/ravenace/blob/main/backend/controllers/aiController.js"
click node_realtime "https://github.com/shrouk-saleh/ravenace/blob/main/backend/utils/socket.js"
click node_mongo "https://github.com/shrouk-saleh/ravenace/blob/main/backend/config/db.js"
click node_integrations "https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/stripeRoutes.js"
click node_electron_main "https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/main/main.js"
click node_exam_engine "https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/core/ExamEngine.js"
click node_electron_transport "https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/services/ExamService.js"
click node_security "https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/core/security/SecurityManager.js"
click node_guardian "https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/services/SessionGuardian.js"
click node_gemini "https://github.com/shrouk-saleh/ravenace/blob/main/backend/services/geminiService.js"
click node_stripe "https://github.com/shrouk-saleh/ravenace/blob/main/backend/services/stripeService.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_browser_app,node_browser_session,node_browser_exam,node_browser_socket toneBlue
class node_api_server,node_access,node_identity_org,node_exam_authoring,node_attempts,node_reporting,node_ai,node_realtime,node_mongo,node_integrations toneAmber
class node_electron_main,node_exam_engine,node_electron_transport,node_security,node_guardian toneMint
class node_gemini,node_stripe toneRose
```

## Components

### Browser client

- [React SPA](https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/main.jsx): browser application · `frontend/src/main.jsx`
- [Session & API client](https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/context/AuthContext.jsx): client state · Authenticated state and HTTP transport. · `frontend/src/context/AuthContext.jsx`
- [Browser exam UI](https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/pages/ExamInterface.jsx): exam interface · Includes anti-cheat interaction behavior. · `frontend/src/pages/ExamInterface.jsx`
- [Socket client](https://github.com/shrouk-saleh/ravenace/blob/main/frontend/src/api/socket.js): realtime client · `frontend/src/api/socket.js`

### Backend API

- [Express API](https://github.com/shrouk-saleh/ravenace/blob/main/backend/server.js): API application · Routes requests into domain controllers and services. · `backend/server.js`
- [Access & tenant boundary](https://github.com/shrouk-saleh/ravenace/blob/main/backend/middleware/authMiddleware.js): middleware · Authentication, roles, and organization scoping. · `backend/middleware/authMiddleware.js`
- [Identity & organizations](https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/authRoutes.js): domain API · Auth lifecycle and organization administration. · `backend/routes/authRoutes.js`
- [Exam authoring](https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/examRoutes.js): domain API · Exam and question authoring workflows. · `backend/routes/examRoutes.js`
- [Attempt lifecycle](https://github.com/shrouk-saleh/ravenace/blob/main/backend/controllers/attemptController.js): controller · Starts, records, submits, and grades exam attempts. · `backend/controllers/attemptController.js`
- [Results & certificates](https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/resultRoutes.js): reporting API · Results, rankings, certificate issuance and verification. · `backend/routes/resultRoutes.js`
- [AI grading & analysis](https://github.com/shrouk-saleh/ravenace/blob/main/backend/controllers/aiController.js): AI service layer · Generation, tutoring, grading, plagiarism, and cheat analysis. · `backend/controllers/aiController.js`
- [Socket server](https://github.com/shrouk-saleh/ravenace/blob/main/backend/utils/socket.js): realtime gateway · `backend/utils/socket.js`
- [MongoDB](https://github.com/shrouk-saleh/ravenace/blob/main/backend/config/db.js): database · Stores users, organizations, exams, attempts, certificates, and analysis records. · `backend/config/db.js`
- [Billing & integrations](https://github.com/shrouk-saleh/ravenace/blob/main/backend/routes/stripeRoutes.js): integration API · Stripe, enterprise credentials, and email delivery. · `backend/routes/stripeRoutes.js`

### Secure exam client

- [Electron main & IPC](https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/main/main.js): desktop runtime · Main/preload isolation and IPC handlers. · `electron-engine/main/main.js`
- [Controlled exam engine](https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/core/ExamEngine.js): exam runtime · Coordinates secure exam execution. · `electron-engine/core/ExamEngine.js`
- [Exam sync services](https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/services/ExamService.js): desktop service layer · Loads exams, autosaves, and submits through HTTP. · `electron-engine/services/ExamService.js`
- [Security monitoring](https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/core/security/SecurityManager.js): proctoring layer · Detects environment and input integrity anomalies. · `electron-engine/core/security/SecurityManager.js`
- [Session guardian](https://github.com/shrouk-saleh/ravenace/blob/main/electron-engine/services/SessionGuardian.js): integrity service · Feeds security events into the session lifecycle. · `electron-engine/services/SessionGuardian.js`

### External services

- [Gemini AI](https://github.com/shrouk-saleh/ravenace/blob/main/backend/services/geminiService.js): AI provider · `backend/services/geminiService.js`
- [Stripe](https://github.com/shrouk-saleh/ravenace/blob/main/backend/services/stripeService.js): payment provider · `backend/services/stripeService.js`

## Connections

- React SPA → Session & API client: uses
- React SPA → Browser exam UI: renders
- React SPA → Socket client: connects
- Session & API client → Express API: HTTPS API
- Browser exam UI → Express API: attempt actions
- Socket client → Socket server: Socket.IO
- Express API → Access & tenant boundary: protects requests
- Access & tenant boundary → Identity & organizations: authorizes
- Access & tenant boundary → Exam authoring: scopes
- Access & tenant boundary → Attempt lifecycle: scopes
- Express API → Results & certificates: routes
- Express API → AI grading & analysis: routes
- Identity & organizations → MongoDB: persists
- Exam authoring → MongoDB: persists exams/questions
- Attempt lifecycle → MongoDB: persists attempts
- Attempt lifecycle → AI grading & analysis: grades and analyzes
- AI grading & analysis → MongoDB: stores analysis
- AI grading & analysis → Gemini AI: generation/tutoring
- Results & certificates → MongoDB: reads results/certificates
- Express API → Billing & integrations: routes
- Billing & integrations → Stripe: billing
- Electron main & IPC → Controlled exam engine: hosts
- Controlled exam engine → Exam sync services: exam state
- Controlled exam engine → Security monitoring: monitors session
- Security monitoring → Session guardian: security events
- Session guardian → Controlled exam engine: enforces integrity
- Exam sync services → Express API: HTTPS sync/submission
