# rausahankumar/tally-talk architecture

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

- Interactive diagram: https://gitdiagram.com/rausahankumar/tally-talk
- Repository: https://github.com/rausahankumar/tally-talk

## Overview

TallyTalk turns Telegram transaction descriptions into validated, user-confirmed TallyPrime vouchers. The main path is webhook security and parsing, AI extraction, deterministic draft validation and clarification, GST and posting-readiness checks, preview and explicit confirmation, then deterministic voucher posting. Separately, a manual/startup master-data sync populates the cache used by verification. SQLite also stores conversation state and an append-only audit log. The map follows documented behavior and shown imports; some sync and callback internals were not excerpted, so uncertain links are omitted.

Main entry points: [`src/conversation/handleMessage.js`](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/handleMessage.js) (Message workflow), [`src/channels/telegram/webhook.js`](https://github.com/rausahankumar/tally-talk/blob/main/src/channels/telegram/webhook.js) (Webhook security and routing), [`src/conversation/handleCallback.js`](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/handleCallback.js) (Confirm and cancel), [`src/server.js`](https://github.com/rausahankumar/tally-talk/blob/main/src/server.js) (Server wiring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application and channel"]
  node_server["Server wiring<br/>[server.js]"]
  node_app["HTTP application<br/>[app.js]"]
  node_webhook["Webhook security and routing<br/>[webhook.js]"]
  node_telegram_client["Telegram client<br/>[client.js]"]
end

subgraph group_conversation["Conversation workflow"]
  node_llm["Draft extraction<br/>[client.js]"]
  node_message_handler["Message workflow<br/>[handleMessage.js]"]
  node_clarification["Clarification<br/>[clarification.js]"]
  node_messages["Preview and replies<br/>[messages.js]"]
  node_callback["Confirm and cancel<br/>[handleCallback.js]"]
end

subgraph group_verification["Verification and GST"]
  node_validation["Draft validation<br/>[validateDraft.js]"]
  node_refresh["Refresh and resolution"]
  node_readiness["GST and posting readiness"]
  node_gst_rules["GST treatment and states<br/>[treatment.js]"]
end

subgraph group_tally["Tally integration"]
  node_sync["Master-data synchronization<br/>[fullSync.js]"]
  node_tally_client["Tally XML client<br/>[client.js]"]
  node_master_cache[("Master cache<br/>[cache.js]")]
  node_posting["Voucher posting<br/>[posting.js]"]
  node_voucher_xml["Voucher XML generation<br/>[postingXml.js]"]
end

subgraph group_state["Persistence and audit"]
  node_database[("SQLite schema and stores<br/>[schema.js]")]
  node_conversation_store[("Conversation state<br/>[store.js]")]
  node_audit[("Append-only audit log<br/>[log.js]")]
end

node_operator(("Telegram user"))
node_telegram(("Telegram service"))
node_tally_service(("TallyPrime"))

node_operator -->|"sends update"| node_telegram
node_telegram -->|"delivers update"| node_webhook
node_webhook -->|"routes text"| node_message_handler
node_webhook -->|"routes callback"| node_callback
node_message_handler -->|"extracts draft"| node_llm
node_message_handler -->|"resolves draft"| node_refresh
node_refresh -->|"validates draft"| node_validation
node_refresh -->|"checks readiness"| node_readiness
node_readiness -->|"determines treatment"| node_gst_rules
node_readiness -->|"reads masters"| node_master_cache
node_message_handler -->|"resolves replies"| node_clarification
node_message_handler -->|"builds responses"| node_messages
node_message_handler -->|"stores draft"| node_conversation_store
node_message_handler -->|"sends replies"| node_telegram_client
node_callback -->|"posts confirmed voucher"| node_posting
node_callback -->|"builds outcome"| node_messages
node_callback -->|"sends outcome"| node_telegram_client
node_posting -->|"generates XML"| node_voucher_xml
node_posting -->|"imports voucher"| node_tally_service
node_sync -->|"requests masters"| node_tally_client
node_sync -->|"replaces cached masters"| node_master_cache
node_tally_client -->|"sends XML requests"| node_tally_service
node_server -->|"runs startup sync"| node_sync
node_server -->|"creates application"| node_app
node_app -->|"mounts route"| node_webhook
node_server -->|"opens database"| node_database
node_conversation_store -->|"uses schema"| node_database
node_audit -->|"uses schema"| node_database
node_webhook -->|"records events"| node_audit

click node_server "https://github.com/rausahankumar/tally-talk/blob/main/src/server.js"
click node_app "https://github.com/rausahankumar/tally-talk/blob/main/src/app.js"
click node_webhook "https://github.com/rausahankumar/tally-talk/blob/main/src/channels/telegram/webhook.js"
click node_telegram_client "https://github.com/rausahankumar/tally-talk/blob/main/src/channels/telegram/client.js"
click node_llm "https://github.com/rausahankumar/tally-talk/blob/main/src/llm/client.js"
click node_message_handler "https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/handleMessage.js"
click node_clarification "https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/clarification.js"
click node_messages "https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/messages.js"
click node_callback "https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/handleCallback.js"
click node_validation "https://github.com/rausahankumar/tally-talk/blob/main/src/validation/validateDraft.js"
click node_refresh "https://github.com/rausahankumar/tally-talk/blob/main/src/tally/masterResolutionRefresh.js"
click node_readiness "https://github.com/rausahankumar/tally-talk/blob/main/src/gst/postingReadiness.js"
click node_gst_rules "https://github.com/rausahankumar/tally-talk/blob/main/src/gst/treatment.js"
click node_sync "https://github.com/rausahankumar/tally-talk/blob/main/src/tally/fullSync.js"
click node_tally_client "https://github.com/rausahankumar/tally-talk/blob/main/src/tally/client.js"
click node_master_cache "https://github.com/rausahankumar/tally-talk/blob/main/src/tally/cache.js"
click node_posting "https://github.com/rausahankumar/tally-talk/blob/main/src/tally/posting.js"
click node_voucher_xml "https://github.com/rausahankumar/tally-talk/blob/main/src/tally/postingXml.js"
click node_database "https://github.com/rausahankumar/tally-talk/blob/main/src/db/schema.js"
click node_conversation_store "https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/store.js"
click node_audit "https://github.com/rausahankumar/tally-talk/blob/main/src/audit/log.js"

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_server,node_app,node_webhook,node_telegram_client,node_operator toneBlue
class node_llm,node_message_handler,node_clarification,node_messages,node_callback toneAmber
class node_validation,node_refresh,node_readiness,node_gst_rules toneMint
class node_sync,node_tally_client,node_master_cache,node_posting,node_voucher_xml toneRose
class node_database,node_conversation_store,node_audit,node_telegram,node_tally_service toneIndigo
```

## Components

### Application and channel

- [Server wiring](https://github.com/rausahankumar/tally-talk/blob/main/src/server.js): `src/server.js`
- [HTTP application](https://github.com/rausahankumar/tally-talk/blob/main/src/app.js): `src/app.js`
- [Webhook security and routing](https://github.com/rausahankumar/tally-talk/blob/main/src/channels/telegram/webhook.js): `src/channels/telegram/webhook.js`
- [Telegram client](https://github.com/rausahankumar/tally-talk/blob/main/src/channels/telegram/client.js): `src/channels/telegram/client.js`

### Conversation workflow

- [Draft extraction](https://github.com/rausahankumar/tally-talk/blob/main/src/llm/client.js): `src/llm/client.js`
- [Message workflow](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/handleMessage.js): `src/conversation/handleMessage.js`
- [Clarification](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/clarification.js): `src/conversation/clarification.js`
- [Preview and replies](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/messages.js): `src/conversation/messages.js`
- [Confirm and cancel](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/handleCallback.js): `src/conversation/handleCallback.js`

### Verification and GST

- [Draft validation](https://github.com/rausahankumar/tally-talk/blob/main/src/validation/validateDraft.js): `src/validation/validateDraft.js`
- [Refresh and resolution](https://github.com/rausahankumar/tally-talk/blob/main/src/tally/masterResolutionRefresh.js): `src/tally/masterResolutionRefresh.js`
- [GST and posting readiness](https://github.com/rausahankumar/tally-talk/blob/main/src/gst/postingReadiness.js): `src/gst/postingReadiness.js`
- [GST treatment and states](https://github.com/rausahankumar/tally-talk/blob/main/src/gst/treatment.js): `src/gst/treatment.js`

### Tally integration

- [Master-data synchronization](https://github.com/rausahankumar/tally-talk/blob/main/src/tally/fullSync.js): `src/tally/fullSync.js`
- [Tally XML client](https://github.com/rausahankumar/tally-talk/blob/main/src/tally/client.js): `src/tally/client.js`
- [Master cache](https://github.com/rausahankumar/tally-talk/blob/main/src/tally/cache.js): `src/tally/cache.js`
- [Voucher posting](https://github.com/rausahankumar/tally-talk/blob/main/src/tally/posting.js): `src/tally/posting.js`
- [Voucher XML generation](https://github.com/rausahankumar/tally-talk/blob/main/src/tally/postingXml.js): `src/tally/postingXml.js`

### Persistence and audit

- [SQLite schema and stores](https://github.com/rausahankumar/tally-talk/blob/main/src/db/schema.js): `src/db/schema.js`
- [Conversation state](https://github.com/rausahankumar/tally-talk/blob/main/src/conversation/store.js): `src/conversation/store.js`
- [Append-only audit log](https://github.com/rausahankumar/tally-talk/blob/main/src/audit/log.js): `src/audit/log.js`

### Other components

- **Telegram user**
- **Telegram service**
- **TallyPrime**

## Connections

- Telegram user → Telegram service: sends update (evidence: `README.md`)
- Telegram service → Webhook security and routing: delivers update (evidence: `README.md`)
- Webhook security and routing → Message workflow: routes text (evidence: `src/channels/telegram/webhook.js`)
- Webhook security and routing → Confirm and cancel: routes callback (evidence: `src/channels/telegram/webhook.js`)
- Message workflow → Draft extraction: extracts draft (evidence: `src/conversation/handleMessage.js`)
- Message workflow → Refresh and resolution: resolves draft (evidence: `src/conversation/handleMessage.js`)
- Refresh and resolution → Draft validation: validates draft (evidence: `src/tally/masterResolutionRefresh.js`)
- Refresh and resolution → GST and posting readiness: checks readiness (evidence: `src/tally/masterResolutionRefresh.js`)
- GST and posting readiness → GST treatment and states: determines treatment (evidence: `src/gst/postingReadiness.js`)
- GST and posting readiness → Master cache: reads masters (evidence: `src/gst/postingReadiness.js`)
- Message workflow → Clarification: resolves replies (evidence: `src/conversation/handleMessage.js`)
- Message workflow → Preview and replies: builds responses (evidence: `src/conversation/handleMessage.js`)
- Message workflow → Conversation state: stores draft (evidence: `src/conversation/handleMessage.js`)
- Message workflow → Telegram client: sends replies
- Confirm and cancel → Voucher posting: posts confirmed voucher (evidence: `src/conversation/handleCallback.js`)
- Confirm and cancel → Preview and replies: builds outcome (evidence: `src/conversation/handleCallback.js`)
- Confirm and cancel → Telegram client: sends outcome (evidence: `src/conversation/handleCallback.js`)
- Voucher posting → Voucher XML generation: generates XML (evidence: `src/tally/posting.js`)
- Voucher posting → TallyPrime: imports voucher (evidence: `README.md`)
- Master-data synchronization → Tally XML client: requests masters (evidence: `src/tally/fullSync.js`)
- Master-data synchronization → Master cache: replaces cached masters (evidence: `src/tally/fullSync.js`)
- Tally XML client → TallyPrime: sends XML requests (evidence: `src/tally/client.js`)
- Server wiring → Master-data synchronization: runs startup sync (evidence: `src/server.js`)
- Server wiring → HTTP application: creates application (evidence: `src/server.js`)
- HTTP application → Webhook security and routing: mounts route (evidence: `src/app.js`)
- Server wiring → SQLite schema and stores: opens database (evidence: `src/server.js`)
- Conversation state → SQLite schema and stores: uses schema (evidence: `src/conversation/store.js`)
- Append-only audit log → SQLite schema and stores: uses schema (evidence: `src/audit/log.js`)
- Webhook security and routing → Append-only audit log: records events (evidence: `src/channels/telegram/webhook.js`)
