# eitaar/snapi architecture

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

- Interactive diagram: https://gitdiagram.com/eitaar/snapi
- Repository: https://github.com/eitaar/snapi

## Overview

This is an experimental operator-facing CLI and TypeScript client for one or more Snapchat Web sessions. The principal workflow selects an account, loads and validates its sealed session and build, initializes Snapchat’s pinned messaging runtime, obtains request authentication, then sends or watches Chat/Snap traffic through gRPC-Web and Gateway. Separate workflows register profiles, import or refresh session state from browser exports/HARs, and inspect friends. The README documents automatic SSO renewal and Web-session heartbeats. Edges reflect README statements or shown imports/calls; several command-specific implementations and runtime internals were not sampled, so uncertain wiring is omitted.

Main entry points: [`src/client.ts`](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/client.ts) (Client composition), [`src/cli/index.ts`](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/cli/index.ts) (Command dispatcher), [`src/cli/commands/session-refresh-har.ts`](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/cli/commands/session-refresh-har.ts) (Session commands), [`src/transport/grpc-client.ts`](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/grpc-client.ts) (gRPC-Web transport)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and profiles"]
  node_cli["Command dispatcher<br/>[index.ts]"]
  node_account_profiles["Account profiles<br/>[profile-store.ts]"]
  node_configuration["Configuration<br/>[config.ts]"]
end

subgraph group_session["Session lifecycle"]
  node_session_commands["Session commands"]
  node_session_store[("Sealed session store<br/>[sealed-store.ts]")]
  node_browser_export["Browser export<br/>[cdp.ts]"]
  node_har_auth["HAR authentication import<br/>[har-auth.ts]"]
end

subgraph group_runtime["Messaging runtime"]
  node_compatibility["Build compatibility<br/>[guard.ts]"]
  node_official_runtime["Pinned official runtime"]
  node_runtime_client["Runtime client<br/>[worker-client.ts]"]
end

subgraph group_services["Product capabilities"]
  node_client["Client composition<br/>[client.ts]"]
  node_messaging["Chat messaging<br/>[client.ts]"]
  node_media["Snap media<br/>[client.ts]"]
  node_friends["Friends snapshots<br/>[snapshot.ts]"]
  node_gateway["Gateway events<br/>[client.ts]"]
end

subgraph group_network["Authentication and network"]
  node_auth_provider["Request auth<br/>[auth-provider.ts]"]
  node_attestation["Web attestation<br/>[web-attestation.ts]"]
  node_sso_refresh["SSO renewal"]
  node_grpc["gRPC-Web transport<br/>[grpc-client.ts]"]
end

node_operator(("Operator"))
node_snapchat(("Snapchat services"))

node_operator -->|"runs commands"| node_cli
node_cli -->|"resolves settings"| node_configuration
node_cli -->|"selects profiles"| node_account_profiles
node_configuration -->|"loads session"| node_session_store
node_cli -->|"dispatches session"| node_session_commands
node_session_commands -->|"imports HAR auth"| node_har_auth
node_session_commands -->|"exports browser state"| node_browser_export
node_session_commands -->|"persists session"| node_session_store
node_cli -->|"creates client"| node_client
node_client -->|"reads session"| node_session_store
node_client -->|"validates build"| node_compatibility
node_client -->|"initializes runtime"| node_runtime_client
node_runtime_client -->|"dispatches runtime calls"| node_official_runtime
node_client -->|"composes messaging"| node_messaging
node_client -->|"composes media"| node_media
node_client -->|"composes friends"| node_friends
node_client -->|"composes gateway"| node_gateway
node_messaging -->|"encrypts content"| node_runtime_client
node_media -->|"protects Snap content"| node_runtime_client
node_messaging -->|"sends messages"| node_grpc
node_media -->|"transfers media"| node_grpc
node_friends -.->|"requests friend data"| node_snapchat
node_grpc -->|"gets request auth"| node_auth_provider
node_auth_provider -->|"refreshes credentials"| node_sso_refresh
node_sso_refresh -->|"requests attestation"| node_attestation
node_grpc -->|"calls private API"| node_snapchat
node_gateway -->|"connects WebSocket"| node_snapchat
node_gateway -->|"authenticates reconnect"| node_auth_provider

