X Tutup
Skip to content

micro/chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micro Chat

An open source, AI-native group chat platform. Self-hosted, real-time, with Claude as a first-class participant — not a bolted-on integration.

Design principles:

  • Open data — self-hosted, your messages are fully searchable and exportable, no API gatekeeping
  • AI-native — Claude participates in group conversations with full access to chat history and context
  • MCP-native — extensible through Model Context Protocol so Claude can use tools, skills, and plugins
  • Open APIs — every message, channel, and user accessible via REST and WebSocket

Built as a modular monolith using Go with real-time WebSocket communication and a Material-inspired dark UI.

Login Chat
Login Chat
Channel List @claude Mention
Channels Claude

Features

Core Chat

  • Real-time messaging via WebSocket with instant delivery
  • Channels - public and private chats
  • Groups - organize teams with shared channel collections
  • User presence - online/offline/away status indicators
  • Typing indicators - see who's composing a message
  • Message reactions - emoji reactions on messages
  • Message threading - reply to specific messages (parent_id support)
  • Message editing & deletion - modify your own messages
  • Message search - full-text search within channels

Claude AI Integration

  • @claude mention - type @claude followed by your question in any channel
  • Model selector - choose between Claude Sonnet 4.6 (fast) and Claude Opus 4.6 (powerful) via the UI toggle
  • Conversation context - Claude receives the last 20 messages for context-aware responses
  • AI summarization - one-click channel conversation summaries
  • Markdown rendering - Claude responses render with proper formatting

Users & Auth

  • JWT authentication with 72-hour token expiry
  • User registration & login with bcrypt password hashing
  • User profiles - display name, avatar, status message
  • Role-based access - admin and member roles
  • User search - find users by username or display name

Groups & Organizations

  • Group creation with description
  • Group membership management (add/remove members)
  • Group chats - associate channels with groups
  • Group roles - admin and member within groups

Architecture

Modular Monolith (Go Micro Pattern)

The application uses Go Micro (go-micro.dev/v5) as its modular monolith framework. Each domain is a micro.Service and all services are bundled via micro.NewGroup() for shared lifecycle management:

gateway  := micro.New("gateway", micro.BeforeStart(initDB), micro.AfterStop(closeDB))
users    := micro.New("users")
chats    := micro.New("chats")
groups   := micro.New("groups")
agent    := micro.New("agent")
mcp      := micro.New("mcp")
search   := micro.New("search")
threads  := micro.New("threads")
webhooks := micro.New("webhooks")
sso      := micro.New("sso")
audit    := micro.New("audit")

g := micro.NewGroup(gateway, users, chats, groups, agent, mcp, search, threads, webhooks, sso, audit)
g.Run()  // starts all, blocks on signal, then stops all

Project structure:

service/
  users/              # User registration, login, profiles, search
  chats/              # Chat CRUD, membership, messages, WebSocket hub
  groups/             # Group CRUD, membership, chat associations
  agent/              # Claude AI agent, model selection, chat/summarize
  mcp/                # MCP server, JSON-RPC 2.0, tools & resources
  search/             # Global search, semantic FTS5, filtered agent search
  threads/            # Threaded conversations with replies
  webhooks/           # Inbound/outbound webhooks with HMAC signing
  sso/                # SSO/OIDC authentication (Authorization Code flow)
  audit/              # Audit log with filtering and export
  invites/            # Invite system with codes and expiry
  files/              # File upload and attachment management
  export/             # Data export (JSON, CSV)
cmd/server/           # Application entry point, service wiring
internal/
  auth/               # JWT tokens, password hashing, token extraction
  api/                # HTTP REST handlers, routing
  middleware/          # Auth middleware, CORS, logging
  database/           # SQLite setup, migrations
web/static/           # Frontend SPA (HTML/CSS/JS)

Each service is a top-level directory with its own package. Services communicate through direct function calls (no message bus overhead) while maintaining clean interfaces. Services can later be extracted into separate binaries with minimal refactoring.

Technology Stack

