How yincongcyincong/musebot works
Project type and purpose
• This is a full-stack, modular, monolithic Go application (“MuseBot”) that:
• Exposes HTTP/Web APIs
• Hosts a separate Admin UI (React/Vite)
• Connects to many chat platforms (Telegram, Discord, Slack, Lark, DingDing, QQ, WeChat, etc.)
• Integrates with multiple LLM providers (DeepSeek, OpenAI, Gemini, VolcEngine, OpenRouter, 302.AI, etc.)
• Optionally uses RAG (retrieval‐augmented generation) over a knowledge store
• Supports service registration (etcd), metrics, logging, and database (SQLite/MySQL)
File structure
• Top-level Go modules:
• main.go: entrypoint, initializes config, logger, router, services
• http/: HTTP server handlers, middleware, service orchestration
• robot/: chat‐platform connectors, one submodule per platform
• llm/: LLM‐provider adapters, one submodule per provider plus mix/mcp logic
• register/: etcd service registration
• db/: data persistence (user, msgrecord, rag_files)
• conf/: application configuration (i18n, LLM, RAG, tools, media)
• admin/: separate Admin UI backend (Go) and front-end files under admin/packages/adminui
• static/: markdown docs for each feature & platform
• metrics/, logger/, utils/, param/ etc.: cross‐cutting concerns
• Deployment files: Dockerfile, Makefile, shell scripts
• Tests under each module
README for additional insights
• Primary workflows: user sends message on chat platform → platform connector → core service → LLM adapter → LLM provider → stream response back
• Admin platform manages bots, users, settings (served as SPA)
• Service registry allows multiple MuseBot instances to auto‐register and discover each other
• RAG pulls context from ./data/knowledge via db/rag_files
Main components & interactions (to include
a. Clients & entrypoints
• Chat Platforms (Telegram, Discord, Slack, Lark, Ding, QQ, WeChat, custom web)
• Admin UI (browser)
b. API Gateway / HTTP Server
• http/http.go: routes requests from web clients & bots
c. Chat Connectors (“robot/*”)
• One adapter per platform, transforms platform events into internal messages
d. Core Service Layer
• communicate.go: orchestrates session, context tracking
• service.go: high‐level business logic (commands, routing to LLM, tools, RAG)
e. LLM Adapter Layer (“llm/*”)
• Provider‐specific modules (openai.go, deepseek.go, gemini.go, etc.)
• mix.go: dynamic dispatch based on TYPE config
• mcp.go: protocol conversion for function‐calls
f. Persistence
• db/: users, message records, RAG file metadata
• data/knowledge: plaintext or vector store for RAG
g. Configuration & i18n
• conf/: central config loader, env vars, locale files
h. Service Registration & Discovery
• register/etcd.go: auto‐register to etcd
i. Admin Platform
• Go backend (admin/main.go) for API, serves static React build
• React/Vite SPA (admin/packages/adminui) for dashboards, user management
j. Observability
• metrics/prom.go: Prometheus metrics
• logger/logger.go: structured logging
Architectural patterns & design principles
• Modular adapter pattern for both chat platforms and LLM providers
• Layered architecture: Transport (HTTP, bots) → Application core → Persistence → External services
• Plugin-style registration of new providers/connectors
• Singleton config + dependency injection via package-level initializers
• Service registry (etcd) for clustering