# mhdsahil1/zline architecture

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

- Interactive diagram: https://gitdiagram.com/mhdsahil1/zline
- Repository: https://github.com/mhdsahil1/zline

## Overview

Zline is a real-time messaging and calling platform with multi-device end-to-end encryption and an AI assistant grounded in platform knowledge and web research. The main workflow is account access, opening chats, encrypting and sending messages, and synchronizing them across trusted devices; calls, group features, and AI research are distinct capabilities. The graph also shows persistence and the AI research layers. Some relationships are documented in the README rather than verified in sampled implementation, and unsampled internals are not inferred.

Main entry points: [`app/chat/page.tsx`](https://github.com/mhdsahil1/zline/blob/main/app/chat/page.tsx) (Chat Workspace), [`app/api/messages/route.ts`](https://github.com/mhdsahil1/zline/blob/main/app/api/messages/route.ts) (Message APIs), [`app/api/ai/chat/route.ts`](https://github.com/mhdsahil1/zline/blob/main/app/api/ai/chat/route.ts) (AI Chat Endpoint), [`lib/models/Chat.ts`](https://github.com/mhdsahil1/zline/blob/main/lib/models/Chat.ts) (Chat Records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Identity and Devices"]
  node_auth_ui["Sign-in and Registration<br/>[page.tsx]"]
  node_auth_api["Authentication API<br/>[route.ts]"]
  node_auth_logic["Auth Configuration<br/>[auth.ts]"]
  node_device_ui["Device Pairing UI"]
  node_device_api["Device and Pairing APIs<br/>[route.ts]"]
  node_crypto["Device Crypto<br/>[crypto.ts]"]
end

subgraph group_messaging["Messaging and Storage"]
  node_chat_ui["Chat Workspace<br/>[page.tsx]"]
  node_message_api["Message APIs<br/>[route.ts]"]
  node_chat_api["Chat APIs<br/>[route.ts]"]
  node_group_poll_api["Groups and Polls<br/>[route.ts]"]
  node_message_model[("Message Records<br/>[Message.ts]")]
  node_chat_model[("Chat Records<br/>[Chat.ts]")]
  node_user_model[("User Records<br/>[User.ts]")]
  node_database[("MongoDB Connector<br/>[db.ts]")]
end

subgraph group_realtime["Realtime and Calls"]
  node_socket["Socket.IO Server<br/>[io.ts]"]
  node_call_api["Call Signaling API<br/>[route.ts]"]
  node_call_ui["Call Interfaces<br/>[CallModal.tsx]"]
  node_group_call_ui["Group Calls<br/>[GroupCallModal.tsx]"]
end

subgraph group_assistant["AI and Research"]
  node_ai_api["AI Chat Endpoint<br/>[route.ts]"]
  node_classifier["Search Intent"]
  node_researcher["Web Research<br/>[researcher.ts]"]
  node_context["RAG Context Builder<br/>[context-builder.ts]"]
  node_knowledge["Platform Knowledge Base<br/>[knowledge-base.ts]"]
  node_obscura["Obscura Browser"]
  node_tavily["Tavily Search<br/>[tavily.ts]"]
end

subgraph group_experience["User Experience"]
  node_landing["Product Landing<br/>[page.tsx]"]
  node_link_preview["Link Preview API<br/>[route.ts]"]
  node_preview_card["Link Preview Card"]
end

node_person(("User"))

node_person -->|"signs in"| node_auth_ui
node_auth_ui -.->|"authenticates"| node_auth_api
node_auth_api -.->|"uses options"| node_auth_logic
node_auth_logic -->|"looks up"| node_user_model
node_person -->|"pairs device"| node_device_ui
node_device_ui -->|"registers device"| node_device_api
node_device_api -->|"verifies fingerprint"| node_crypto
node_chat_ui -->|"encrypts messages"| node_crypto
node_chat_ui -->|"registers device"| node_device_api
node_chat_ui -.->|"sends messages"| node_message_api
node_message_api -->|"connects"| node_database
node_message_api -->|"creates and reads"| node_message_model
node_message_api -->|"finds chat"| node_chat_model
node_message_api -->|"checks users"| node_user_model
node_chat_api -->|"connects"| node_database
node_chat_api -->|"reads and updates"| node_chat_model
node_group_poll_api -->|"creates and updates"| node_message_model
node_group_poll_api -->|"finds chat"| node_chat_model
node_message_model -.->|"persists in"| node_database
node_chat_model -.->|"persists in"| node_database
node_person -->|"messages and calls"| node_chat_ui
node_chat_ui -.->|"realtime events"| node_socket
node_chat_ui -->|"starts calls"| node_call_ui
node_chat_ui -->|"starts group calls"| node_group_call_ui
node_call_ui -.->|"signals calls"| node_call_api
node_person -->|"asks Zino"| node_ai_api
node_ai_api -->|"classifies query"| node_classifier
node_ai_api -->|"requests research"| node_researcher
node_ai_api -->|"builds prompt"| node_context
node_context -->|"uses knowledge"| node_knowledge
node_researcher -->|"searches web"| node_tavily
node_researcher -->|"browses pages"| node_obscura
node_person -->|"discovers product"| node_landing
node_chat_ui -.->|"fetches metadata"| node_link_preview
node_link_preview -.->|"renders preview"| node_preview_card

click node_auth_ui "https://github.com/mhdsahil1/zline/blob/main/app/(auth)/login/page.tsx"
click node_auth_api "https://github.com/mhdsahil1/zline/blob/main/app/api/auth/%5B...nextauth%5D/route.ts"
click node_auth_logic "https://github.com/mhdsahil1/zline/blob/main/lib/auth.ts"
click node_device_ui "https://github.com/mhdsahil1/zline/blob/main/components/DevicePairingModal.tsx"
click node_device_api "https://github.com/mhdsahil1/zline/blob/main/app/api/devices/route.ts"
click node_crypto "https://github.com/mhdsahil1/zline/blob/main/lib/crypto.ts"
click node_chat_ui "https://github.com/mhdsahil1/zline/blob/main/app/chat/page.tsx"
click node_message_api "https://github.com/mhdsahil1/zline/blob/main/app/api/messages/route.ts"
click node_chat_api "https://github.com/mhdsahil1/zline/blob/main/app/api/chats/route.ts"
click node_group_poll_api "https://github.com/mhdsahil1/zline/blob/main/app/api/polls/route.ts"
click node_message_model "https://github.com/mhdsahil1/zline/blob/main/lib/models/Message.ts"
click node_chat_model "https://github.com/mhdsahil1/zline/blob/main/lib/models/Chat.ts"
click node_user_model "https://github.com/mhdsahil1/zline/blob/main/lib/models/User.ts"
click node_database "https://github.com/mhdsahil1/zline/blob/main/lib/db.ts"
click node_socket "https://github.com/mhdsahil1/zline/blob/main/pages/api/socket/io.ts"
click node_call_api "https://github.com/mhdsahil1/zline/blob/main/app/api/calls/route.ts"
click node_call_ui "https://github.com/mhdsahil1/zline/blob/main/components/CallModal.tsx"
click node_group_call_ui "https://github.com/mhdsahil1/zline/blob/main/components/GroupCallModal.tsx"
click node_ai_api "https://github.com/mhdsahil1/zline/blob/main/app/api/ai/chat/route.ts"
click node_classifier "https://github.com/mhdsahil1/zline/blob/main/lib/searchClassifier.ts"
click node_researcher "https://github.com/mhdsahil1/zline/blob/main/lib/ai/researcher.ts"
click node_context "https://github.com/mhdsahil1/zline/blob/main/lib/ai/context-builder.ts"
click node_knowledge "https://github.com/mhdsahil1/zline/blob/main/lib/ai/knowledge-base.ts"
click node_obscura "https://github.com/mhdsahil1/zline/tree/main/lib/obscura"
click node_tavily "https://github.com/mhdsahil1/zline/blob/main/lib/tavily.ts"
click node_landing "https://github.com/mhdsahil1/zline/blob/main/app/page.tsx"
click node_link_preview "https://github.com/mhdsahil1/zline/blob/main/app/api/link-preview/route.ts"
click node_preview_card "https://github.com/mhdsahil1/zline/blob/main/components/LinkPreviewCard.tsx"

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_auth_ui,node_auth_api,node_auth_logic,node_device_ui,node_device_api,node_crypto,node_person toneBlue
class node_chat_ui,node_message_api,node_chat_api,node_group_poll_api,node_message_model,node_chat_model,node_user_model,node_database toneAmber
class node_socket,node_call_api,node_call_ui,node_group_call_ui toneMint
class node_ai_api,node_classifier,node_researcher,node_context,node_knowledge,node_obscura,node_tavily toneRose
class node_landing,node_link_preview,node_preview_card toneIndigo
```

## Components

### Identity and Devices

- [Sign-in and Registration](https://github.com/mhdsahil1/zline/blob/main/app/(auth)/login/page.tsx): `app/(auth)/login/page.tsx`
- [Authentication API](https://github.com/mhdsahil1/zline/blob/main/app/api/auth/%5B...nextauth%5D/route.ts): `app/api/auth/[...nextauth]/route.ts`
- [Auth Configuration](https://github.com/mhdsahil1/zline/blob/main/lib/auth.ts): `lib/auth.ts`
- [Device Pairing UI](https://github.com/mhdsahil1/zline/blob/main/components/DevicePairingModal.tsx): `components/DevicePairingModal.tsx`
- [Device and Pairing APIs](https://github.com/mhdsahil1/zline/blob/main/app/api/devices/route.ts): `app/api/devices/route.ts`
- [Device Crypto](https://github.com/mhdsahil1/zline/blob/main/lib/crypto.ts): `lib/crypto.ts`

### Messaging and Storage

- [Chat Workspace](https://github.com/mhdsahil1/zline/blob/main/app/chat/page.tsx): `app/chat/page.tsx`
- [Message APIs](https://github.com/mhdsahil1/zline/blob/main/app/api/messages/route.ts): `app/api/messages/route.ts`
- [Chat APIs](https://github.com/mhdsahil1/zline/blob/main/app/api/chats/route.ts): `app/api/chats/route.ts`
- [Groups and Polls](https://github.com/mhdsahil1/zline/blob/main/app/api/polls/route.ts): `app/api/polls/route.ts`
- [Message Records](https://github.com/mhdsahil1/zline/blob/main/lib/models/Message.ts): `lib/models/Message.ts`
- [Chat Records](https://github.com/mhdsahil1/zline/blob/main/lib/models/Chat.ts): `lib/models/Chat.ts`
- [User Records](https://github.com/mhdsahil1/zline/blob/main/lib/models/User.ts): `lib/models/User.ts`
- [MongoDB Connector](https://github.com/mhdsahil1/zline/blob/main/lib/db.ts): `lib/db.ts`

### Realtime and Calls

- [Socket.IO Server](https://github.com/mhdsahil1/zline/blob/main/pages/api/socket/io.ts): `pages/api/socket/io.ts`
- [Call Signaling API](https://github.com/mhdsahil1/zline/blob/main/app/api/calls/route.ts): `app/api/calls/route.ts`
- [Call Interfaces](https://github.com/mhdsahil1/zline/blob/main/components/CallModal.tsx): `components/CallModal.tsx`
- [Group Calls](https://github.com/mhdsahil1/zline/blob/main/components/GroupCallModal.tsx): `components/GroupCallModal.tsx`

### AI and Research

- [AI Chat Endpoint](https://github.com/mhdsahil1/zline/blob/main/app/api/ai/chat/route.ts): `app/api/ai/chat/route.ts`
- [Search Intent](https://github.com/mhdsahil1/zline/blob/main/lib/searchClassifier.ts): `lib/searchClassifier.ts`
- [Web Research](https://github.com/mhdsahil1/zline/blob/main/lib/ai/researcher.ts): `lib/ai/researcher.ts`
- [RAG Context Builder](https://github.com/mhdsahil1/zline/blob/main/lib/ai/context-builder.ts): `lib/ai/context-builder.ts`
- [Platform Knowledge Base](https://github.com/mhdsahil1/zline/blob/main/lib/ai/knowledge-base.ts): `lib/ai/knowledge-base.ts`
- [Obscura Browser](https://github.com/mhdsahil1/zline/tree/main/lib/obscura): `lib/obscura`
- [Tavily Search](https://github.com/mhdsahil1/zline/blob/main/lib/tavily.ts): `lib/tavily.ts`

### User Experience

- [Product Landing](https://github.com/mhdsahil1/zline/blob/main/app/page.tsx): `app/page.tsx`
- [Link Preview API](https://github.com/mhdsahil1/zline/blob/main/app/api/link-preview/route.ts): `app/api/link-preview/route.ts`
- [Link Preview Card](https://github.com/mhdsahil1/zline/blob/main/components/LinkPreviewCard.tsx): `components/LinkPreviewCard.tsx`

### Other components

- **User**

## Connections

- User → Sign-in and Registration: signs in (evidence: `README.md`)
- Sign-in and Registration → Authentication API: authenticates
- Authentication API → Auth Configuration: uses options
- Auth Configuration → User Records: looks up (evidence: `lib/auth.ts`)
- User → Device Pairing UI: pairs device (evidence: `README.md`)
- Device Pairing UI → Device and Pairing APIs: registers device
- Device and Pairing APIs → Device Crypto: verifies fingerprint (evidence: `app/api/devices/route.ts`)
- Chat Workspace → Device Crypto: encrypts messages (evidence: `app/chat/page.tsx`)
- Chat Workspace → Device and Pairing APIs: registers device (evidence: `app/chat/page.tsx`)
- Chat Workspace → Message APIs: sends messages
- Message APIs → MongoDB Connector: connects (evidence: `app/api/messages/route.ts`)
- Message APIs → Message Records: creates and reads (evidence: `app/api/messages/route.ts`)
- Message APIs → Chat Records: finds chat (evidence: `app/api/messages/route.ts`)
- Message APIs → User Records: checks users (evidence: `app/api/messages/route.ts`)
- Chat APIs → MongoDB Connector: connects (evidence: `app/api/chats/route.ts`)
- Chat APIs → Chat Records: reads and updates (evidence: `app/api/chats/route.ts`)
- Groups and Polls → Message Records: creates and updates (evidence: `app/api/polls/route.ts`)
- Groups and Polls → Chat Records: finds chat (evidence: `app/api/polls/route.ts`)
- Message Records → MongoDB Connector: persists in
- Chat Records → MongoDB Connector: persists in
- User → Chat Workspace: messages and calls (evidence: `README.md`)
- Chat Workspace → Socket.IO Server: realtime events
- Chat Workspace → Call Interfaces: starts calls (evidence: `app/chat/page.tsx`)
- Chat Workspace → Group Calls: starts group calls (evidence: `app/chat/page.tsx`)
- Call Interfaces → Call Signaling API: signals calls
- User → AI Chat Endpoint: asks Zino (evidence: `README.md`)
- AI Chat Endpoint → Search Intent: classifies query (evidence: `app/api/ai/chat/route.ts`)
- AI Chat Endpoint → Web Research: requests research (evidence: `app/api/ai/chat/route.ts`)
- AI Chat Endpoint → RAG Context Builder: builds prompt (evidence: `app/api/ai/chat/route.ts`)
- RAG Context Builder → Platform Knowledge Base: uses knowledge (evidence: `lib/ai/context-builder.ts`)
- Web Research → Tavily Search: searches web (evidence: `lib/ai/researcher.ts`)
- Web Research → Obscura Browser: browses pages (evidence: `lib/ai/researcher.ts`)
- User → Product Landing: discovers product (evidence: `app/page.tsx`)
- Chat Workspace → Link Preview API: fetches metadata
- Link Preview API → Link Preview Card: renders preview
