# milesprovus/monocle-teleprompter architecture

> Architecture diagram of the GitHub repository milesprovus/monocle-teleprompter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/milesprovus/monocle-teleprompter
- Repository: https://github.com/milesprovus/monocle-teleprompter

## Overview

##### Project type and purpose
- This is a hybrid full-stack teleprompter application targeting the “Monocle” AR device by Brilliant Labs.
- It comprises three logical layers:
- A Node.js/Express backend that handles OAuth2 and Google Slides API calls
- A browser-based frontend (HTML/JS/CSS) that authenticates the user, displays controls, and pipes notes to the Monocle
- A Python script (`main.py`) that can run standalone on the Monocle device to fetch and render speaker notes

##### File structure
Top-level files:
- server.js: Express server entrypoint
- credentials.json: OAuth client secrets for server-side Google API calls
- package.json / package-lock.json: Node dependencies
- main.py: Python runtime for on-device operation
- .brilliant/*: configuration manifest for device deployment
public/ (browser UI assets):
- index.html + public/src/*.js: handles authentication, UI, “Brilliant.connect()” device linkage
- style.css: styling
img/: screenshots (for README)
README.md: setup instructions, app description

##### README for additional insights
- Uses Google Slides API to pull speaker notes
- OAuth2 flow: browser obtains client ID + API key, then authorizes Slides scope
- Web client runs on localhost:3000; Monocle touchpads send navigation events back to the UI
- An alternate deployment path is to upload main.py to the Monocle directly

##### Main components & interactions
a. External service:
– Google Slides API (via HTTPS REST, OAuth2)
b. Backend:
– Node.js/Express server (server.js + credentials.json)
– Exposes endpoints for the frontend to fetch slide notes JSON
c. Frontend (browser):
– UI layer (public/index.html, script.js) for login, slide preview, nav controls
– auth.js + connect.js handle OAuth2 token injection and device connection (WebUSB / Brilliant JS SDK)
d. Monocle device:
– Runs either:
1) The browser UI pushes notes over WebUSB / socket to the device
2) `main.py` runs directly on‐device (Python) and polls the Google Slides API itself
– Touchpad events on the Monocle trigger next/prev slide requests back into the system

##### Architectural patterns & design principles
- Client-Server (REST API + OAuth2)
- Single-Page Application for control plane (HTML/JS)
- IoT integration via WebUSB / Python runtime on device
- Separation of concerns:
- Authentication & data retrieval (backend)
- Presentation & device communication (frontend)
- On-device rendering (Python or JS SDK)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Services"
        Google["Google Slides API"]:::external
    end

    subgraph "Backend Layer"
        Express["server.js"]:::backend
        Cred["credentials.json"]:::backend
        Pkg["package.json"]:::backend
        PkgLock["package-lock.json"]:::backend
    end

    subgraph "Frontend Layer"
        HTML["public/index.html"]:::frontend
        CSS["public/style.css"]:::frontend
        Auth["public/src/auth.js"]:::frontend
        Connect["public/src/connect.js"]:::frontend
        Script["public/src/script.js"]:::frontend
    end

    subgraph "Device Layer"
        DeviceBrowser["Browser ↔ Monocle Device\n(WebUSB / Brilliant SDK)"]:::device
        Python["main.py"]:::device
        Config1[".brilliant/device-files.json"]:::device
        Config2[".brilliant/screens.json"]:::device
    end

    subgraph "Docs & Assets"
        Readme["README.md"]:::doc
        Img["img/"]:::doc
    end

    HTML -->|"GET /slides, OAuth2"| Express
    Express -->|"HTTPS: GET slides"| Google
    Google -->|"JSON speaker notes"| Express
    Express -->|"JSON response"| HTML
    HTML -->|"pushNotes()"| DeviceBrowser
    DeviceBrowser -->|"onTouch() → next/prev"| HTML
    Python -.->|"HTTPS: GET slides"| Google

    classDef external fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1;
    classDef backend fill:#C8E6C9,stroke:#2E7D32,color:#1B5E20;
    classDef frontend fill:#FFF59D,stroke:#FDD835,color:#F57F17;
    classDef device fill:#FFCC80,stroke:#EF6C00,color:#E65100;
    classDef doc fill:#E1BEE7,stroke:#8E24AA,color:#4A148C;

    click Express "https://github.com/milesprovus/monocle-teleprompter/blob/main/server.js"
    click Cred "https://github.com/milesprovus/monocle-teleprompter/blob/main/credentials.json"
    click Pkg "https://github.com/milesprovus/monocle-teleprompter/blob/main/package.json"
    click PkgLock "https://github.com/milesprovus/monocle-teleprompter/blob/main/package-lock.json"
    click HTML "https://github.com/milesprovus/monocle-teleprompter/blob/main/public/index.html"
    click CSS "https://github.com/milesprovus/monocle-teleprompter/blob/main/public/style.css"
    click Auth "https://github.com/milesprovus/monocle-teleprompter/blob/main/public/src/auth.js"
    click Connect "https://github.com/milesprovus/monocle-teleprompter/blob/main/public/src/connect.js"
    click Script "https://github.com/milesprovus/monocle-teleprompter/blob/main/public/src/script.js"
    click Python "https://github.com/milesprovus/monocle-teleprompter/blob/main/main.py"
    click Config1 "https://github.com/milesprovus/monocle-teleprompter/blob/main/.brilliant/device-files.json"
    click Config2 "https://github.com/milesprovus/monocle-teleprompter/blob/main/.brilliant/screens.json"
    click Readme "https://github.com/milesprovus/monocle-teleprompter/blob/main/README.md"
    click Img "https://github.com/milesprovus/monocle-teleprompter/tree/main/img/"
```
