# chandan-kr-dev/talkwithme architecture

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

- Interactive diagram: https://gitdiagram.com/chandan-kr-dev/talkwithme
- Repository: https://github.com/chandan-kr-dev/talkwithme

## Overview

TalkWithMe is a web chat product: users register or sign in, verify accounts by email, connect with friends, open direct or group conversations, and exchange messages and attachments with delivery/read feedback. The main UI is split between the auth page and chat shell; API routes implement account, social, chat, and message operations, with MongoDB models providing persistence. README capabilities include password recovery, presence, notifications, and PWA support; some corresponding implementation details were not sampled, so their internal wiring is shown conservatively.

Main entry points: [`models/User.ts`](https://github.com/chandan-kr-dev/talkwithme/blob/main/models/User.ts) (User records), [`app/page.tsx`](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/page.tsx) (Auth screens), [`app/api/message/route.ts`](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/message/route.ts) (Message operations), [`app/chat/page.tsx`](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/chat/page.tsx) (Chat shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_account["Accounts"]
  node_authui["Auth screens<br/>[page.tsx]"]
  node_register["Registration<br/>[route.ts]"]
  node_login["Login<br/>[route.ts]"]
  node_verify["Email verification<br/>[route.ts]"]
  node_authapi["Auth routes"]
  node_mailer["OTP mailer<br/>[mailer.ts]"]
  node_userdoc[("User records<br/>[User.ts]")]
end

subgraph group_social["Social graph"]
  node_friendapi["Friend requests<br/>[route.ts]"]
  node_userapi["User search/profile<br/>[route.ts]"]
end

subgraph group_messaging["Conversations"]
  node_chatshell["Chat shell<br/>[page.tsx]"]
  node_sidebar["Chat sidebar<br/>[Sidebar.tsx]"]
  node_chatwindow["Message composer<br/>[ChatWindow.tsx]"]
  node_groupui["Group controls<br/>[GroupChatModal.tsx]"]
  node_chatapi["Direct chats<br/>[route.ts]"]
  node_groupapi["Group chats<br/>[route.ts]"]
  node_messageapi["Message operations<br/>[route.ts]"]
  node_readapi["Read receipts<br/>[route.ts]"]
  node_chatdoc[("Chat records<br/>[Chat.ts]")]
  node_messagedoc[("Message records<br/>[Message.ts]")]
  node_encrypt["Message encryption<br/>[encryption.ts]"]
end

subgraph group_realtime["Live experience"]
  node_notificationapi["Notifications<br/>[route.ts]"]
  node_notificationdoc[("Notification records<br/>[Notification.ts]")]
  node_socketclient["Socket client<br/>[socketClient.ts]"]
  node_socketserver["Socket server<br/>[server.ts]"]
  node_store["Chat state<br/>[chatStore.ts]"]
  node_pushapi["Push subscriptions<br/>[route.ts]"]
  node_pushdoc[("Subscription records")]
  node_serviceworker["Push worker<br/>[push-sw.js]"]
end

subgraph group_services["Platform services"]
  node_uploadapi["Attachment upload<br/>[route.ts]"]
  node_cloudlib["Cloudinary client<br/>[cloudinary.ts]"]
end

node_user(("User"))
node_smtp["SMTP provider"]
node_cloudinary[("Cloudinary storage")]
node_database[("MongoDB")]

node_user -->|"uses"| node_authui
node_authui -->|"registers via"| node_register
node_authui -->|"signs in via"| node_login
node_authui -->|"verifies via"| node_verify
node_authui -.->|"password recovery"| node_authapi
node_register -->|"creates account"| node_userdoc
node_register -->|"sends OTP"| node_mailer
node_login -->|"checks credentials"| node_userdoc
node_login -->|"resends OTP"| node_mailer
node_verify -->|"verifies account"| node_userdoc
node_mailer -->|"delivers email"| node_smtp
node_register -->|"connects through"| node_database
node_login -->|"connects through"| node_database
node_chatshell -->|"renders"| node_sidebar
node_chatshell -->|"renders"| node_chatwindow
node_chatshell -->|"sets up"| node_socketclient
node_chatshell -->|"uses state"| node_store
node_user -->|"manages contacts"| node_sidebar
node_sidebar -->|"requests relationships"| node_friendapi
node_sidebar -->|"searches users"| node_userapi
node_user -->|"creates groups"| node_groupui
node_groupui -->|"manages groups"| node_groupapi
node_chatwindow -->|"sends and fetches"| node_messageapi
node_chatwindow -->|"marks read"| node_readapi
node_chatwindow -->|"uploads files"| node_uploadapi
node_chatapi -->|"reads and writes"| node_chatdoc
node_groupapi -->|"reads and writes"| node_chatdoc
node_messageapi -->|"loads chat"| node_chatdoc
node_messageapi -->|"reads and writes"| node_messagedoc
node_messageapi -->|"encrypts content"| node_encrypt
node_messageapi -->|"checks friendship"| node_userdoc
node_readapi -->|"updates read state"| node_messagedoc
node_friendapi -->|"updates relationships"| node_userdoc
node_userapi -->|"searches and updates"| node_userdoc
node_uploadapi -->|"uploads media"| node_cloudlib
node_cloudlib -->|"stores files"| node_cloudinary
node_notificationapi -->|"reads and updates"| node_notificationdoc
node_notificationapi -->|"decrypts preview"| node_encrypt
node_pushapi -->|"saves subscriptions"| node_pushdoc
node_serviceworker -.->|"shows push alerts"| node_user
node_socketserver -->|"serves realtime"| node_socketclient
node_socketserver -.->|"uses persistence"| node_database
node_pushdoc -->|"persists in"| node_database
node_notificationdoc -->|"persists in"| node_database
node_userdoc -->|"persists in"| node_database
node_chatdoc -->|"persists in"| node_database
node_messagedoc -->|"persists in"| node_database

click node_authui "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/page.tsx"
click node_register "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/auth/register/route.ts"
click node_login "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/auth/login/route.ts"
click node_verify "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/auth/verify-email/route.ts"
click node_authapi "https://github.com/chandan-kr-dev/talkwithme/tree/main/app/api/auth"
click node_mailer "https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/mailer.ts"
click node_userdoc "https://github.com/chandan-kr-dev/talkwithme/blob/main/models/User.ts"
click node_chatshell "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/chat/page.tsx"
click node_sidebar "https://github.com/chandan-kr-dev/talkwithme/blob/main/components/Sidebar.tsx"
click node_chatwindow "https://github.com/chandan-kr-dev/talkwithme/blob/main/components/ChatWindow.tsx"
click node_groupui "https://github.com/chandan-kr-dev/talkwithme/blob/main/components/GroupChatModal.tsx"
click node_chatapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/chat/route.ts"
click node_groupapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/chat/group/route.ts"
click node_messageapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/message/route.ts"
click node_readapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/message/read/route.ts"
click node_chatdoc "https://github.com/chandan-kr-dev/talkwithme/blob/main/models/Chat.ts"
click node_messagedoc "https://github.com/chandan-kr-dev/talkwithme/blob/main/models/Message.ts"
click node_encrypt "https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/encryption.ts"
click node_friendapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/friends/route.ts"
click node_userapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/user/route.ts"
click node_uploadapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/upload/route.ts"
click node_notificationapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/notification/route.ts"
click node_notificationdoc "https://github.com/chandan-kr-dev/talkwithme/blob/main/models/Notification.ts"
click node_socketclient "https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/socketClient.ts"
click node_socketserver "https://github.com/chandan-kr-dev/talkwithme/blob/main/server.ts"
click node_store "https://github.com/chandan-kr-dev/talkwithme/blob/main/store/chatStore.ts"
click node_pushapi "https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/push/subscribe/route.ts"
click node_pushdoc "https://github.com/chandan-kr-dev/talkwithme/blob/main/models/PushSubscription.ts"
click node_serviceworker "https://github.com/chandan-kr-dev/talkwithme/blob/main/public/push-sw.js"
click node_cloudlib "https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/cloudinary.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_authui,node_register,node_login,node_verify,node_authapi,node_mailer,node_userdoc,node_user toneBlue
class node_friendapi,node_userapi,node_cloudinary,node_database toneAmber
class node_chatshell,node_sidebar,node_chatwindow,node_groupui,node_chatapi,node_groupapi,node_messageapi,node_readapi,node_chatdoc,node_messagedoc,node_encrypt toneMint
class node_notificationapi,node_notificationdoc,node_socketclient,node_socketserver,node_store,node_pushapi,node_pushdoc,node_serviceworker toneRose
class node_uploadapi,node_cloudlib,node_smtp toneIndigo
```

## Components

### Accounts

- [Auth screens](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/page.tsx): `app/page.tsx`
- [Registration](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/auth/register/route.ts): `app/api/auth/register/route.ts`
- [Login](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/auth/login/route.ts): `app/api/auth/login/route.ts`
- [Email verification](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/auth/verify-email/route.ts): `app/api/auth/verify-email/route.ts`
- [Auth routes](https://github.com/chandan-kr-dev/talkwithme/tree/main/app/api/auth): `app/api/auth`
- [OTP mailer](https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/mailer.ts): `lib/mailer.ts`
- [User records](https://github.com/chandan-kr-dev/talkwithme/blob/main/models/User.ts): `models/User.ts`

### Social graph

- [Friend requests](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/friends/route.ts): `app/api/friends/route.ts`
- [User search/profile](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/user/route.ts): `app/api/user/route.ts`

### Conversations

- [Chat shell](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/chat/page.tsx): `app/chat/page.tsx`
- [Chat sidebar](https://github.com/chandan-kr-dev/talkwithme/blob/main/components/Sidebar.tsx): `components/Sidebar.tsx`
- [Message composer](https://github.com/chandan-kr-dev/talkwithme/blob/main/components/ChatWindow.tsx): `components/ChatWindow.tsx`
- [Group controls](https://github.com/chandan-kr-dev/talkwithme/blob/main/components/GroupChatModal.tsx): `components/GroupChatModal.tsx`
- [Direct chats](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Group chats](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/chat/group/route.ts): `app/api/chat/group/route.ts`
- [Message operations](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/message/route.ts): `app/api/message/route.ts`
- [Read receipts](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/message/read/route.ts): `app/api/message/read/route.ts`
- [Chat records](https://github.com/chandan-kr-dev/talkwithme/blob/main/models/Chat.ts): `models/Chat.ts`
- [Message records](https://github.com/chandan-kr-dev/talkwithme/blob/main/models/Message.ts): `models/Message.ts`
- [Message encryption](https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/encryption.ts): `lib/encryption.ts`

### Live experience

- [Notifications](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/notification/route.ts): `app/api/notification/route.ts`
- [Notification records](https://github.com/chandan-kr-dev/talkwithme/blob/main/models/Notification.ts): `models/Notification.ts`
- [Socket client](https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/socketClient.ts): `lib/socketClient.ts`
- [Socket server](https://github.com/chandan-kr-dev/talkwithme/blob/main/server.ts): `server.ts`
- [Chat state](https://github.com/chandan-kr-dev/talkwithme/blob/main/store/chatStore.ts): `store/chatStore.ts`
- [Push subscriptions](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/push/subscribe/route.ts): `app/api/push/subscribe/route.ts`
- [Subscription records](https://github.com/chandan-kr-dev/talkwithme/blob/main/models/PushSubscription.ts): `models/PushSubscription.ts`
- [Push worker](https://github.com/chandan-kr-dev/talkwithme/blob/main/public/push-sw.js): `public/push-sw.js`

### Platform services

- [Attachment upload](https://github.com/chandan-kr-dev/talkwithme/blob/main/app/api/upload/route.ts): `app/api/upload/route.ts`
- [Cloudinary client](https://github.com/chandan-kr-dev/talkwithme/blob/main/lib/cloudinary.ts): `lib/cloudinary.ts`

### Other components

- **User**
- **SMTP provider**
- **Cloudinary storage**
- **MongoDB**

## Connections

- User → Auth screens: uses
- Auth screens → Registration: registers via
- Auth screens → Login: signs in via
- Auth screens → Email verification: verifies via
- Auth screens → Auth routes: password recovery
- Registration → User records: creates account
- Registration → OTP mailer: sends OTP
- Login → User records: checks credentials
- Login → OTP mailer: resends OTP
- Email verification → User records: verifies account
- OTP mailer → SMTP provider: delivers email
- Registration → MongoDB: connects through
- Login → MongoDB: connects through
- Chat shell → Chat sidebar: renders
- Chat shell → Message composer: renders
- Chat shell → Socket client: sets up
- Chat shell → Chat state: uses state
- User → Chat sidebar: manages contacts
- Chat sidebar → Friend requests: requests relationships
- Chat sidebar → User search/profile: searches users
- User → Group controls: creates groups
- Group controls → Group chats: manages groups
- Message composer → Message operations: sends and fetches
- Message composer → Read receipts: marks read
- Message composer → Attachment upload: uploads files
- Direct chats → Chat records: reads and writes
- Group chats → Chat records: reads and writes
- Message operations → Chat records: loads chat
- Message operations → Message records: reads and writes
- Message operations → Message encryption: encrypts content
- Message operations → User records: checks friendship
- Read receipts → Message records: updates read state
- Friend requests → User records: updates relationships
- User search/profile → User records: searches and updates
- Attachment upload → Cloudinary client: uploads media
- Cloudinary client → Cloudinary storage: stores files
- Notifications → Notification records: reads and updates
- Notifications → Message encryption: decrypts preview
- Push subscriptions → Subscription records: saves subscriptions
- Push worker → User: shows push alerts
- Socket server → Socket client: serves realtime
- Socket server → MongoDB: uses persistence
- Subscription records → MongoDB: persists in
- Notification records → MongoDB: persists in
- User records → MongoDB: persists in
- Chat records → MongoDB: persists in
- Message records → MongoDB: persists in
