Yamen Ahmad e2aa8031ff
Some checks failed
CI / Frontend — lint + build + e2e (pull_request) Failing after 1m20s
CI / Backend — Odoo HttpCase (pull_request) Failing after 1s
feat(ai): LangGraph as core runtime + AI Agents/Tools console + full-demo seed
Core AI runtime
- New encoach.ai.agent + encoach.ai.tool models with M2M tool binding,
  graph topology (simple|plan_review_revise|rag|react), model + fallback,
  temperature, max_tokens, response_format, max_revisions, quality checks
  and system prompt fields.
- services/agent_runtime.py compiles a langgraph.StateGraph per agent
  and caches the build per (key, write_date). Emits a structured trace
  (output, tool_calls, retrieval_hits, revisions, quality_issues,
  ms, model_used, fallback_used) and auto-falls-back on rate-limit/5xx.
- services/agent_tools.py registers 11 tool handlers wrapping existing
  services: resources.search, rubric.fetch, outcomes.fetch,
  student.profile, quality.cefr_check, quality.ai_detect,
  quality.content_gate, course_plan.save (mutates),
  course_plan.save_materials (mutates), scoring.grade_writing,
  scoring.grade_speaking.
- 7 default agents seeded via data/agents_defaults.xml: course_planner,
  course_week_materials, exam_generator, exercise_generator, lms_tutor,
  writing_grader, speaking_grader.
- Feature flag encoach_ai.use_langgraph_runtime (default True).
- encoach_ai_course pipeline now routes through AgentRuntime when on,
  legacy SDK path kept as fallback.

Admin UI
- /admin/ai/prompts is now a tabbed Agents | Tools | Prompts console.
- AIAgentsPanel: card grid + config dialog (model/temp/graph/tools/
  system prompt) + built-in Test Runner showing live trace.
- AIToolsPanel: registry table with category badges, mutates flag,
  schema viewer, edit dialog.
- New /api/ai/agents* and /api/ai/tools* controller (list/get/update/
  test, list-tools, toggle-tool).
- Sidebar label nav.aiPrompts -> nav.aiAgents (AI Agents and Tools).
- EN + AR (RTL) translations for ~80 new keys.

Smart Wizard pages
- /admin/quick-setup hub + CourseWizard, CoursePlanWizard,
  RubricWizard, ExamStructureWizard step-by-step flows.
- /admin/course-plans list + detail pages.
- /teacher/quick-setup mirror.

Full demo seed + 8-role E2E
- seed_full_demo.py adds the 5 missing user_types (approver, corporate,
  mastercorporate, agent, developer), activates a 2-stage exam-approval
  workflow with one pending request, creates a GE1-aligned 12-week B1
  course plan with 6 detailed Week-1 materials (reading 400w, writing,
  listening 4-min script, speaking, grammar present simple vs continuous,
  vocabulary), and inserts sample ai.log + ai.feedback rows.
- reset_demo_passwords.py forces every demo login back to canonical
  passwords (admin123/teacher123/student123/approver123/corporate123/
  master123/agent123/dev123).
- e2e_full_scenario.py: 46/46 PASS read-only API smoke across all
  8 roles, including a live LangGraph round-trip on writing_grader.
- e2e_approval_chain.py: 6/6 PASS mutation E2E - approver approves
  stage 1, admin approves stage 2, linked encoach.exam.custom flips
  to status=published, verified via psql.

Docs
- docs/PROJECT_SUMMARY.md updated to 2026-04-25: new Latest events
  bullets, refreshed credentials table, full sections 22 (LangGraph
  runtime) and 23 (full demo seed + 8-role E2E).
- docs/ENCOACH_FULL_DEMO_QA_REPORT.md added with credentials,
  per-endpoint PASS/FAIL, mutation chain proof, LangGraph live output.
- backend/GE1 Course Outline_ Fall AY25-26.pdf vendored as the
  reference outline the GE1 plan/materials are aligned to.

Dependencies
- requirements.txt: langgraph>=0.2.0, langchain-core>=0.3.0.
- encoach_ai/__manifest__.py: external_dependencies updated.

Made-with: Cursor
2026-04-25 03:14:22 +04:00

EnCoach — Adaptive AI Learning Platform

EnCoach is a smart learning environment for individual and collaborative learning, fully integrated with AI and equipped with intelligent, professional-grade exercises, assessments, and e-exams.

This repository hosts the full stack:

  • Backend — Odoo 19 + ~30 encoach_* modules (Python 3.12, PostgreSQL 16)
  • Frontend — React 18 + Vite + TypeScript single-page app
  • AI layer — OpenAI + pgvector RAG, quality-gate validation, IELTS validator
  • Ops — Docker Compose, JWT auth with refresh tokens, Prometheus-compatible metrics, dynamic OpenAPI 3.0 spec

Canonical trees: backend/ (all server code) and frontend/ (all client code). The legacy new_project/ directory is deprecated — see new_project/DEPRECATED.md.


1. Quickstart

docker compose up -d
# Odoo:     http://localhost:8069
# Frontend: cd frontend && npm install && npm run dev  (http://localhost:8080)

Create a new Odoo database on first visit, then install the encoach_api module to pull in every encoach_* dependency.

Source

Prerequisites: Python 3.12, PostgreSQL 16, Node 20, npm 10.

# Backend
./setup.sh          # creates venv, installs requirements.txt
./run.sh            # starts Odoo on :8069

# Frontend
cd frontend
npm install
npm run dev         # starts Vite on :8080, proxies /api → :8069

See MANUAL-RUN.md for a step-by-step walkthrough and CONNECT-POSTGRES.md for database wiring.


2. Repository layout

