# minimax-ai/cli architecture

> Architecture diagram of the GitHub repository minimax-ai/cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/minimax-ai/cli
- Repository: https://github.com/minimax-ai/cli

## Overview

1. **What this repo is**
   - `mmx-cli` is a TypeScript command-line client for the MiniMax AI Platform.
   - It targets Node.js 18+ and is built as a terminal/agent-facing tool, not a web app.
   - The repo also ships as an agent “skill” (`skill/SKILL.md`) and has release/CI automation in GitHub Actions.

2. **Top-level execution path**
   - The CLI entrypoint is `src/main.ts`.
   - Command-line parsing and dispatch flow through `src/args.ts`, `src/command.ts`, and `src/registry.ts`.
   - Commands are organized by domain under `src/commands/*`, so the architecture is “thin CLI shell + shared client/auth/config layers.”

3. **Command subsystem**
   - Each user-facing feature is a separate command module: text, image, video, speech, music, vision, search, file, quota, config, auth, update, help.
   - The command layer is responsible for validating flags, assembling request payloads, invoking the API client, and choosing the output format.
   - Some commands represent long-running workflows, especially video generation, which is split into generate, task-get, and download.

4. **API client boundary**
   - `src/client/http.ts` is the transport boundary for talking to MiniMax services.
   - `src/client/endpoints.ts` centralizes API route definitions, while `src/client/stream.ts` supports streaming responses.
   - `src/types/api.ts` captures the platform response/request shapes, keeping service integration isolated from CLI logic.

5. **Authentication subsystem**
   - Auth lives under `src/auth/*` and supports both API-key login and OAuth/browser-based login.
   - `src/auth/credentials.ts`, `oauth.ts`, `refresh.ts`, and `resolver.ts` together handle credential acquisition, storage, refresh, and lookup.
   - The README shows two auth persistence paths: OAuth credentials in `~/.mmx/credentials.json` and API-key config in `~/.mmx/config.json`.

6. **Configuration and region handling**
   - `src/config/*` handles config loading, schema validation, file paths, and automatic region detection.
   - The app supports dual-region operation: Global (`api.minimax.io`) and CN (`api.minimaxi.com`), which affects endpoint selection and likely auth/config defaults.
   - `src/config/schema.ts` and `src/utils/schema.ts` suggest a strongly validated config model, with `mmx config export-schema` exposing that schema to users.

7. **Output and terminal UX**
   - `src/output/*` contains presentation logic for text, JSON, audio playback, progress bars, status bars, and quota tables.
   - This is a distinct architectural layer: commands produce data; output modules render it appropriately for terminal use.
   - Streaming and async jobs depend on these output helpers to keep the CLI responsive and readable.

8. **Async workflow support**
   - `src/polling/poll.ts` implements polling for tasks that are not instantly complete, especially video generation.
   - `src/files/download.ts` and `src/commands/video/download.ts` indicate a file-transfer boundary for retrieving generated assets after task completion.
   - This creates a common pattern: submit job → poll status → download artifact → render progress/result.

9. **Error model**
   - Errors are normalized under `src/errors/*` with base classes, API-specific errors, codes, and a handler.
   - `src/errors/api.ts` and `src/errors/codes.ts` imply the CLI maps platform responses into user-facing exit/error behavior.
   - This is important for architecture because API failures, auth problems, rate limits, and validation errors are handled centrally rather than per command.

10. **Updates and packaging**
   - `src/update/*` handles self-update checks and update execution.
   - The presence of `build.ts`, GitHub release workflow, and `bin/mmx` shows the project is packaged as an installable executable.
   - The release path is likely “TypeScript build → publish CLI binary/package → npm release,” with CI enforcing tests and linting.

11. **Utility and shared support**
   - `src/utils/*` contains cross-cutting helpers for env access, filesystem, prompting, token handling, and schema utilities.
   - These are supporting pieces used by auth, config, and command modules to keep those layers focused on domain behavior.

12. **Testing and verification**
   - The `test/` tree mirrors the source structure, with unit and command-level tests for auth, client HTTP, output formatting, and each feature command.
   - Fixtures and a mock server indicate the architecture is tested at the API-boundary level, not just pure functions.
   - This makes the repo’s diagram fairly clean: a CLI command layer above shared auth/config/client services, with output and polling as cross-cutting runtime services.

