How edx/learning-assistant works
Project type and purpose
• This is a Django “plugin” app named learning_assistant that integrates into the Open edX LMS (and related services) to provide a chat-based learning assistant backend.
• It exposes REST/JSON endpoints consumed by a separate React frontend library (frontend-lib-learning-assistant) and orchestrates calls to an external Chat Completion API.
File structure
• Top-level: configuration (Makefile, setup.py, requirements/, .github/CI, docs/), Django management entry (manage.py), test suite (tests/).
• The learning_assistant/ folder is a standard Django app:
• models.py (ORM definitions)
• serializers.py and api.py/views.py (DRF serializers & view logic)
• urls.py (URL routing)
• plugins_api.py (Open edX plugin interface)
• toggles.py (waffle flags)
• management/commands/ (custom Django commands)
• conf/locale/ (i18n)
• Migration files under learning_assistant/migrations/ track database schema.
• Test files parallel the logic to ensure coverage.
Key insights from README
• The app depends on:
• edx-platform (LMS + Discovery + Ecommerce)
• External chat service (configured by CHAT_COMPLETION_API & API key)
• Frontend static package (frontend-lib-learning-assistant)
• Waffle feature flags for activation.
Components
a. Main Components
• User’s Browser & React frontend (frontend-lib-learning-assistant)
• edX LMS Platform (Django host)
• Django Core & edx-platform services (LMS, Discovery, Ecommerce)
• learning_assistant Django app
· API layer (api.py/views.py)
· Serializers & Plugins API
· Business logic (utils.py, text_utils.py, data.py)
· Database (PostgreSQL via Django ORM)
· Feature toggles (toggles.py)
· Management commands (e.g., retire old messages)
• External Chat Completion Service (e.g., OpenAI-like endpoint)
b. Relationships & Interactions
1. Browser loads course page + injects React widget from frontend-lib-learning-assistant.
2. Widget sends AJAX calls to LMS at /learning-assistant/api/....
3. Django REST views authenticate/authorize (respect waffle toggles).
4. Incoming messages get serialized and saved to DB (models).
5. Business logic packages a prompt and issues HTTP request to external CHAT_COMPLETION_API.
6. Response received, persisted (audit trail), returned as JSON to frontend.
7. User sees response in chat UI.
8. Periodic cleanup via management command (retire_user_messages).
c. Architectural Patterns & Design Principles
• Modular Django app following MVC (models, views, templates are replaced by serializers+API).
• DRF for API design.
• Open edX plugin interface for service discovery/registration.
• Waffle flags for feature gating.
• Strict separation: “frontend” (React widget) vs. “backend” (Django app) vs. external AI service.
d. Key Technologies & Frameworks
• Python 3 + Django
• Django REST Framework
• edX plugin framework
• PostgreSQL (via Django ORM)
• Waffle (feature flags)
• External Chat Completion API
• pytest, tox for CI/testing
• Docker/devstack for local environment