--- url: "https://asyncapi.com/docs/tools/cli/architecture" titulek: "CLI Architecture | AsyncAPI Initiative for event-driven APIs" h1: "CLI Architecture" popis: "CLI Architecture Overview The AsyncAPI CLI is built with oclif and provides both command-line operations and a REST API server for working with AsyncAPI specifications. Architecture Diagram ┌────" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 02:46:26" znaku: 4164 slov: 481 kodovani: "utf-8" sha256: "ace4fb0d2c0b8c5bc0adba19232310eb6eb968f0bae56b4cefeba22e8f2de521" --- ##### On this page CLI Architecture Overview Architecture Diagram Directory Structure Core Components CLI Application API Server Domain Services Domain Models Error Classes Execution Flow Extension Points Configuration Technology Stack # CLI Architecture Found an error? Have a suggestion?[Edit this page on GitHub](https://github.com/asyncapi/cli/tree/master/docs/architecture.md) # CLI Architecture ## Overview The AsyncAPI CLI is built with [oclif](https://oclif.io/) and provides both command-line operations and a REST API server for working with AsyncAPI specifications. --- ## Architecture Diagram ``` ┌─────────────────────────────────────────────────┐ │ Entry Points │ │ ┌──────────┐ ┌──────────┐ │ │ │ CLI │ │ API │ │ │ │ (oclif) │ │ (Express)│ │ │ └────┬─────┘ └────┬─────┘ │ └───────┼─────────────────────────┼───────────────┘ └───────────┬─────────────┘ ▼ ┌───────────────────────┐ │ Domain Services │ │ Validation, Generator│ │ Convert, Config │ └───────────┬───────────┘ ▼ ┌───────────────────────┐ │ Domain Models │ │ Specification,Context│ └───────────┬───────────┘ ▼ ┌───────────────────────┐ │ Utilities │ │ Logger, Helpers │ └───────────────────────┘ ``` --- ## Directory Structure ``` src/ ├── apps/ │ ├── cli/ # CLI commands & internals │ └── api/ # REST API (Express) ├── domains/ │ ├── models/ # Specification, Context │ └── services/ # Business logic ├── errors/ # Custom errors ├── interfaces/ # TypeScript types └── utils/ # Utilities ``` --- ## Core Components ### CLI Application | Component | Description | | --- | --- | | **Entry Points** | `bin/run` (dev), `bin/run_bin` (prod) | | **Base Command** | Metrics, parser integration, error handling | **Commands:** - **Core:** `validate` , `convert` , `format` , `optimize` , `diff` , `bundle` - **Generation:** `generate client` , `generate models` , `generate fromTemplate` - **Config:** `config context` , `config analytics` , `config versions` - **Utility:** `new file` , `new template` , `start api|studio|preview` , `pretty` ### API Server **Endpoints:** `/v1/validate`, `/v1/parse`, `/v1/generate`, `/v1/convert`, `/v1/bundle`, `/v1/diff`, `/v1/docs`, `/v1/help`, `/v1/version` **Features:** Express with Helmet security, CORS, compression, RFC 7807 error responses ### Domain Services All services extend `BaseService` and return `ServiceResult`: | Service | Purpose | | --- | --- | | `ValidationService` | Validates specs with Spectral, calculates scores | | `GeneratorService` | Generates code/models | | `ConvertService` | Converts between AsyncAPI/OpenAPI formats | | `ConfigService` | Manages CLI config and contexts | | `ArchiverService` | Creates ZIP archives | ### Domain Models | Model | Purpose | | --- | --- | | **Specification** | Loads from file, URL, or context; auto-detects `asyncapi.json\|yml\|yaml` | | **Context** | Manages multiple AsyncAPI contexts; stored in `~/.asyncapi/` | ### Error Classes `ContextError`, `SpecificationFileError`, `ValidationError`, `GeneratorError`, `DiffError` --- ## Execution Flow **CLI Command:** ``` User Command → oclif → Base Command → Domain Service → ServiceResult ``` **API Request:** ``` HTTP Request → Express → Controller → Domain Service → HTTP Response ``` --- ## Extension Points | Add | Steps | | --- | --- | | **New Command** | Create in `src/apps/cli/commands/`, extend `Command`, implement `run()` | | **New API Endpoint** | Create controller in `src/apps/api/controllers/`, register in `index.ts` | | **New Service** | Create in `src/domains/services/`, extend `BaseService`, return `ServiceResult` | --- ## Configuration | Config | Location | | --- | --- | | CLI Context | `~/.asyncapi/contexts.json`, `~/.asyncapi/.current` | | Analytics | `~/.asyncapi-analytics` | **Environment Variables:** - `NODE_ENV` — `development` | `production` | `test` - `PORT` — API server port (default: 3000) - `ASYNCAPI_METRICS_*` — Metrics configuration --- ## Technology Stack | Category | Technologies | | --- | --- | | **Core** | oclif, TypeScript, Express | | **AsyncAPI** | @asyncapi/parser, generator, converter, bundler, diff, optimizer | | **Supporting** | winston, ajv, chalk, @clack/prompts | [Go BackAuto-complete setup](/docs/tools/cli/autocompleteEnabled) [Up NextUsage](/docs/tools/cli/usage) Was this helpful? Help us improve the docs by sharing your feedback. [Submit Feedback](https://github.com/asyncapi/website/issues/new?template=docs-feedback.yml&title=Docs%20Feedback%3A%20%2Fdocs%2Ftools%2Fcli%2Farchitecture&labels=%F0%9F%93%91%20docs) OR [Create Issue on GitHub](https://github.com/asyncapi/website/issues/new/choose)