Layer Technology
Framework Go Micro v5 (go-micro.dev/v5)
Language Go 1.24
Database SQLite with WAL mode
Auth JWT (HS256) + bcrypt
Real-time WebSocket (gorilla/websocket)
AI Anthropic Claude API (Messages API)
Frontend Vanilla JS SPA, Material-inspired CSS
HTTP Go standard library net/http (Go 1.22+ routing)

Database Schema

users             - User accounts with profiles and roles
chats             - Chat channels (public/private)
chat_members      - Chat membership with roles
groups            - Team/org groups
group_members     - Group membership with roles
group_chats       - Chat-to-group associations
messages          - Chat messages with threading support
message_reactions - Emoji reactions on messages

Quick Start

Prerequisites

  • Go 1.22+ (uses new ServeMux routing patterns)
  • GCC/C compiler (for SQLite CGo bindings)

Run

# Clone and enter
git clone <repo-url> && cd chat

# Run directly
go run ./cmd/server/

# Or build and run
go build -o microchat ./cmd/server/
./microchat

The server starts on http://localhost:8080 with a seeded admin account:

  • Username: admin
  • Password: admin123

Three default channels are created: #general, #random, and #claude-ai.

Enable Claude AI

Set your Anthropic API key to enable AI features:

export ANTHROPIC_API_KEY=sk-ant-...
go run ./cmd/server/

Configuration

All configuration is via environment variables:

Variable Default Description
PORT 8080 HTTP server port
DB_PATH chat.db SQLite database file path
JWT_SECRET (auto-generated) Secret for JWT signing
ANTHROPIC_API_KEY (none) Anthropic API key for Claude

API Reference

Authentication

Method Endpoint Description
POST /api/auth/register Register new user
POST /api/auth/login Login, returns JWT
GET /api/auth/me Get current user

Users

Method Endpoint Description
GET /api/users List all users
GET /api/users/search?q= Search users
GET /api/users/{id} Get user by ID
PUT /api/users/profile Update profile
PUT /api/users/status Update status

Admin (requires admin role)

Method Endpoint Description
PUT /api/admin/users/{id}/role Set user role ({"role": "admin"} or {"role": "member"})
DELETE /api/admin/users/{id} Delete a user and their memberships

Chats

Method Endpoint Description
POST /api/chats Create channel
GET /api/chats List user's channels
GET /api/chats/public List public channels
GET /api/chats/{id} Get channel details
POST /api/chats/{id}/join Join channel
POST /api/chats/{id}/leave Leave channel
GET /api/chats/{id}/members List members
POST /api/chats/{id}/members Add member
DELETE /api/chats/{id} Delete channel

Messages

Method Endpoint Description
GET /api/chats/{id}/messages List messages (paginated)
POST /api/chats/{id}/messages Send message
PUT /api/messages/{id} Edit message
DELETE /api/messages/{id} Delete message
GET /api/chats/{id}/messages/search?q= Search messages

Groups

Method Endpoint Description
POST /api/groups Create group
GET /api/groups List user's groups
GET /api/groups/{id} Get group with members
POST /api/groups/{id}/members Add member
DELETE /api/groups/{id}/members/{userId} Remove member
POST /api/groups/{id}/chats Add chat to group
DELETE /api/groups/{id} Delete group

AI

Method Endpoint Description
GET /api/ai/models List available models
POST /api/ai/chat Chat with Claude (REST)
POST /api/ai/summarize/{chatId} Summarize channel

Search

Method Endpoint Description
GET /api/search?q= Global search across all channels
GET /api/search/semantic?q= FTS5 semantic search with BM25 ranking
POST /api/search/query Filtered search (user, channel, date range, group)

Threads

Method Endpoint Description
GET /api/chats/{id}/threads List threads in a channel
GET /api/threads/{id} Get full thread (root + replies)
GET /api/threads/{id}/replies Get paginated thread replies
POST /api/threads/{id}/replies Reply to a thread

Webhooks

Method Endpoint Description
POST /api/webhooks Create webhook
GET /api/webhooks List webhooks
PUT /api/webhooks/{id} Update webhook
DELETE /api/webhooks/{id} Delete webhook
GET /api/webhooks/{id}/logs Get delivery logs
POST /api/webhooks/{id}/inbound Receive inbound webhook

