# benj4368/cinemate architecture

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

- Interactive diagram: https://gitdiagram.com/benj4368/cinemate
- Repository: https://github.com/benj4368/cinemate

## Overview

Cinemate is a browser extension for synchronizing video playback between people in peer-to-peer rooms. A user creates or joins a room in the popup; the background worker manages membership and PeerJS connections, relays playback and ad state, and sends synchronization commands to the content script, which controls the page’s video and displays room status. Excerpts show these message paths, but omit many worker and content-script handlers, so the graph avoids inferring details of those unseen paths.

Main entry points: [`src/background/worker.js`](https://github.com/benj4368/cinemate/blob/main/src/background/worker.js) (Room worker), [`src/popup/popup.js`](https://github.com/benj4368/cinemate/blob/main/src/popup/popup.js) (Room popup), [`src/content/content.js`](https://github.com/benj4368/cinemate/blob/main/src/content/content.js) (Page controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Extension UI"]
  node_popup["Room popup<br/>[popup.js]"]
end

subgraph group_coordination["Room coordination"]
  node_worker["Room worker<br/>[worker.js]"]
  node_peerjs["PeerJS network"]
  node_room(("P2P room peers"))
end

subgraph group_playback["Playback sync"]
  node_content["Page controller<br/>[content.js]"]
  node_video["Page video"]
end

node_user(("User"))

node_user -->|"creates or joins"| node_popup
node_popup -->|"requests room actions"| node_worker
node_popup -->|"probes video"| node_content
node_worker -->|"updates room state"| node_popup
node_content -->|"sends playback state"| node_worker
node_worker -->|"sends sync commands"| node_content
node_content -->|"observes and controls"| node_video
node_worker -->|"uses connections"| node_peerjs
node_peerjs -.->|"connects peers"| node_room

click node_popup "https://github.com/benj4368/cinemate/blob/main/src/popup/popup.js"
click node_content "https://github.com/benj4368/cinemate/blob/main/src/content/content.js"
click node_worker "https://github.com/benj4368/cinemate/blob/main/src/background/worker.js"

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_popup,node_user toneBlue
class node_worker,node_peerjs,node_room toneAmber
class node_content,node_video toneMint
```

## Components

### Extension UI

- [Room popup](https://github.com/benj4368/cinemate/blob/main/src/popup/popup.js): `src/popup/popup.js`

### Room coordination

- [Room worker](https://github.com/benj4368/cinemate/blob/main/src/background/worker.js): `src/background/worker.js`
- **PeerJS network**
- **P2P room peers**

### Playback sync

- [Page controller](https://github.com/benj4368/cinemate/blob/main/src/content/content.js): `src/content/content.js`
- **Page video**

### Other components

- **User**

## Connections

- User → Room popup: creates or joins (evidence: `src/popup/popup.js`)
- Room popup → Room worker: requests room actions (evidence: `src/popup/popup.js`)
- Room popup → Page controller: probes video (evidence: `src/popup/popup.js`)
- Room worker → Room popup: updates room state (evidence: `src/popup/popup.js`)
- Page controller → Room worker: sends playback state (evidence: `src/content/content.js`)
- Room worker → Page controller: sends sync commands (evidence: `src/background/worker.js`)
- Page controller → Page video: observes and controls (evidence: `src/content/content.js`)
- Room worker → PeerJS network: uses connections (evidence: `src/background/worker.js`)
- PeerJS network → P2P room peers: connects peers
