# toshniwalpranav/whatsgateway-typescript-nextjs architecture

> Architecture diagram of the GitHub repository toshniwalpranav/whatsgateway-typescript-nextjs, 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/toshniwalpranav/whatsgateway-typescript-nextjs
- Repository: https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs

## Overview

WA-AKG is a multi-session WhatsApp gateway with a web dashboard for messaging and automation. A user or integrating app manages a session through the dashboard or REST API; API handlers authorize requests and dispatch WhatsApp operations, while session management maintains Baileys connections and persistence. The README also documents scheduled messaging, broadcasts, auto-replies, webhooks, contacts, stickers, and MCP integration. The graph preserves these major capabilities, but several are connected only where the README or indexed source references support the relationship; unsampled implementation details are not inferred.

Main entry points: [`src/modules/whatsapp/manager.ts`](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/manager.ts) (Session Manager), [`src/app/api`](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/api) (REST API), [`src/lib/prisma.ts`](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/prisma.ts) (Prisma Database), [`src/server/index.ts`](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/server/index.ts) (HTTP / Socket Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Dashboard Experience"]
  node_dashboard["Dashboard"]
  node_chat_ui["Chat Interface<br/>[chat-window.tsx]"]
  node_chat_actions["Chat Actions<br/>[actions.ts]"]
  node_session_ui["Session Manager UI"]
end

subgraph group_gateway["Gateway API"]
  node_rest_api["REST API"]
  node_mcp_api["MCP API"]
  node_webhook_api["Webhook API<br/>[route.ts]"]
end

subgraph group_messaging["WhatsApp Runtime"]
  node_wa_manager["Session Manager<br/>[manager.ts]"]
  node_wa_instance["WhatsApp Instance<br/>[instance.ts]"]
  node_chat_service["Chat Service<br/>[chat.service.ts]"]
  node_contacts["Contact Management<br/>[contacts.ts]"]
  node_stickers["Sticker Tools<br/>[route.ts]"]
end

subgraph group_automation["Automation Integrations"]
  node_mcp_runtime["MCP Integration<br/>[mcp.ts]"]
  node_scheduler["Message Scheduler<br/>[scheduler.ts]"]
  node_broadcast["Auto Broadcast<br/>[auto-broadcast.ts]"]
  node_autoreplies["Auto Replies<br/>[autoreply.ts]"]
  node_bot_commands["Bot Commands<br/>[command-handler.ts]"]
  node_webhooks["Webhook Delivery<br/>[webhook.ts]"]
end

subgraph group_platform["Platform Services"]
  node_auth_api["API Authorization<br/>[api-auth.ts]"]
  node_database[("Prisma Database<br/>[prisma.ts]")]
  node_quota["Plan &amp; Quota<br/>[rate-limit.ts]"]
  node_auth["Web Authentication<br/>[auth.ts]"]
  node_server["HTTP / Socket Server<br/>[index.ts]"]
  node_socket_client["Socket Client<br/>[socket-client.ts]"]
end

node_user(("User / App"))
node_whatsapp(("WhatsApp"))
node_external_webhook(("External CRM / API"))

node_user -->|"uses"| node_dashboard
node_user -->|"calls REST"| node_rest_api
node_dashboard -.->|"opens chat"| node_chat_ui
node_chat_ui -->|"uses actions"| node_chat_actions
node_session_ui -->|"creates socket"| node_socket_client
node_rest_api -->|"authorizes requests"| node_auth_api
node_auth_api -->|"checks session"| node_auth
node_auth_api -->|"reads access"| node_database
node_rest_api -->|"reads and writes"| node_database
node_rest_api -->|"enforces quota"| node_quota
node_rest_api -->|"dispatches WhatsApp"| node_wa_manager
node_rest_api -->|"uses Baileys"| node_whatsapp
node_wa_manager -->|"creates instances"| node_wa_instance
node_wa_manager -->|"persists sessions"| node_database
node_wa_instance -->|"connects"| node_whatsapp
node_chat_actions -.->|"delegates chat"| node_chat_service
node_chat_service -->|"gets instance"| node_wa_manager
node_mcp_api -->|"routes messages"| node_mcp_runtime
node_scheduler -.->|"scheduled dispatch"| node_wa_manager
node_broadcast -.->|"broadcast dispatch"| node_wa_manager
node_autoreplies -.->|"replies automatically"| node_whatsapp
node_bot_commands -.->|"handles commands"| node_whatsapp
node_webhook_api -->|"stores registrations"| node_database
node_webhooks -->|"forwards events"| node_external_webhook
node_whatsapp -->|"sends events"| node_webhooks
node_contacts -.->|"stores contacts"| node_database
node_stickers -.->|"sends stickers"| node_whatsapp
node_server -->|"initializes sessions"| node_wa_manager
node_server -->|"starts scheduler"| node_scheduler
node_server -->|"starts broadcast"| node_broadcast
node_socket_client -.->|"connects realtime"| node_server
node_wa_manager -->|"loads sessions"| node_database

click node_dashboard "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/dashboard"
click node_chat_ui "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/components/chat/chat-window.tsx"
click node_chat_actions "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/app/dashboard/chat/actions.ts"
click node_session_ui "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/components/dashboard/session-manager.tsx"
click node_rest_api "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/api"
click node_auth_api "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/api-auth.ts"
click node_mcp_api "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/mcp"
click node_mcp_runtime "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/mcp.ts"
click node_wa_manager "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/manager.ts"
click node_wa_instance "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/instance.ts"
click node_chat_service "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/chat.service.ts"
click node_scheduler "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/scheduler.ts"
click node_broadcast "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/auto-broadcast.ts"
click node_autoreplies "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/store/autoreply.ts"
click node_bot_commands "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/bot/command-handler.ts"
click node_webhooks "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/webhook.ts"
click node_webhook_api "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/app/api/webhooks/route.ts"
click node_contacts "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/store/contacts.ts"
click node_stickers "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/app/api/messages/%5BsessionId%5D/%5Bjid%5D/sticker/route.ts"
click node_database "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/prisma.ts"
click node_quota "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/rate-limit.ts"
click node_auth "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/auth.ts"
click node_server "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/server/index.ts"
click node_socket_client "https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/socket-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_dashboard,node_chat_ui,node_chat_actions,node_session_ui,node_user toneBlue
class node_rest_api,node_mcp_api,node_webhook_api toneAmber
class node_wa_manager,node_wa_instance,node_chat_service,node_contacts,node_stickers,node_external_webhook toneMint
class node_mcp_runtime,node_scheduler,node_broadcast,node_autoreplies,node_bot_commands,node_webhooks toneRose
class node_auth_api,node_database,node_quota,node_auth,node_server,node_socket_client,node_whatsapp toneIndigo
```

## Components

### Dashboard Experience

- [Dashboard](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/dashboard): `src/app/dashboard`
- [Chat Interface](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/components/chat/chat-window.tsx): `src/components/chat/chat-window.tsx`
- [Chat Actions](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/app/dashboard/chat/actions.ts): `src/app/dashboard/chat/actions.ts`
- [Session Manager UI](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/components/dashboard/session-manager.tsx): `src/components/dashboard/session-manager.tsx`

### Gateway API

- [REST API](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/api): `src/app/api`
- [MCP API](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/tree/main/src/app/mcp): `src/app/mcp`
- [Webhook API](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/app/api/webhooks/route.ts): `src/app/api/webhooks/route.ts`

### WhatsApp Runtime

- [Session Manager](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/manager.ts): `src/modules/whatsapp/manager.ts`
- [WhatsApp Instance](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/instance.ts): `src/modules/whatsapp/instance.ts`
- [Chat Service](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/chat.service.ts): `src/modules/whatsapp/chat.service.ts`
- [Contact Management](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/store/contacts.ts): `src/modules/whatsapp/store/contacts.ts`
- [Sticker Tools](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/app/api/messages/%5BsessionId%5D/%5Bjid%5D/sticker/route.ts): `src/app/api/messages/[sessionId]/[jid]/sticker/route.ts`

### Automation Integrations

- [MCP Integration](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/mcp.ts): `src/lib/mcp.ts`
- [Message Scheduler](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/scheduler.ts): `src/modules/whatsapp/scheduler.ts`
- [Auto Broadcast](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/auto-broadcast.ts): `src/modules/whatsapp/auto-broadcast.ts`
- [Auto Replies](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/store/autoreply.ts): `src/modules/whatsapp/store/autoreply.ts`
- [Bot Commands](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/modules/whatsapp/bot/command-handler.ts): `src/modules/whatsapp/bot/command-handler.ts`
- [Webhook Delivery](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/webhook.ts): `src/lib/webhook.ts`

### Platform Services

- [API Authorization](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/api-auth.ts): `src/lib/api-auth.ts`
- [Prisma Database](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`
- [Plan & Quota](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/rate-limit.ts): `src/lib/rate-limit.ts`
- [Web Authentication](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [HTTP / Socket Server](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/server/index.ts): `src/server/index.ts`
- [Socket Client](https://github.com/toshniwalpranav/whatsgateway-typescript-nextjs/blob/main/src/lib/socket-client.ts): `src/lib/socket-client.ts`

### Other components

- **User / App**
- **WhatsApp**
- **External CRM / API**

## Connections

- User / App → Dashboard: uses (evidence: `README.md`)
- User / App → REST API: calls REST (evidence: `README.md`)
- Dashboard → Chat Interface: opens chat (evidence: `src/components/chat/chat-window.tsx`)
- Chat Interface → Chat Actions: uses actions (evidence: `src/components/chat/chat-window.tsx`)
- Session Manager UI → Socket Client: creates socket (evidence: `src/components/dashboard/session-manager.tsx`)
- REST API → API Authorization: authorizes requests (evidence: `src/app/api/media/route.ts`)
- API Authorization → Web Authentication: checks session (evidence: `src/lib/api-auth.ts`)
- API Authorization → Prisma Database: reads access (evidence: `src/lib/api-auth.ts`)
- REST API → Prisma Database: reads and writes (evidence: `src/app/api/media/route.ts`)
- REST API → Plan & Quota: enforces quota (evidence: `src/app/api/jpm-swgc/[sessionId]/route.ts`)
- REST API → Session Manager: dispatches WhatsApp (evidence: `src/app/api/jpm-swgc/[sessionId]/route.ts`)
- REST API → WhatsApp: uses Baileys (evidence: `README.md`)
- Session Manager → WhatsApp Instance: creates instances (evidence: `src/modules/whatsapp/manager.ts`)
- Session Manager → Prisma Database: persists sessions (evidence: `src/modules/whatsapp/manager.ts`)
- WhatsApp Instance → WhatsApp: connects (evidence: `README.md`)
- Chat Actions → Chat Service: delegates chat
- Chat Service → Session Manager: gets instance (evidence: `src/modules/whatsapp/chat.service.ts`)
- MCP API → MCP Integration: routes messages (evidence: `src/app/mcp/route.ts`)
- Message Scheduler → Session Manager: scheduled dispatch
- Auto Broadcast → Session Manager: broadcast dispatch
- Auto Replies → WhatsApp: replies automatically
- Bot Commands → WhatsApp: handles commands
- Webhook API → Prisma Database: stores registrations (evidence: `src/app/api/webhooks/route.ts`)
- Webhook Delivery → External CRM / API: forwards events (evidence: `README.md`)
- WhatsApp → Webhook Delivery: sends events (evidence: `README.md`)
- Contact Management → Prisma Database: stores contacts
- Sticker Tools → WhatsApp: sends stickers
- HTTP / Socket Server → Session Manager: initializes sessions (evidence: `src/server/index.ts`)
- HTTP / Socket Server → Message Scheduler: starts scheduler (evidence: `src/server/index.ts`)
- HTTP / Socket Server → Auto Broadcast: starts broadcast (evidence: `src/server/index.ts`)
- Socket Client → HTTP / Socket Server: connects realtime
- Session Manager → Prisma Database: loads sessions (evidence: `src/modules/whatsapp/manager.ts`)
