Skip to content

Repository structure ​

This page explains what each directory in the repo is responsible for, and how the work is divided among the server's domain modules, the Web feature directories, and the daemon modules.

Top-level directories ​

DirectoryResponsibility
apps/webWeb client (React + Vite). src/ui/ holds the design system components, src/features/<domain>/ organizes pages and components by domain, and src/app/ is the application shell
apps/serverServer (Fastify + Drizzle + PostgreSQL). src/modules/<domain>/ organizes routes and services by domain; src/db/schema.ts is the single table definition, with migrations in drizzle/; src/daemon/ is the daemon WebSocket gateway, and src/realtime/ is the realtime channel pushed to browsers
apps/desktopThe desktop app 「共工空间」 (Tauri). src/ is the React UI and src-tauri/ is the Rust shell, which depends directly on crates/gonggong to run the daemon in-process
crates/gonggongThe daemon and gg CLI (binary name gg) that run on members' machines; integration tests live in tests/
packages/protocolEvery wire contract (zod): Web ⇄ server APIs, daemon ⇄ server messages, preview tunnel frames, and built-in MCP tools. fixtures/*.json are shared samples of the daemon protocol that both TS and Rust must round-trip; cases/ holds other cross-language shared cases
tools/mock-agentA scriptable ACP Agent. The daemon tests and some end-to-end tests use it in place of a real Agent; its behavior is chosen by the prompt (e.g. mock:echo, mock:slow, mock:crash)
tools/mcp-echoA minimal stdio MCP server (a single echo tool) that end-to-end tests use to verify MCP injection
e2ePlaywright end-to-end tests: real server + Web + daemon + Agent
scriptsDevelopment and operations scripts: pg.sh (in-repo PostgreSQL), dev-cert.sh (self-signed dev certificate), backup.sh / restore.sh, release.sh, and more
websiteThis help manual (VitePress)
docsRequirements and design documents, kept as background reference; where they conflict with the code, the code wins

Server domain modules ​

Located in apps/server/src/modules/. Each directory usually contains routes.ts (HTTP/WS routes) and service.ts (business logic).

ModuleResponsibility
adminAdmin console: system parameters (params.ts) and audit log queries
agent-toolsThe built-in MCP tools answered by the server (reading chat history, group info, run records, etc.); the daemon forwards calls using the in-progress run as the credential
approvalsApprovals: creating, approving, denying, and voiding an Agent's out-of-tier requests
attachmentsUploading, storing, and downloading message attachments
authLogin, sessions, registration, and creating admin on first startup (bootstrap.ts)
botsCreating, updating, and deleting Bots, binding them to machines, permission tiers, and Agent configuration
candidates@ candidates in the message box: fetches the workspace file list from the Bot's daemon, falling back to a cache when it is slow or offline
commandsParsing and executing in-group commands (/cd, stop, system commands, Agent commands)
git-accountsMembers' Git hosting accounts (tokens), used for repository access
groupsGroups and direct chats: members, Bots, settings, repositories, titles
liveLive view for previews (LiveKit): watching, control, and gg-cast status
machinesMachine binding, logout, details, network measurement, and Agent tools read and written live through the daemon
mcpGlobal MCP servers configured by admins and injected when a session is created (the name gonggong is reserved for the built-in server)
messagesSending, quoting, and recalling messages, and appending during a run
notificationsNotification center and Web Push
previewsPreviews: tunnels, gateway proxy, managed services, public share links
providersA machine's model providers: only forwarded live to the daemon, never written to the database
questionsQuestion cards that a Bot sends to group members, and their answers
reactionsEmoji reactions on messages
releasesClient releases: uploading daemon builds for daemons to download when self-upgrading
reposTeam repository history and repository accessibility probes
runsThe core of runs: triggering, scheduling, receiving daemon reports, redaction, stopping, reconciliation, and retention cleanup
searchGlobal search (messages, changed files)
usageUsage statistics
usersUser profile cards, deactivation
workspacesThe workspace for each (group, Bot): preparation, /cd, file browsing, diff, and status

Web feature directories ​

Located in apps/web/src/features/.

DirectoryContents
adminAdmin console layout and pages (accounts, groups, machines, system parameters, client releases, audit)
attachmentsMessage box attachments, message attachment display, and the viewer
authLogin, registration, password change, avatar menu
botsNew Bot, Bot settings, Agent configuration, the Bot direct chat page, personality role avatars, the admin Bot page
chatMain group message view: message timeline, message box and candidates, Git bar, context usage, new group
configAdmin console · configuration center
diffDiff panel
filesFile viewer
groupsGroup info, group announcements, group settings
machinesBind new machine, machine details, Agent tools, provider editing and import, unbinding
notificationsNotification center and browser push
previewsPreview cards, live view, share links, the admin public link page
reactionsEmoji reactions
reposRepository picker and repository access check
runsRun card pieces: process panel, approvals, questions, interrupt and append
searchSearch overlay
settingsPersonal settings
usageUsage page
usersUser card (profile on hover)
workbenchTabs in the right-hand workbench (run, diff, files, web page, mini program, live view)
workspacesWorkspace and directory picker

Main daemon modules ​

Located in crates/gonggong/src/. main.rs is the gg CLI entry point, and lib.rs collects the modules so the desktop app can reuse them.

ModuleResponsibility
daemon.rsTop-level daemon handle (shared by gg run and the desktop app): single-instance lock, service and engine, revocation cleanup, live status
service.rsWebSocket connection to the server, sending and receiving, and a byte-capped send buffer
engine.rsExecutes runs dispatched by the server; one ACP adapter process per (group, Bot); installs pinned adapter versions
session.rsA single (group, Bot) session: adapter process, ACP session, and turns
turn.rsPure per-turn logic: building the prompt, mapping ACP updates to run events, permission tier policy
permission.rsDetecting macOS Screen Recording and Accessibility permissions (used by previews)
protocol.rsWire types matching packages/protocol
ask.rsBuilt-in gonggong MCP server (local loopback, a separate URL per session): asking group members questions, forwarding server tools, answering daemon tools
mcp_call.rsParses MCP tool calls from ACP updates (Claude and Codex use different formats)
agents.rsDetects installed Agent CLIs and their versions
tools.rsManaged installation of Node.js, Claude Code, and Codex (no sudo, global npm untouched)
manage.rsAnswers server requests for Agent tools, providers, and CC Switch
providers.rsLocal model provider storage (providers.json; always masked when sent out)
provider_cli.rsThe gg provider subcommand
inject.rsInjects the provider used by a run into the adapter process (keys never appear in command-line arguments or logs)
ccswitch.rsRead-only import of providers from the local CC Switch
local.rsLocal settings (local.json): Agent CLI paths, command approval rules, model catalog
configure.rsThe gg agents and gg config subcommands
config.rsLocal state root (~/.gonggong, overridable with GONGGONG_HOME) and binding info
bind.rsLocal machine info and machine identifier reported to the server
bots.rsgg bots: lists the Bots bound to this machine
workspace.rsThe workspace for each (group, Bot): managed clone, /cd binding, directory picking
git.rsWorkspace git operations (calls the local git, reusing local credentials)
repo.rsRemote repository identification and access probing (ssh ⇄ https fallback)
files.rs@ file candidates
explorer.rsRead-only workspace file browsing and path validation
attachments.rsSaves attachments to the workspace's .gonggong/attachments/
tunnel.rsPreview tunnel binary frames and forwarding
previews.rsLocal preview and managed service lists (used by the desktop app)
hosted.rsManaged services (such as dev servers) whose processes are owned by the daemon and outlive a single turn
static_site.rsServes a workspace directory as a static site on the loopback address
snapshot.rsRenders a first-screen screenshot of a preview with a local Chrome-family browser
cast.rsLive view: starts gg-cast on demand to stream a window to LiveKit
wechatide.rsWeChat DevTools: opens mini program projects and captures the simulator screen
tls.rsHTTPS/WSS connection to the server, accepting any certificate (no pinning); plain http is allowed to any host
net.rsMeasures latency and bandwidth to the server
upgrade.rsSelf-upgrade: downloads the new version, verifies sha256, replaces itself, and restarts
revoke.rsCleans up managed workspaces and tokens after the machine is revoked
diag.rsgg doctor self-check and redacted diagnostics bundle
logs.rsdaemon logs (daily rotation + in-memory ring buffer)
status.rsLive status for the UI: connection, heartbeat, latency, runs in progress
lock.rsOnly one daemon per local directory (file lock)
coalesce.rsCoalesces concurrent requests with the same key into a single computation

Released under the Apache License 2.0