# hmk8386/locket.js architecture

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

- Interactive diagram: https://gitdiagram.com/hmk8386/locket.js
- Repository: https://github.com/hmk8386/locket.js

## Overview

locket.js is a Node.js SDK for programmatic access to Locket Camera. Developers initialize a client, authenticate through Firebase, then use its user, moments, friends, and chat modules to retrieve or change account data. The moments workflow includes media preparation and upload before posting; chat supports message operations and optional live streaming. Device emulation and shared HTTP/API handling are internal layers. The excerpts show core calls, but some feature internals are omitted; README-documented capabilities are retained where implementation details were not sampled.

Main entry points: [`lib/client.js`](https://github.com/hmk8386/locket.js/blob/main/lib/client.js) (Locket client), [`lib/modules/user.js`](https://github.com/hmk8386/locket.js/blob/main/lib/modules/user.js) (User profiles), [`lib/session.js`](https://github.com/hmk8386/locket.js/blob/main/lib/session.js) (Session manager), [`lib/modules/chat.js`](https://github.com/hmk8386/locket.js/blob/main/lib/modules/chat.js) (Chat operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["SDK client"]
  node_entry["Public exports<br/>[index.js]"]
  node_locket_client["Locket client<br/>[client.js]"]
end

subgraph group_account["Identity and device"]
  node_device["Device emulation<br/>[device.js]"]
  node_session["Session manager<br/>[session.js]"]
end

subgraph group_features["Locket features"]
  node_user["User profiles<br/>[user.js]"]
  node_moments["Moments and feed<br/>[moments.js]"]
  node_caption_presets["Caption presets"]
  node_friends["Friends and groups<br/>[friends.js]"]
  node_chat["Chat operations<br/>[chat.js]"]
end

subgraph group_transport["Network and storage"]
  node_http["HTTP helper<br/>[http.js]"]
  node_local_session["Session file"]
  node_local_history["Chat history file"]
  node_errors["Typed errors<br/>[exceptions.js]"]
end

node_developer(("SDK developer"))
node_firebase_auth["Firebase Auth"]
node_api["Locket API"]
node_storage["Firebase Storage"]
node_websocket["Chat WebSocket"]

node_developer -->|"imports SDK"| node_entry
node_entry -->|"exports client"| node_locket_client
node_locket_client -->|"creates profile"| node_device
node_locket_client -->|"creates manager"| node_session
node_locket_client -->|"creates module"| node_user
node_locket_client -->|"creates module"| node_moments
node_locket_client -->|"creates module"| node_friends
node_locket_client -->|"creates module"| node_chat
node_locket_client -->|"delegates login"| node_session
node_session -->|"authenticates and refreshes"| node_firebase_auth
node_session -->|"sends requests"| node_http
node_session -->|"loads and saves"| node_local_session
node_session -->|"uses profile"| node_device
node_locket_client -->|"gets valid token"| node_session
node_locket_client -->|"sets request headers"| node_device
node_locket_client -->|"posts API requests"| node_api
node_locket_client -->|"sends requests"| node_http
node_locket_client -->|"raises API errors"| node_errors
node_user -->|"calls API"| node_locket_client
node_user -->|"resolves usernames"| node_friends
node_user -->|"looks up and updates account"| node_firebase_auth
node_user -->|"uploads avatar"| node_storage
node_moments -->|"calls API"| node_locket_client
node_moments -->|"uploads media"| node_storage
node_moments -->|"uses presets"| node_caption_presets
node_moments -->|"persists moment history"| node_local_history
node_friends -->|"calls API"| node_locket_client
node_friends -->|"fetches friend profiles"| node_user
node_friends -->|"reads Firestore"| node_api
node_friends -->|"sends requests"| node_http
node_chat -->|"calls API"| node_locket_client
node_chat -->|"gets valid token"| node_session
node_chat -->|"loads and records"| node_local_history
node_chat -->|"fetches messages"| node_http
node_chat -->|"streams messages"| node_websocket
node_chat -->|"resolves username"| node_user
node_user -.->|"may raise upload errors"| node_errors
node_moments -->|"raises upload errors"| node_errors
node_friends -->|"uses SDK errors"| node_errors

click node_entry "https://github.com/hmk8386/locket.js/blob/main/index.js"
click node_locket_client "https://github.com/hmk8386/locket.js/blob/main/lib/client.js"
click node_device "https://github.com/hmk8386/locket.js/blob/main/lib/device.js"
click node_session "https://github.com/hmk8386/locket.js/blob/main/lib/session.js"
click node_user "https://github.com/hmk8386/locket.js/blob/main/lib/modules/user.js"
click node_moments "https://github.com/hmk8386/locket.js/blob/main/lib/modules/moments.js"
click node_caption_presets "https://github.com/hmk8386/locket.js/blob/main/caption_presets.json"
click node_friends "https://github.com/hmk8386/locket.js/blob/main/lib/modules/friends.js"
click node_chat "https://github.com/hmk8386/locket.js/blob/main/lib/modules/chat.js"
click node_http "https://github.com/hmk8386/locket.js/blob/main/lib/http.js"
click node_errors "https://github.com/hmk8386/locket.js/blob/main/lib/exceptions.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_entry,node_locket_client toneBlue
class node_device,node_session,node_storage toneAmber
class node_user,node_moments,node_caption_presets,node_friends,node_chat,node_api toneMint
class node_http,node_local_session,node_local_history,node_errors toneRose
class node_developer,node_firebase_auth,node_websocket toneIndigo
```

## Components

### SDK client

- [Public exports](https://github.com/hmk8386/locket.js/blob/main/index.js): `index.js`
- [Locket client](https://github.com/hmk8386/locket.js/blob/main/lib/client.js): `lib/client.js`

### Identity and device

- [Device emulation](https://github.com/hmk8386/locket.js/blob/main/lib/device.js): `lib/device.js`
- [Session manager](https://github.com/hmk8386/locket.js/blob/main/lib/session.js): `lib/session.js`

### Locket features

- [User profiles](https://github.com/hmk8386/locket.js/blob/main/lib/modules/user.js): `lib/modules/user.js`
- [Moments and feed](https://github.com/hmk8386/locket.js/blob/main/lib/modules/moments.js): `lib/modules/moments.js`
- [Caption presets](https://github.com/hmk8386/locket.js/blob/main/caption_presets.json): `caption_presets.json`
- [Friends and groups](https://github.com/hmk8386/locket.js/blob/main/lib/modules/friends.js): `lib/modules/friends.js`
- [Chat operations](https://github.com/hmk8386/locket.js/blob/main/lib/modules/chat.js): `lib/modules/chat.js`

### Network and storage

- [HTTP helper](https://github.com/hmk8386/locket.js/blob/main/lib/http.js): `lib/http.js`
- **Session file**
- **Chat history file**
- [Typed errors](https://github.com/hmk8386/locket.js/blob/main/lib/exceptions.js): `lib/exceptions.js`

### Other components

- **SDK developer**
- **Firebase Auth**
- **Locket API**
- **Firebase Storage**
- **Chat WebSocket**

## Connections

- SDK developer → Public exports: imports SDK (evidence: `README.md`)
- Public exports → Locket client: exports client (evidence: `index.js`)
- Locket client → Device emulation: creates profile (evidence: `lib/client.js`)
- Locket client → Session manager: creates manager (evidence: `lib/client.js`)
- Locket client → User profiles: creates module (evidence: `lib/client.js`)
- Locket client → Moments and feed: creates module (evidence: `lib/client.js`)
- Locket client → Friends and groups: creates module (evidence: `lib/client.js`)
- Locket client → Chat operations: creates module (evidence: `lib/client.js`)
- Locket client → Session manager: delegates login (evidence: `lib/client.js`)
- Session manager → Firebase Auth: authenticates and refreshes (evidence: `lib/session.js`)
- Session manager → HTTP helper: sends requests (evidence: `lib/session.js`)
- Session manager → Session file: loads and saves (evidence: `lib/session.js`)
- Session manager → Device emulation: uses profile (evidence: `lib/session.js`)
- Locket client → Session manager: gets valid token (evidence: `lib/client.js`)
- Locket client → Device emulation: sets request headers (evidence: `lib/client.js`)
- Locket client → Locket API: posts API requests (evidence: `lib/client.js`)
- Locket client → HTTP helper: sends requests (evidence: `lib/client.js`)
- Locket client → Typed errors: raises API errors (evidence: `lib/client.js`)
- User profiles → Locket client: calls API (evidence: `lib/modules/user.js`)
- User profiles → Friends and groups: resolves usernames (evidence: `lib/modules/user.js`)
- User profiles → Firebase Auth: looks up and updates account (evidence: `lib/modules/user.js`)
- User profiles → Firebase Storage: uploads avatar (evidence: `lib/modules/user.js`)
- Moments and feed → Locket client: calls API (evidence: `lib/modules/moments.js`)
- Moments and feed → Firebase Storage: uploads media (evidence: `lib/modules/moments.js`)
- Moments and feed → Caption presets: uses presets (evidence: `README.md`)
- Moments and feed → Chat history file: persists moment history (evidence: `lib/modules/moments.js`)
- Friends and groups → Locket client: calls API (evidence: `lib/modules/friends.js`)
- Friends and groups → User profiles: fetches friend profiles (evidence: `lib/modules/friends.js`)
- Friends and groups → Locket API: reads Firestore (evidence: `lib/modules/friends.js`)
- Friends and groups → HTTP helper: sends requests (evidence: `lib/modules/friends.js`)
- Chat operations → Locket client: calls API (evidence: `lib/modules/chat.js`)
- Chat operations → Session manager: gets valid token (evidence: `lib/modules/chat.js`)
- Chat operations → Chat history file: loads and records (evidence: `lib/modules/chat.js`)
- Chat operations → HTTP helper: fetches messages (evidence: `lib/modules/chat.js`)
- Chat operations → Chat WebSocket: streams messages (evidence: `README.md`)
- Chat operations → User profiles: resolves username (evidence: `lib/modules/chat.js`)
- User profiles → Typed errors: may raise upload errors
- Moments and feed → Typed errors: raises upload errors (evidence: `lib/modules/moments.js`)
- Friends and groups → Typed errors: uses SDK errors (evidence: `lib/modules/friends.js`)
