# mkcodec/mwsm architecture

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

- Interactive diagram: https://gitdiagram.com/mkcodec/mwsm
- Repository: https://github.com/mkcodec/mwsm

## Overview

Mwsm is a Node.js API that connects MkAuth billing/customer workflows with WhatsApp messaging. Its documented product workflow is MkAuth integration and billing synchronization followed by automated customer communications; the sampled code also shows webhook handling, scheduling records, message/document endpoints, and PDF generation. The main implementation is concentrated in mwsm.js, so several domain stages share that path. Evidence is partial: unsampled queue, dashboard, gateway-specific, and other integrations are not expanded into speculative call chains.

Main entry points: [`mwsm.js`](https://github.com/mkcodec/mwsm/blob/main/mwsm.js) (HTTP API), [`mwsm.db`](https://github.com/mkcodec/mwsm/blob/main/mwsm.db) (SQLite State), [`mwsm.py`](https://github.com/mkcodec/mwsm/blob/main/mwsm.py) (Embedding Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["MkAuth Integration"]
  node_mkauth{{"MkAuth API"}}
  node_webhook["Webhook Intake<br/>[mwsm.js]"]
  node_billing["Billing Sync<br/>[mwsm.js]"]
  node_scheduling["Message Scheduling<br/>[mwsm.js]"]
end

subgraph group_messaging["WhatsApp Messaging"]
  node_api["HTTP API<br/>[mwsm.js]"]
  node_whatsapp{{"WhatsApp Web"}}
  node_document["Document Delivery<br/>[mwsm.js]"]
  node_pdf["PDF Generation<br/>[mwsm.js]"]
end

subgraph group_operations["Service Operations"]
  node_dashboard["Web Dashboard<br/>[index.html]"]
  node_realtime["Realtime Events<br/>[mwsm.js]"]
end

subgraph group_persistence["State and Embeddings"]
  node_sqlite[("SQLite State<br/>[mwsm.db]")]
  node_embedding["Embedding Service<br/>[mwsm.py]"]
end

node_mkauth -->|"posts events"| node_webhook
node_billing -->|"fetches billing data"| node_mkauth
node_api -.->|"sends messages"| node_whatsapp
node_api -->|"handles documents"| node_document
node_api -->|"serves build route"| node_pdf
node_webhook -->|"stores scheduling data"| node_sqlite
node_scheduling -->|"reads and writes"| node_sqlite
node_api -->|"updates settings"| node_sqlite
node_api -->|"emits events"| node_realtime
node_api -.->|"requests embeddings"| node_embedding

click node_webhook "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_billing "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_scheduling "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_api "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_document "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_pdf "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_dashboard "https://github.com/mkcodec/mwsm/blob/main/index.html"
click node_realtime "https://github.com/mkcodec/mwsm/blob/main/mwsm.js"
click node_sqlite "https://github.com/mkcodec/mwsm/blob/main/mwsm.db"
click node_embedding "https://github.com/mkcodec/mwsm/blob/main/mwsm.py"

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_mkauth,node_webhook,node_billing,node_scheduling toneBlue
class node_api,node_whatsapp,node_document,node_pdf toneAmber
class node_dashboard,node_realtime toneMint
class node_sqlite,node_embedding toneRose
```

## Components

### MkAuth Integration

- **MkAuth API**
- [Webhook Intake](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`
- [Billing Sync](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`
- [Message Scheduling](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`

### WhatsApp Messaging

- [HTTP API](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`
- **WhatsApp Web**
- [Document Delivery](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`
- [PDF Generation](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`

### Service Operations

- [Web Dashboard](https://github.com/mkcodec/mwsm/blob/main/index.html): `index.html`
- [Realtime Events](https://github.com/mkcodec/mwsm/blob/main/mwsm.js): `mwsm.js`

### State and Embeddings

- [SQLite State](https://github.com/mkcodec/mwsm/blob/main/mwsm.db): `mwsm.db`
- [Embedding Service](https://github.com/mkcodec/mwsm/blob/main/mwsm.py): `mwsm.py`

## Connections

- MkAuth API → Webhook Intake: posts events (evidence: `mwsm.js`)
- Billing Sync → MkAuth API: fetches billing data (evidence: `mwsm.js`)
- HTTP API → WhatsApp Web: sends messages (evidence: `README.md`)
- HTTP API → Document Delivery: handles documents (evidence: `mwsm.js`)
- HTTP API → PDF Generation: serves build route (evidence: `mwsm.js`)
- Webhook Intake → SQLite State: stores scheduling data (evidence: `mwsm.js`)
- Message Scheduling → SQLite State: reads and writes (evidence: `mwsm.js`)
- HTTP API → SQLite State: updates settings (evidence: `mwsm.js`)
- HTTP API → Realtime Events: emits events (evidence: `mwsm.js`)
- HTTP API → Embedding Service: requests embeddings
