# haitruongfla-max/chatpht architecture

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

- Interactive diagram: https://gitdiagram.com/haitruongfla-max/chatpht
- Repository: https://github.com/haitruongfla-max/chatpht

## Overview

SwiftChat is a mobile 1-to-1 messaging app. Its documented main journey is account creation or login, finding a user by username, sending and accepting a friend request, then chatting and sharing media. The graph includes the client, API/domain layer, and storage/push services, plus the substantial calling implementation present in the tree. The README says calling is not yet implemented, so treat that branch as code present rather than a documented user capability; unsampled modules and their connections are not inferred.

Main entry points: [`server/routers.ts`](https://github.com/haitruongfla-max/chatpht/blob/main/server/routers.ts) (Domain procedures), [`lib/trpc.ts`](https://github.com/haitruongfla-max/chatpht/blob/main/lib/trpc.ts) (API client), [`app/chat/[id].tsx`](https://github.com/haitruongfla-max/chatpht/blob/main/app/chat/%5Bid%5D.tsx) (Conversation), [`server/media-access.ts`](https://github.com/haitruongfla-max/chatpht/blob/main/server/media-access.ts) (Media authorization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Mobile app"]
  node_authscreen["Login<br/>[login.tsx]"]
  node_authstate["Auth state<br/>[use-auth.ts]"]
  node_authstorage["Session storage<br/>[auth.ts]"]
  node_search["Find friends<br/>[search.tsx]"]
  node_inbox["Inbox and contacts<br/>[index.tsx]"]
  node_chat["Conversation<br/>[&#91;id&#93;.tsx]"]
  node_api["API client<br/>[trpc.ts]"]
end

subgraph group_domain["API and domain"]
  node_routers["Domain procedures<br/>[routers.ts]"]
  node_database[("Application data<br/>[db.ts]")]
  node_push["Push notifications<br/>[push.ts]"]
  node_realtime["Realtime server<br/>[realtime.ts]"]
end

subgraph group_media["Media and storage"]
  node_upload["Direct media upload"]
  node_storage["Object storage<br/>[storage.ts]"]
  node_access["Media authorization<br/>[media-access.ts]"]
end

subgraph group_calling["Calling implementation"]
  node_callingmanager["Call manager"]
  node_webrtc["WebRTC controller<br/>[useWebRTC.ts]"]
  node_signaling["Call signaling<br/>[callSignaling.ts]"]
end

node_person(("User"))

node_person -->|"signs in"| node_authscreen
node_authscreen -.->|"establishes session"| node_authstate
node_authstate -->|"reads session"| node_authstorage
node_person -->|"finds username"| node_search
node_person -->|"opens inbox"| node_inbox
node_person -->|"opens conversation"| node_chat
node_search -->|"requests search"| node_api
node_inbox -->|"loads inbox"| node_api
node_chat -->|"loads and sends"| node_api
node_api -->|"calls procedures"| node_routers
node_routers -->|"reads and writes"| node_database
node_routers -->|"dispatches alerts"| node_push
node_chat -->|"uploads media"| node_upload
node_routers -->|"creates upload URL"| node_storage
node_routers -->|"creates signed access"| node_access
node_access -->|"checks membership"| node_database
node_access -->|"resolves media"| node_storage
node_callingmanager -->|"controls calls"| node_webrtc
node_webrtc -->|"exchanges signals"| node_signaling
node_webrtc -->|"calls procedures"| node_api
node_routers -->|"uses realtime"| node_realtime

click node_authscreen "https://github.com/haitruongfla-max/chatpht/blob/main/app/login.tsx"
click node_authstate "https://github.com/haitruongfla-max/chatpht/blob/main/hooks/use-auth.ts"
click node_authstorage "https://github.com/haitruongfla-max/chatpht/blob/main/lib/_core/auth.ts"
click node_search "https://github.com/haitruongfla-max/chatpht/blob/main/app/search.tsx"
click node_inbox "https://github.com/haitruongfla-max/chatpht/blob/main/app/(tabs)/index.tsx"
click node_chat "https://github.com/haitruongfla-max/chatpht/blob/main/app/chat/%5Bid%5D.tsx"
click node_api "https://github.com/haitruongfla-max/chatpht/blob/main/lib/trpc.ts"
click node_routers "https://github.com/haitruongfla-max/chatpht/blob/main/server/routers.ts"
click node_database "https://github.com/haitruongfla-max/chatpht/blob/main/server/db.ts"
click node_push "https://github.com/haitruongfla-max/chatpht/blob/main/server/push.ts"
click node_upload "https://github.com/haitruongfla-max/chatpht/blob/main/lib/direct-media-upload.ts"
click node_storage "https://github.com/haitruongfla-max/chatpht/blob/main/server/storage.ts"
click node_access "https://github.com/haitruongfla-max/chatpht/blob/main/server/media-access.ts"
click node_callingmanager "https://github.com/haitruongfla-max/chatpht/blob/main/components/calling-manager.tsx"
click node_webrtc "https://github.com/haitruongfla-max/chatpht/blob/main/src/features/webrtc-calling/hooks/useWebRTC.ts"
click node_signaling "https://github.com/haitruongfla-max/chatpht/blob/main/src/features/webrtc-calling/services/callSignaling.ts"
click node_realtime "https://github.com/haitruongfla-max/chatpht/blob/main/server/_core/realtime.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_authscreen,node_authstate,node_authstorage,node_search,node_inbox,node_chat,node_api,node_person toneBlue
class node_routers,node_database,node_push,node_realtime toneAmber
class node_upload,node_storage,node_access toneMint
class node_callingmanager,node_webrtc,node_signaling toneRose
```

## Components

### Mobile app

- [Login](https://github.com/haitruongfla-max/chatpht/blob/main/app/login.tsx): `app/login.tsx`
- [Auth state](https://github.com/haitruongfla-max/chatpht/blob/main/hooks/use-auth.ts): `hooks/use-auth.ts`
- [Session storage](https://github.com/haitruongfla-max/chatpht/blob/main/lib/_core/auth.ts): `lib/_core/auth.ts`
- [Find friends](https://github.com/haitruongfla-max/chatpht/blob/main/app/search.tsx): `app/search.tsx`
- [Inbox and contacts](https://github.com/haitruongfla-max/chatpht/blob/main/app/(tabs)/index.tsx): `app/(tabs)/index.tsx`
- [Conversation](https://github.com/haitruongfla-max/chatpht/blob/main/app/chat/%5Bid%5D.tsx): `app/chat/[id].tsx`
- [API client](https://github.com/haitruongfla-max/chatpht/blob/main/lib/trpc.ts): `lib/trpc.ts`

### API and domain

- [Domain procedures](https://github.com/haitruongfla-max/chatpht/blob/main/server/routers.ts): `server/routers.ts`
- [Application data](https://github.com/haitruongfla-max/chatpht/blob/main/server/db.ts): `server/db.ts`
- [Push notifications](https://github.com/haitruongfla-max/chatpht/blob/main/server/push.ts): `server/push.ts`
- [Realtime server](https://github.com/haitruongfla-max/chatpht/blob/main/server/_core/realtime.ts): `server/_core/realtime.ts`

### Media and storage

- [Direct media upload](https://github.com/haitruongfla-max/chatpht/blob/main/lib/direct-media-upload.ts): `lib/direct-media-upload.ts`
- [Object storage](https://github.com/haitruongfla-max/chatpht/blob/main/server/storage.ts): `server/storage.ts`
- [Media authorization](https://github.com/haitruongfla-max/chatpht/blob/main/server/media-access.ts): `server/media-access.ts`

### Calling implementation

- [Call manager](https://github.com/haitruongfla-max/chatpht/blob/main/components/calling-manager.tsx): `components/calling-manager.tsx`
- [WebRTC controller](https://github.com/haitruongfla-max/chatpht/blob/main/src/features/webrtc-calling/hooks/useWebRTC.ts): `src/features/webrtc-calling/hooks/useWebRTC.ts`
- [Call signaling](https://github.com/haitruongfla-max/chatpht/blob/main/src/features/webrtc-calling/services/callSignaling.ts): `src/features/webrtc-calling/services/callSignaling.ts`

### Other components

- **User**

## Connections

- User → Login: signs in (evidence: `README.md`)
- Login → Auth state: establishes session
- Auth state → Session storage: reads session (evidence: `hooks/use-auth.ts`)
- User → Find friends: finds username (evidence: `README.md`)
- User → Inbox and contacts: opens inbox (evidence: `README.md`)
- User → Conversation: opens conversation (evidence: `README.md`)
- Find friends → API client: requests search (evidence: `app/search.tsx`)
- Inbox and contacts → API client: loads inbox (evidence: `app/(tabs)/index.tsx`)
- Conversation → API client: loads and sends (evidence: `app/chat/[id].tsx`)
- API client → Domain procedures: calls procedures (evidence: `lib/trpc.ts`)
- Domain procedures → Application data: reads and writes (evidence: `server/routers.ts`)
- Domain procedures → Push notifications: dispatches alerts (evidence: `server/routers.ts`)
- Conversation → Direct media upload: uploads media (evidence: `app/chat/[id].tsx`)
- Domain procedures → Object storage: creates upload URL (evidence: `server/routers.ts`)
- Domain procedures → Media authorization: creates signed access (evidence: `server/routers.ts`)
- Media authorization → Application data: checks membership (evidence: `server/media-access.ts`)
- Media authorization → Object storage: resolves media (evidence: `server/media-access.ts`)
- Call manager → WebRTC controller: controls calls (evidence: `components/calling-manager.tsx`)
- WebRTC controller → Call signaling: exchanges signals (evidence: `src/features/webrtc-calling/hooks/useWebRTC.ts`)
- WebRTC controller → API client: calls procedures (evidence: `src/features/webrtc-calling/hooks/useWebRTC.ts`)
- Domain procedures → Realtime server: uses realtime (evidence: `server/routers.ts`)
