# lakey82/watchpartybackend architecture

> Architecture diagram of the GitHub repository lakey82/watchpartybackend, 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/lakey82/watchpartybackend
- Repository: https://github.com/lakey82/watchpartybackend

## Overview

ReelSync is a watch-party backend whose main workflow is account authentication, room creation or joining, then synchronized playback and live interaction among room participants. REST handlers manage room membership, playback updates, and persisted chat history; Socket.io supports live room state, chat, participant events, and WebRTC signaling. A separate authenticated endpoint supplies optional TURN credentials. The README and sampled code support these major branches, though the socket implementation excerpt is partial, so only its evidenced interactions are mapped.

Main entry points: [`src/socket/socket.js`](https://github.com/lakey82/watchpartybackend/blob/main/src/socket/socket.js) (Socket Events), [`src/app.js`](https://github.com/lakey82/watchpartybackend/blob/main/src/app.js) (Express App), [`src/server.js`](https://github.com/lakey82/watchpartybackend/blob/main/src/server.js) (Server Bootstrap), [`src/routes/authRoutes.js`](https://github.com/lakey82/watchpartybackend/blob/main/src/routes/authRoutes.js) (Auth Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["Server Bootstrap<br/>[server.js]"]
  node_app["Express App<br/>[app.js]"]
  node_database_config["DB Connection<br/>[db.js]"]
end

subgraph group_identity["Identity"]
  node_auth_routes["Auth Routes<br/>[authRoutes.js]"]
  node_auth_middleware["JWT Guard<br/>[authMiddleware.js]"]
  node_auth_controller["Auth Controller<br/>[authController.js]"]
  node_user_model[("User Store<br/>[User.js]")]
end

subgraph group_rooms["Room Domain"]
  node_room_routes["Room Routes<br/>[roomRoutes.js]"]
  node_room_controller["Room Controller<br/>[roomController.js]"]
  node_room_model[("Room Store<br/>[Room.js]")]
  node_message_model[("Message Store<br/>[Message.js]")]
end

subgraph group_realtime["Realtime"]
  node_turn_routes["TURN Routes<br/>[turnRoutes.js]"]
  node_turn_controller["TURN Credentials<br/>[turnController.js]"]
  node_socket["Socket Events<br/>[socket.js]"]
  node_live_state[("Live Room State<br/>[socket.js]")]
end

node_client(("Watch Party Client"))
node_mongo[("MongoDB")]
node_metered["Metered TURN"]

node_client -->|"sends REST requests"| node_app
node_server -->|"creates HTTP server"| node_app
node_server -->|"connects database"| node_database_config
node_server -->|"initializes sockets"| node_socket
node_app -->|"mounts auth API"| node_auth_routes
node_app -->|"mounts room API"| node_room_routes
node_app -->|"mounts TURN API"| node_turn_routes
node_auth_routes -->|"guards profile route"| node_auth_middleware
node_auth_routes -->|"dispatches auth handlers"| node_auth_controller
node_auth_controller -->|"reads and writes users"| node_user_model
node_room_routes -->|"guards room routes"| node_auth_middleware
node_room_routes -->|"dispatches room handlers"| node_room_controller
node_room_controller -->|"reads and writes rooms"| node_room_model
node_room_controller -->|"reads and deletes messages"| node_message_model
node_turn_routes -->|"guards credentials route"| node_auth_middleware
node_turn_routes -->|"dispatches credentials"| node_turn_controller
node_turn_controller -.->|"fetches TURN servers"| node_metered
node_client -->|"exchanges live events"| node_socket
node_socket -->|"loads joining user"| node_user_model
node_socket -->|"loads room settings"| node_room_model
node_socket -->|"persists chat"| node_message_model
node_socket -->|"updates playback state"| node_live_state
node_socket -->|"relays room events"| node_client
node_database_config -->|"connects to"| node_mongo

click node_server "https://github.com/lakey82/watchpartybackend/blob/main/src/server.js"
click node_app "https://github.com/lakey82/watchpartybackend/blob/main/src/app.js"
click node_auth_routes "https://github.com/lakey82/watchpartybackend/blob/main/src/routes/authRoutes.js"
click node_auth_middleware "https://github.com/lakey82/watchpartybackend/blob/main/src/middleware/authMiddleware.js"
click node_auth_controller "https://github.com/lakey82/watchpartybackend/blob/main/src/controllers/authController.js"
click node_user_model "https://github.com/lakey82/watchpartybackend/blob/main/src/models/User.js"
click node_room_routes "https://github.com/lakey82/watchpartybackend/blob/main/src/routes/roomRoutes.js"
click node_room_controller "https://github.com/lakey82/watchpartybackend/blob/main/src/controllers/roomController.js"
click node_room_model "https://github.com/lakey82/watchpartybackend/blob/main/src/models/Room.js"
click node_message_model "https://github.com/lakey82/watchpartybackend/blob/main/src/models/Message.js"
click node_turn_routes "https://github.com/lakey82/watchpartybackend/blob/main/src/routes/turnRoutes.js"
click node_turn_controller "https://github.com/lakey82/watchpartybackend/blob/main/src/controllers/turnController.js"
click node_socket "https://github.com/lakey82/watchpartybackend/blob/main/src/socket/socket.js"
click node_live_state "https://github.com/lakey82/watchpartybackend/blob/main/src/socket/socket.js"
click node_database_config "https://github.com/lakey82/watchpartybackend/blob/main/src/config/db.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_server,node_app,node_database_config,node_client toneBlue
class node_auth_routes,node_auth_middleware,node_auth_controller,node_user_model,node_mongo toneAmber
class node_room_routes,node_room_controller,node_room_model,node_message_model toneMint
class node_turn_routes,node_turn_controller,node_socket,node_live_state toneRose
class node_metered toneIndigo
```

## Components

### HTTP API

- [Server Bootstrap](https://github.com/lakey82/watchpartybackend/blob/main/src/server.js): `src/server.js`
- [Express App](https://github.com/lakey82/watchpartybackend/blob/main/src/app.js): `src/app.js`
- [DB Connection](https://github.com/lakey82/watchpartybackend/blob/main/src/config/db.js): `src/config/db.js`

### Identity

- [Auth Routes](https://github.com/lakey82/watchpartybackend/blob/main/src/routes/authRoutes.js): `src/routes/authRoutes.js`
- [JWT Guard](https://github.com/lakey82/watchpartybackend/blob/main/src/middleware/authMiddleware.js): `src/middleware/authMiddleware.js`
- [Auth Controller](https://github.com/lakey82/watchpartybackend/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [User Store](https://github.com/lakey82/watchpartybackend/blob/main/src/models/User.js): `src/models/User.js`

### Room Domain

- [Room Routes](https://github.com/lakey82/watchpartybackend/blob/main/src/routes/roomRoutes.js): `src/routes/roomRoutes.js`
- [Room Controller](https://github.com/lakey82/watchpartybackend/blob/main/src/controllers/roomController.js): `src/controllers/roomController.js`
- [Room Store](https://github.com/lakey82/watchpartybackend/blob/main/src/models/Room.js): `src/models/Room.js`
- [Message Store](https://github.com/lakey82/watchpartybackend/blob/main/src/models/Message.js): `src/models/Message.js`

### Realtime

- [TURN Routes](https://github.com/lakey82/watchpartybackend/blob/main/src/routes/turnRoutes.js): `src/routes/turnRoutes.js`
- [TURN Credentials](https://github.com/lakey82/watchpartybackend/blob/main/src/controllers/turnController.js): `src/controllers/turnController.js`
- [Socket Events](https://github.com/lakey82/watchpartybackend/blob/main/src/socket/socket.js): `src/socket/socket.js`
- [Live Room State](https://github.com/lakey82/watchpartybackend/blob/main/src/socket/socket.js): `src/socket/socket.js`

### Other components

- **Watch Party Client**
- **MongoDB**
- **Metered TURN**

## Connections

- Watch Party Client → Express App: sends REST requests
- Server Bootstrap → Express App: creates HTTP server
- Server Bootstrap → DB Connection: connects database
- Server Bootstrap → Socket Events: initializes sockets
- Express App → Auth Routes: mounts auth API
- Express App → Room Routes: mounts room API
- Express App → TURN Routes: mounts TURN API
- Auth Routes → JWT Guard: guards profile route
- Auth Routes → Auth Controller: dispatches auth handlers
- Auth Controller → User Store: reads and writes users
- Room Routes → JWT Guard: guards room routes
- Room Routes → Room Controller: dispatches room handlers
- Room Controller → Room Store: reads and writes rooms
- Room Controller → Message Store: reads and deletes messages
- TURN Routes → JWT Guard: guards credentials route
- TURN Routes → TURN Credentials: dispatches credentials
- TURN Credentials → Metered TURN: fetches TURN servers
- Watch Party Client → Socket Events: exchanges live events
- Socket Events → User Store: loads joining user
- Socket Events → Room Store: loads room settings
- Socket Events → Message Store: persists chat
- Socket Events → Live Room State: updates playback state
- Socket Events → Watch Party Client: relays room events
- DB Connection → MongoDB: connects to
