mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 20:39:39 +02:00
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>
2.2 KiB
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
- Create
internal/plugins/mybot/mybot.go - Implement
plugin.Plugininterface - Register via
func init() { plugin.Register("mybot", func() plugin.Plugin { return &MyBot{} }) } - Import in
cmd/server/main.go:_ "github.com/manacore/mana-matrix-bot/internal/plugins/mybot" - 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 URLREDIS_HOST,REDIS_PORT,REDIS_PASSWORD— Redis for sessionsSTT_URL,TTS_URL— Voice services
Per Plugin (legacy env var names supported)
MATRIX_{NAME}_BOT_TOKEN— Matrix access tokenMATRIX_{NAME}_BOT_ROOMS— Comma-separated allowed room IDs{NAME}_BACKEND_URL— Backend service URL