# larksuite/cli architecture

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

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

## Overview

lark-cli is the official Lark/Feishu command-line client for people and AI agents. The main workflow is invoking a CLI command, shaping it through a human- and agent-friendly shortcut or a lower-level API command, sending requests to Lark, then rendering structured output. The product also supports credential setup and login, event consumption, and enterprise embedding through extension points. The README documents broad business-domain coverage and a three-layer command model; sampled source confirms event processing and API-request behavior, but not every command’s internal wiring.

Main entry points: [`main.go`](https://github.com/larksuite/cli/blob/main/main.go) (CLI entry), [`internal/client/client.go`](https://github.com/larksuite/cli/blob/main/internal/client/client.go) (API client), [`internal/event/consume/consume.go`](https://github.com/larksuite/cli/blob/main/internal/event/consume/consume.go) (Event runtime), [`cmd/service/service.go`](https://github.com/larksuite/cli/blob/main/cmd/service/service.go) (API commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and setup"]
  node_cli["CLI entry<br/>[main.go]"]
  node_setup["Config and auth<br/>[init.go]"]
end

subgraph group_commands["Command surfaces"]
  node_shortcuts["Domain shortcuts"]
  node_api_commands["API commands<br/>[service.go]"]
  node_raw_api["Raw API access<br/>[api.go]"]
  node_base["Base operations"]
  node_apps["Apps operations"]
end

subgraph group_platform["Platform access"]
  node_auth["Credential flow<br/>[token_store.go]"]
  node_client["API client<br/>[client.go]"]
  node_output["Structured output<br/>[emit.go]"]
end

subgraph group_events["Event processing"]
  node_event_cli["Event commands<br/>[consume.go]"]
  node_event_runtime["Event runtime<br/>[consume.go]"]
  node_event_adapter["Event adapters<br/>[source.go]"]
  node_event_pipeline["Event pipeline<br/>[pipeline.go]"]
  node_event_subscriptions["Event handlers<br/>[all.go]"]
end

subgraph group_embedding["Enterprise embedding"]
  node_extension["Extension platform<br/>[handler.go]"]
  node_transport_registry["Transport registry<br/>[registry.go]"]
  node_policy["Command policy<br/>[engine.go]"]
end

node_user(("User or agent"))
node_lark{{"Lark platform"}}

node_user -->|"invokes"| node_cli
node_cli -->|"dispatches setup"| node_setup
node_setup -->|"configures credentials"| node_auth
node_cli -->|"dispatches shortcut"| node_shortcuts
node_cli -->|"dispatches command"| node_api_commands
node_cli -->|"dispatches raw API"| node_raw_api
node_shortcuts -->|"routes Base"| node_base
node_shortcuts -->|"routes Apps"| node_apps
node_base -->|"requests API"| node_client
node_apps -->|"requests API"| node_client
node_api_commands -->|"uses client"| node_client
node_raw_api -->|"uses client"| node_client
node_client -->|"sends requests"| node_lark
node_client -->|"returns response"| node_output
node_cli -->|"renders results"| node_output
node_cli -->|"dispatches events"| node_event_cli
node_event_cli -->|"starts consumption"| node_event_runtime
node_event_runtime -->|"receives events"| node_event_adapter
node_event_adapter -->|"delivers events"| node_event_runtime
node_event_runtime -->|"dispatches handlers"| node_event_subscriptions
node_event_cli -->|"processes stream"| node_event_pipeline
node_event_pipeline -->|"prints events"| node_output
node_event_pipeline -.->|"receives callbacks"| node_lark
node_extension -->|"registers transports"| node_transport_registry
node_extension -.->|"hosts commands"| node_api_commands
node_policy -->|"evaluates command tree"| node_api_commands

click node_cli "https://github.com/larksuite/cli/blob/main/main.go"
click node_setup "https://github.com/larksuite/cli/blob/main/cmd/config/init.go"
click node_auth "https://github.com/larksuite/cli/blob/main/internal/auth/token_store.go"
click node_shortcuts "https://github.com/larksuite/cli/tree/main/shortcuts"
click node_api_commands "https://github.com/larksuite/cli/blob/main/cmd/service/service.go"
click node_raw_api "https://github.com/larksuite/cli/blob/main/cmd/api/api.go"
click node_base "https://github.com/larksuite/cli/tree/main/shortcuts/base"
click node_apps "https://github.com/larksuite/cli/tree/main/shortcuts/apps"
click node_client "https://github.com/larksuite/cli/blob/main/internal/client/client.go"
click node_output "https://github.com/larksuite/cli/blob/main/internal/output/emit.go"
click node_event_cli "https://github.com/larksuite/cli/blob/main/cmd/event/consume.go"
click node_event_runtime "https://github.com/larksuite/cli/blob/main/internal/event/consume/consume.go"
click node_event_adapter "https://github.com/larksuite/cli/blob/main/internal/event/adapter/lark/websocket/source.go"
click node_event_pipeline "https://github.com/larksuite/cli/blob/main/shortcuts/event/pipeline.go"
click node_event_subscriptions "https://github.com/larksuite/cli/blob/main/events/all.go"
click node_extension "https://github.com/larksuite/cli/blob/main/extension/platform/handler.go"
click node_transport_registry "https://github.com/larksuite/cli/blob/main/extension/transport/registry.go"
click node_policy "https://github.com/larksuite/cli/blob/main/internal/cmdpolicy/engine.go"

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_cli,node_setup,node_user toneBlue
class node_shortcuts,node_api_commands,node_raw_api,node_base,node_apps toneAmber
class node_auth,node_client,node_output toneMint
class node_event_cli,node_event_runtime,node_event_adapter,node_event_pipeline,node_event_subscriptions toneRose
class node_extension,node_transport_registry,node_policy,node_lark toneIndigo
```

## Components

### CLI and setup

- [CLI entry](https://github.com/larksuite/cli/blob/main/main.go): `main.go`
- [Config and auth](https://github.com/larksuite/cli/blob/main/cmd/config/init.go): `cmd/config/init.go`

### Command surfaces

- [Domain shortcuts](https://github.com/larksuite/cli/tree/main/shortcuts): `shortcuts`
- [API commands](https://github.com/larksuite/cli/blob/main/cmd/service/service.go): `cmd/service/service.go`
- [Raw API access](https://github.com/larksuite/cli/blob/main/cmd/api/api.go): `cmd/api/api.go`
- [Base operations](https://github.com/larksuite/cli/tree/main/shortcuts/base): `shortcuts/base`
- [Apps operations](https://github.com/larksuite/cli/tree/main/shortcuts/apps): `shortcuts/apps`

### Platform access

- [Credential flow](https://github.com/larksuite/cli/blob/main/internal/auth/token_store.go): `internal/auth/token_store.go`
- [API client](https://github.com/larksuite/cli/blob/main/internal/client/client.go): `internal/client/client.go`
- [Structured output](https://github.com/larksuite/cli/blob/main/internal/output/emit.go): `internal/output/emit.go`

### Event processing

- [Event commands](https://github.com/larksuite/cli/blob/main/cmd/event/consume.go): `cmd/event/consume.go`
- [Event runtime](https://github.com/larksuite/cli/blob/main/internal/event/consume/consume.go): `internal/event/consume/consume.go`
- [Event adapters](https://github.com/larksuite/cli/blob/main/internal/event/adapter/lark/websocket/source.go): `internal/event/adapter/lark/websocket/source.go`
- [Event pipeline](https://github.com/larksuite/cli/blob/main/shortcuts/event/pipeline.go): `shortcuts/event/pipeline.go`
- [Event handlers](https://github.com/larksuite/cli/blob/main/events/all.go): `events/all.go`

### Enterprise embedding

- [Extension platform](https://github.com/larksuite/cli/blob/main/extension/platform/handler.go): `extension/platform/handler.go`
- [Transport registry](https://github.com/larksuite/cli/blob/main/extension/transport/registry.go): `extension/transport/registry.go`
- [Command policy](https://github.com/larksuite/cli/blob/main/internal/cmdpolicy/engine.go): `internal/cmdpolicy/engine.go`

### Other components

- **User or agent**
- **Lark platform**

## Connections

- User or agent → CLI entry: invokes
- CLI entry → Config and auth: dispatches setup
- Config and auth → Credential flow: configures credentials
- CLI entry → Domain shortcuts: dispatches shortcut
- CLI entry → API commands: dispatches command
- CLI entry → Raw API access: dispatches raw API
- Domain shortcuts → Base operations: routes Base
- Domain shortcuts → Apps operations: routes Apps
- Base operations → API client: requests API
- Apps operations → API client: requests API
- API commands → API client: uses client
- Raw API access → API client: uses client
- API client → Lark platform: sends requests
- API client → Structured output: returns response
- CLI entry → Structured output: renders results
- CLI entry → Event commands: dispatches events
- Event commands → Event runtime: starts consumption
- Event runtime → Event adapters: receives events
- Event adapters → Event runtime: delivers events
- Event runtime → Event handlers: dispatches handlers
- Event commands → Event pipeline: processes stream
- Event pipeline → Structured output: prints events
- Event pipeline → Lark platform: receives callbacks
- Extension platform → Transport registry: registers transports
- Extension platform → API commands: hosts commands
- Command policy → API commands: evaluates command tree
