# sophiamyang/finger-frame-effect-lucy architecture

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

- Interactive diagram: https://gitdiagram.com/sophiamyang/finger-frame-effect-lucy
- Repository: https://github.com/sophiamyang/finger-frame-effect-lucy

## Overview

#### Purpose and entry points
This is a static browser demo for a “finger frame” effect: a user frames an area with both hands, and the framed region displays a live AI video-to-video transformation. The app is served directly as static files, with `index.html` as the browser entry point and `main.js` containing the application behavior. `examples/lucy.mp4` is a demonstration asset, not part of the live pipeline.

#### Browser UI and rendering surface
`index.html` defines the full-screen interactive page, including controls for API-key entry, style selection, and custom prompts. `main.js` owns webcam setup, UI event handling, and composition of camera and transformed video onto a canvas. The camera view is mirrored; the AI output is clipped/mapped to the detected finger-frame quadrilateral.

Paths: `index.html`, `main.js`

#### Camera acquisition and local fallback
The primary source is a 1280×720, 30fps webcam `MediaStream`, requested from the browser after user permission. That stream supplies both local rendering and the remote AI session. If no Decart key/session is available, the framed region falls back to a local color-filter effect so hand tracking remains usable. A `?demo` mode substitutes a synthetic feed/fake hands and disables AI.

Paths: `main.js`, `index.html`

#### Hand tracking and frame geometry
MediaPipe Hand Landmarker runs client-side against the camera feed. Its output is converted into an ordered four-corner “finger frame” quad. The tracking stage includes gesture qualification and temporal stabilization described by the project: anatomical corner ordering, hysteresis, teleport rejection, velocity-adaptive smoothing, and temporary dropout holding. This is the key boundary between raw hand landmarks and rendering geometry.

Paths: `main.js`

#### Realtime AI transport
With a user-provided Decart platform key, the camera stream is sent to Decart Lucy 2.5 through a WebRTC session. The service returns a transformed live video track; the browser draws this returned track only inside the tracked quad while retaining the original mirrored camera outside it. API-key storage and use remain browser-side, but the key is necessarily passed to Decart for session establishment.

Paths: `main.js`, `index.html`

#### Prompt/style control flow
Keyboard shortcuts 1–6 and UI controls select predefined visual styles. A custom style uses the prompt entered in the key/prompt panel. Prompt changes update the active Lucy session rather than reconnecting, separating session lifecycle from style mutation.

Paths: `main.js`, `index.html`

#### Runtime and deployment boundary
There is no backend in this repository. The runtime is a modern browser with camera permission, Canvas/video APIs, MediaPipe hand tracking, WebRTC, and the external Decart realtime model service. Development/deployment is static hosting; the documented local server is sufficient because browser camera access requires an HTTP(S) origin.

Paths: `README.md`, `index.html`, `main.js`

