# stormhaha/green-api-chat architecture

> Architecture diagram of the GitHub repository stormhaha/green-api-chat, 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/stormhaha/green-api-chat
- Repository: https://github.com/stormhaha/green-api-chat

## Overview

GREEN-API Chat is a browser messenger for Telegram: users authenticate an instance, create or select a chat, send text, and receive polled notifications. The app layer coordinates login and the messenger; chat actions resolve recipients, dispatch messages and notifications into reducer state, and persist per-instance history locally. The README also documents exclusive-tab handling, retry/status, unread counts, and incoming chats. Links follow explicit README or indexed source references; unsampled reducer and UI behavior is not expanded beyond those references.

Main entry points: [`src/hooks/useChats.ts`](https://github.com/stormhaha/green-api-chat/blob/main/src/hooks/useChats.ts) (Chat actions), [`src/components/Messenger/Messenger.tsx`](https://github.com/stormhaha/green-api-chat/blob/main/src/components/Messenger/Messenger.tsx) (Messenger shell), [`src/App.tsx`](https://github.com/stormhaha/green-api-chat/blob/main/src/App.tsx) (App coordinator), [`src/components/Sidebar/Sidebar.tsx`](https://github.com/stormhaha/green-api-chat/blob/main/src/components/Sidebar/Sidebar.tsx) (Chat list)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App and access"]
  node_app["App coordinator<br/>[App.tsx]"]
  node_login["Instance login<br/>[LoginScreen.tsx]"]
  node_tabguard["Exclusive tab guard<br/>[TabGuard.tsx]"]
end

subgraph group_experience["Chat interface"]
  node_messenger["Messenger shell<br/>[Messenger.tsx]"]
  node_sidebar["Chat list<br/>[Sidebar.tsx]"]
  node_newchat["New chat dialog<br/>[NewChatDialog.tsx]"]
  node_chatview["Conversation view<br/>[ChatView.tsx]"]
  node_composer["Message composer<br/>[Composer.tsx]"]
  node_messagelist["Message timeline<br/>[MessageList.tsx]"]
  node_bubble["Message rendering<br/>[MessageBubble.tsx]"]
end

subgraph group_workflow["Messaging workflow"]
  node_chatactions["Chat actions<br/>[useChats.ts]"]
  node_polling["Notification polling"]
  node_phone["Phone normalization<br/>[phone.ts]"]
  node_notificationparse["Notification parsing<br/>[notifications.ts]"]
  node_domainchat["Chat domain helpers<br/>[chat.ts]"]
end

subgraph group_state["Chat state"]
  node_reducer["Chat reducer<br/>[chatReducer.ts]"]
  node_selectors["Chat selectors<br/>[selectors.ts]"]
  node_storage[("Local persistence<br/>[storage.ts]")]
end

subgraph group_integration["GREEN-API integration"]
  node_api["GREEN-API client<br/>[greenApi.ts]"]
end

node_user(("Messenger user"))
node_greenapi["GREEN-API service"]

node_user -->|"opens app"| node_app
node_app -->|"shows when logged out"| node_login
node_app -->|"loads and saves credentials"| node_storage
node_login -->|"checks instance"| node_api
node_login -->|"submits credentials"| node_app
node_app -->|"wraps authenticated view"| node_tabguard
node_tabguard -->|"hosts when active"| node_messenger
node_tabguard -->|"offers tab takeover"| node_user
node_messenger -->|"uses chat actions"| node_chatactions
node_messenger -->|"starts polling"| node_polling
node_messenger -->|"renders chat list"| node_sidebar
node_messenger -->|"renders conversation"| node_chatview
node_sidebar -->|"opens dialog"| node_newchat
node_sidebar -->|"sorts chats"| node_selectors
node_newchat -->|"normalizes recipient"| node_phone
node_chatview -->|"renders composer"| node_composer
node_chatview -->|"renders timeline"| node_messagelist
node_messagelist -->|"renders messages"| node_bubble
node_chatview -->|"uses chat helpers"| node_domainchat
node_composer -->|"submits message"| node_chatactions
node_newchat -->|"requests chat creation"| node_chatactions
node_chatactions -->|"formats fallback chat ID"| node_phone
node_chatactions -->|"checks and sends"| node_api
node_polling -->|"receives and deletes"| node_api
node_polling -->|"delivers notifications"| node_chatactions
node_chatactions -->|"parses notification"| node_notificationparse
node_chatactions -->|"dispatches chat events"| node_reducer
node_chatactions -->|"loads and persists state"| node_storage
node_sidebar -->|"reads chat ordering"| node_selectors
node_api -->|"calls HTTP API"| node_greenapi
node_storage -->|"retains local history"| node_user
node_reducer -.->|"provides chat state"| node_selectors

click node_app "https://github.com/stormhaha/green-api-chat/blob/main/src/App.tsx"
click node_login "https://github.com/stormhaha/green-api-chat/blob/main/src/components/LoginScreen/LoginScreen.tsx"
click node_tabguard "https://github.com/stormhaha/green-api-chat/blob/main/src/components/TabGuard/TabGuard.tsx"
click node_messenger "https://github.com/stormhaha/green-api-chat/blob/main/src/components/Messenger/Messenger.tsx"
click node_sidebar "https://github.com/stormhaha/green-api-chat/blob/main/src/components/Sidebar/Sidebar.tsx"
click node_newchat "https://github.com/stormhaha/green-api-chat/blob/main/src/components/NewChatDialog/NewChatDialog.tsx"
click node_chatview "https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/ChatView.tsx"
click node_composer "https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/Composer.tsx"
click node_messagelist "https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/MessageList.tsx"
click node_bubble "https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/MessageBubble.tsx"
click node_chatactions "https://github.com/stormhaha/green-api-chat/blob/main/src/hooks/useChats.ts"
click node_polling "https://github.com/stormhaha/green-api-chat/blob/main/src/hooks/useNotificationPolling.ts"
click node_phone "https://github.com/stormhaha/green-api-chat/blob/main/src/domain/phone.ts"
click node_notificationparse "https://github.com/stormhaha/green-api-chat/blob/main/src/domain/notifications.ts"
click node_domainchat "https://github.com/stormhaha/green-api-chat/blob/main/src/domain/chat.ts"
click node_reducer "https://github.com/stormhaha/green-api-chat/blob/main/src/state/chatReducer.ts"
click node_selectors "https://github.com/stormhaha/green-api-chat/blob/main/src/state/selectors.ts"
click node_storage "https://github.com/stormhaha/green-api-chat/blob/main/src/state/storage.ts"
click node_api "https://github.com/stormhaha/green-api-chat/blob/main/src/api/greenApi.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_app,node_login,node_tabguard,node_user toneBlue
class node_messenger,node_sidebar,node_newchat,node_chatview,node_composer,node_messagelist,node_bubble toneAmber
class node_chatactions,node_polling,node_phone,node_notificationparse,node_domainchat,node_greenapi toneMint
class node_reducer,node_selectors,node_storage toneRose
class node_api toneIndigo
```

## Components

### App and access

- [App coordinator](https://github.com/stormhaha/green-api-chat/blob/main/src/App.tsx): `src/App.tsx`
- [Instance login](https://github.com/stormhaha/green-api-chat/blob/main/src/components/LoginScreen/LoginScreen.tsx): `src/components/LoginScreen/LoginScreen.tsx`
- [Exclusive tab guard](https://github.com/stormhaha/green-api-chat/blob/main/src/components/TabGuard/TabGuard.tsx): `src/components/TabGuard/TabGuard.tsx`

### Chat interface

- [Messenger shell](https://github.com/stormhaha/green-api-chat/blob/main/src/components/Messenger/Messenger.tsx): `src/components/Messenger/Messenger.tsx`
- [Chat list](https://github.com/stormhaha/green-api-chat/blob/main/src/components/Sidebar/Sidebar.tsx): `src/components/Sidebar/Sidebar.tsx`
- [New chat dialog](https://github.com/stormhaha/green-api-chat/blob/main/src/components/NewChatDialog/NewChatDialog.tsx): `src/components/NewChatDialog/NewChatDialog.tsx`
- [Conversation view](https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/ChatView.tsx): `src/components/ChatView/ChatView.tsx`
- [Message composer](https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/Composer.tsx): `src/components/ChatView/Composer.tsx`
- [Message timeline](https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/MessageList.tsx): `src/components/ChatView/MessageList.tsx`
- [Message rendering](https://github.com/stormhaha/green-api-chat/blob/main/src/components/ChatView/MessageBubble.tsx): `src/components/ChatView/MessageBubble.tsx`

### Messaging workflow

- [Chat actions](https://github.com/stormhaha/green-api-chat/blob/main/src/hooks/useChats.ts): `src/hooks/useChats.ts`
- [Notification polling](https://github.com/stormhaha/green-api-chat/blob/main/src/hooks/useNotificationPolling.ts): `src/hooks/useNotificationPolling.ts`
- [Phone normalization](https://github.com/stormhaha/green-api-chat/blob/main/src/domain/phone.ts): `src/domain/phone.ts`
- [Notification parsing](https://github.com/stormhaha/green-api-chat/blob/main/src/domain/notifications.ts): `src/domain/notifications.ts`
- [Chat domain helpers](https://github.com/stormhaha/green-api-chat/blob/main/src/domain/chat.ts): `src/domain/chat.ts`

### Chat state

- [Chat reducer](https://github.com/stormhaha/green-api-chat/blob/main/src/state/chatReducer.ts): `src/state/chatReducer.ts`
- [Chat selectors](https://github.com/stormhaha/green-api-chat/blob/main/src/state/selectors.ts): `src/state/selectors.ts`
- [Local persistence](https://github.com/stormhaha/green-api-chat/blob/main/src/state/storage.ts): `src/state/storage.ts`

### GREEN-API integration

- [GREEN-API client](https://github.com/stormhaha/green-api-chat/blob/main/src/api/greenApi.ts): `src/api/greenApi.ts`

### Other components

- **Messenger user**
- **GREEN-API service**

## Connections

- Messenger user → App coordinator: opens app (evidence: `src/App.tsx`)
- App coordinator → Instance login: shows when logged out (evidence: `src/App.tsx`)
- App coordinator → Local persistence: loads and saves credentials (evidence: `src/App.tsx`)
- Instance login → GREEN-API client: checks instance (evidence: `src/components/LoginScreen/LoginScreen.tsx`)
- Instance login → App coordinator: submits credentials (evidence: `src/components/LoginScreen/LoginScreen.tsx`)
- App coordinator → Exclusive tab guard: wraps authenticated view (evidence: `src/App.tsx`)
- Exclusive tab guard → Messenger shell: hosts when active (evidence: `src/App.tsx`)
- Exclusive tab guard → Messenger user: offers tab takeover (evidence: `README.md`)
- Messenger shell → Chat actions: uses chat actions (evidence: `src/components/Messenger/Messenger.tsx`)
- Messenger shell → Notification polling: starts polling (evidence: `src/components/Messenger/Messenger.tsx`)
- Messenger shell → Chat list: renders chat list (evidence: `src/components/Messenger/Messenger.tsx`)
- Messenger shell → Conversation view: renders conversation (evidence: `src/components/Messenger/Messenger.tsx`)
- Chat list → New chat dialog: opens dialog (evidence: `src/components/Sidebar/Sidebar.tsx`)
- Chat list → Chat selectors: sorts chats (evidence: `src/components/Sidebar/Sidebar.tsx`)
- New chat dialog → Phone normalization: normalizes recipient (evidence: `src/components/NewChatDialog/NewChatDialog.tsx`)
- Conversation view → Message composer: renders composer (evidence: `src/components/ChatView/ChatView.tsx`)
- Conversation view → Message timeline: renders timeline (evidence: `src/components/ChatView/ChatView.tsx`)
- Message timeline → Message rendering: renders messages (evidence: `src/components/ChatView/MessageList.tsx`)
- Conversation view → Chat domain helpers: uses chat helpers (evidence: `src/components/ChatView/ChatView.tsx`)
- Message composer → Chat actions: submits message
- New chat dialog → Chat actions: requests chat creation
- Chat actions → Phone normalization: formats fallback chat ID (evidence: `src/hooks/useChats.ts`)
- Chat actions → GREEN-API client: checks and sends (evidence: `src/hooks/useChats.ts`)
- Notification polling → GREEN-API client: receives and deletes (evidence: `src/hooks/useNotificationPolling.ts`)
- Notification polling → Chat actions: delivers notifications (evidence: `src/components/Messenger/Messenger.tsx`)
- Chat actions → Notification parsing: parses notification (evidence: `src/hooks/useChats.ts`)
- Chat actions → Chat reducer: dispatches chat events (evidence: `src/hooks/useChats.ts`)
- Chat actions → Local persistence: loads and persists state (evidence: `src/hooks/useChats.ts`)
- Chat list → Chat selectors: reads chat ordering (evidence: `src/components/Sidebar/Sidebar.tsx`)
- GREEN-API client → GREEN-API service: calls HTTP API (evidence: `README.md`)
- Local persistence → Messenger user: retains local history (evidence: `README.md`)
- Chat reducer → Chat selectors: provides chat state
