# kenithlabonite/ocr_project architecture

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

- Interactive diagram: https://gitdiagram.com/kenithlabonite/ocr_project
- Repository: https://github.com/kenithlabonite/ocr_project

## Overview

This is a web-based OCR and exam-management system: users authenticate, upload PDFs, generate and download questionnaires, and submit exams for grading. The frontend is an ASP.NET Razor Pages client; the backend exposes APIs backed by MySQL, AI generation, OCR/grading, email, and audit services. The README provides no architectural detail. Backend controller and model relationships are supported by the source index; several frontend-to-API links are inferred from the page roles and are therefore dashed and uncited.

Main entry points: [`Project_OLMS/Project_OLMS/Data/AppDbContext.cs`](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Data/AppDbContext.cs) (Application database), [`Project_OLMS/Project_OLMS/Controllers/ExamController.cs`](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/ExamController.cs) (Exam API), [`Project_OLMS/Project_OLMS/Controllers/AuthController.cs`](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/AuthController.cs) (Authentication API), [`OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs`](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs) (Account pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Razor frontend"]
  node_pages_auth["Account pages<br/>[Login.cshtml.cs]"]
  node_pages_docs["Document pages"]
  node_pages_exams["Exam pages"]
  node_pages_grading["Grading pages"]
  node_pages_admin["Admin pages<br/>[Admin.cshtml.cs]"]
  node_session_middleware["Session validation"]
  node_cookie_helper["Auth cookies"]
  node_error_helper["API error parsing<br/>[ApiErrorHelper.cs]"]
  node_frontend_session["Frontend instance"]
end

subgraph group_api["Backend API"]
  node_auth_api["Authentication API<br/>[AuthController.cs]"]
  node_admin_api["Administration API<br/>[AdminController.cs]"]
  node_dashboard_api["Dashboard API"]
end

subgraph group_processing["Document and exams"]
  node_upload_api["PDF upload API"]
  node_ocr_grading["OCR and grading<br/>[Tesseract.cs]"]
  node_exam_api["Exam API<br/>[ExamController.cs]"]
  node_gemini["Gemini AI<br/>[GeminiService.cs]"]
end

subgraph group_platform["Identity and persistence"]
  node_database[("Application database<br/>[AppDbContext.cs]")]
  node_auth_model["User accounts<br/>[Auth.cs]"]
  node_document_model["PDF documents<br/>[Document.cs]"]
  node_questionnaire_model["Questionnaires"]
  node_question_model["Question items<br/>[QuestionItem.cs]"]
  node_graded_model["Graded sheets"]
  node_audit_model["Audit records<br/>[AuditLog.cs]"]
  node_audit_service["Audit logging<br/>[AuditLogService.cs]"]
  node_email_service["Email delivery<br/>[EmailService.cs]"]
  node_system_session["Backend instance"]
end

node_user(("User"))

node_user -->|"signs in"| node_pages_auth
node_user -->|"uploads PDFs"| node_pages_docs
node_user -->|"requests exams"| node_pages_exams
node_user -->|"submits answers"| node_pages_grading
node_user -->|"manages users"| node_pages_admin
node_pages_auth -.->|"calls API"| node_auth_api
node_pages_docs -.->|"calls API"| node_upload_api
node_pages_exams -.->|"calls API"| node_exam_api
node_pages_grading -.->|"calls API"| node_ocr_grading
node_pages_admin -.->|"calls API"| node_admin_api
node_session_middleware -->|"reads and clears"| node_cookie_helper
node_session_middleware -->|"checks instance"| node_frontend_session
node_session_middleware -->|"validates session"| node_auth_api
node_pages_auth -->|"sets cookies"| node_cookie_helper
node_pages_auth -->|"parses errors"| node_error_helper
node_pages_docs -.->|"attaches token"| node_cookie_helper
node_pages_docs -->|"parses errors"| node_error_helper
node_pages_exams -->|"parses errors"| node_error_helper
node_pages_grading -->|"parses errors"| node_error_helper
node_auth_api -->|"reads and writes"| node_database
node_auth_api -->|"sends email"| node_email_service
node_auth_api -->|"issues instance-bound tokens"| node_system_session
node_admin_api -->|"reads and writes"| node_database
node_dashboard_api -->|"reads data"| node_database
node_upload_api -->|"stores metadata"| node_database
node_ocr_grading -->|"reads and writes"| node_database
node_exam_api -->|"reads and writes"| node_database
node_exam_api -->|"generates questions"| node_gemini
node_exam_api -.->|"logs exam actions"| node_audit_service
node_audit_service -->|"writes logs"| node_database
node_database -->|"maps entity"| node_auth_model
node_database -->|"maps entity"| node_document_model
node_database -->|"maps entity"| node_questionnaire_model
node_database -->|"maps entity"| node_graded_model
node_database -->|"maps entity"| node_audit_model
node_exam_api -->|"loads document"| node_document_model
node_exam_api -->|"creates questionnaire"| node_questionnaire_model
node_exam_api -->|"serializes questions"| node_question_model
node_gemini -->|"produces questions"| node_question_model
node_ocr_grading -->|"uses questions"| node_question_model
node_ocr_grading -->|"creates graded sheets"| node_graded_model

click node_pages_auth "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs"
click node_pages_docs "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/UploadPdf.cshtml.cs"
click node_pages_exams "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/GenerateQuestionnaire.cshtml.cs"
click node_pages_grading "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/GradeExam.cshtml.cs"
click node_pages_admin "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/Admin.cshtml.cs"
click node_session_middleware "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Middleware/SessionValidationMiddleware.cs"
click node_cookie_helper "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Helpers/AuthCookieHelper.cs"
click node_error_helper "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Helpers/ApiErrorHelper.cs"
click node_frontend_session "https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Services/FrontendSessionService.cs"
click node_auth_api "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/AuthController.cs"
click node_admin_api "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/AdminController.cs"
click node_dashboard_api "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/DashboardController.cs"
click node_upload_api "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/PdfUploadController.cs"
click node_ocr_grading "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/Tesseract.cs"
click node_exam_api "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/ExamController.cs"
click node_gemini "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/GeminiService.cs"
click node_database "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Data/AppDbContext.cs"
click node_auth_model "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/Auth.cs"
click node_document_model "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/Document.cs"
click node_questionnaire_model "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/ExamQuestionnaire.cs"
click node_question_model "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/QuestionItem.cs"
click node_graded_model "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/GradedAnswerSheet.cs"
click node_audit_model "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/AuditLog.cs"
click node_audit_service "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/AuditLogService.cs"
click node_email_service "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/EmailService.cs"
click node_system_session "https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/SystemSessionService.cs"

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_pages_auth,node_pages_docs,node_pages_exams,node_pages_grading,node_pages_admin,node_session_middleware,node_cookie_helper,node_error_helper,node_frontend_session,node_user toneBlue
class node_auth_api,node_admin_api,node_dashboard_api toneAmber
class node_upload_api,node_ocr_grading,node_exam_api,node_gemini toneMint
class node_database,node_auth_model,node_document_model,node_questionnaire_model,node_question_model,node_graded_model,node_audit_model,node_audit_service,node_email_service,node_system_session toneRose
```

## Components

### Razor frontend

- [Account pages](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs): `OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs`
- [Document pages](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/UploadPdf.cshtml.cs): `OCR_Frontend/OCR_Frontend/Pages/UploadPdf.cshtml.cs`
- [Exam pages](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/GenerateQuestionnaire.cshtml.cs): `OCR_Frontend/OCR_Frontend/Pages/GenerateQuestionnaire.cshtml.cs`
- [Grading pages](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/GradeExam.cshtml.cs): `OCR_Frontend/OCR_Frontend/Pages/GradeExam.cshtml.cs`
- [Admin pages](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Pages/Admin.cshtml.cs): `OCR_Frontend/OCR_Frontend/Pages/Admin.cshtml.cs`
- [Session validation](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Middleware/SessionValidationMiddleware.cs): `OCR_Frontend/OCR_Frontend/Middleware/SessionValidationMiddleware.cs`
- [Auth cookies](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Helpers/AuthCookieHelper.cs): `OCR_Frontend/OCR_Frontend/Helpers/AuthCookieHelper.cs`
- [API error parsing](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Helpers/ApiErrorHelper.cs): `OCR_Frontend/OCR_Frontend/Helpers/ApiErrorHelper.cs`
- [Frontend instance](https://github.com/kenithlabonite/ocr_project/blob/main/OCR_Frontend/OCR_Frontend/Services/FrontendSessionService.cs): `OCR_Frontend/OCR_Frontend/Services/FrontendSessionService.cs`

### Backend API

- [Authentication API](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/AuthController.cs): `Project_OLMS/Project_OLMS/Controllers/AuthController.cs`
- [Administration API](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/AdminController.cs): `Project_OLMS/Project_OLMS/Controllers/AdminController.cs`
- [Dashboard API](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/DashboardController.cs): `Project_OLMS/Project_OLMS/Controllers/DashboardController.cs`

### Document and exams

- [PDF upload API](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/PdfUploadController.cs): `Project_OLMS/Project_OLMS/Controllers/PdfUploadController.cs`
- [OCR and grading](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/Tesseract.cs): `Project_OLMS/Project_OLMS/Controllers/Tesseract.cs`
- [Exam API](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Controllers/ExamController.cs): `Project_OLMS/Project_OLMS/Controllers/ExamController.cs`
- [Gemini AI](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/GeminiService.cs): `Project_OLMS/Project_OLMS/Services/GeminiService.cs`

### Identity and persistence

- [Application database](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Data/AppDbContext.cs): `Project_OLMS/Project_OLMS/Data/AppDbContext.cs`
- [User accounts](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/Auth.cs): `Project_OLMS/Project_OLMS/Models/Auth.cs`
- [PDF documents](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/Document.cs): `Project_OLMS/Project_OLMS/Models/Document.cs`
- [Questionnaires](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/ExamQuestionnaire.cs): `Project_OLMS/Project_OLMS/Models/ExamQuestionnaire.cs`
- [Question items](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/QuestionItem.cs): `Project_OLMS/Project_OLMS/Models/QuestionItem.cs`
- [Graded sheets](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/GradedAnswerSheet.cs): `Project_OLMS/Project_OLMS/Models/GradedAnswerSheet.cs`
- [Audit records](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Models/AuditLog.cs): `Project_OLMS/Project_OLMS/Models/AuditLog.cs`
- [Audit logging](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/AuditLogService.cs): `Project_OLMS/Project_OLMS/Services/AuditLogService.cs`
- [Email delivery](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/EmailService.cs): `Project_OLMS/Project_OLMS/Services/EmailService.cs`
- [Backend instance](https://github.com/kenithlabonite/ocr_project/blob/main/Project_OLMS/Project_OLMS/Services/SystemSessionService.cs): `Project_OLMS/Project_OLMS/Services/SystemSessionService.cs`

### Other components

- **User**

## Connections

- User → Account pages: signs in
- User → Document pages: uploads PDFs
- User → Exam pages: requests exams
- User → Grading pages: submits answers
- User → Admin pages: manages users
- Account pages → Authentication API: calls API
- Document pages → PDF upload API: calls API
- Exam pages → Exam API: calls API
- Grading pages → OCR and grading: calls API
- Admin pages → Administration API: calls API
- Session validation → Auth cookies: reads and clears (evidence: `OCR_Frontend/OCR_Frontend/Middleware/SessionValidationMiddleware.cs`)
- Session validation → Frontend instance: checks instance (evidence: `OCR_Frontend/OCR_Frontend/Middleware/SessionValidationMiddleware.cs`)
- Session validation → Authentication API: validates session (evidence: `OCR_Frontend/OCR_Frontend/Middleware/SessionValidationMiddleware.cs`)
- Account pages → Auth cookies: sets cookies (evidence: `OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs`)
- Account pages → API error parsing: parses errors (evidence: `OCR_Frontend/OCR_Frontend/Pages/Login.cshtml.cs`)
- Document pages → Auth cookies: attaches token (evidence: `OCR_Frontend/OCR_Frontend/Pages/UploadPdf.cshtml.cs`)
- Document pages → API error parsing: parses errors (evidence: `OCR_Frontend/OCR_Frontend/Pages/UploadPdf.cshtml.cs`)
- Exam pages → API error parsing: parses errors (evidence: `OCR_Frontend/OCR_Frontend/Pages/GenerateQuestionnaire.cshtml.cs`)
- Grading pages → API error parsing: parses errors (evidence: `OCR_Frontend/OCR_Frontend/Pages/GradeExam.cshtml.cs`)
- Authentication API → Application database: reads and writes (evidence: `Project_OLMS/Project_OLMS/Controllers/AuthController.cs`)
- Authentication API → Email delivery: sends email (evidence: `Project_OLMS/Project_OLMS/Controllers/AuthController.cs`)
- Authentication API → Backend instance: issues instance-bound tokens (evidence: `Project_OLMS/Project_OLMS/Controllers/AuthController.cs`)
- Administration API → Application database: reads and writes (evidence: `Project_OLMS/Project_OLMS/Controllers/AdminController.cs`)
- Dashboard API → Application database: reads data (evidence: `Project_OLMS/Project_OLMS/Controllers/DashboardController.cs`)
- PDF upload API → Application database: stores metadata (evidence: `Project_OLMS/Project_OLMS/Controllers/PdfUploadController.cs`)
- OCR and grading → Application database: reads and writes (evidence: `Project_OLMS/Project_OLMS/Controllers/Tesseract.cs`)
- Exam API → Application database: reads and writes (evidence: `Project_OLMS/Project_OLMS/Controllers/ExamController.cs`)
- Exam API → Gemini AI: generates questions (evidence: `Project_OLMS/Project_OLMS/Controllers/ExamController.cs`)
- Exam API → Audit logging: logs exam actions
- Audit logging → Application database: writes logs (evidence: `Project_OLMS/Project_OLMS/Services/AuditLogService.cs`)
- Application database → User accounts: maps entity (evidence: `Project_OLMS/Project_OLMS/Data/AppDbContext.cs`)
- Application database → PDF documents: maps entity (evidence: `Project_OLMS/Project_OLMS/Data/AppDbContext.cs`)
- Application database → Questionnaires: maps entity (evidence: `Project_OLMS/Project_OLMS/Data/AppDbContext.cs`)
- Application database → Graded sheets: maps entity (evidence: `Project_OLMS/Project_OLMS/Data/AppDbContext.cs`)
- Application database → Audit records: maps entity (evidence: `Project_OLMS/Project_OLMS/Data/AppDbContext.cs`)
- Exam API → PDF documents: loads document (evidence: `Project_OLMS/Project_OLMS/Controllers/ExamController.cs`)
- Exam API → Questionnaires: creates questionnaire (evidence: `Project_OLMS/Project_OLMS/Controllers/ExamController.cs`)
- Exam API → Question items: serializes questions (evidence: `Project_OLMS/Project_OLMS/Controllers/ExamController.cs`)
- Gemini AI → Question items: produces questions (evidence: `Project_OLMS/Project_OLMS/Services/GeminiService.cs`)
- OCR and grading → Question items: uses questions (evidence: `Project_OLMS/Project_OLMS/Controllers/Tesseract.cs`)
- OCR and grading → Graded sheets: creates graded sheets (evidence: `Project_OLMS/Project_OLMS/Controllers/Tesseract.cs`)