SSO / OIDC

Method Endpoint Description
GET /api/sso/providers List enabled SSO providers
POST /api/admin/sso/providers Create OIDC provider (admin)
PUT /api/admin/sso/providers/{id} Update provider (admin)
DELETE /api/admin/sso/providers/{id} Delete provider (admin)
GET /api/sso/auth/{id} Redirect to OIDC provider login
GET /api/sso/callback/{id} OIDC callback, returns JWT

Audit Log (admin)

Method Endpoint Description
GET /api/admin/audit List audit entries with filters
GET /api/admin/audit/export Export audit log (JSON/CSV)

WebSocket

Connect to /ws?token=<jwt> for real-time events.

Client -> Server events:

{"type": "send_message",  "payload": {"room_id": "...", "content": "...", "parent_id": ""}}
{"type": "ask_claude",    "payload": {"room_id": "...", "content": "...", "model": "claude-sonnet-4-6"}}
{"type": "typing",        "payload": {"room_id": "..."}}
{"type": "join_room",     "payload": {"room_id": "..."}}
{"type": "reaction",      "payload": {"message_id": "...", "emoji": "..."}}

Server -> Client events:

{"type": "new_message",  "payload": { /* message object */ }}
{"type": "typing",       "payload": {"user_id": "...", "username": "...", "room_id": "..."}}
{"type": "presence",     "payload": {"user_id": "...", "status": "online|offline"}}
{"type": "reaction",     "payload": {"message_id": "...", "reactions": [...]}}
{"type": "error",        "payload": {"message": "..."}}

Using Claude in Chat

Type @claude followed by your question in any channel:

@claude What are the best practices for Go error handling?
@claude Summarize what we've been discussing
@claude Write a function to parse CSV files in Python

Select your preferred model using the sparkle button next to the message input:

  • Sonnet 4.6 - Fast responses, great for everyday questions
  • Opus 4.6 - Maximum reasoning power for complex tasks

Claude receives the recent conversation context, so it can follow along with the discussion and provide relevant responses.

Roadmap

Baseline — deploy and use today

  • Real-time group chat with channels, groups, presence
  • Claude AI in conversations via @mention with model selection
  • User registration, login, JWT auth
  • Admin role with user management (promote, demote, delete)
  • Per-channel message search
  • Admin UI — manage users, roles, and channels from the web interface
  • Invite system — invite users by email or link instead of open registration
  • Channel permissions — restrict who can create channels, control private channel access
  • Image & file uploads — share images, documents, and files in chat messages
  • Link previews & web fetch — paste a URL and Claude can fetch and summarize the content
  • GitHub integration — link to repos, PRs, issues with rich previews; Claude can review code
  • Data export — full export of messages, users, channels in open formats (JSON, CSV)

AI & MCP — make Claude a real participant

  • MCP server — expose chat data (messages, channels, users, search) as MCP resources so Claude and other AI tools can query your history directly
  • MCP client in agent — let Claude call external MCP tools (databases, APIs, internal services) from within a conversation
  • Tool use / function calling — upgrade Claude from plain text to tool-use so it can take actions (search messages, look up users, query systems)
  • Custom system prompts per channel — configure Claude's role per channel (support bot, code reviewer, summarizer)
  • Agent memory — persistent context across conversations so Claude builds institutional knowledge
  • Web fetch tool — Claude can fetch URLs shared in chat to read docs, articles, GitHub READMEs
  • Image analysis — Claude can view and describe uploaded images
  • Plugin registry — register MCP servers as plugins that extend what Claude can do

Search & data access

  • Global search — search across all channels with relevance ranking
  • Semantic search — FTS5-based similarity search so Claude finds relevant context even with different wording
  • Search API for agents — programmatic search with filters (user, channel, date range, group)

Platform

  • Threads — full threaded conversations with AI participation
  • Webhooks — inbound/outbound webhooks for external services with HMAC signing
  • SSO / OIDC — enterprise authentication via OpenID Connect
  • Audit log — full audit trail for compliance with export support

License

See LICENSE file.

X Tutup