# krupashetty004/khel-khoj-ai architecture

> Architecture diagram of the GitHub repository krupashetty004/khel-khoj-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krupashetty004/khel-khoj-ai
- Repository: https://github.com/krupashetty004/khel-khoj-ai

## Overview

Khel-Khoj AI is a sports-video analysis product with a Next.js client, Express/MongoDB account and job API, and a Python analysis service. The documented user journey is upload, create and process a job, save analysis artifacts, then poll and display metrics and a report. The AI pipeline includes frame and pose processing, activity classification and metrics, optional similarity lookup, and report generation. Some links are based on README documentation or SOURCE INDEX references; unsampled implementation details are not inferred beyond those connections.

Main entry points: [`python-api/khelkhoj_ai/pipeline_runner.py`](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline_runner.py) (Pipeline runner), [`my-next-app/src/app/analyze/page.tsx`](https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/analyze/page.tsx) (Video analysis UI), [`backend/src/controllers/userController.js`](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/controllers/userController.js) (User profiles), [`python-api/main.py`](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/main.py) (Analysis API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web app"]
  node_web_analyze["Video analysis UI<br/>[page.tsx]"]
  node_web_history["Athlete history<br/>[page.tsx]"]
  node_web_profile["Athlete profile<br/>[page.tsx]"]
  node_web_auth["Sign-in<br/>[page.tsx]"]
  node_auth_context["Auth context<br/>[AuthContext.tsx]"]
end

subgraph group_api["Backend API"]
  node_backend_server["Express server<br/>[server.js]"]
  node_job_routes["Job routes<br/>[jobs.js]"]
  node_job_controller["Job controller<br/>[jobController.js]"]
  node_job_service["Job orchestration<br/>[jobService.js]"]
  node_job_model[("Analysis jobs<br/>[AnalysisJob.js]")]
  node_user_routes["User routes<br/>[users.js]"]
  node_user_controller["User profiles<br/>[userController.js]"]
  node_user_model[("User records<br/>[User.js]")]
  node_athlete_model[("Athlete records<br/>[Athlete.js]")]
end

subgraph group_analysis["Video analysis"]
  node_ai_api["Analysis API<br/>[main.py]"]
  node_celery_tasks["Celery tasks<br/>[tasks.py]"]
  node_pipeline["Pipeline runner<br/>[pipeline_runner.py]"]
  node_frame_extract["Frame extraction<br/>[frame_extractor.py]"]
  node_pose_estimator["Pose estimation<br/>[pose_estimator.py]"]
  node_action_classifier["Action classifier"]
  node_activity_controller["Activity tracking"]
  node_exercise_metrics["Exercise metrics<br/>[exercise.py]"]
  node_motion_metrics["Motion metrics<br/>[motion.py]"]
  node_artifact_store["Analysis artifacts<br/>[artifacts.py]"]
  node_vector_store[("Athlete similarity<br/>[store.py]")]
  node_report_generator["Report generation<br/>[generator.py]"]
  node_report_schema["Report schema<br/>[schema.py]"]
  node_llm_provider["Report provider<br/>[providers.py]"]
end

node_athlete_user(("Athlete / coach"))

node_athlete_user -->|"uploads video"| node_web_analyze
node_web_analyze -->|"creates job"| node_job_routes
node_job_routes -->|"routes requests"| node_job_controller
node_job_controller -->|"creates / polls"| node_job_service
node_job_service -->|"persists job"| node_job_model
node_job_service -->|"submits / polls"| node_ai_api
node_ai_api -->|"runs analysis"| node_pipeline
node_pipeline -->|"extracts frames"| node_frame_extract
node_pipeline -->|"estimates poses"| node_pose_estimator
node_pipeline -->|"classifies actions"| node_action_classifier
node_pipeline -->|"tracks activity"| node_activity_controller
node_pipeline -->|"calculates metrics"| node_exercise_metrics
node_pipeline -->|"calculates motion"| node_motion_metrics
node_pipeline -->|"saves artifacts"| node_artifact_store
node_pipeline -->|"queries similarity"| node_vector_store
node_pipeline -->|"generates report"| node_report_generator
node_report_generator -->|"builds report"| node_report_schema
node_report_generator -->|"requests narrative"| node_llm_provider
node_job_controller -->|"returns job status"| node_web_analyze
node_web_analyze -->|"polls results"| node_ai_api
node_web_analyze -->|"shows history"| node_web_history
node_athlete_user -->|"signs in"| node_web_auth
node_web_auth -.->|"uses auth state"| node_auth_context
node_backend_server -->|"mounts routes"| node_job_routes
node_backend_server -->|"mounts routes"| node_user_routes
node_user_routes -->|"routes requests"| node_user_controller
node_user_controller -->|"reads / writes"| node_user_model
node_user_controller -->|"updates profiles"| node_athlete_model
node_user_controller -->|"lists user jobs"| node_job_model
node_celery_tasks -->|"runs pipeline"| node_pipeline
node_ai_api -.->|"dispatches work"| node_celery_tasks

click node_web_analyze "https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/analyze/page.tsx"
click node_web_history "https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/athletes/page.tsx"
click node_web_profile "https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/athletes/%5Bid%5D/page.tsx"
click node_web_auth "https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/login/page.tsx"
click node_auth_context "https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/context/AuthContext.tsx"
click node_backend_server "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/server.js"
click node_job_routes "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/routes/jobs.js"
click node_job_controller "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/controllers/jobController.js"
click node_job_service "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/services/jobService.js"
click node_job_model "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/models/AnalysisJob.js"
click node_user_routes "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/routes/users.js"
click node_user_controller "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/controllers/userController.js"
click node_user_model "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/models/User.js"
click node_athlete_model "https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/models/Athlete.js"
click node_ai_api "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/main.py"
click node_celery_tasks "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/tasks.py"
click node_pipeline "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline_runner.py"
click node_frame_extract "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/frame_extractor.py"
click node_pose_estimator "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/pose_estimator.py"
click node_action_classifier "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/action_classifier.py"
click node_activity_controller "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/activity_logic_controller.py"
click node_exercise_metrics "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/metrics/exercise.py"
click node_motion_metrics "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/metrics/motion.py"
click node_artifact_store "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/storage/artifacts.py"
click node_vector_store "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/vector/store.py"
click node_report_generator "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/report/generator.py"
click node_report_schema "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/report/schema.py"
click node_llm_provider "https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/providers/providers.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_analyze,node_web_history,node_web_profile,node_web_auth,node_auth_context toneBlue
class node_backend_server,node_job_routes,node_job_controller,node_job_service,node_job_model,node_user_routes,node_user_controller,node_user_model,node_athlete_model toneAmber
class node_ai_api,node_celery_tasks,node_pipeline,node_frame_extract,node_pose_estimator,node_action_classifier,node_activity_controller,node_exercise_metrics,node_motion_metrics,node_artifact_store,node_vector_store,node_report_generator,node_report_schema,node_llm_provider toneMint
class node_athlete_user toneIndigo
```

## Components

### Web app

- [Video analysis UI](https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/analyze/page.tsx): `my-next-app/src/app/analyze/page.tsx`
- [Athlete history](https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/athletes/page.tsx): `my-next-app/src/app/athletes/page.tsx`
- [Athlete profile](https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/athletes/%5Bid%5D/page.tsx): `my-next-app/src/app/athletes/[id]/page.tsx`
- [Sign-in](https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/app/login/page.tsx): `my-next-app/src/app/login/page.tsx`
- [Auth context](https://github.com/krupashetty004/khel-khoj-ai/blob/main/my-next-app/src/context/AuthContext.tsx): `my-next-app/src/context/AuthContext.tsx`

### Backend API

- [Express server](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/server.js): `backend/src/server.js`
- [Job routes](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/routes/jobs.js): `backend/src/routes/jobs.js`
- [Job controller](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/controllers/jobController.js): `backend/src/controllers/jobController.js`
- [Job orchestration](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/services/jobService.js): `backend/src/services/jobService.js`
- [Analysis jobs](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/models/AnalysisJob.js): `backend/src/models/AnalysisJob.js`
- [User routes](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/routes/users.js): `backend/src/routes/users.js`
- [User profiles](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/controllers/userController.js): `backend/src/controllers/userController.js`
- [User records](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/models/User.js): `backend/src/models/User.js`
- [Athlete records](https://github.com/krupashetty004/khel-khoj-ai/blob/main/backend/src/models/Athlete.js): `backend/src/models/Athlete.js`

### Video analysis

- [Analysis API](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/main.py): `python-api/main.py`
- [Celery tasks](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/tasks.py): `python-api/tasks.py`
- [Pipeline runner](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline_runner.py): `python-api/khelkhoj_ai/pipeline_runner.py`
- [Frame extraction](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/frame_extractor.py): `python-api/khelkhoj_ai/pipeline/frame_extractor.py`
- [Pose estimation](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/pose_estimator.py): `python-api/khelkhoj_ai/pipeline/pose_estimator.py`
- [Action classifier](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/action_classifier.py): `python-api/khelkhoj_ai/pipeline/action_classifier.py`
- [Activity tracking](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/pipeline/activity_logic_controller.py): `python-api/khelkhoj_ai/pipeline/activity_logic_controller.py`
- [Exercise metrics](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/metrics/exercise.py): `python-api/khelkhoj_ai/metrics/exercise.py`
- [Motion metrics](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/metrics/motion.py): `python-api/khelkhoj_ai/metrics/motion.py`
- [Analysis artifacts](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/storage/artifacts.py): `python-api/khelkhoj_ai/storage/artifacts.py`
- [Athlete similarity](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/vector/store.py): `python-api/khelkhoj_ai/vector/store.py`
- [Report generation](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/report/generator.py): `python-api/khelkhoj_ai/report/generator.py`
- [Report schema](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/report/schema.py): `python-api/khelkhoj_ai/report/schema.py`
- [Report provider](https://github.com/krupashetty004/khel-khoj-ai/blob/main/python-api/khelkhoj_ai/providers/providers.py): `python-api/khelkhoj_ai/providers/providers.py`

### Other components

- **Athlete / coach**

## Connections

- Athlete / coach → Video analysis UI: uploads video (evidence: `README.md`)
- Video analysis UI → Job routes: creates job (evidence: `README.md`)
- Job routes → Job controller: routes requests (evidence: `backend/src/routes/jobs.js`)
- Job controller → Job orchestration: creates / polls (evidence: `backend/src/controllers/jobController.js`)
- Job orchestration → Analysis jobs: persists job (evidence: `backend/src/services/jobService.js`)
- Job orchestration → Analysis API: submits / polls (evidence: `backend/src/services/jobService.js`)
- Analysis API → Pipeline runner: runs analysis (evidence: `python-api/main.py`)
- Pipeline runner → Frame extraction: extracts frames (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Pose estimation: estimates poses (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Action classifier: classifies actions (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Activity tracking: tracks activity (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Exercise metrics: calculates metrics (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Motion metrics: calculates motion (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Analysis artifacts: saves artifacts (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Athlete similarity: queries similarity (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Pipeline runner → Report generation: generates report (evidence: `python-api/khelkhoj_ai/pipeline_runner.py`)
- Report generation → Report schema: builds report (evidence: `python-api/khelkhoj_ai/report/generator.py`)
- Report generation → Report provider: requests narrative (evidence: `python-api/khelkhoj_ai/report/generator.py`)
- Job controller → Video analysis UI: returns job status (evidence: `README.md`)
- Video analysis UI → Analysis API: polls results (evidence: `README.md`)
- Video analysis UI → Athlete history: shows history (evidence: `README.md`)
- Athlete / coach → Sign-in: signs in (evidence: `README.md`)
- Sign-in → Auth context: uses auth state
- Express server → Job routes: mounts routes (evidence: `backend/src/server.js`)
- Express server → User routes: mounts routes (evidence: `backend/src/server.js`)
- User routes → User profiles: routes requests
- User profiles → User records: reads / writes (evidence: `backend/src/controllers/userController.js`)
- User profiles → Athlete records: updates profiles (evidence: `backend/src/controllers/userController.js`)
- User profiles → Analysis jobs: lists user jobs (evidence: `backend/src/controllers/userController.js`)
- Celery tasks → Pipeline runner: runs pipeline (evidence: `python-api/tasks.py`)
- Analysis API → Celery tasks: dispatches work
