managarten/services/mana-matrix-bot/CLAUDE.md
Till JS 819568c3df feat(infra): consolidate 21 Matrix bots into Go binary + add Go API gateway
Replace 21 separate NestJS Matrix bot processes (~2.1 GB RAM, ~4.2 GB Docker images)
with a single Go binary using plugin architecture (8.6 MB binary, ~30 MB RAM).

New services:
- services/mana-matrix-bot/ — Go Matrix bot with 21 plugins (mautrix-go, Redis sessions)
- services/mana-api-gateway-go/ — Go API gateway (rate limiting, API keys, credit billing)

Deleted:
- 21 services/matrix-*-bot/ directories
- packages/bot-services/ and packages/matrix-bot-common/
- Legacy deploy scripts and CI build jobs

Updated:
- docker-compose.macmini.yml: new Go services, legacy bots removed
- CI/CD: change detection + build jobs for Go services
- Root package.json: new dev:matrix, build:matrix, test:matrix scripts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 21:03:00 +01:00

2.2 KiB

mana-matrix-bot

Consolidated Go Matrix bot replacing 21 separate NestJS bot services.

Architecture

  • Language: Go 1.23
  • Matrix SDK: mautrix-go
  • Port: 4000 (health/metrics)
  • Pattern: Plugin architecture with compile-time registration

Structure

cmd/server/main.go          # Entry point, imports all plugins
internal/
  config/                    # Env-based configuration
  runtime/                   # Plugin lifecycle, Matrix sync, event routing
  matrix/                    # Matrix client wrapper, markdown, media
  plugin/                    # Plugin interface, registry, command routing
  session/                   # In-memory + Redis session store
  services/                  # Backend HTTP client, voice (STT/TTS)
  plugins/                   # One directory per bot plugin
    todo/                    # @todo-bot
    calendar/                # @calendar-bot
    gateway/                 # @mana-bot (composite: AI + todo + calendar + clock + voice)
    ...

Adding a New Plugin

  1. Create internal/plugins/mybot/mybot.go
  2. Implement plugin.Plugin interface
  3. Register via func init() { plugin.Register("mybot", func() plugin.Plugin { return &MyBot{} }) }
  4. Import in cmd/server/main.go: _ "github.com/manacore/mana-matrix-bot/internal/plugins/mybot"
  5. Set env: MATRIX_MYBOT_BOT_TOKEN=syt_xxx

Commands

# Build
go build -o dist/mana-matrix-bot ./cmd/server

# Run
PORT=4000 MATRIX_HOMESERVER_URL=http://localhost:8008 MATRIX_TODO_BOT_TOKEN=xxx ./dist/mana-matrix-bot

# Test
go test ./...

# Docker
docker build -t mana-matrix-bot:local -f Dockerfile .

Environment Variables

Global

  • PORT — Health server port (default: 4000)
  • MATRIX_HOMESERVER_URL — Matrix homeserver (default: http://localhost:8008)
  • MATRIX_STORAGE_PATH — Sync state directory (default: ./data)
  • MANA_CORE_AUTH_URL — Auth service URL
  • REDIS_HOST, REDIS_PORT, REDIS_PASSWORD — Redis for sessions
  • STT_URL, TTS_URL — Voice services

Per Plugin (legacy env var names supported)

  • MATRIX_{NAME}_BOT_TOKEN — Matrix access token
  • MATRIX_{NAME}_BOT_ROOMS — Comma-separated allowed room IDs
  • {NAME}_BACKEND_URL — Backend service URL