# anhadlamba30/jlens-playground architecture

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

- Interactive diagram: https://gitdiagram.com/anhadlamba30/jlens-playground
- Repository: https://github.com/anhadlamba30/jlens-playground

## Overview

Local JLens Playground lets an engineer select a demo or configured model, submit a prompt for Jacobian Lens readouts, and explore the resulting layer-by-position data in the browser. The UI also supports chat generation, interventions, prompt comparison, diagnostics, and importing/exporting runs. The backend routes API requests to synthetic demo behavior or a loaded model/lens; real-model execution tokenizes prompts and applies the lens. Edges reflect explicit calls, imports, or README-described behavior; unsampled details are left unconnected where ownership is unclear.

Main entry points: [`frontend/src/actions.js`](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/actions.js) (UI Actions), [`backend/app/main.py`](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/main.py) (API Routes), [`frontend/src/render/chat.js`](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/chat.js) (Chat Explorer), [`backend/app/runner.py`](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/runner.py) (Loaded Model Runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Browser Explorer"]
  node_actions["UI Actions<br/>[actions.js]"]
  node_browser_api["API Client<br/>[api.js]"]
  node_ui_state["UI State<br/>[state.js]"]
  node_prompt_controls["Prompt Controls<br/>[controls.js]"]
  node_analysis_views["Analysis Views<br/>[grid.js]"]
  node_aggregation_view["Aggregation View<br/>[aggregation.js]"]
  node_chart_view["Chart View<br/>[chart.js]"]
  node_heatmap_view["Heatmap View<br/>[heatmap.js]"]
  node_inspector_view["Cell Inspector<br/>[inspector.js]"]
  node_comparison_view["Comparison View<br/>[comparison.js]"]
  node_chat_view["Chat Explorer<br/>[chat.js]"]
  node_diagnostics_view["Diagnostics View<br/>[diagnostics.js]"]
end

subgraph group_api["API and Routing"]
  node_api_routes["API Routes<br/>[main.py]"]
  node_request_models["Request Schemas<br/>[schemas.py]"]
  node_model_config["Model Configuration<br/>[config.py]"]
  node_demo_engine["Synthetic Readout<br/>[demo.py]"]
end

subgraph group_inference["Model Inference"]
  node_model_runner["Loaded Model Runner<br/>[runner.py]"]
  node_chat_format["Chat Formatting<br/>[chat_templates.py]"]
  node_text_generation["Text Generation<br/>[generation.py]"]
end

subgraph group_intervention["Interventions"]
  node_intervention_hooks["Intervention Hooks<br/>[hooks.py]"]
  node_vector_lookup["Vector Lookup<br/>[vector_lookup.py]"]
  node_intervention_schema["Intervention Schemas<br/>[schemas.py]"]
end

node_engineer(("Engineer"))
node_external_model["Transformers Model"]
node_lens["Jacobian Lens"]

node_engineer -->|"enters prompt"| node_prompt_controls
node_prompt_controls -->|"starts analysis"| node_actions
node_actions -->|"requests analysis"| node_browser_api
node_browser_api -->|"posts request"| node_api_routes
node_api_routes -->|"validates request"| node_request_models
node_api_routes -->|"loads configuration"| node_model_config
node_api_routes -->|"runs demo"| node_demo_engine
node_api_routes -->|"runs inference"| node_model_runner
node_model_runner -->|"loads model"| node_external_model
node_model_runner -->|"applies lens"| node_lens
node_model_runner -->|"formats chat"| node_chat_format
node_model_runner -->|"generates text"| node_text_generation
node_actions -->|"stores result"| node_ui_state
node_actions -->|"renders grid"| node_analysis_views
node_actions -->|"renders summary"| node_aggregation_view
node_actions -->|"renders chart"| node_chart_view
node_actions -->|"renders heatmap"| node_heatmap_view
node_actions -->|"renders selection"| node_inspector_view
node_actions -->|"renders comparison"| node_comparison_view
node_actions -->|"renders diagnostics"| node_diagnostics_view
node_chat_view -->|"requests generation"| node_browser_api
node_chat_view -->|"renders readouts"| node_analysis_views
node_chat_view -->|"renders summary"| node_aggregation_view
node_chat_view -->|"renders heatmap"| node_heatmap_view
node_chat_view -->|"renders chart"| node_chart_view
node_chat_view -->|"renders inspector"| node_inspector_view
node_api_routes -->|"checks intervention"| node_intervention_hooks
node_intervention_hooks -->|"looks up vectors"| node_vector_lookup
node_api_routes -->|"accepts settings"| node_intervention_schema
node_engineer -->|"uses chat"| node_chat_view
node_engineer -->|"opens diagnostics"| node_diagnostics_view

click node_actions "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/actions.js"
click node_browser_api "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/api.js"
click node_ui_state "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/state.js"
click node_prompt_controls "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/controls.js"
click node_analysis_views "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/grid.js"
click node_aggregation_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/aggregation.js"
click node_chart_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/chart.js"
click node_heatmap_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/heatmap.js"
click node_inspector_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/inspector.js"
click node_comparison_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/comparison.js"
click node_chat_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/chat.js"
click node_diagnostics_view "https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/diagnostics.js"
click node_api_routes "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/main.py"
click node_request_models "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/schemas.py"
click node_model_config "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/config.py"
click node_demo_engine "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/demo.py"
click node_model_runner "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/runner.py"
click node_chat_format "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/chat_templates.py"
click node_text_generation "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/generation.py"
click node_intervention_hooks "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/interventions/hooks.py"
click node_vector_lookup "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/interventions/vector_lookup.py"
click node_intervention_schema "https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/interventions/schemas.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_actions,node_browser_api,node_ui_state,node_prompt_controls,node_analysis_views,node_aggregation_view,node_chart_view,node_heatmap_view,node_inspector_view,node_comparison_view,node_chat_view,node_diagnostics_view toneBlue
class node_api_routes,node_request_models,node_model_config,node_demo_engine toneAmber
class node_model_runner,node_chat_format,node_text_generation toneMint
class node_intervention_hooks,node_vector_lookup,node_intervention_schema toneRose
class node_engineer,node_external_model,node_lens toneIndigo
```

## Components

### Browser Explorer

- [UI Actions](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/actions.js): `frontend/src/actions.js`
- [API Client](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/api.js): `frontend/src/api.js`
- [UI State](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/state.js): `frontend/src/state.js`
- [Prompt Controls](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/controls.js): `frontend/src/render/controls.js`
- [Analysis Views](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/grid.js): `frontend/src/render/grid.js`
- [Aggregation View](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/aggregation.js): `frontend/src/render/aggregation.js`
- [Chart View](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/chart.js): `frontend/src/render/chart.js`
- [Heatmap View](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/heatmap.js): `frontend/src/render/heatmap.js`
- [Cell Inspector](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/inspector.js): `frontend/src/render/inspector.js`
- [Comparison View](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/comparison.js): `frontend/src/render/comparison.js`
- [Chat Explorer](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/chat.js): `frontend/src/render/chat.js`
- [Diagnostics View](https://github.com/anhadlamba30/jlens-playground/blob/main/frontend/src/render/diagnostics.js): `frontend/src/render/diagnostics.js`

### API and Routing

- [API Routes](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/main.py): `backend/app/main.py`
- [Request Schemas](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/schemas.py): `backend/app/schemas.py`
- [Model Configuration](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/config.py): `backend/app/config.py`
- [Synthetic Readout](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/demo.py): `backend/app/demo.py`

### Model Inference

- [Loaded Model Runner](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/runner.py): `backend/app/runner.py`
- [Chat Formatting](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/chat_templates.py): `backend/app/chat_templates.py`
- [Text Generation](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/generation.py): `backend/app/generation.py`

### Interventions

- [Intervention Hooks](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/interventions/hooks.py): `backend/app/interventions/hooks.py`
- [Vector Lookup](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/interventions/vector_lookup.py): `backend/app/interventions/vector_lookup.py`
- [Intervention Schemas](https://github.com/anhadlamba30/jlens-playground/blob/main/backend/app/interventions/schemas.py): `backend/app/interventions/schemas.py`

### Other components

- **Engineer**
- **Transformers Model**
- **Jacobian Lens**

## Connections

- Engineer → Prompt Controls: enters prompt
- Prompt Controls → UI Actions: starts analysis (evidence: `frontend/src/render/controls.js`)
- UI Actions → API Client: requests analysis (evidence: `frontend/src/actions.js`)
- API Client → API Routes: posts request (evidence: `frontend/src/api.js`)
- API Routes → Request Schemas: validates request (evidence: `backend/app/main.py`)
- API Routes → Model Configuration: loads configuration (evidence: `backend/app/main.py`)
- API Routes → Synthetic Readout: runs demo (evidence: `backend/app/main.py`)
- API Routes → Loaded Model Runner: runs inference (evidence: `backend/app/main.py`)
- Loaded Model Runner → Transformers Model: loads model (evidence: `backend/app/runner.py`)
- Loaded Model Runner → Jacobian Lens: applies lens (evidence: `backend/app/runner.py`)
- Loaded Model Runner → Chat Formatting: formats chat (evidence: `backend/app/runner.py`)
- Loaded Model Runner → Text Generation: generates text (evidence: `backend/app/runner.py`)
- UI Actions → UI State: stores result (evidence: `frontend/src/actions.js`)
- UI Actions → Analysis Views: renders grid (evidence: `frontend/src/actions.js`)
- UI Actions → Aggregation View: renders summary (evidence: `frontend/src/actions.js`)
- UI Actions → Chart View: renders chart (evidence: `frontend/src/actions.js`)
- UI Actions → Heatmap View: renders heatmap (evidence: `frontend/src/actions.js`)
- UI Actions → Cell Inspector: renders selection (evidence: `frontend/src/actions.js`)
- UI Actions → Comparison View: renders comparison (evidence: `frontend/src/actions.js`)
- UI Actions → Diagnostics View: renders diagnostics (evidence: `frontend/src/actions.js`)
- Chat Explorer → API Client: requests generation (evidence: `frontend/src/render/chat.js`)
- Chat Explorer → Analysis Views: renders readouts (evidence: `frontend/src/render/chat.js`)
- Chat Explorer → Aggregation View: renders summary (evidence: `frontend/src/render/chat.js`)
- Chat Explorer → Heatmap View: renders heatmap (evidence: `frontend/src/render/chat.js`)
- Chat Explorer → Chart View: renders chart (evidence: `frontend/src/render/chat.js`)
- Chat Explorer → Cell Inspector: renders inspector (evidence: `frontend/src/render/chat.js`)
- API Routes → Intervention Hooks: checks intervention (evidence: `backend/app/main.py`)
- Intervention Hooks → Vector Lookup: looks up vectors (evidence: `backend/app/interventions/hooks.py`)
- API Routes → Intervention Schemas: accepts settings (evidence: `backend/app/main.py`)
- Engineer → Chat Explorer: uses chat
- Engineer → Diagnostics View: opens diagnostics
