#ARCHITECTURE
This document describes CodexManager the current repository structure, running relationships, and release links. The goal is to help collaborators quickly determine which layer the changes should fall on.
CodexManager consists of two types of operating modes:
- Desktop mode: Tauri Desktop + local service process
- Service Mode: Standalone service + web UI, can be used with server, Docker or no desktop environment
Unified goal:
- Manage accounts, usage, and platform keys
- Provide local gateway capabilities
- Externally compatible with OpenAI style entry, and adapted to multiple upstream protocols
.
├─ apps/ # 前端与 Tauri 桌面端
│ ├─ src/ # Next.js App Router + TypeScript 前端
│ ├─ src-tauri/ # Tauri 桌面壳与原生命令桥接
│ ├─ tests/ # 前端 UI/结构测试
│ └─ out/ # Next.js 静态导出产物
├─ crates/
│ ├─ core/ # 数据库迁移、存储基础、认证/用量底层能力
│ ├─ service/ # 本地 HTTP/RPC 服务、网关、协议适配、设置持久化
│ ├─ web/ # Web UI 服务壳,可嵌入前端静态资源
│ └─ start/ # Service 一键启动器(拉起 service + web)
├─ scripts/ # 本地构建、统一版本、测试探针、发布辅助脚本
├─ docker/ # Dockerfile 与 compose 配置
├─ assets/ # README 图片、Logo 等静态资源
└─ .github/workflows/ # CI / release workflow
apps/src/app/layout.tsx: App Router root layout and global providersapps/src/components/providers.tsx: React Query, theme, i18n, and toast providersapps/src/components/layout/app-bootstrap.tsx: Desktop/Web runtime initialization and service connection setupapps/src/lib/api/transport.ts: Unified Tauri invoke and Web RPC transport facade
apps/src-tauri/src/lib.rs: Tauri Application assembly entryapps/src-tauri/src/commands/settings/mod.rs: Desktop settings command moduleapps/src-tauri/src/service_runtime.rs: Desktop embedded service life cycleapps/src-tauri/src/rpc_client/mod.rs: Desktop RPC call infrastructure
crates/service/src/lib.rs: Service main entrance and runtime assemblycrates/service/src/http/: HTTP routing entrycrates/service/src/rpc_dispatch/: RPC Distribution entrancecrates/service/src/gateway/mod.rs: Gateway aggregation entrycrates/service/src/gateway/observability/http_bridge/mod.rs: Request tracking, protocol bridging, and log writingcrates/service/src/gateway/protocol_adapter/request_router.rs: OpenAI/Codex request routing and upstream protocol selectioncrates/service/src/gateway/protocol_adapter/types.rs: Shared protocol adapter request/response typescrates/service/src/gateway/observability/http_bridge/stream_readers/: Streaming response readers for supported upstream protocolscrates/service/src/gateway/request/request_rewrite.rs: Request overrides and compatibility rewrites
crates/service/src/app_settings/: Set up persistence, environment variable coverage, runtime synchronizationcrates/service/src/auth/web_access.rs: Web Access password and session token
Desktop mode consists of the following parts:
apps/src/: Front-end UIapps/src-tauri/: Desktop shellcrates/service/: local service
How to run:
- The user launches the desktop application.
- Tauri The shell is responsible for desktop behaviors such as windows, trays, updates, single instances, and setting bridges.
- The desktop communicates with
codexmanager-servicevia RPC or a local address. - The front-end UI displays pages such as account, usage, request log, and settings.
The Service pattern consists of the following binaries:
codexmanager-servicecodexmanager-webcodexmanager-start
Responsibilities:
codexmanager-service: Core service process, providing account management, gateway forwarding, request logs, setting persistence, and RPC/HTTP interfaces.codexmanager-web: Web UI service shell, which can directly provide front-end pages and proxy to local services.codexmanager-start: A one-click launcher for publishing packages, responsible for launching service and web at the same time.
Mainly responsible for:
- Page rendering
- user interaction
- Status management
- Call local API / Tauri command
- Front-end logic of settings page and account page
Mainly responsible for:
- Tauri Application startup
- Single instance control
- System tray and window events
- Desktop updates and installer behavior
- Bridge front-end operations to service/local runtime
Mainly responsible for:
- SQLite Migration
- Storage underlying capabilities
- Core basic logic such as authentication/usage
- Data access capabilities that can be reused by services
Mainly responsible for:
- HTTP / RPC Portal
- Account, usage, API Key management
- Local gateway capabilities
- Protocol adaptation and upstream forwarding
- Request logging and setting persistence
- Runtime configuration synchronization
Key subdirectories:
src/gateway/: Gateway, protocol adaptation, streaming and non-streaming conversionsrc/http/: HTTP routing entrysrc/rpc_dispatch/: RPC Distributionsrc/account/,src/apikey/,src/requestlog/,src/usage/: Domain logic
Mainly responsible for:
- Provide Web UI static resources
- Mount or proxy to service
- Optionally embed
apps/outinto the binary to form a single-file distribution
Mainly responsible for:
- Provide a more direct startup entry in the Service release package
- Coordinate the life cycle of service and web
Desktop mode uses SQLite. Service mode can use the SeaORM storage adapter for SQLite,
MySQL, or PostgreSQL when an explicit CODEXMANAGER_DATABASE_URL is configured.
Database migrations are located at:
crates/core/migrations/: desktop SQLite migrationscrates/storage-seaorm/src/migration.rs: service-mode cross-database migrations
The database not only stores accounts, but also assumes:
- API Key
- Request log
- token statistics
- app settings
The main sources of configuration include:
- Environment variables
CODEXMANAGER_* .env/codexmanager.envin the application running directoryapp_settingsPersistence table- Desktop settings page
Current agreement:
- Configurations that must take effect before startup are retained at the environment variable layer.
- Runtime tunable configurations are first managed through the settings page +
app_settings. - Setting changes should not be scattered across desktops, frontends, and services without boundaries.
Typical request links are as follows:
- The client or UI initiates the request.
- Requests enter the HTTP/RPC layer of
crates/service. - The gateway module determines the forwarding strategy, account number, header strategy, upstream proxy, etc.
- The protocol adaptation layer is responsible for processing:
/v1/chat/completions/v1/responses- Streaming SSE
- Non-streaming JSON
tool_calls/ tools mapping and aggregation
- The results are written back to the request log and statistics, and then returned to the caller.
front end:
pnpm -C apps run devpnpm -C apps run buildpnpm -C apps run check
Rust:
cargo test --workspacecargo build -p codexmanager-service --releasecargo build -p codexmanager-web --releasecargo build -p codexmanager-start --release
Desktop:
scripts/rebuild.ps1scripts/rebuild-linux.shscripts/rebuild-macos.sh
The version is currently maintained uniformly by the root workspace:
- Root
Cargo.tomlof[workspace.package].version
Additional synchronization on desktop:
apps/src-tauri/Cargo.tomlapps/src-tauri/tauri.conf.json
Version changes are made directly in the workspace and Tauri manifests
(Cargo.toml, apps/src-tauri/Cargo.toml, and apps/src-tauri/tauri.conf.json);
no scripts/bump-version.ps1 helper is currently checked in.
Main publishing entrance:
.github/workflows/release-all.yml
Responsibilities:
- Build Windows / macOS / Linux Desktop Product
- Build version Service artifact
- Upload GitHub Release attachment
- Determine release type based on tag /
prereleaseinput
The current repository needs to focus on the following issues:
apps/src-tauri/src/lib.rsIt is still thick, and the desktop shell assembly and command implementation still need to be disassembled.crates/service/src/lib.rsConfiguration, runtime synchronization, and side effect boundaries are not clear enough.crates/service/src/gateway/protocol_adapter/has many compatibility branches and a high regression risk..github/workflows/release-all.ymlStill long, multi-platform logic requires persistence constraints.
In order to reduce structural pollution, new demands should be targeted according to the following principles:
- New pages or front-end interactions: Priority falls in
apps/src/app/,apps/src/components/,apps/src/lib/ - New Desktop Capabilities: Prioritize standalone modules that fall into
apps/src-tauri/src/, rather than continuing to cram them all intolib.rs - New setting item: first determine whether it belongs to environment variables, persistent configuration or runtime state
- Compatible with new protocols: priority should be placed in the gateway / protocol adapter submodule, and do not continue to stack conditional branches out of order.
- New release logic: Give priority to drawing scripts or reusing steps, and do not repeat modifications three times on three platforms.