Main entry points: [`src/command.ts`](https://github.com/minimax-ai/cli/blob/main/src/command.ts) (Dispatch), [`src/client/http.ts`](https://github.com/minimax-ai/cli/blob/main/src/client/http.ts) (HTTP), [`src/output/formatter.ts`](https://github.com/minimax-ai/cli/blob/main/src/output/formatter.ts) (Output), [`src/commands/image/generate.ts`](https://github.com/minimax-ai/cli/blob/main/src/commands/image/generate.ts) (Media)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Entry<br/>[main.ts]"]
  node_args["Args<br/>cli parsing<br/>[args.ts]"]
  node_command["Dispatch<br/>command runner<br/>[command.ts]"]
  node_registry["Registry<br/>command map<br/>[registry.ts]"]
  node_text_cmd["Text<br/>chat command<br/>[chat.ts]"]
  node_media_cmds["Media<br/>generation commands<br/>[generate.ts]"]
  node_vision_search_cmds["Vision/Search<br/>query commands<br/>[describe.ts]"]
  node_file_cmds["Files<br/>file commands<br/>[upload.ts]"]
  node_auth_cmds["Auth CLI<br/>auth commands<br/>[login.ts]"]
  node_config_cmds["Config CLI<br/>config commands<br/>[show.ts]"]
  node_quota_cmd["Quota<br/>usage command<br/>[show.ts]"]
  node_client_http["HTTP<br/>api transport<br/>[http.ts]"]
  node_client_endpoints["Endpoints<br/>route catalog<br/>[endpoints.ts]"]
  node_client_stream["Stream<br/>[stream.ts]"]
  node_auth_core["Auth Core<br/>credential flow<br/>[resolver.ts]"]
  node_config_core["Config Core<br/>config layer<br/>[loader.ts]"]
  node_output["Output<br/>terminal renderer<br/>[formatter.ts]"]
  node_polling["Polling<br/>async workflow<br/>[poll.ts]"]
  node_download["Download<br/>file transfer<br/>[download.ts]"]
end

subgraph group_support["Support"]
  node_errors["Errors<br/>error handling<br/>[handler.ts]"]
  node_update["Update<br/>[self-update.ts]"]
  node_types["Types<br/>api models<br/>[api.ts]"]
  node_utils["Utils<br/>shared helpers<br/>[schema.ts]"]
end

subgraph group_verification["Verification"]
  node_tests["Tests<br/>verification suite"]
end

node_main -->|"parses"| node_args
node_args -->|"dispatches"| node_command
node_command -->|"resolves"| node_registry
node_command -->|"runs"| node_text_cmd
node_command -->|"runs"| node_media_cmds
node_command -->|"runs"| node_vision_search_cmds
node_command -->|"runs"| node_file_cmds
node_command -->|"runs"| node_auth_cmds
node_command -->|"runs"| node_config_cmds
node_command -->|"runs"| node_quota_cmd
node_text_cmd -->|"calls"| node_client_http
node_media_cmds -->|"calls"| node_client_http
node_vision_search_cmds -->|"calls"| node_client_http
node_file_cmds -->|"calls"| node_client_http
node_auth_cmds -->|"uses"| node_auth_core
node_config_cmds -->|"uses"| node_config_core
node_client_http -->|"uses"| node_client_endpoints
node_client_http -->|"uses"| node_client_stream
node_client_http -->|"shapes"| node_types
node_auth_core -->|"reads"| node_config_core
node_config_core -->|"uses"| node_utils
node_command -->|"renders"| node_output
node_polling -->|"reports"| node_output
node_download -->|"reports"| node_output
node_media_cmds -->|"polls"| node_polling
node_media_cmds -->|"downloads"| node_download
node_client_http -->|"maps"| node_errors
node_update -->|"reports"| node_output
node_tests -.->|"covers"| node_client_http
node_tests -.->|"covers"| node_auth_core
node_tests -.->|"covers"| node_output

click node_main "https://github.com/minimax-ai/cli/blob/main/src/main.ts"
click node_args "https://github.com/minimax-ai/cli/blob/main/src/args.ts"
click node_command "https://github.com/minimax-ai/cli/blob/main/src/command.ts"
click node_registry "https://github.com/minimax-ai/cli/blob/main/src/registry.ts"
click node_text_cmd "https://github.com/minimax-ai/cli/blob/main/src/commands/text/chat.ts"
click node_media_cmds "https://github.com/minimax-ai/cli/blob/main/src/commands/image/generate.ts"
click node_vision_search_cmds "https://github.com/minimax-ai/cli/blob/main/src/commands/vision/describe.ts"
click node_file_cmds "https://github.com/minimax-ai/cli/blob/main/src/commands/file/upload.ts"
click node_auth_cmds "https://github.com/minimax-ai/cli/blob/main/src/commands/auth/login.ts"
click node_config_cmds "https://github.com/minimax-ai/cli/blob/main/src/commands/config/show.ts"
click node_quota_cmd "https://github.com/minimax-ai/cli/blob/main/src/commands/quota/show.ts"
click node_client_http "https://github.com/minimax-ai/cli/blob/main/src/client/http.ts"
click node_client_endpoints "https://github.com/minimax-ai/cli/blob/main/src/client/endpoints.ts"
click node_client_stream "https://github.com/minimax-ai/cli/blob/main/src/client/stream.ts"
click node_auth_core "https://github.com/minimax-ai/cli/blob/main/src/auth/resolver.ts"
click node_config_core "https://github.com/minimax-ai/cli/blob/main/src/config/loader.ts"
click node_output "https://github.com/minimax-ai/cli/blob/main/src/output/formatter.ts"
click node_polling "https://github.com/minimax-ai/cli/blob/main/src/polling/poll.ts"
click node_download "https://github.com/minimax-ai/cli/blob/main/src/files/download.ts"
click node_errors "https://github.com/minimax-ai/cli/blob/main/src/errors/handler.ts"
click node_update "https://github.com/minimax-ai/cli/blob/main/src/update/self-update.ts"
click node_types "https://github.com/minimax-ai/cli/blob/main/src/types/api.ts"
click node_utils "https://github.com/minimax-ai/cli/blob/main/src/utils/schema.ts"
click node_tests "https://github.com/minimax-ai/cli/tree/main/test"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_args,node_command,node_registry,node_text_cmd,node_media_cmds,node_vision_search_cmds,node_file_cmds,node_auth_cmds,node_config_cmds,node_quota_cmd,node_client_http,node_client_endpoints,node_client_stream,node_auth_core,node_config_core,node_output,node_polling,node_download toneBlue
class node_errors,node_update,node_types,node_utils toneAmber
class node_tests toneMint
```

## Components

### Runtime

CLI execution, commands, and shared services

- [Entry](https://github.com/minimax-ai/cli/blob/main/src/main.ts): cli entrypoint · Starts the CLI process and hands off to argument parsing and dispatch · `src/main.ts`
- [Args](https://github.com/minimax-ai/cli/blob/main/src/args.ts): cli parsing · Parses argv, flags, and top-level invocation shape · `src/args.ts`
- [Dispatch](https://github.com/minimax-ai/cli/blob/main/src/command.ts): command runner · Routes parsed input to the selected command implementation · `src/command.ts`
- [Registry](https://github.com/minimax-ai/cli/blob/main/src/registry.ts): command map · Registers available commands and command metadata · `src/registry.ts`
- [Text](https://github.com/minimax-ai/cli/blob/main/src/commands/text/chat.ts): chat command · Text chat and conversational request flow · `src/commands/text/chat.ts`
- [Media](https://github.com/minimax-ai/cli/blob/main/src/commands/image/generate.ts): generation commands · Image, video, speech, and music command families · `src/commands/image/generate.ts`
- [Vision/Search](https://github.com/minimax-ai/cli/blob/main/src/commands/vision/describe.ts): query commands · Vision description and search query commands · `src/commands/vision/describe.ts`
- [Files](https://github.com/minimax-ai/cli/blob/main/src/commands/file/upload.ts): file commands · Upload, list, and delete file workflows · `src/commands/file/upload.ts`
- [Auth CLI](https://github.com/minimax-ai/cli/blob/main/src/commands/auth/login.ts): auth commands · Login, logout, refresh, and status flows · `src/commands/auth/login.ts`
- [Config CLI](https://github.com/minimax-ai/cli/blob/main/src/commands/config/show.ts): config commands · Show, set, and export configuration schema · `src/commands/config/show.ts`
- [Quota](https://github.com/minimax-ai/cli/blob/main/src/commands/quota/show.ts): usage command · Displays current account or API quota state · `src/commands/quota/show.ts`
- [HTTP](https://github.com/minimax-ai/cli/blob/main/src/client/http.ts): api transport · Transport boundary for MiniMax API requests · `src/client/http.ts`
- [Endpoints](https://github.com/minimax-ai/cli/blob/main/src/client/endpoints.ts): route catalog · Central definitions for API routes and paths · `src/client/endpoints.ts`
- [Stream](https://github.com/minimax-ai/cli/blob/main/src/client/stream.ts): streaming client · Handles streaming or incremental API responses · `src/client/stream.ts`
- [Auth Core](https://github.com/minimax-ai/cli/blob/main/src/auth/resolver.ts): credential flow · Credential acquisition, refresh, and lookup for API key and OAuth · `src/auth/resolver.ts`
- [Config Core](https://github.com/minimax-ai/cli/blob/main/src/config/loader.ts): config layer · Loads, validates, and resolves runtime configuration and region · `src/config/loader.ts`
- [Output](https://github.com/minimax-ai/cli/blob/main/src/output/formatter.ts): terminal renderer · Formats text, JSON, audio, progress, status, and quota displays · `src/output/formatter.ts`
- [Polling](https://github.com/minimax-ai/cli/blob/main/src/polling/poll.ts): async workflow · Polls long-running jobs until completion · `src/polling/poll.ts`
- [Download](https://github.com/minimax-ai/cli/blob/main/src/files/download.ts): file transfer · Retrieves generated artifacts after async job completion · `src/files/download.ts`

### Support

Errors, updates, utilities, and packaging

- [Errors](https://github.com/minimax-ai/cli/blob/main/src/errors/handler.ts): error handling · Normalizes API and CLI failures into user-facing behavior · `src/errors/handler.ts`
- [Update](https://github.com/minimax-ai/cli/blob/main/src/update/self-update.ts): self-update · Checks for and applies CLI updates · `src/update/self-update.ts`
- [Types](https://github.com/minimax-ai/cli/blob/main/src/types/api.ts): api models · Shared request and response shapes for the platform · `src/types/api.ts`
- [Utils](https://github.com/minimax-ai/cli/blob/main/src/utils/schema.ts): shared helpers · Cross-cutting helpers for env, fs, prompts, schema, and tokens · `src/utils/schema.ts`

### Verification

Tests and fixtures

- [Tests](https://github.com/minimax-ai/cli/tree/main/test): verification suite · Command, client, auth, output, and error tests with fixtures · `test`

## Connections

- Entry → Args: parses · CLI entrypoint forwards argv into parsing
- Args → Dispatch: dispatches · Parsed invocation is routed to command execution
- Dispatch → Registry: resolves · Dispatcher looks up available commands in the registry
- Dispatch → Text: runs · Example command family executed through dispatcher
- Dispatch → Media: runs · Media-oriented commands are dispatched here
- Dispatch → Vision/Search: runs · Vision and search commands are dispatched here
- Dispatch → Files: runs · File workflow commands are dispatched here
- Dispatch → Auth CLI: runs · Auth commands are dispatched here
- Dispatch → Config CLI: runs · Config commands are dispatched here
- Dispatch → Quota: runs · Usage/quota command is dispatched here
- Text → HTTP: calls · Commands use the transport boundary for API requests
- Media → HTTP: calls · Media workflows submit jobs through the client
- Vision/Search → HTTP: calls · Query commands invoke the API client
- Files → HTTP: calls · File operations use API transport
- Auth CLI → Auth Core: uses · Auth commands rely on shared credential logic
- Config CLI → Config Core: uses · Config commands load and validate runtime settings
- HTTP → Endpoints: uses · HTTP layer depends on centralized route definitions
- HTTP → Stream: uses · Transport delegates streaming cases to stream support
- HTTP → Types: shapes · Requests and responses are typed against shared API models
- Auth Core → Config Core: reads · Auth resolution depends on config and region context
- Config Core → Utils: uses · Configuration layer uses shared schema and filesystem helpers
- Dispatch → Output: renders · Commands select terminal output formatting for results
- Polling → Output: reports · Async job polling updates progress and status output
- Download → Output: reports · Download flows surface progress and completion status
- Media → Polling: polls · Long-running generation workflows wait on task completion
- Media → Download: downloads · Video workflows fetch generated artifacts after completion
- HTTP → Errors: maps · API failures are normalized into CLI error handling
- Update → Output: reports · Update flow uses terminal output for user feedback
- Tests → HTTP: covers · Fixture-backed tests exercise the API boundary
- Tests → Auth Core: covers · Tests verify credential and refresh behavior
- Tests → Output: covers · Tests validate formatting and terminal presentation
