This document explains the end-to-end architecture of the y.ai system, including service topology, data flow, model responsibilities, and explainability layers.
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.
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.yamlk8s/secrets.yamlk8s/statefulsets.yamlk8s/deployments.yamlk8s/platform-services.yamlk8s/nginx-ingress.yaml
- User connects Google/YouTube via auth service.
- Raw profile/watch data is persisted as JSON + processed records.
- ML pipelines convert raw data into features for recommendation and risk scoring.
- Frontend sends learner features to backend endpoints (
/predict,/recommend,/whatif,/compare). - Backend computes predictions and explanation payloads.
- Workers handle heavier tasks asynchronously (SHAP/counterfactual/drift/retrain queues).
- Feature-level attributions are generated from model internals.
- Concept-level aggregation maps feature groups into educational dimensions.
- Counterfactual and causal layers provide “why” and “what to change” evidence.
- 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
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
- SHAP engine (
backend/app/xai/shap_engine.pyand 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
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
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
Main dashboard modules:
frontend/src/app/dashboard/page.tsx— learner metrics + SHAP + recommendation cardsfrontend/src/app/dashboard/whatif/page.tsx— feature sliders, risk + derived metrics deltasfrontend/src/app/dashboard/causal/page.tsx— DAG visualization and effect panelfrontend/src/app/dashboard/compare/page.tsx— multi-model disagreement analysisfrontend/src/components/InstructorDashboard.tsx— instructor-focused control terminal
Prometheus scrape config:
monitoring/prometheus.yml
Grafana provisioning:
- datasource:
monitoring/grafana/datasources/prometheus.yaml - dashboards:
monitoring/grafana/dashboards/model_health.jsonmonitoring/grafana/dashboards/observability_overview.json
Custom backend metrics include:
yai_requests_totalyai_request_duration_secondsyai_inflight_requests
Plus standard FastAPI instrumentator metrics via /metrics.
Single-shot Kubernetes bootstrap script:
run.sh
What it does:
- Builds project images
- Creates namespace/secrets/configmaps from
.envand monitoring/db files - Applies all Kubernetes manifests
- Waits for rollouts
- Runs in-cluster verification checks for API/frontend/auth/mlflow/flower/prometheus/grafana
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.
- Ingress host defaults to
learnos.localand 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.