/mastery-quiz/submit` | Submit mastery quiz. Body: `{ "answers": [...] }`. Returns score, pass/fail, updated mastery. | JWT |
| `POST` | `/api/coach/hint` | Request a hint. Body: `{ "questionId": "...", "topicId": 105, "currentAnswer": "..." }`. Returns hint text. | JWT |
| `POST` | `/api/coach/explain` | Request explanation. Body: `{ "questionId": "...", "topicId": 105, "studentAnswer": "...", "correctAnswer": "..." }`. Returns detailed explanation. | JWT |
| `POST` | `/api/coach/suggest` | Get study suggestions. Body: `{ "subjectId": 1 }`. Returns personalized study advice. | JWT |
### 10.7 Analytics Endpoints
| Method | Path | Description | Auth |
|--------|------|-------------|------|
| `GET` | `/api/analytics/student` | Student's own analytics. Query: `?subjectId=1`. | JWT |
| `GET` | `/api/analytics/class` | Class-level analytics (teacher/admin). Query: `?subjectId=1&classroomId=5`. | JWT (teacher/admin) |
| `GET` | `/api/analytics/subject` | Subject-level analytics (admin). Query: `?subjectId=1`. | JWT (admin) |
| `GET` | `/api/analytics/content-gaps` | Content gap report (admin/staff). Query: `?subjectId=1`. | JWT (admin/staff) |
---
## 11. AI Integration Specification
### 11.1 New Odoo Module: `encoach_adaptive_ai`
This module provides AI services for the adaptive learning system. It follows the same patterns as `encoach_ai_generation` and `encoach_ai_grading`: a service class that calls `EncoachOpenAIService` with subject-specific prompts.
### 11.2 GPT-4o Prompt Templates
#### 11.2.1 Diagnostic Question Generation
**Math Example:**
```
System: You are a mathematics assessment expert. Generate an adaptive diagnostic question.
Given:
- Subject: Mathematics
- Domain: {domain_name}
- Topic: {topic_name}
- Difficulty: {difficulty_level} (easy/medium/hard/advanced)
- Question type: {question_type}
- Learning objectives: {objectives_list}
Generate a single question with:
1. "question": The question text (use LaTeX notation for formulas: $...$)
2. "options": Array of 4 options (for multiple_choice only)
3. "correct_answer": The correct answer
4. "explanation": Brief explanation of why the answer is correct
5. "grading_rubric": How to grade (for open-ended: key concepts to look for)
6. "difficulty_tag": The actual difficulty of the generated question
Respond in JSON format only.
```
**IT Example:**
```
System: You are an Information Technology assessment expert. Generate an adaptive diagnostic question.
Given:
- Subject: Information Technology
- Domain: {domain_name}
- Topic: {topic_name}
- Difficulty: {difficulty_level}
- Question type: {question_type}
- Learning objectives: {objectives_list}
Generate a single question with:
1. "question": The question text (use ```code blocks``` for code snippets)
2. "options": Array of 4 options (for multiple_choice/true_false)
3. "correct_answer": The correct answer
4. "explanation": Brief explanation
5. "grading_rubric": How to grade
6. "difficulty_tag": Actual difficulty
For code_completion type, include:
- "starter_code": Code with blanks/comments for student to complete
- "expected_output": What correct code should produce
- "evaluation_criteria": ["correctness", "approach", "efficiency"]
Respond in JSON format only.
```
#### 11.2.2 Learning Plan Generation
```
System: You are an adaptive learning plan advisor. Create a personalized study plan.
Given:
- Student proficiency profile:
{proficiency_json}
- Subject taxonomy with prerequisites:
{taxonomy_json}
- Target completion date: {target_date}
- Mastery threshold: {mastery_threshold}%
Generate a study plan with:
1. "summary": A 2-3 sentence motivational overview of the plan, acknowledging strengths and addressing weaknesses
2. "recommended_sequence": Ordered list of topic IDs to study, respecting prerequisites
3. "estimated_hours_per_topic": Object mapping topic_id to estimated study hours (adjusted by current mastery)
4. "milestones": Array of milestone objects with {"name", "topic_ids", "target_date", "description"}
5. "focus_areas": Top 3 domains/topics that need the most attention
6. "study_advice": Specific tips for the student based on their profile
Respond in JSON format only.
```
#### 11.2.3 Content Generation
```
System: You are an expert {subject_name} tutor. Generate learning content for the following topic.
Given:
- Subject: {subject_name}
- Topic: {topic_name}
- Learning objectives: {objectives_list}
- Student mastery level: {mastery_level} ({mastery_percentage}%)
- Content type: {content_type} (explanation/worked_example/key_takeaways)
- Available context: {resource_summaries} (summaries of human-uploaded resources, if any)
For "explanation":
Generate a clear, structured explanation of {topic_name} that:
- Starts from the student's current level ({mastery_level})
- Covers all learning objectives
- Uses concrete examples
- For Math: uses LaTeX notation ($...$) for formulas
- For IT: uses ```language``` code blocks for code examples
- Ends with a brief summary
For "worked_example":
Generate 2-3 step-by-step worked examples that:
- Progress from simple to complex
- Show every intermediate step
- Highlight common mistakes to avoid
- For Math: show formula transformations step by step
- For IT: show code evolution or decision reasoning
For "key_takeaways":
Generate 3-5 bullet points summarizing the most important concepts, formulas, or patterns from this topic.
Respond in Markdown format.
```
#### 11.2.4 AI Coaching -- Hint
```
System: You are a helpful {subject_name} tutor providing a hint to a student.
The student is working on this question:
{question_text}
Their current (incomplete or incorrect) answer: {student_answer}
The correct answer: {correct_answer}
Provide a hint that:
- Does NOT reveal the full answer
- Points the student toward the right approach
- References relevant concepts or formulas
- Is encouraging and supportive
- Is 1-3 sentences long
Respond with just the hint text.
```
#### 11.2.5 AI Coaching -- Explanation
```
System: You are a {subject_name} tutor explaining a question result.
Question: {question_text}
Student's answer: {student_answer}
Correct answer: {correct_answer}
Was correct: {is_correct}
Provide an explanation that:
- Acknowledges whether the student was correct or incorrect
- Explains WHY the correct answer is correct
- If the student was wrong, explains the specific misconception
- References the relevant concept/formula/principle
- Suggests what to review if the student was wrong
- For Math: shows the solution steps
- For IT: explains the underlying principle
Respond in Markdown format (2-4 paragraphs).
```
### 11.3 Grading Logic per Question Type
| Question Type | Grading Method | Implementation |
|--------------|---------------|----------------|
| `multiple_choice` | Exact match | Direct comparison: `student_answer == correct_answer` |
| `true_false` | Exact match | Direct comparison |
| `numerical` | Tolerance-based | `abs(student - correct) <= tolerance`. Default tolerance: 0.01. Configurable per topic. |
| `fill_blanks` | Normalized match | Strip whitespace, lowercase, compare. For Math: normalize LaTeX expressions. |
| `short_answer` | AI-graded | GPT-4o evaluates semantic equivalence. Prompt includes correct answer and acceptable variations. |
| `code_completion` | AI-graded | GPT-4o evaluates: (1) correctness of output, (2) approach validity, (3) code quality. Returns score 0-100 + feedback. |
| `worked_problem` | AI-graded | GPT-4o evaluates: (1) final answer correctness, (2) methodology, (3) step completeness. Returns score 0-100 + per-step feedback. |
| `scenario` | AI-graded | GPT-4o evaluates against rubric provided with the question. Returns score 0-100 + explanation. |
### 11.4 FAISS Extension
Create subject-specific FAISS indices for training tips:
| Index | Category | Content Source |
|-------|----------|---------------|
| `math_algebra_tips` | Algebra tips and common mistakes | Curated + AI-generated |
| `math_geometry_tips` | Geometry tips and formulas | Curated + AI-generated |
| `math_statistics_tips` | Statistics tips and methods | Curated + AI-generated |
| `it_networking_tips` | Networking concepts and troubleshooting | Curated + AI-generated |
| `it_database_tips` | SQL tips and database design patterns | Curated + AI-generated |
| `it_programming_tips` | Coding tips and best practices | Curated + AI-generated |
Each index uses `all-MiniLM-L6-v2` for embeddings (same as English), stored as `encoach.training.tip` records with a new `subject_id` field.
---
## 12. Frontend Requirements
### 12.1 New Pages
| Page | Route | Role | Description |
|------|-------|------|-------------|
| **Subject Selection** | `/student/subjects` | Student | List available subjects, show overall mastery per subject, "Start Learning" button |
| **Diagnostic Test** | `/student/diagnostic/:subjectId` | Student | Adaptive test UI: one question at a time, progress indicator, timer, auto-advance on answer |
| **Proficiency Profile** | `/student/proficiency/:subjectId` | Student | Visual mastery map: domain radar chart, per-topic mastery bars, strengths/weaknesses |
| **Learning Plan** | `/student/plan/:subjectId` | Student | Topic sequence with status indicators (locked/available/in-progress/completed), progress bar, timeline |
| **Topic Learning** | `/student/topic/:topicId` | Student | Content viewer: resources list, AI content, practice section, mastery quiz trigger |
| **Practice Session** | `/student/practice/:topicId` | Student | Question-by-question practice with instant feedback, hints, explanations |
| **Mastery Quiz** | `/student/mastery-quiz/:topicId` | Student | Timed quiz, similar to existing exam UI, results with pass/fail and mastery update |
| **AI Coach** | Component (sidebar/modal) | Student | Contextual AI assistant: hint requests, explanations, study suggestions |
| **Taxonomy Manager** | `/admin/taxonomy` | Admin/Staff | CRUD for subjects, domains, topics, objectives, prerequisite mapping |
| **Resource Manager** | `/admin/resources` | Admin/Staff | Upload, tag, manage resources; content gap dashboard |
| **Adaptive Analytics** | `/admin/adaptive-analytics` | Admin | Subject-level analytics, class performance, content gaps |
| **Student Plan View** | `/teacher/student-plan/:studentId/:subjectId` | Teacher | View and override a student's learning plan |
### 12.2 Math-Specific Components
| Component | Technology | Purpose |
|-----------|-----------|---------|
| `MathRenderer` | KaTeX (via `react-katex` or `remark-math` + `rehype-katex`) | Render LaTeX formulas in questions, explanations, and content. Inline: `$x^2$`, block: `$$\frac{a}{b}$$` |
| `MathInput` | `mathlive` or custom LaTeX input | Student enters mathematical expressions as answers. Visual equation editor with keyboard shortcuts. |
| `FormulaReference` | KaTeX | Sidebar panel showing relevant formulas for the current topic |
| `GraphPlot` | `recharts` or `plotly.js` | Display mathematical graphs (for coordinate geometry, functions) |
### 12.3 IT-Specific Components
| Component | Technology | Purpose |
|-----------|-----------|---------|
| `CodeBlock` | `prism-react-renderer` or `react-syntax-highlighter` | Render code snippets with syntax highlighting in questions and content |
| `CodeEditor` | `@monaco-editor/react` (lightweight) or `codemirror` | Student writes/edits code for code_completion questions |
| `TerminalOutput` | Custom styled `` | Display expected program output |
| `NetworkDiagram` | `react-flow` or Mermaid | Display network topology diagrams for networking questions |
### 12.4 Shared Components
| Component | Purpose |
|-----------|---------|
| `MasteryBar` | Horizontal bar showing mastery level with color coding (grey/red/orange/yellow/green) |
| `DomainRadar` | Radar chart showing mastery across all domains in a subject |
| `TopicCard` | Card showing topic name, mastery, status (locked/available/completed), prerequisite indicator |
| `PlanTimeline` | Vertical timeline of learning plan items with status icons |
| `QuizTimer` | Countdown timer for mastery quizzes (reuse from existing exam timer) |
| `ProgressRing` | Circular progress indicator for overall subject mastery |
| `ResourceCard` | Card for learning resources with type icon, title, estimated time, completion checkbox |
| `CoachBubble` | Chat-like bubble for AI coaching responses |
---
## 13. Non-Functional Requirements
### 13.1 Performance
| Metric | Target |
|--------|--------|
| Diagnostic question generation | < 3 seconds per question |
| Practice question generation (batch of 5) | < 5 seconds |
| AI grading (per answer) | < 5 seconds for auto-gradeable, < 10 seconds for AI-graded |
| Learning plan generation | < 10 seconds |
| AI content generation (explanation) | < 15 seconds |
| AI coaching response (hint/explanation) | < 5 seconds |
| Resource file upload | < 30 seconds for files up to 50 MB |
| Proficiency profile load | < 1 second |
| Taxonomy tree load | < 2 seconds |
### 13.2 Scalability
| Dimension | Target |
|-----------|--------|
| Concurrent students per subject | 200 |
| Total topics per subject | 500 |
| Total resources per subject | 1,000 |
| AI content cache entries | 10,000 |
| Proficiency records | 200 students x 500 topics = 100,000 records |
### 13.3 Data Integrity
- Proficiency scores are never overwritten -- all changes are additive (new assessment results update the score via weighted average, never direct replacement)
- Learning plan changes are logged (who changed, when, what was before/after)
- AI-generated content is cached and versioned; regeneration creates a new version, does not delete the old one
- Resource deletions are soft-deletes (is_active = False) to preserve student completion records
### 13.4 Security
- All endpoints require JWT authentication (via existing `_authenticate()`)
- Students can only access their own proficiency and learning plan data
- Teachers can view (but not modify without explicit override) student data in their classrooms
- Admin has full access
- Resource uploads are scanned for file type validation (no executable uploads)
- AI prompts never include student personal data (only anonymized performance metrics)
---
## Appendix A: Implementation Priority
| Priority | Component | Rationale |
|----------|-----------|-----------|
| **P0** | Subject taxonomy models + CRUD API | Foundation for everything else |
| **P0** | Resource model + upload API | Staff needs to start uploading content immediately |
| **P1** | Diagnostic assessment engine + UI | Entry point for students |
| **P1** | Proficiency profile model + API | Required by learning plan |
| **P1** | Learning plan generation + UI | Core student experience |
| **P2** | Content delivery (resource viewer + AI content) | Content consumption |
| **P2** | Practice questions + grading | Practice before mastery quiz |
| **P2** | Mastery quiz + progression | Advancement mechanism |
| **P3** | AI coaching (hints, explanations) | Enhancement to learning experience |
| **P3** | Spaced repetition | Long-term retention |
| **P3** | Analytics dashboards | Monitoring and optimization |
| **P4** | Content gap detection | Operational efficiency |
| **P4** | FAISS training tips per subject | Advanced personalization |
## Appendix B: Dependency Graph for Implementation
```mermaid
graph TB
TaxModels["P0: Taxonomy Models
(Subject, Domain, Topic, Objective)"] --> TaxAPI["P0: Taxonomy CRUD API"]
TaxModels --> ResModels["P0: Resource Model"]
ResModels --> ResAPI["P0: Resource Upload API"]
TaxAPI --> DiagEngine["P1: Diagnostic Engine"]
TaxModels --> ProfModel["P1: Proficiency Model"]
DiagEngine --> ProfModel
ProfModel --> PlanGen["P1: Learning Plan Generation"]
TaxModels --> PlanGen
ResAPI --> ContentDel["P2: Content Delivery"]
PlanGen --> ContentDel
ContentDel --> Practice["P2: Practice Questions"]
Practice --> MasteryQuiz["P2: Mastery Quiz"]
MasteryQuiz --> ProfModel
Practice --> Coaching["P3: AI Coaching"]
MasteryQuiz --> SpacedRep["P3: Spaced Repetition"]
ProfModel --> Analytics["P3: Analytics"]
ResAPI --> GapDetect["P4: Content Gap Detection"]
ProfModel --> FAISSTips["P4: FAISS Tips per Subject"]
```
---
*Document prepared for architect review. All data models, APIs, and specifications are draft and subject to refinement before handoff to the development team.*