# hutrisemendawai/cp-chat architecture

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

- Interactive diagram: https://gitdiagram.com/hutrisemendawai/cp-chat
- Repository: https://github.com/hutrisemendawai/cp-chat

## Overview

CP Chat is a Flutter Android messaging client backed here by a TypeScript REST API and WebSocket gateway. The documented user workflow is account/profile and friend management, conversation setup, encrypted message send and live delivery, then sync and receipts; media, calls, presence, search, and diagnostics are major supporting capabilities. The tree and index establish the backend surfaces, but no Flutter Dart sources are provided, so client-side workflow links and several route-to-domain calls are not asserted. Edges reflect excerpted calls, indexed references, or README documentation.

Main entry points: [`backend/src/http/context.ts`](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/context.ts) (App context), [`backend/src/gateway/chat-gateway.ts`](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/gateway/chat-gateway.ts) (WebSocket gateway), [`backend/src/domain/messages.ts`](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/messages.ts) (Message service), [`backend/src/domain/call-signaling.ts`](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/call-signaling.ts) (Call signaling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_rest["REST server<br/>[rest.ts]"]
  node_routes["HTTP routes"]
  node_context["App context<br/>[context.ts]"]
  node_auth["Authentication<br/>[auth-routes.ts]"]
end

subgraph group_chat["Messaging and realtime"]
  node_conversations["Conversations<br/>[conversations.ts]"]
  node_messages["Message service<br/>[messages.ts]"]
  node_scylla["Scylla history<br/>[scylla-messages.ts]"]
  node_gateway["WebSocket gateway<br/>[chat-gateway.ts]"]
  node_inbound["Inbound dispatch<br/>[inbound.ts]"]
  node_search["Message search<br/>[search-routes.ts]"]
end

subgraph group_social["People and presence"]
  node_users["User profiles<br/>[users.ts]"]
  node_friends["Friends directory<br/>[friends.ts]"]
  node_presence["Presence service<br/>[presence.ts]"]
end

subgraph group_features["Calls and media"]
  node_calls["Call signaling<br/>[call-signaling.ts]"]
  node_callstate["Call records<br/>[calls.ts]"]
  node_media["Media handling<br/>[media.ts]"]
  node_keys["E2EE keys<br/>[keys.ts]"]
end

subgraph group_infra["State and operations"]
  node_postgres[("PostgreSQL<br/>[db.ts]")]
  node_redis[("Redis<br/>[redis.ts]")]
  node_broker["Realtime broker<br/>[broker.ts]"]
  node_push["Push notifications<br/>[fcm.ts]"]
  node_objectstore["Media object storage<br/>[storage.ts]"]
  node_logs[("Log timeline<br/>[log-store.ts]")]
end

node_mobile(("Android client"))

node_mobile -->|"uses REST"| node_rest
node_mobile -->|"uses WebSocket"| node_gateway
node_rest -->|"serves routes"| node_routes
node_routes -->|"uses context"| node_context
node_context -->|"constructs"| node_users
node_context -->|"constructs"| node_conversations
node_context -->|"constructs"| node_messages
node_context -->|"constructs"| node_presence
node_context -->|"constructs"| node_friends
node_context -->|"constructs"| node_calls
node_context -->|"constructs"| node_callstate
node_context -->|"constructs"| node_keys
node_context -->|"uses database"| node_postgres
node_context -->|"uses cache"| node_redis
node_auth -->|"looks up users"| node_users
node_auth -->|"authenticates"| node_context
node_conversations -->|"projects members"| node_users
node_messages -->|"uses history store"| node_scylla
node_messages -->|"queries database"| node_postgres
node_users -->|"queries database"| node_postgres
node_conversations -->|"queries database"| node_postgres
node_gateway -->|"dispatches messages"| node_messages
node_gateway -->|"checks membership"| node_conversations
node_gateway -->|"uses dispatch"| node_inbound
node_gateway -->|"updates presence"| node_presence
node_gateway -->|"publishes frames"| node_broker
node_gateway -->|"reads connections"| node_redis
node_calls -->|"uses call records"| node_callstate
node_calls -->|"publishes signaling"| node_broker
node_calls -->|"sends call alerts"| node_push
node_context -->|"constructs store"| node_logs
node_rest -->|"configures logging"| node_logs
node_logs -->|"stores timeline"| node_redis
node_search -.->|"searches messages"| node_messages
node_media -.->|"stores media"| node_objectstore
node_context -->|"constructs"| node_media
node_context -->|"constructs"| node_broker

click node_rest "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/rest.ts"
click node_routes "https://github.com/hutrisemendawai/cp-chat/tree/main/backend/src/http"
click node_context "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/context.ts"
click node_auth "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/auth-routes.ts"
click node_users "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/users.ts"
click node_friends "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/friends.ts"
click node_presence "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/presence.ts"
click node_conversations "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/conversations.ts"
click node_messages "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/messages.ts"
click node_scylla "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/scylla-messages.ts"
click node_gateway "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/gateway/chat-gateway.ts"
click node_inbound "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/gateway/inbound.ts"
click node_calls "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/call-signaling.ts"
click node_callstate "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/calls.ts"
click node_media "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/media.ts"
click node_keys "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/keys.ts"
click node_postgres "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/db.ts"
click node_redis "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/redis.ts"
click node_broker "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/broker.ts"
click node_push "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/fcm.ts"
click node_objectstore "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/storage.ts"
click node_logs "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/log-store.ts"
click node_search "https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/search-routes.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_rest,node_routes,node_context,node_auth,node_mobile toneBlue
class node_conversations,node_messages,node_scylla,node_gateway,node_inbound,node_search toneAmber
class node_users,node_friends,node_presence toneMint
class node_calls,node_callstate,node_media,node_keys toneRose
class node_postgres,node_redis,node_broker,node_push,node_objectstore,node_logs toneIndigo
```

## Components

### API and identity

- [REST server](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/rest.ts): `backend/src/rest.ts`
- [HTTP routes](https://github.com/hutrisemendawai/cp-chat/tree/main/backend/src/http): `backend/src/http`
- [App context](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/context.ts): `backend/src/http/context.ts`
- [Authentication](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/auth-routes.ts): `backend/src/http/auth-routes.ts`

### Messaging and realtime

- [Conversations](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/conversations.ts): `backend/src/domain/conversations.ts`
- [Message service](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/messages.ts): `backend/src/domain/messages.ts`
- [Scylla history](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/scylla-messages.ts): `backend/src/domain/scylla-messages.ts`
- [WebSocket gateway](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/gateway/chat-gateway.ts): `backend/src/gateway/chat-gateway.ts`
- [Inbound dispatch](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/gateway/inbound.ts): `backend/src/gateway/inbound.ts`
- [Message search](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/http/search-routes.ts): `backend/src/http/search-routes.ts`

### People and presence

- [User profiles](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/users.ts): `backend/src/domain/users.ts`
- [Friends directory](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/friends.ts): `backend/src/domain/friends.ts`
- [Presence service](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/presence.ts): `backend/src/domain/presence.ts`

### Calls and media

- [Call signaling](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/call-signaling.ts): `backend/src/domain/call-signaling.ts`
- [Call records](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/calls.ts): `backend/src/domain/calls.ts`
- [Media handling](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/media.ts): `backend/src/domain/media.ts`
- [E2EE keys](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/domain/keys.ts): `backend/src/domain/keys.ts`

### State and operations

- [PostgreSQL](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/db.ts): `backend/src/lib/db.ts`
- [Redis](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/redis.ts): `backend/src/lib/redis.ts`
- [Realtime broker](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/broker.ts): `backend/src/lib/broker.ts`
- [Push notifications](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/fcm.ts): `backend/src/lib/fcm.ts`
- [Media object storage](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/storage.ts): `backend/src/lib/storage.ts`
- [Log timeline](https://github.com/hutrisemendawai/cp-chat/blob/main/backend/src/lib/log-store.ts): `backend/src/lib/log-store.ts`

### Other components

- **Android client**

## Connections

- Android client → REST server: uses REST (evidence: `README.md`)
- Android client → WebSocket gateway: uses WebSocket (evidence: `README.md`)
- REST server → HTTP routes: serves routes (evidence: `backend/src/rest.ts`)
- HTTP routes → App context: uses context (evidence: `backend/src/http/context.ts`)
- App context → User profiles: constructs (evidence: `backend/src/http/context.ts`)
- App context → Conversations: constructs (evidence: `backend/src/http/context.ts`)
- App context → Message service: constructs (evidence: `backend/src/http/context.ts`)
- App context → Presence service: constructs (evidence: `backend/src/http/context.ts`)
- App context → Friends directory: constructs (evidence: `backend/src/http/context.ts`)
- App context → Call signaling: constructs (evidence: `backend/src/http/context.ts`)
- App context → Call records: constructs (evidence: `backend/src/http/context.ts`)
- App context → E2EE keys: constructs (evidence: `backend/src/http/context.ts`)
- App context → PostgreSQL: uses database (evidence: `backend/src/http/context.ts`)
- App context → Redis: uses cache (evidence: `backend/src/http/context.ts`)
- Authentication → User profiles: looks up users (evidence: `backend/src/http/auth-routes.ts`)
- Authentication → App context: authenticates (evidence: `backend/src/http/auth-routes.ts`)
- Conversations → User profiles: projects members (evidence: `backend/src/domain/conversations.ts`)
- Message service → Scylla history: uses history store (evidence: `backend/src/domain/messages.ts`)
- Message service → PostgreSQL: queries database (evidence: `backend/src/domain/messages.ts`)
- User profiles → PostgreSQL: queries database (evidence: `backend/src/domain/users.ts`)
- Conversations → PostgreSQL: queries database (evidence: `backend/src/domain/conversations.ts`)
- WebSocket gateway → Message service: dispatches messages (evidence: `backend/src/gateway/chat-gateway.ts`)
- WebSocket gateway → Conversations: checks membership (evidence: `backend/src/gateway/chat-gateway.ts`)
- WebSocket gateway → Inbound dispatch: uses dispatch (evidence: `backend/src/gateway/chat-gateway.ts`)
- WebSocket gateway → Presence service: updates presence (evidence: `backend/src/gateway/chat-gateway.ts`)
- WebSocket gateway → Realtime broker: publishes frames (evidence: `backend/src/gateway/chat-gateway.ts`)
- WebSocket gateway → Redis: reads connections (evidence: `backend/src/gateway/chat-gateway.ts`)
- Call signaling → Call records: uses call records (evidence: `backend/src/domain/call-signaling.ts`)
- Call signaling → Realtime broker: publishes signaling (evidence: `backend/src/domain/call-signaling.ts`)
- Call signaling → Push notifications: sends call alerts (evidence: `backend/src/domain/call-signaling.ts`)
- App context → Log timeline: constructs store (evidence: `backend/src/http/context.ts`)
- REST server → Log timeline: configures logging (evidence: `backend/src/rest.ts`)
- Log timeline → Redis: stores timeline (evidence: `backend/src/lib/log-store.ts`)
- Message search → Message service: searches messages
- Media handling → Media object storage: stores media
- App context → Media handling: constructs (evidence: `backend/src/http/context.ts`)
- App context → Realtime broker: constructs (evidence: `backend/src/http/context.ts`)
