# harshita-8605/spatial-lens architecture

> Architecture diagram of the GitHub repository harshita-8605/spatial-lens, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harshita-8605/spatial-lens
- Repository: https://github.com/harshita-8605/spatial-lens

## Overview

Spatial Lens is a real-time webcam AR effect with two implementations: a Python desktop app and a static browser experience. In the desktop workflow, the app loop reads frames, obtains portal corners from hand tracking, then selects idle, portal compositing, or fullscreen stylization before display. The browser version captures camera video, tracks hands, and renders portal or fullscreen effects in a canvas. The README documents both implementations; the browser details are based on the sampled app.js and README, not unsampled HTML or styles.

Main entry points: [`app.js`](https://github.com/harshita-8605/spatial-lens/blob/main/app.js) (Browser frame loop and modes), [`main.py`](https://github.com/harshita-8605/spatial-lens/blob/main/main.py) (Frame and mode loop), [`perception.py`](https://github.com/harshita-8605/spatial-lens/blob/main/perception.py) (Hand tracking and corners), [`anime_engine.py`](https://github.com/harshita-8605/spatial-lens/blob/main/anime_engine.py) (Anime stylization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_desktop_loop["Frame and mode loop<br/>[main.py]"]
end

subgraph group_desktop_processing["Desktop processing"]
  node_hand_tracking["Hand tracking and corners<br/>[perception.py]"]
  node_anime_engine["Anime stylization<br/>[anime_engine.py]"]
  node_portal_compositor["Portal compositing<br/>[compositor.py]"]
end

subgraph group_browser["Browser experience"]
  node_browser_loop["Browser frame loop and modes<br/>[app.js]"]
end

subgraph group_browser_processing["Browser processing"]
  node_browser_hands["Hand detection and corners<br/>[app.js]"]
  node_browser_stylize["Canvas stylization<br/>[app.js]"]
  node_browser_portal["Portal clipping and border<br/>[app.js]"]
  node_landmarker_asset["Hand landmarker model"]
end

node_user(("User"))
node_desktop_camera(("Webcam"))
node_desktop_display(("Display window"))
node_browser_camera(("Browser camera"))
node_browser_display["Browser canvas<br/>[index.html]"]
node_analytics{{"Vercel Analytics"}}

node_user -->|"presents hands"| node_desktop_camera
node_desktop_camera -->|"provides frames"| node_desktop_loop
node_desktop_loop -->|"gets corners"| node_hand_tracking
node_desktop_loop -->|"stylizes frames"| node_anime_engine
node_desktop_loop -->|"composites portal"| node_portal_compositor
node_desktop_loop -->|"shows result"| node_desktop_display
node_user -->|"allows camera"| node_browser_camera
node_browser_camera -->|"provides video"| node_browser_loop
node_browser_loop -->|"loads model"| node_landmarker_asset
node_browser_loop -->|"detects hands"| node_browser_hands
node_browser_loop -->|"stylizes frames"| node_browser_stylize
node_browser_loop -->|"clips portal"| node_browser_portal
node_browser_loop -->|"draws output"| node_browser_display
node_browser_loop -.->|"sends analytics"| node_analytics

click node_desktop_loop "https://github.com/harshita-8605/spatial-lens/blob/main/main.py"
click node_hand_tracking "https://github.com/harshita-8605/spatial-lens/blob/main/perception.py"
click node_anime_engine "https://github.com/harshita-8605/spatial-lens/blob/main/anime_engine.py"
click node_portal_compositor "https://github.com/harshita-8605/spatial-lens/blob/main/compositor.py"
click node_browser_loop "https://github.com/harshita-8605/spatial-lens/blob/main/app.js"
click node_browser_hands "https://github.com/harshita-8605/spatial-lens/blob/main/app.js"
click node_browser_stylize "https://github.com/harshita-8605/spatial-lens/blob/main/app.js"
click node_browser_portal "https://github.com/harshita-8605/spatial-lens/blob/main/app.js"
click node_browser_display "https://github.com/harshita-8605/spatial-lens/blob/main/index.html"
click node_landmarker_asset "https://github.com/harshita-8605/spatial-lens/blob/main/hand_landmarker.task"

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_desktop_loop,node_user,node_browser_camera,node_browser_display toneBlue
class node_hand_tracking,node_anime_engine,node_portal_compositor toneAmber
class node_browser_loop toneMint
class node_browser_hands,node_browser_stylize,node_browser_portal,node_landmarker_asset toneRose
class node_desktop_camera,node_desktop_display,node_analytics toneIndigo
```

## Components

### Desktop experience

- [Frame and mode loop](https://github.com/harshita-8605/spatial-lens/blob/main/main.py): `main.py`

### Desktop processing

- [Hand tracking and corners](https://github.com/harshita-8605/spatial-lens/blob/main/perception.py): `perception.py`
- [Anime stylization](https://github.com/harshita-8605/spatial-lens/blob/main/anime_engine.py): `anime_engine.py`
- [Portal compositing](https://github.com/harshita-8605/spatial-lens/blob/main/compositor.py): `compositor.py`

### Browser experience

- [Browser frame loop and modes](https://github.com/harshita-8605/spatial-lens/blob/main/app.js): `app.js`

### Browser processing

- [Hand detection and corners](https://github.com/harshita-8605/spatial-lens/blob/main/app.js): `app.js`
- [Canvas stylization](https://github.com/harshita-8605/spatial-lens/blob/main/app.js): `app.js`
- [Portal clipping and border](https://github.com/harshita-8605/spatial-lens/blob/main/app.js): `app.js`
- [Hand landmarker model](https://github.com/harshita-8605/spatial-lens/blob/main/hand_landmarker.task): `hand_landmarker.task`

### Other components

- **User**
- **Webcam**
- **Display window**
- **Browser camera**
- [Browser canvas](https://github.com/harshita-8605/spatial-lens/blob/main/index.html): `index.html`
- **Vercel Analytics**

## Connections

- User → Webcam: presents hands (evidence: `README.md`)
- Webcam → Frame and mode loop: provides frames (evidence: `main.py`)
- Frame and mode loop → Hand tracking and corners: gets corners (evidence: `main.py`)
- Frame and mode loop → Anime stylization: stylizes frames (evidence: `main.py`)
- Frame and mode loop → Portal compositing: composites portal (evidence: `main.py`)
- Frame and mode loop → Display window: shows result (evidence: `README.md`)
- User → Browser camera: allows camera (evidence: `README.md`)
- Browser camera → Browser frame loop and modes: provides video (evidence: `app.js`)
- Browser frame loop and modes → Hand landmarker model: loads model (evidence: `app.js`)
- Browser frame loop and modes → Hand detection and corners: detects hands (evidence: `app.js`)
- Browser frame loop and modes → Canvas stylization: stylizes frames (evidence: `app.js`)
- Browser frame loop and modes → Portal clipping and border: clips portal (evidence: `app.js`)
- Browser frame loop and modes → Browser canvas: draws output (evidence: `app.js`)
- Browser frame loop and modes → Vercel Analytics: sends analytics (evidence: `app.js`)
