Skip to content

Latest commit

 

History

History
203 lines (139 loc) · 5.64 KB

architecture.md

File metadata and controls

203 lines (139 loc) · 5.64 KB

y.ai Platform Architecture

This document explains the end-to-end architecture of the y.ai system, including service topology, data flow, model responsibilities, and explainability layers.

1. System Overview

y.ai is a full-stack explainable learning intelligence platform with:

  • learner and instructor web dashboards
  • authentication and YouTube ingestion
  • recommendation and risk inference APIs
  • XAI engines (SHAP, counterfactual, causal analysis)
  • async workers and tracking/observability stack

The design goal is: Prediction -> Explanation -> Diagnosis -> Prescription.

2. Service Topology

Core services:

  • Frontend (Next.js): frontend/
  • Auth service (Node/Express): auth/
  • Backend API (FastAPI): backend/app/main.py
  • Celery worker: backend/app/workers/
  • Redis (broker/cache)
  • Kafka + Zookeeper (event bus)
  • PostgreSQL + TimescaleDB (persistent and time-series storage)
  • MLflow (model/experiment tracking)
  • Prometheus + Grafana (observability)
  • Nginx ingress (routing)

Kubernetes manifests:

  • k8s/namespace.yaml
  • k8s/secrets.yaml
  • k8s/statefulsets.yaml
  • k8s/deployments.yaml
  • k8s/platform-services.yaml
  • k8s/nginx-ingress.yaml

3. Data Flow

3.1 Ingestion

  1. User connects Google/YouTube via auth service.
  2. Raw profile/watch data is persisted as JSON + processed records.
  3. ML pipelines convert raw data into features for recommendation and risk scoring.

3.2 Inference

  1. Frontend sends learner features to backend endpoints (/predict, /recommend, /whatif, /compare).
  2. Backend computes predictions and explanation payloads.
  3. Workers handle heavier tasks asynchronously (SHAP/counterfactual/drift/retrain queues).

3.3 Explainability

  1. Feature-level attributions are generated from model internals.
  2. Concept-level aggregation maps feature groups into educational dimensions.
  3. Counterfactual and causal layers provide “why” and “what to change” evidence.

4. Model Inventory And Responsibilities

4.1 Recommendation & Ranking

  • EASE-based recommendation flow (pipeline-level ranking)
  • Topic clustering and graph proximity signals
  • Weighted fusion signals:
    • content similarity
    • difficulty fit
    • diversity/novelty
    • graph proximity

Used in:

  • dashboard recommendations page
  • top topic ranking
  • intervention suggestions

4.2 Risk Prediction

Risk score computation uses learner behavioral features such as:

  • sessions per week
  • quiz performance/completion
  • streak behavior
  • knowledge gap count
  • interaction and note-taking indicators

Outputs include:

  • dropout risk score
  • mastery probability
  • engagement forecast

Used in:

  • learner dashboard
  • what-if sandbox
  • instructor cohort matrix
  • compare page

4.3 Explainability Models

  • SHAP engine (backend/app/xai/shap_engine.py and yai sidecar equivalent)
    • feature-level attribution
    • top driver extraction
  • Counterfactual engine (backend/app/xai/counterfactual.py)
    • minimal-change scenarios to flip outcome
  • Causal engine (backend/app/xai/causal.py)
    • causal vs correlational influence estimates

Used in:

  • recommendation “Why?” views
  • what-if intervention analysis
  • causal DAG page

4.4 Multi-Model Comparison

Parallel model views are surfaced for:

  • PyTorch-style deep model profile
  • XGBoost-style boosting profile
  • Sklearn linear/regression baseline

Used in:

  • instructor compare workflow
  • disagreement matrix and rank-shift analysis

5. XAI Layer Mapping

The XAI stack is intentionally multi-layered:

  • Prediction-level: risk/score output and confidence
  • Feature-level: SHAP contributions and top ranked factors
  • Concept-level: grouped educational concepts and dominant concept
  • Counterfactual-level: smallest required changes to alter result
  • Causal-level: treatment impact estimates from DAG assumptions

6. Frontend Module Mapping

Main dashboard modules:

  • frontend/src/app/dashboard/page.tsx — learner metrics + SHAP + recommendation cards
  • frontend/src/app/dashboard/whatif/page.tsx — feature sliders, risk + derived metrics deltas
  • frontend/src/app/dashboard/causal/page.tsx — DAG visualization and effect panel
  • frontend/src/app/dashboard/compare/page.tsx — multi-model disagreement analysis
  • frontend/src/components/InstructorDashboard.tsx — instructor-focused control terminal

7. Observability Architecture

Prometheus scrape config:

  • monitoring/prometheus.yml

Grafana provisioning:

  • datasource: monitoring/grafana/datasources/prometheus.yaml
  • dashboards:
    • monitoring/grafana/dashboards/model_health.json
    • monitoring/grafana/dashboards/observability_overview.json

Custom backend metrics include:

  • yai_requests_total
  • yai_request_duration_seconds
  • yai_inflight_requests

Plus standard FastAPI instrumentator metrics via /metrics.

8. Deployment Path

Single-shot Kubernetes bootstrap script:

  • run.sh

What it does:

  1. Builds project images
  2. Creates namespace/secrets/configmaps from .env and monitoring/db files
  3. Applies all Kubernetes manifests
  4. Waits for rollouts
  5. Runs in-cluster verification checks for API/frontend/auth/mlflow/flower/prometheus/grafana

9. Security & Configuration

Secrets are sourced from .env and applied to learnos-secrets.

Critical keys:

  • database URLs and credentials
  • API keys (Anthropic/YouTube)
  • OAuth client secrets
  • Grafana admin password

Use production-grade secret management for real deployments.

10. Operational Notes

  • Ingress host defaults to learnos.local and requires local DNS/hosts entry.
  • If cluster cannot pull local images, use a local registry or cluster-specific image load path.
  • For strict production, replace sqlite MLflow backend with PostgreSQL and persistent volumes.