odoo19/
├── backend/
│   └── custom_addons/
│       ├── encoach_api/              REST base + JWT + OpenAPI + metrics
│       ├── encoach_core/             Users, entities, roles, permissions
│       ├── encoach_taxonomy/         Subject → Domain → Topic
│       ├── encoach_ai/               OpenAI wrapper, cefr_mapper, validator
│       ├── encoach_ai_course/        AI course/exam generation pipelines
│       ├── encoach_ai_grading/       AI grading (writing/speaking/math/IT)
│       ├── encoach_ai_media/         TTS (Polly), STT (Whisper), ELAI
│       ├── encoach_vector/           pgvector store + RAG embeddings
│       ├── encoach_exam_template/    Canonical exam + student attempt models
│       ├── encoach_scoring/          Score computation, CEFR mapping
│       ├── encoach_quality_gate/     Automated content-quality checks
│       ├── encoach_ielts_validation/ IELTS-specific validators
│       ├── encoach_adaptive/         Adaptive engine, style matcher
│       ├── encoach_lms_api/          OpenEduCat bridge + LMS endpoints
│       ├── encoach_branding/         White-label config per entity
│       └── … (other encoach_* modules)
├── frontend/
│   ├── src/
│   │   ├── pages/                    Route pages (React.lazy code-split)
│   │   ├── components/               Shared UI (shadcn/ui + custom)
│   │   ├── services/                 Thin API wrappers over fetch
│   │   ├── hooks/queries/            React Query hooks + keys
│   │   ├── lib/api-client.ts         Fetch + auto JWT refresh
│   │   └── types/                    Shared DTO types
│   └── vite.config.ts                manualChunks: react, query, charts, radix…
├── docs/
│   ├── PROJECT_SUMMARY.md            Release notes & architecture history
│   ├── adr/                          Architecture Decision Records
│   └── ENCOACH_*.md                  SRS, workflows, user stories
├── docker-compose.yml
├── Dockerfile
├── requirements.txt                  Python deps (pgvector, textstat, etc.)
└── README.md                         You are here

3. Architecture at a glance

┌────────────────────┐     HTTPS/JWT      ┌────────────────────┐
│  React SPA (Vite)  │  ───────────────►  │   Odoo 19 + FastAPI-style   │
│  - React Query     │  ◄───────────────  │   controllers (encoach_*)   │
│  - next-themes     │   X-Request-Id     └──────┬─────────────┘
│  - shadcn/ui       │                           │
└────────────────────┘                           ▼
                                          ┌──────────────┐
                                          │  PostgreSQL  │
                                          │  + pgvector  │
                                          └──────┬───────┘
                                                 │
                                                 ▼
                                          ┌──────────────┐
                                          │   OpenAI,    │
                                          │   Whisper,   │
                                          │   Polly…     │
                                          └──────────────┘

Every request carries an X-Request-Id and emits structured JSON logs. Prometheus-compatible counters are exposed at /api/metrics, and the live OpenAPI 3.0 spec is at /api/openapi.json.


4. Key conventions

  • Canonical response envelope — list endpoints return { items: T[], total, page, size, data: T[] } (see encoach_api.controllers.base.paginated_envelope).
  • CEFR mapping — only encoach_ai.services.cefr_mapper is canonical. Do not reintroduce local band_to_cefr copies.
  • JWT tokens — short-lived access tokens (1h) + revocable refresh tokens (7d). Only access tokens are accepted as Bearer credentials; refresh tokens must go through /api/auth/refresh. See docs/adr/0002-jwt-refresh-token-flow.md.
  • RAG metadata — vector embeddings carry course_id, subject_id, entity_id, taxonomy, content_hash. Chunking kicks in above 2 000 chars.
  • Frontend paginationPaginatedResponse<T> exposes both items and data. Read from items in new code.
  • Frontend theming — tokens live in frontend/src/index.css (:root and .dark). Always use hsl(var(--token)) instead of raw hex.

5. Health, observability, docs

Endpoint Purpose
GET /api/health Liveness (always 200 when server is up)
GET /api/health/ready Readiness (DB + required config)
GET /api/openapi.json Dynamic OpenAPI 3.0 spec generated from @http.route
GET /api/metrics Prometheus-format counters per route

6. Deployment

Staging and production both use Docker Compose. The staging server rebuilds automatically from main; never force-push. See INSTALL-ODOO-SUMMARY.md for bootstrap notes.

Service Staging URL
Odoo backend http://5.189.151.117:8069
React frontend http://5.189.151.117:3000

The .env file is never committed. On staging it lives at /opt/encoach/backend-v2/.env.


7. Further reading

Document Description
docs/PROJECT_SUMMARY.md Release notes + architecture history
docs/adr/ Architecture Decision Records (why we built it this way)
docs/ENCOACH_UNIFIED_SRS.md Unified frontend + backend SRS
docs/ENCOACH_ODOO19_BACKEND_SRS.md Backend SRS v3.0
docs/ENCOACH_WORKFLOWS_BACKEND_SRS.md Backend workflows
docs/ENCOACH_WORKFLOWS_FRONTEND_SRS.md Frontend workflows

8. Contributing

  1. Branch from main — never push direct. Branch protection enforces it.
  2. Run npx tsc --noEmit -p tsconfig.app.json (frontend) and the module smoke tests before opening a PR.
  3. Every architectural decision should be captured as an ADR under docs/adr/. Copy 0000-template.md to start one.
  4. Open the PR against main and request review from devops (Talal).
Description
No description provided
Readme 375 MiB
Languages
Python 70.8%
HTML 22.1%
JavaScript 3.9%
SCSS 2.1%
CSS 1.1%