click node_cli "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/cli/index.ts"
click node_account_profiles "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/accounts/profile-store.ts"
click node_configuration "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/config.ts"
click node_client "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/client.ts"
click node_session_commands "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/cli/commands/session-refresh-har.ts"
click node_session_store "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/session/sealed-store.ts"
click node_browser_export "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/browser/cdp.ts"
click node_har_auth "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/session/har-auth.ts"
click node_compatibility "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/compat/guard.ts"
click node_official_runtime "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/runtime/official-worker-entry.ts"
click node_runtime_client "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/runtime/worker-client.ts"
click node_messaging "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/messaging/client.ts"
click node_media "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/media/client.ts"
click node_friends "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/friends/snapshot.ts"
click node_gateway "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/gateway/client.ts"
click node_auth_provider "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/auth-provider.ts"
click node_attestation "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/auth/web-attestation.ts"
click node_sso_refresh "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/sso-auth-refresh.ts"
click node_grpc "https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/grpc-client.ts"

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_cli,node_account_profiles,node_configuration toneBlue
class node_session_commands,node_session_store,node_browser_export,node_har_auth toneAmber
class node_compatibility,node_official_runtime,node_runtime_client toneMint
class node_client,node_messaging,node_media,node_friends,node_gateway toneRose
class node_auth_provider,node_attestation,node_sso_refresh,node_grpc,node_operator,node_snapchat toneIndigo
```

## Components

### CLI and profiles

- [Command dispatcher](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/cli/index.ts): `src/cli/index.ts`
- [Account profiles](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/accounts/profile-store.ts): `src/accounts/profile-store.ts`
- [Configuration](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/config.ts): `src/config.ts`

### Session lifecycle

- [Session commands](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/cli/commands/session-refresh-har.ts): `src/cli/commands/session-refresh-har.ts`
- [Sealed session store](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/session/sealed-store.ts): `src/session/sealed-store.ts`
- [Browser export](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/browser/cdp.ts): `src/browser/cdp.ts`
- [HAR authentication import](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/session/har-auth.ts): `src/session/har-auth.ts`

### Messaging runtime

- [Build compatibility](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/compat/guard.ts): `src/compat/guard.ts`
- [Pinned official runtime](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/runtime/official-worker-entry.ts): `src/runtime/official-worker-entry.ts`
- [Runtime client](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/runtime/worker-client.ts): `src/runtime/worker-client.ts`

### Product capabilities

- [Client composition](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/client.ts): `src/client.ts`
- [Chat messaging](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/messaging/client.ts): `src/messaging/client.ts`
- [Snap media](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/media/client.ts): `src/media/client.ts`
- [Friends snapshots](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/friends/snapshot.ts): `src/friends/snapshot.ts`
- [Gateway events](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/gateway/client.ts): `src/gateway/client.ts`

### Authentication and network

- [Request auth](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/auth-provider.ts): `src/transport/auth-provider.ts`
- [Web attestation](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/auth/web-attestation.ts): `src/auth/web-attestation.ts`
- [SSO renewal](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/sso-auth-refresh.ts): `src/transport/sso-auth-refresh.ts`
- [gRPC-Web transport](https://github.com/eitaar/snapi/blob/feat/snap-private-cli/src/transport/grpc-client.ts): `src/transport/grpc-client.ts`

### Other components

- **Operator**
- **Snapchat services**

## Connections

- Operator → Command dispatcher: runs commands (evidence: `README.md`)
- Command dispatcher → Configuration: resolves settings (evidence: `src/cli/index.ts`)
- Command dispatcher → Account profiles: selects profiles (evidence: `src/cli/index.ts`)
- Configuration → Sealed session store: loads session (evidence: `src/config.ts`)
- Command dispatcher → Session commands: dispatches session (evidence: `src/cli/index.ts`)
- Session commands → HAR authentication import: imports HAR auth (evidence: `README.md`)
- Session commands → Browser export: exports browser state (evidence: `README.md`)
- Session commands → Sealed session store: persists session (evidence: `README.md`)
- Command dispatcher → Client composition: creates client (evidence: `src/cli/index.ts`)
- Client composition → Sealed session store: reads session (evidence: `src/client.ts`)
- Client composition → Build compatibility: validates build (evidence: `src/client.ts`)
- Client composition → Runtime client: initializes runtime (evidence: `src/client.ts`)
- Runtime client → Pinned official runtime: dispatches runtime calls (evidence: `src/runtime/worker-client.ts`)
- Client composition → Chat messaging: composes messaging (evidence: `src/client.ts`)
- Client composition → Snap media: composes media (evidence: `src/client.ts`)
- Client composition → Friends snapshots: composes friends (evidence: `src/client.ts`)
- Client composition → Gateway events: composes gateway (evidence: `src/client.ts`)
- Chat messaging → Runtime client: encrypts content (evidence: `README.md`)
- Snap media → Runtime client: protects Snap content (evidence: `README.md`)
- Chat messaging → gRPC-Web transport: sends messages (evidence: `src/messaging/client.ts`)
- Snap media → gRPC-Web transport: transfers media (evidence: `src/media/client.ts`)
- Friends snapshots → Snapchat services: requests friend data
- gRPC-Web transport → Request auth: gets request auth (evidence: `src/transport/grpc-client.ts`)
- Request auth → SSO renewal: refreshes credentials (evidence: `README.md`)
- SSO renewal → Web attestation: requests attestation (evidence: `README.md`)
- gRPC-Web transport → Snapchat services: calls private API (evidence: `README.md`)
- Gateway events → Snapchat services: connects WebSocket (evidence: `src/gateway/client.ts`)
- Gateway events → Request auth: authenticates reconnect (evidence: `README.md`)
