Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

docs: regenerate AGENTS.md with accurate metrics and missing files

Aldino Kemalb7bbe67ef60b
diff --git a/AGENTS.md b/AGENTS.md
index a5bb70ea..604f0563 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,6 +1,8 @@
# PROJECT KNOWLEDGE BASE
-**Generated:** 2026-03-01
+**Generated:** 2026-04-02
+**Commit:** 0e0af10
+**Branch:** main
## OVERVIEW
@@ -13,15 +15,15 @@ go-whatsapp-web-multidevice/
│ ├── cmd/ # Cobra CLI commands (rest, mcp)
│ ├── domains/ # Business domain contracts (interfaces + DTOs)
│ ├── infrastructure/ # External integrations
-│ │ ├── whatsapp/ # WhatsApp protocol (whatsmeow) — 28 files
-│ │ ├── chatstorage/ # SQLite chat/message persistence
-│ │ └── chatwoot/ # Chatwoot CRM integration
+│ │ ├── whatsapp/ # WhatsApp protocol (whatsmeow) — 24 Go files
+│ │ ├── chatstorage/ # SQLite/PostgreSQL chat+message persistence
+│ │ └── chatwoot/ # Chatwoot CRM integration (sync + client)
│ ├── ui/ # Transport layers (REST, MCP, WebSocket)
│ ├── usecase/ # Application logic (bridges domain ↔ infra)
-│ ├── validations/ # ozzo-validation input checks + tests
-│ ├── views/ # Vue.js 3 components (Semantic UI)
-│ ├── pkg/ # Shared utilities
-│ ├── config/ # Viper config binding
+│ ├── validations/ # ozzo-validation input checks + tests (19 test files total)
+│ ├── views/ # Vue.js 3 components (Semantic UI) — 49 components
+│ ├── pkg/ # Shared utilities (utils/ + error/)
+│ ├── config/ # Viper config binding (settings.go)
│ └── storages/ # Runtime DB files (SQLite)
├── docs/ # OpenAPI spec (openapi.yaml)
└── gallery/ # Screenshot examples
@@ -33,18 +35,19 @@ go-whatsapp-web-multidevice/
|------|----------|-------|
| Add new message type | `domains/send/`, `usecase/send.go`, `validations/send_validation.go` | 3-file pattern |
| Add new API endpoint | `ui/rest/`, `usecase/`, `domains/` | Handler → usecase → domain |
+| Add MCP tool | `ui/mcp/` | Mirrors REST; includes `query.go` for read ops |
| Handle WhatsApp event | `infrastructure/whatsapp/event_*.go` | Register in `event_handler.go` switch |
-| Add DB migration | `infrastructure/chatstorage/sqlite_repository.go` → `getMigrations()` | Append only, never insert |
-| Add MCP tool | `ui/mcp/` | Mirrors REST endpoints |
+| Add DB migration | `infrastructure/chatstorage/sqlite_repository.go` → `getMigrations()` | Append only — currently 15 migrations |
| Add Vue component | `views/components/` | Plain JS, no .vue SFC |
-| Device management | `infrastructure/whatsapp/device_manager.go` | 602-line central orchestrator |
+| Device management | `infrastructure/whatsapp/device_manager.go` | 615-line central orchestrator |
+| Chatwoot integration | `infrastructure/chatwoot/` | `client.go` (API) + `sync.go` (bidirectional sync) |
## COMMANDS
```bash
cd src && go run . rest # Run REST API mode
cd src && go run . mcp # Run MCP server mode
cd src && go build -o whatsapp # Build binary
-cd src && go test ./... # Run all tests
+cd src && go test ./... # Run all tests (19 test files)
cd src && go vet ./... # Static analysis
cd src && go fmt ./... # Format code
go mod tidy # Update dependencies
@@ -86,10 +89,13 @@ deviceID := client.Store.ID.ToNonAD().String() // ✅ "[email protected]
|---------|------|
| `go.mau.fi/whatsmeow` | WhatsApp Web protocol |
| `github.com/gofiber/fiber/v2` | REST web framework |
-| `github.com/mark3labs/mcp-go` | MCP server |
+| `github.com/mark3labs/mcp-go` | MCP server (v0.45.0) |
| `github.com/spf13/cobra` | CLI framework |
| `github.com/spf13/viper` | Config management |
-| `github.com/ozzo/ozzo-validation` | Input validation |
+| `github.com/go-ozzo/ozzo-validation/v4` | Input validation |
+| `github.com/sirupsen/logrus` | Structured logging |
+| `github.com/mattn/go-sqlite3` | SQLite driver |
+| `github.com/lib/pq` | PostgreSQL driver |
## NOTES
@@ -99,3 +105,5 @@ deviceID := client.Store.ID.ToNonAD().String() // ✅ "[email protected]
- FFmpeg required for media processing
- HTML/JS assets embedded in binary via Go's `embed`
- Database: SQLite default, PostgreSQL supported via `DB_URI`
+- Docker: `docker-compose.yml` with volume mounts for `storages/` and `statics/`
+- CI: GoReleaser builds for Linux/Windows, GitHub Actions for release + Docker image
diff --git a/src/domains/AGENTS.md b/src/domains/AGENTS.md
index 73c09820..b0555479 100644
--- a/src/domains/AGENTS.md
+++ b/src/domains/AGENTS.md
@@ -1,6 +1,6 @@
# domains
-Business domain layer. Each subdomain has `interfaces.go` (usecase interface) + request/response structs.
+Business domain layer. Each subdomain has `interfaces.go` (usecase interface) + request/response structs. 10 domain packages.
## STRUCTURE
```
@@ -12,7 +12,7 @@ domains/
├── group/ # Group CRUD + participants
├── message/ # Message operations (react, delete, revoke, star)
├── newsletter/ # Newsletter/channel operations
-├── send/ # Message sending (text, image, video, document, etc.)
+├── send/ # Message sending (text, image, video, document, etc.) — 15 request files
├── settings/ # Application settings
└── user/ # User info, avatar, privacy, contacts
```
@@ -22,6 +22,7 @@ domains/
- Use `*bool` for optional boolean filters (e.g., `Archived *bool` in `ListChatsRequest`)
- Request structs validate via `ozzo-validation` in `validations/` package
- `chatstorage/` is the only domain with a repository interface — others use whatsmeow directly
+- `send/` has the most request files (one per message type)
## ANTI-PATTERNS
- Never put business logic in domain packages — they define contracts only
diff --git a/src/infrastructure/chatstorage/AGENTS.md b/src/infrastructure/chatstorage/AGENTS.md
index 8c150430..07fd2d18 100644
--- a/src/infrastructure/chatstorage/AGENTS.md
+++ b/src/infrastructure/chatstorage/AGENTS.md
@@ -1,20 +1,30 @@
# infrastructure/chatstorage
-SQLite-based chat and message persistence. Single implementation file with migration system.
+SQLite/PostgreSQL chat and message persistence. Single implementation file with sequential migration system.
## KEY FILES
-- `sqlite_repository.go` (1169 lines) — Full `IChatStorageRepository` implementation
+- `sqlite_repository.go` (1263 lines) — Full `IChatStorageRepository` implementation (39 methods)
- `device_repository.go` — Wrapper that injects device_id into all calls (mirrors `chatstorage_wrapper.go` in `whatsapp/`)
## MIGRATION SYSTEM
-Migrations are sequential, numbered from 1. Add new ones at the end of `getMigrations()`. Each migration runs in a transaction with version tracking in `schema_version` table.
+Migrations are sequential string slices returned by `getMigrations()`. Each runs in a transaction with version tracking in `schema_info` table.
-Current: 14 migrations (latest: `idx_chats_archived` index).
+Current: **15 migrations** (latest: `call_metadata TEXT` column on messages table).
+
+Tables: `chats` (PK: jid+device_id), `messages` (PK: id+chat_jid+device_id), `devices` (PK: device_id), `schema_info`.
+
+## KEY METHODS
+- `CreateMessage(ctx, evt)` — Full message ingestion: resolve device → normalize JIDs → upsert chat → store message
+- `StoreSentMessageWithContext(ctx, ...)` — Outbound messages with context cancellation support
+- `CreateIncomingCallRecord(ctx, evt, autoRejected)` — Synthetic call rows (media_type="call")
+- `GetChatNameWithPushNameByDevice(...)` — Name resolution: existing > pushName > sender > JID
+- `GetFilteredChatCount(filter)` — Use this for pagination totals, NOT `GetTotalChatCount()`
## CONVENTIONS
- All chat queries must be device-scoped (use `device_id` column)
-- Filter methods (e.g., `GetFilteredChatCount`) must mirror `GetChats` filter logic exactly
+- Filter methods must mirror `GetChats` filter logic exactly via `buildChatFilterQuery`
- New interface methods → add to `device_repository.go` AND `whatsapp/chatstorage_wrapper.go`
+- Cross-DB compatible SQL: avoid SQLite-specific or PostgreSQL-specific syntax in migrations
## ANTI-PATTERNS
- Never add a migration in the middle — always append
diff --git a/src/infrastructure/whatsapp/AGENTS.md b/src/infrastructure/whatsapp/AGENTS.md
index f106a6ac..c9be9e91 100644
--- a/src/infrastructure/whatsapp/AGENTS.md
+++ b/src/infrastructure/whatsapp/AGENTS.md
@@ -5,28 +5,30 @@ WhatsApp protocol integration layer using whatsmeow. Handles device management,
## STRUCTURE
```
whatsapp/
-├── device_manager.go # DeviceManager: multi-device lifecycle (602 lines)
-├── device_instance.go # DeviceInstance: ID()/JID() + client wrapper
-├── event_handler.go # Central event dispatcher (switch on event type)
-├── event_message.go # Message event → storage + webhook
-├── event_archive.go # Archive event → local DB update
-├── event_receipt.go # Read receipts
-├── event_call.go # Call events
-├── event_delete.go # Message deletion events
-├── event_group.go # Group info changes
-├── event_newsletter.go # Newsletter events
-├── history_sync.go # WhatsApp history sync to local DB
-├── chatstorage_wrapper.go # deviceChatStorage: injects device_id into all repo calls
-├── jid_utils.go # NormalizeJIDFromLID: @lid → @s.whatsapp.net
-├── webhook.go # Webhook dispatch
-├── webhook_forward.go # Forward events to external webhooks
-├── client_lifecycle.go # Connect/disconnect/reconnect logic
-├── context_device.go # Context helpers for device resolution
-├── auto_reply.go # Auto-reply message handling
-├── cleanup.go # Resource cleanup
-├── database.go # DB connection setup
-├── init.go # Package initialization
-└── logger.go # Custom whatsmeow logger adapter
+├── device_manager.go # DeviceManager: multi-device lifecycle (615 lines)
+├── device_instance.go # DeviceInstance: ID()/JID() + client wrapper
+├── event_handler.go # Central event dispatcher (switch on event type)
+├── event_message.go # Message event → storage + webhook
+├── event_message_handler.go # Message handler helpers
+├── event_archive.go # Archive event → local DB update
+├── event_receipt.go # Read receipts (primary device only)
+├── event_call.go # Call events → synthetic message rows
+├── event_chat_presence.go # Chat presence (typing, online) events
+├── event_delete.go # Message deletion events
+├── event_group.go # Group info changes
+├── event_newsletter.go # Newsletter events
+├── history_sync.go # WhatsApp history sync to local DB
+├── chatstorage_wrapper.go # deviceChatStorage: injects device_id into all repo calls
+├── jid_utils.go # NormalizeJIDFromLID: @lid → @s.whatsapp.net
+├── webhook.go # Webhook dispatch
+├── webhook_forward.go # Forward events to external webhooks (484 lines)
+├── client_lifecycle.go # Connect/disconnect/reconnect logic
+├── context_device.go # Context helpers for device resolution
+├── auto_reply.go # Auto-reply message handling
+├── cleanup.go # Resource cleanup
+├── database.go # DB connection setup
+├── init.go # Package initialization
+└── logger.go # Custom whatsmeow logger adapter
```
## CRITICAL PATTERNS
@@ -48,6 +50,8 @@ deviceID := client.Store.ID.ToNonAD().String() // "[email protected]
### Event Handler Pattern
All event handlers follow: `func handleX(ctx, evt, chatStorageRepo, client)` → normalize JIDs → lookup/update DB → forward to webhook.
+Receipt forwarding restricted to primary device only (`Device == 0`).
+
### Wrapper Pattern
`deviceChatStorage` / `DeviceRepository` wrap all `IChatStorageRepository` calls to inject device_id automatically. New interface methods must be added to BOTH wrappers.
diff --git a/src/ui/AGENTS.md b/src/ui/AGENTS.md
index 1c11ea78..5697cafb 100644
--- a/src/ui/AGENTS.md
+++ b/src/ui/AGENTS.md
@@ -6,9 +6,13 @@ User interface layer. Three transport modes: REST API, MCP server, WebSocket.
```
ui/
├── rest/ # Fiber HTTP handlers (9 files, 1:1 with domains)
-│ ├── helpers/ # Response formatting, device resolution
-│ └── middleware/ # Auth, logging, CORS
+│ ├── helpers/ # common.go: ResponseSuccess, device resolution
+│ └── middleware/ # basicauth, device, recovery, timeout (+test)
├── mcp/ # MCP (Model Context Protocol) tools for AI agents
+│ ├── app.go # Login/logout/reconnect tools
+│ ├── group.go # Group management tools (779 lines, largest)
+│ ├── send.go # Message sending tools
+│ ├── query.go # Read-only query tools (chats, messages, devices)
│ └── helpers/ # MCP-specific utilities
└── websocket/ # Real-time WebSocket events
```
@@ -22,11 +26,15 @@ Each handler file maps to one domain. Pattern:
Device resolution: `helpers.ResolveDevice(c)` extracts from `X-Device-Id` header.
+## MCP TOOL PATTERN
+Each MCP file registers tools via `mcp-go`. Same usecase calls as REST, different transport. `query.go` handles read-only operations (chat list, messages, device info).
+
## CONVENTIONS
- Query param parsing: use `c.Query("param")` for strings, `strconv` for booleans
- Boolean query params: parse to `*bool` (nil = not provided)
- All REST handlers are in `rest/` directory, one file per domain
-- MCP tools mirror REST endpoints but with different transport
+- REST has `chatwoot.go` handler for Chatwoot webhook integration
+- Middleware: `basicauth` (optional), `device` (resolve device context), `recovery`, `timeout`
## ANTI-PATTERNS
- Never put business logic in handlers — delegate to usecase layer
diff --git a/src/usecase/AGENTS.md b/src/usecase/AGENTS.md
index d6387fbb..a52bab01 100644
--- a/src/usecase/AGENTS.md
+++ b/src/usecase/AGENTS.md
@@ -3,11 +3,14 @@
Application use cases. Each file bridges one domain to infrastructure. 1:1 mapping with domain packages.
## KEY FILES
-- `send.go` (1710 lines) — Largest. Handles all message types (text, image, video, document, sticker, audio, poll, contact, location, link)
-- `chat.go` — Chat list, messages, archive, pin, disappearing timer, label
-- `group.go` (536 lines) — Group CRUD, participants, settings
+- `send.go` (1820 lines) — Largest. Handles all message types (text, image, video, document, sticker, audio, poll, contact, location, link)
+- `chat.go` (375 lines) — Chat list, messages, archive, pin, disappearing timer, label
+- `group.go` (614 lines) — Group CRUD, participants, settings
+- `user.go` (413 lines) — User info, avatar, privacy, contacts
+- `message.go` — Message operations (react, delete, revoke, star)
- `app.go` — Login, logout, reconnect
- `device.go` — Multi-device management operations
+- `newsletter.go` — Newsletter/channel operations
## CONVENTIONS
- Each usecase struct: `type serviceX struct { repo, whatsmeow deps }`
diff --git a/src/validations/AGENTS.md b/src/validations/AGENTS.md
index 1b906483..ea97603f 100644
--- a/src/validations/AGENTS.md
+++ b/src/validations/AGENTS.md
@@ -1,6 +1,6 @@
# validations
-Input validation using `ozzo-validation`. Each domain has a `*_validation.go` + `*_validation_test.go` pair.
+Input validation using `ozzo-validation`. Each domain has a `*_validation.go` + `*_validation_test.go` pair (16 files total).
## PATTERN
```go
@@ -11,10 +11,20 @@ func ValidateXxx(ctx context.Context, request *domain.XxxRequest) error {
}
```
+## FILE MAP
+| Domain | Validation | Test | Notes |
+|--------|-----------|------|-------|
+| send | send_validation.go (516 lines) | send_validation_test.go (1113 lines) | Largest; also `send_validation_test_sticker.go` |
+| group | group_validation.go | group_validation_test.go (708 lines) | Second largest test file |
+| chat | chat_validation.go | chat_validation_test.go | |
+| message | message_validation.go | message_validation_test.go | |
+| user | user_validation.go | user_validation_test.go | |
+| app | app_validation.go | app_validation_test.go | |
+| newsletter | newsletter_validation.go | newsletter_validation_test.go | |
+
## CONVENTIONS
- Validation functions are standalone (not methods) for easy testing
- Test files use table-driven tests with `testify/assert`
-- `send_validation.go` (516 lines) is the largest — validates all message types
- Context parameter is required even if unused (for future device-scoped validation)
## ANTI-PATTERNS
diff --git a/src/views/AGENTS.md b/src/views/AGENTS.md
index 01daf85e..bc2110c9 100644
--- a/src/views/AGENTS.md
+++ b/src/views/AGENTS.md
@@ -5,7 +5,7 @@ Vue.js 3 frontend components using Semantic UI. Served as embedded HTML via Go's
## STRUCTURE
```
views/
-├── components/ # 48 Vue.js components (one per feature)
+├── components/ # 49 Vue.js components (one per feature)
│ ├── App*.js # Login, logout, reconnect
│ ├── Account*.js # Avatar, profile, privacy, contacts
│ ├── Chat*.js # ChatList, ChatMessages, ChatPinManager, ChatDisappearingManager