# samarth6840/contextlens architecture

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

- Interactive diagram: https://gitdiagram.com/samarth6840/contextlens
- Repository: https://github.com/samarth6840/contextlens

## Overview

ADSCENE analyzes uploaded video to identify brands and context, then presents evidence and collaboration recommendations. Its principal workflow runs through the Flask job API into the multimodal pipeline: visual and audio evidence is extracted, resolved and fused, then used for recommendations and unknown-brand identification. A separate Streamlit interface also exposes pipeline analysis. The README is empty and the pipeline/server excerpts are partial, so several component links reflect documented layer responsibilities rather than inspected call sites; uncertain integrations are omitted.

Main entry points: [`src/pipeline.py`](https://github.com/samarth6840/contextlens/blob/main/src/pipeline.py) (Analysis pipeline), [`server.py`](https://github.com/samarth6840/contextlens/blob/main/server.py) (Flask API), [`static/app.js`](https://github.com/samarth6840/contextlens/blob/main/static/app.js) (ADSCENE frontend), [`app.py`](https://github.com/samarth6840/contextlens/blob/main/app.py) (Streamlit interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_flask_ui["ADSCENE frontend<br/>[app.js]"]
  node_streamlit_ui["Streamlit interface<br/>[app.py]"]
end

subgraph group_orchestration["Job Orchestration"]
  node_api["Flask API<br/>[server.py]"]
  node_jobs["Background jobs<br/>[server.py]"]
  node_pipeline["Analysis pipeline<br/>[pipeline.py]"]
end

subgraph group_evidence["Evidence Extraction"]
  node_visual["Visual embeddings"]
  node_objects["Object detection<br/>[detector.py]"]
  node_logos["Logo detection<br/>[logo_detector.py]"]
  node_ocr["Text recognition<br/>[ocr.py]"]
  node_audio["Speech and audio<br/>[audio.py]"]
  node_vision["Vision-language model<br/>[qwen3vl.py]"]
  node_products[("Product index<br/>[product_index.py]")]
end

subgraph group_reasoning["Brand Reasoning"]
  node_resolver["Brand resolution<br/>[brand_resolver.py]"]
  node_fusion["Evidence fusion<br/>[fusion.py]"]
  node_quality["Quality estimation"]
  node_confidence["Confidence scoring<br/>[confidence.py]"]
  node_spatial["Spatial labels<br/>[spatial_label.py]"]
  node_catalog[("Brand catalog<br/>[brand_catalog.py]")]
  node_openset["Unknown-brand search<br/>[openset.py]"]
  node_knowledge[("Brand knowledge graph<br/>[knowledge_graph.py]")]
  node_recommendations["Brand recommendations<br/>[recommender.py]"]
end

node_creator(("Video creator"))
node_browser(("Web browser"))

node_creator -->|"selects video"| node_browser
node_browser -->|"uploads video"| node_flask_ui
node_flask_ui -->|"calls API"| node_api
node_api -->|"queues analysis"| node_jobs
node_jobs -->|"runs analysis"| node_pipeline
node_api -->|"serves frontend"| node_flask_ui
node_browser -->|"uploads video"| node_streamlit_ui
node_streamlit_ui -->|"runs analysis"| node_pipeline
node_pipeline -->|"extracts features"| node_visual
node_pipeline -->|"detects objects"| node_objects
node_pipeline -->|"detects logos"| node_logos
node_pipeline -->|"extracts text"| node_ocr
node_pipeline -->|"analyzes audio"| node_audio
node_pipeline -->|"analyzes frames"| node_vision
node_pipeline -->|"queries matches"| node_products
node_pipeline -->|"resolves brands"| node_resolver
node_pipeline -->|"fuses evidence"| node_fusion
node_pipeline -->|"estimates quality"| node_quality
node_pipeline -->|"scores evidence"| node_confidence
node_pipeline -->|"labels spatial context"| node_spatial
node_pipeline -->|"builds text queries"| node_catalog
node_api -->|"identifies unknowns"| node_openset
node_api -->|"reads recommendations"| node_recommendations
node_recommendations -->|"queries graph"| node_knowledge
node_api -->|"returns results"| node_browser
node_pipeline -->|"returns analysis"| node_api

click node_flask_ui "https://github.com/samarth6840/contextlens/blob/main/static/app.js"
click node_streamlit_ui "https://github.com/samarth6840/contextlens/blob/main/app.py"
click node_api "https://github.com/samarth6840/contextlens/blob/main/server.py"
click node_jobs "https://github.com/samarth6840/contextlens/blob/main/server.py"
click node_pipeline "https://github.com/samarth6840/contextlens/blob/main/src/pipeline.py"
click node_visual "https://github.com/samarth6840/contextlens/blob/main/src/layer1/visual_embeddings.py"
click node_objects "https://github.com/samarth6840/contextlens/blob/main/src/layer1/detector.py"
click node_logos "https://github.com/samarth6840/contextlens/blob/main/src/layer1/logo_detector.py"
click node_ocr "https://github.com/samarth6840/contextlens/blob/main/src/layer1/ocr.py"
click node_audio "https://github.com/samarth6840/contextlens/blob/main/src/layer1/audio.py"
click node_vision "https://github.com/samarth6840/contextlens/blob/main/src/layer1/qwen3vl.py"
click node_products "https://github.com/samarth6840/contextlens/blob/main/src/layer1/product_index.py"
click node_resolver "https://github.com/samarth6840/contextlens/blob/main/src/layer2/brand_resolver.py"
click node_fusion "https://github.com/samarth6840/contextlens/blob/main/src/layer2/fusion.py"
click node_quality "https://github.com/samarth6840/contextlens/blob/main/src/layer2/quality_estimator.py"
click node_confidence "https://github.com/samarth6840/contextlens/blob/main/src/layer2/confidence.py"
click node_spatial "https://github.com/samarth6840/contextlens/blob/main/src/layer2/spatial_label.py"
click node_catalog "https://github.com/samarth6840/contextlens/blob/main/src/brand_catalog.py"
click node_openset "https://github.com/samarth6840/contextlens/blob/main/src/openset.py"
click node_knowledge "https://github.com/samarth6840/contextlens/blob/main/src/layer3/knowledge_graph.py"
click node_recommendations "https://github.com/samarth6840/contextlens/blob/main/src/layer3/recommender.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_flask_ui,node_streamlit_ui,node_browser toneBlue
class node_api,node_jobs,node_pipeline toneAmber
class node_visual,node_objects,node_logos,node_ocr,node_audio,node_vision,node_products toneMint
class node_resolver,node_fusion,node_quality,node_confidence,node_spatial,node_catalog,node_openset,node_knowledge,node_recommendations toneRose
class node_creator toneIndigo
```

## Components

### User Interfaces

- [ADSCENE frontend](https://github.com/samarth6840/contextlens/blob/main/static/app.js): `static/app.js`
- [Streamlit interface](https://github.com/samarth6840/contextlens/blob/main/app.py): `app.py`

### Job Orchestration

- [Flask API](https://github.com/samarth6840/contextlens/blob/main/server.py): `server.py`
- [Background jobs](https://github.com/samarth6840/contextlens/blob/main/server.py): `server.py`
- [Analysis pipeline](https://github.com/samarth6840/contextlens/blob/main/src/pipeline.py): `src/pipeline.py`

### Evidence Extraction

- [Visual embeddings](https://github.com/samarth6840/contextlens/blob/main/src/layer1/visual_embeddings.py): `src/layer1/visual_embeddings.py`
- [Object detection](https://github.com/samarth6840/contextlens/blob/main/src/layer1/detector.py): `src/layer1/detector.py`
- [Logo detection](https://github.com/samarth6840/contextlens/blob/main/src/layer1/logo_detector.py): `src/layer1/logo_detector.py`
- [Text recognition](https://github.com/samarth6840/contextlens/blob/main/src/layer1/ocr.py): `src/layer1/ocr.py`
- [Speech and audio](https://github.com/samarth6840/contextlens/blob/main/src/layer1/audio.py): `src/layer1/audio.py`
- [Vision-language model](https://github.com/samarth6840/contextlens/blob/main/src/layer1/qwen3vl.py): `src/layer1/qwen3vl.py`
- [Product index](https://github.com/samarth6840/contextlens/blob/main/src/layer1/product_index.py): `src/layer1/product_index.py`

### Brand Reasoning

- [Brand resolution](https://github.com/samarth6840/contextlens/blob/main/src/layer2/brand_resolver.py): `src/layer2/brand_resolver.py`
- [Evidence fusion](https://github.com/samarth6840/contextlens/blob/main/src/layer2/fusion.py): `src/layer2/fusion.py`
- [Quality estimation](https://github.com/samarth6840/contextlens/blob/main/src/layer2/quality_estimator.py): `src/layer2/quality_estimator.py`
- [Confidence scoring](https://github.com/samarth6840/contextlens/blob/main/src/layer2/confidence.py): `src/layer2/confidence.py`
- [Spatial labels](https://github.com/samarth6840/contextlens/blob/main/src/layer2/spatial_label.py): `src/layer2/spatial_label.py`
- [Brand catalog](https://github.com/samarth6840/contextlens/blob/main/src/brand_catalog.py): `src/brand_catalog.py`
- [Unknown-brand search](https://github.com/samarth6840/contextlens/blob/main/src/openset.py): `src/openset.py`
- [Brand knowledge graph](https://github.com/samarth6840/contextlens/blob/main/src/layer3/knowledge_graph.py): `src/layer3/knowledge_graph.py`
- [Brand recommendations](https://github.com/samarth6840/contextlens/blob/main/src/layer3/recommender.py): `src/layer3/recommender.py`

### Other components

- **Video creator**
- **Web browser**

## Connections

- Video creator → Web browser: selects video
- Web browser → ADSCENE frontend: uploads video
- ADSCENE frontend → Flask API: calls API
- Flask API → Background jobs: queues analysis
- Background jobs → Analysis pipeline: runs analysis
- Flask API → ADSCENE frontend: serves frontend
- Web browser → Streamlit interface: uploads video
- Streamlit interface → Analysis pipeline: runs analysis
- Analysis pipeline → Visual embeddings: extracts features
- Analysis pipeline → Object detection: detects objects
- Analysis pipeline → Logo detection: detects logos
- Analysis pipeline → Text recognition: extracts text
- Analysis pipeline → Speech and audio: analyzes audio
- Analysis pipeline → Vision-language model: analyzes frames
- Analysis pipeline → Product index: queries matches
- Analysis pipeline → Brand resolution: resolves brands
- Analysis pipeline → Evidence fusion: fuses evidence
- Analysis pipeline → Quality estimation: estimates quality
- Analysis pipeline → Confidence scoring: scores evidence
- Analysis pipeline → Spatial labels: labels spatial context
- Analysis pipeline → Brand catalog: builds text queries
- Flask API → Unknown-brand search: identifies unknowns
- Flask API → Brand recommendations: reads recommendations
- Brand recommendations → Brand knowledge graph: queries graph
- Flask API → Web browser: returns results
- Analysis pipeline → Flask API: returns analysis
