Repository navigation
Evaluation Workflow
- Introduction
- Project Structure
- Core Components
- Architecture Overview
- Detailed Component Analysis
- Dependency Analysis
- Performance Considerations
- Troubleshooting Guide
- Conclusion
This document explains the complete AI evaluation workflow in PersonalLearningPro, from answer submission to grade calculation and feedback delivery. It covers the end-to-end process across frontend submission, backend evaluation processing, and persistent storage. It also documents the evaluation pipeline stages (AI assessment, score normalization, feedback generation), workflow coordination between evaluation functions, and data persistence. Examples of complete evaluation scenarios, error handling, and performance optimization strategies are included, along with API endpoint definitions and data flow.
The evaluation workflow spans three layers:
- Frontend (client): Submission of answers, OCR processing, and rubric authoring for subjective questions.
- Backend (server): Route orchestration, authorization checks, AI evaluation, and persistence.
- Persistence (shared): MongoDB schemas for tests, attempts, questions, and answers.
graph TB
subgraph "Frontend (Client)"
FE_QF["QuestionForm<br/>Author rubrics"]
FE_OCR["OCRUpload<br/>Image to text"]
FE_STD_DASH["StudentDashboard<br/>Results display"]
FE_PAR_DASH["ParentDashboard<br/>Progress charts"]
end
subgraph "Backend (Server)"
BE_ROUTES["Routes<br/>/api/answers, /api/evaluate, /api/ocr"]
BE_STORAGE["Storage<br/>MongoStorage"]
BE_OPENAI["OpenAI Module<br/>aiChat, evaluateSubjectiveAnswer"]
end
subgraph "Persistence"
DB_SCHEMAS["Mongo Schemas<br/>Test, Question, TestAttempt, Answer"]
end
FE_QF --> BE_ROUTES
FE_OCR --> BE_ROUTES
FE_STD_DASH --> BE_ROUTES
FE_PAR_DASH --> BE_ROUTES
BE_ROUTES --> BE_STORAGE
BE_ROUTES --> BE_OPENAI
BE_STORAGE --> DB_SCHEMAS
Diagram sources
- routes.ts
- storage.ts
- openai.ts
- mongo-schema.ts
Section sources
- routes.ts
- storage.ts
- openai.ts
- mongo-schema.ts
- AI evaluation module: Provides AI-assisted evaluation for subjective answers and test performance analysis.
- Routes: Expose endpoints for answer submission, OCR processing, and manual/automatic evaluation.
- Storage: Implements CRUD operations for tests, attempts, questions, and answers with MongoDB.
- Frontend forms: Allow teachers to define rubrics and enable students to submit answers and OCR text.
Key responsibilities:
- Authorization: Ensure only authorized roles access evaluation endpoints.
- Data validation: Validate inputs using Zod schemas before persisting.
- AI scoring: Normalize scores to question max marks and return confidence and feedback.
- Persistence: Store answers, scores, and feedback for later retrieval and reporting.
Section sources
- openai.ts
- routes.ts
- storage.ts
- mongo-schema.ts
The evaluation workflow integrates frontend submission, backend orchestration, AI services, and persistent storage.
sequenceDiagram
participant Student as "Student"
participant FE as "Frontend"
participant API as "Routes (/api)"
participant AI as "OpenAI Module"
participant DB as "Storage/Mongo"
Student->>FE : "Submit answer or OCR"
FE->>API : "POST /api/answers"
API->>DB : "Create Answer"
DB-->>API : "Answer saved"
API-->>FE : "Answer created"
FE->>API : "POST /api/evaluate (teacher)"
API->>DB : "Load Answer, Question, Attempt, Test"
API->>AI : "evaluateSubjectiveAnswer(text, question, rubric, marks)"
AI-->>API : "{score, confidence, feedback}"
API->>DB : "Update Answer with score, feedback, confidence"
DB-->>API : "Answer updated"
API-->>FE : "Updated answer"
Diagram sources
- routes.ts
- openai.ts
- storage.ts
The AI evaluation pipeline performs:
- Prompt construction with question, rubric, and student answer.
- JSON response parsing with strict validation and bounds checking.
- Normalization of score to the question’s max marks.
- Confidence and feedback delivery for teacher review.
flowchart TD
Start(["Start Evaluation"]) --> BuildPrompt["Build prompt with question, rubric, answer"]
BuildPrompt --> CallAI["Call OpenAI API (JSON response)"]
CallAI --> ParseResp{"Parse JSON response"}
ParseResp --> |Success| Normalize["Clamp score to [0, maxMarks]<br/>Clamp confidence to [0, 100]"]
ParseResp --> |Failure| Fallback["Return fallback result (score=0, feedback error)"]
Normalize --> Return["Return {score, confidence, feedback}"]
Fallback --> Return
Diagram sources
- openai.ts
Section sources
- openai.ts
- Validates session role (student), attempt ownership, and attempt status.
- Supports automatic evaluation for MCQ questions.
- Persists answer and returns created record.
sequenceDiagram
participant FE as "Frontend"
participant API as "POST /api/answers"
participant DB as "Storage"
FE->>API : "Answer payload"
API->>API : "Validate session and attempt ownership"
API->>DB : "Get Question"
API->>API : "If MCQ -> compute score/isCorrect"
API->>DB : "Create Answer"
DB-->>API : "Answer"
API-->>FE : "Answer created"
Diagram sources
- routes.ts
- storage.ts
Section sources
- routes.ts
- storage.ts
- Requires teacher role and validates ownership of the test.
- Uses either raw text or OCR-derived text for evaluation.
- Updates answer with AI-generated score, confidence, and feedback.
sequenceDiagram
participant Teacher as "Teacher"
participant API as "POST /api/evaluate"
participant DB as "Storage"
participant AI as "OpenAI Module"
Teacher->>API : "answerId"
API->>DB : "Load Answer, Question, Attempt, Test"
API->>API : "Verify ownership (teacherId)"
API->>AI : "evaluateSubjectiveAnswer(text, question, rubric, marks)"
AI-->>API : "{score, confidence, feedback}"
API->>DB : "Update Answer"
DB-->>API : "Updated Answer"
API-->>Teacher : "Updated Answer"
Diagram sources
- routes.ts
- openai.ts
- storage.ts
Section sources
- routes.ts
- openai.ts
- storage.ts
- Accepts base64 image data and returns extracted text and confidence.
- Enforces file size/type constraints in the frontend.
sequenceDiagram
participant Student as "Student"
participant FE as "OCRUpload"
participant API as "POST /api/ocr"
Student->>FE : "Upload image(s)"
FE->>API : "Base64 image data"
API-->>FE : "{text, confidence}"
FE-->>Student : "Display OCR result"
Diagram sources
- routes.ts
- ocr-upload.tsx
Section sources
- routes.ts
- ocr-upload.tsx
- Teachers define rubrics during question creation to guide AI evaluation.
- Rubrics are stored with the question and used during evaluation.
flowchart TD
Start(["Create Question"]) --> FillFields["Fill question text, type, marks"]
FillFields --> TypeCheck{"Type == subjective?"}
TypeCheck --> |Yes| EnterRubric["Enter AI Rubric"]
TypeCheck --> |No| SkipRubric["Skip rubric"]
EnterRubric --> Save["Save Question with Rubric"]
SkipRubric --> Save
Save --> End(["Ready for Evaluation"])
Diagram sources
- question-form.tsx
- mongo-schema.ts
Section sources
- question-form.tsx
- mongo-schema.ts
- Answers store both raw text and OCR-derived text, plus AI-assigned score, confidence, and feedback.
- Test attempts track status and can be updated to evaluated after AI scoring.
erDiagram
TEST ||--o{ QUESTION : "contains"
TEST ||--o{ TEST_ATTEMPT : "assigned"
TEST_ATTEMPT ||--o{ ANSWER : "records"
QUESTION ||--o{ ANSWER : "answers"
TEST {
int id PK
string title
string subject
int teacherId
string status
}
QUESTION {
int id PK
int testId FK
string type
string text
string aiRubric
number marks
}
TEST_ATTEMPT {
int id PK
int testId FK
int studentId
datetime startTime
datetime endTime
number score
string status
}
ANSWER {
int id PK
int attemptId FK
int questionId FK
string text
number selectedOption
string imageUrl
string ocrText
number score
number aiConfidence
string aiFeedback
boolean isCorrect
}
Diagram sources
- mongo-schema.ts
Section sources
- mongo-schema.ts
- storage.ts
- Student submits an MCQ answer.
- Backend computes correctness and score immediately.
- Answer persisted with isCorrect and score.
Section sources
- routes.ts
- storage.ts
- Teacher triggers AI evaluation using stored rubric.
- AI returns normalized score, confidence, and feedback.
- Answer updated with AI results.
Section sources
- routes.ts
- openai.ts
- Student uploads scanned answer sheet.
- OCR extracts text and confidence.
- Teacher evaluates using OCR text and rubric.
Section sources
- routes.ts
- ocr-upload.tsx
- routes.ts
- Routes depend on Storage for database operations and OpenAI module for AI evaluation.
- OpenAI module depends on environment configuration for API keys.
- Frontend components depend on routes for data operations and schemas for type safety.
graph TB
R["routes.ts"] --> O["openai.ts"]
R --> S["storage.ts"]
S --> M["mongo-schema.ts"]
QF["question-form.tsx"] --> R
OCR["ocr-upload.tsx"] --> R
STD["student-dashboard.tsx"] --> R
PAR["parent-dashboard.tsx"] --> R
Diagram sources
- routes.ts
- openai.ts
- storage.ts
- mongo-schema.ts
Section sources
- routes.ts
- openai.ts
- storage.ts
- mongo-schema.ts
- Minimize AI calls: Prefer automatic MCQ scoring; batch manual evaluations when feasible.
- Cache rubrics and question metadata to reduce repeated loads.
- Use pagination and indexing for analytics and reporting views.
- Optimize OCR uploads: Validate file size/type early to avoid unnecessary processing.
- Monitor OpenAI rate limits and implement retry/backoff strategies.
Common issues and resolutions:
- Unauthorized access: Ensure session role and ownership checks pass for evaluation endpoints.
- Missing data: Verify answer, question, attempt, and test exist before evaluation.
- AI parsing failures: The AI evaluation function returns safe defaults when JSON parsing fails.
- OCR errors: Validate image constraints and handle frontend errors gracefully.
Section sources
- routes.ts
- openai.ts
- ocr-upload.tsx
PersonalLearningPro’s evaluation workflow integrates frontend submission, backend orchestration, AI-powered scoring, and robust persistence. The system supports automatic MCQ scoring and manual AI evaluation for subjective questions, with rubrics authored by teachers. Data is normalized and persisted for reporting and analytics, while error handling ensures resilience. By following the documented endpoints, data flows, and best practices, stakeholders can reliably evaluate student performance and improve learning outcomes.