Main entry points: [`main.js`](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js) (Application controller), [`index.html`](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/index.html) (Key and style controls), [`README.md`](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/README.md) (Static hosting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser app"]
  node_static_page["Interactive page<br/>HTML entry<br/>[index.html]"]
  node_app_controller["Application controller<br/>browser app<br/>[main.js]"]
  node_camera(("Webcam stream<br/>MediaStream<br/>[main.js]"))
  node_demo_feed["Demo feed<br/>synthetic input<br/>[main.js]"]
  node_ui_controls["Key and style controls<br/>UI controls<br/>[index.html]"]
  node_static_host["Static hosting<br/>deployment<br/>[README.md]"]
end

subgraph group_vision["Tracking and compositing"]
  node_canvas["Canvas compositor<br/>Canvas renderer<br/>[main.js]"]
  node_hand_landmarker["Hand Landmarker<br/>MediaPipe tracking<br/>[main.js]"]
  node_frame_geometry["Finger-frame geometry<br/>quad stabilizer<br/>[main.js]"]
  node_local_effect["Local color fallback<br/>canvas effect<br/>[main.js]"]
end

subgraph group_decart["Decart realtime service"]
  node_session["Lucy WebRTC session<br/>realtime transport<br/>[main.js]"]
  node_lucy_service{{"Decart Lucy 2.5<br/>external AI service"}}
  node_ai_track["Transformed video track<br/>remote video<br/>[main.js]"]
end

node_static_host -->|"serves"| node_static_page
node_static_page -->|"loads"| node_app_controller
node_ui_controls -->|"events and prompt"| node_app_controller
node_app_controller -->|"requests permission"| node_camera
node_demo_feed -.->|"replaces input in ?demo"| node_app_controller
node_camera -->|"video frames"| node_hand_landmarker
node_hand_landmarker -->|"landmarks"| node_frame_geometry
node_camera -->|"mirrored base video"| node_canvas
node_frame_geometry -->|"clip quad"| node_canvas
node_camera -->|"outbound video"| node_session
node_app_controller -->|"key and session control"| node_session
node_ui_controls -->|"style/prompt updates"| node_session
node_session -->|"WebRTC session"| node_lucy_service
node_lucy_service -->|"transformed stream"| node_ai_track
node_ai_track -->|"draw inside quad"| node_canvas
node_local_effect -.->|"fallback framed output"| node_canvas
node_app_controller -.->|"when no session"| node_local_effect

click node_static_page "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/index.html"
click node_app_controller "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_camera "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_demo_feed "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_ui_controls "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/index.html"
click node_canvas "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_hand_landmarker "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_frame_geometry "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_local_effect "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_session "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_ai_track "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js"
click node_static_host "https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/README.md"

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_static_page,node_app_controller,node_camera,node_demo_feed,node_ui_controls,node_static_host toneBlue
class node_canvas,node_hand_landmarker,node_frame_geometry,node_local_effect toneAmber
class node_session,node_lucy_service,node_ai_track toneMint
```

## Components

### Browser app

Static client-side runtime.

- [Interactive page](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/index.html): HTML entry · Full-screen controls and rendering surface. · `index.html`
- [Application controller](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): browser app · Owns camera, UI, sessions, and canvas composition. · `main.js`
- [Webcam stream](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): MediaStream · 1280×720 30fps camera input after permission. · `main.js`
- [Demo feed](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): synthetic input · Fake camera and hands for ?demo mode. · `main.js`
- [Key and style controls](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/index.html): UI controls · API key, presets, and custom prompt input. · `index.html`
- [Static hosting](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/README.md): deployment · Serves the app from an HTTP(S) origin. · `README.md`

### Tracking and compositing

- [Canvas compositor](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): Canvas renderer · Mirrors camera and clips AI output to the finger frame. · `main.js`
- [Hand Landmarker](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): MediaPipe tracking · Runs locally on camera frames. · `main.js`
- [Finger-frame geometry](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): quad stabilizer · Qualifies gestures and stabilizes the ordered four-corner quad. · `main.js`
- [Local color fallback](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): canvas effect · Used when no Decart session is available. · `main.js`

### Decart realtime service

- [Lucy WebRTC session](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): realtime transport · Separates session lifecycle from prompt updates. · `main.js`
- **Decart Lucy 2.5**: external AI service · Transforms the submitted live video stream.
- [Transformed video track](https://github.com/sophiamyang/finger-frame-effect-lucy/blob/main/main.js): remote video · Returned WebRTC video used inside the quad. · `main.js`

## Connections

- Static hosting → Interactive page: serves
- Interactive page → Application controller: loads
- Key and style controls → Application controller: events and prompt
- Application controller → Webcam stream: requests permission
- Demo feed → Application controller: replaces input in ?demo
- Webcam stream → Hand Landmarker: video frames
- Hand Landmarker → Finger-frame geometry: landmarks
- Webcam stream → Canvas compositor: mirrored base video
- Finger-frame geometry → Canvas compositor: clip quad
- Webcam stream → Lucy WebRTC session: outbound video
- Application controller → Lucy WebRTC session: key and session control
- Key and style controls → Lucy WebRTC session: style/prompt updates
- Lucy WebRTC session → Decart Lucy 2.5: WebRTC session
- Decart Lucy 2.5 → Transformed video track: transformed stream
- Transformed video track → Canvas compositor: draw inside quad
- Local color fallback → Canvas compositor: fallback framed output
- Application controller → Local color fallback: when no session
