# adonisjs/ace architecture

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

- Interactive diagram: https://gitdiagram.com/adonisjs/ace
- Repository: https://github.com/adonisjs/ace

## Overview

#### Purpose and Public Surface
`@adonisjs/ace` is a lightweight, test-oriented Node.js CLI framework for defining, discovering, parsing, and executing commands. The package entry point is `index.ts`; command examples demonstrate consumer integration in `examples/main.ts` and `examples/parent.ts`.

#### Kernel: Application Control Plane
The kernel owns CLI lifecycle: bootstrapping command sources, resolving a command, applying global behavior, and executing or handling failures. It is the principal orchestration boundary between raw process input and command instances.
- `src/kernel.ts`
- `src/types.ts`
- `src/tracing_channels.ts`

#### Command Model and Built-in Commands
Commands extend a common base abstraction that defines arguments, flags, validation, serialization, and execution contract. Built-in `help` and `list` commands expose framework metadata and discovered commands through the same command pipeline.
- `src/commands/base.ts`
- `src/commands/help.ts`
- `src/commands/list.ts`

#### Command Registration and Discovery
Commands can be supplied directly through an in-memory list or discovered from the filesystem. Loader implementations isolate discovery mechanics from the kernel, allowing application-specific command inventories without changing execution logic.
- `src/loaders/list_loader.ts`
- `src/loaders/fs_loader.ts`
- `src/kernel.ts`

#### Input Parsing and Declaration Metadata
The parser converts CLI tokens into command names, positional arguments, and flags. Decorators provide the declarative API for attaching argument and flag definitions to command classes; shared types carry this metadata across parsing, validation, and formatting.
- `src/parser.ts`
- `src/decorators/args.ts`
- `src/decorators/flags.ts`

#### Execution, Errors, and Diagnostics
After resolution and parsing, the kernel invokes command execution and routes failures through a centralized exception handler. Debug and tracing facilities provide observability without making command implementations responsible for process-level error presentation.
- `src/exception_handler.ts`
- `src/errors.ts`
- `src/debug.ts`

#### Output and Introspection
Formatters turn command, argument, flag, and list metadata into CLI-facing output, principally supporting help and command-list flows. This keeps display concerns separate from command definition and parser behavior.
- `src/formatters/command.ts`
- `src/formatters/info.ts`
- `src/formatters/list.ts`

#### Runtime and Distribution
The project is TypeScript targeting the Node.js/npm ecosystem. Package generation includes an index generator and command-loader stubs, indicating support for generated entry/loading code in consuming projects. CI, release, and npm publishing are GitHub Actions/npm concerns rather than runtime dependencies.
- `package.json`
- `src/generators/index_generator.ts`
- `stubs/commands_loader.stub`

Main entry points: [`src/kernel.ts`](https://github.com/adonisjs/ace/blob/14.x/src/kernel.ts) (Kernel), [`src/commands/base.ts`](https://github.com/adonisjs/ace/blob/14.x/src/commands/base.ts) (Base command), [`src/commands/help.ts`](https://github.com/adonisjs/ace/blob/14.x/src/commands/help.ts) (Help command), [`src/exception_handler.ts`](https://github.com/adonisjs/ace/blob/14.x/src/exception_handler.ts) (Exception handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_entry["Package entry<br/>TypeScript entry<br/>[index.ts]"]
  node_examples["Consumer examples<br/>Example commands<br/>[main.ts]"]
end

subgraph group_runtime["CLI Runtime"]
  node_kernel{{"Kernel<br/>CLI lifecycle<br/>[kernel.ts]"}}
  node_types["Shared types<br/>Metadata contracts<br/>[types.ts]"]
  node_tracing["Tracing channels<br/>Observability"]
  node_list_loader["List loader<br/>Command loader<br/>[list_loader.ts]"]
  node_fs_loader["Filesystem loader<br/>Command loader<br/>[fs_loader.ts]"]
end

subgraph group_commands["Commands &amp; Metadata"]
  node_parser["CLI parser<br/>Token parser<br/>[parser.ts]"]
  node_base_command["Base command<br/>Command abstraction<br/>[base.ts]"]
  node_arg_decorators["Argument decorators<br/>Declaration API<br/>[args.ts]"]
  node_flag_decorators["Flag decorators<br/>Declaration API<br/>[flags.ts]"]
  node_help_command["Help command<br/>Built-in command<br/>[help.ts]"]
  node_list_command["List command<br/>Built-in command<br/>[list.ts]"]
end

subgraph group_presentation["Output &amp; Diagnostics"]
  node_exception_handler["Exception handler<br/>Failure boundary"]
  node_errors["Error definitions<br/>Error model<br/>[errors.ts]"]
  node_debug["Debug facilities<br/>Diagnostics<br/>[debug.ts]"]
  node_command_formatter["Command formatter<br/>CLI formatter<br/>[command.ts]"]
  node_info_formatter["Info formatter<br/>CLI formatter<br/>[info.ts]"]
  node_list_formatter["List formatter<br/>CLI formatter<br/>[list.ts]"]
end

subgraph group_distribution["Generation &amp; Distribution"]
  node_index_generator["Index generator<br/>Build generator<br/>[index_generator.ts]"]
  node_loader_stub["Command loader stub<br/>Consumer scaffold"]
  node_package["Package manifest<br/>npm package<br/>[package.json]"]
end

node_entry -->|"exports"| node_kernel
node_examples -->|"consumes"| node_entry
node_kernel -->|"loads commands"| node_list_loader
node_kernel -->|"discovers commands"| node_fs_loader
node_kernel -->|"parses input"| node_parser
node_kernel -->|"resolves and executes"| node_base_command
node_kernel -->|"routes failures"| node_exception_handler
node_kernel -.->|"emits lifecycle traces"| node_tracing
node_parser -->|"uses metadata contracts"| node_types
node_base_command -->|"defines metadata"| node_types
node_arg_decorators -->|"declares arguments"| node_base_command
node_flag_decorators -->|"declares flags"| node_base_command
node_help_command -->|"extends"| node_base_command
node_list_command -->|"extends"| node_base_command
node_help_command -->|"formats help"| node_command_formatter
node_help_command -->|"formats metadata"| node_info_formatter
node_list_command -->|"formats command list"| node_list_formatter
node_exception_handler -->|"handles"| node_errors
node_exception_handler -.->|"reports diagnostics"| node_debug
node_index_generator -.->|"supports generated loader"| node_loader_stub
node_package -->|"publishes"| node_entry

click node_entry "https://github.com/adonisjs/ace/blob/14.x/index.ts"
click node_examples "https://github.com/adonisjs/ace/blob/14.x/examples/main.ts"
click node_kernel "https://github.com/adonisjs/ace/blob/14.x/src/kernel.ts"
click node_types "https://github.com/adonisjs/ace/blob/14.x/src/types.ts"
click node_tracing "https://github.com/adonisjs/ace/blob/14.x/src/tracing_channels.ts"
click node_list_loader "https://github.com/adonisjs/ace/blob/14.x/src/loaders/list_loader.ts"
click node_fs_loader "https://github.com/adonisjs/ace/blob/14.x/src/loaders/fs_loader.ts"
click node_parser "https://github.com/adonisjs/ace/blob/14.x/src/parser.ts"
click node_base_command "https://github.com/adonisjs/ace/blob/14.x/src/commands/base.ts"
click node_arg_decorators "https://github.com/adonisjs/ace/blob/14.x/src/decorators/args.ts"
click node_flag_decorators "https://github.com/adonisjs/ace/blob/14.x/src/decorators/flags.ts"
click node_help_command "https://github.com/adonisjs/ace/blob/14.x/src/commands/help.ts"
click node_list_command "https://github.com/adonisjs/ace/blob/14.x/src/commands/list.ts"
click node_exception_handler "https://github.com/adonisjs/ace/blob/14.x/src/exception_handler.ts"
click node_errors "https://github.com/adonisjs/ace/blob/14.x/src/errors.ts"
click node_debug "https://github.com/adonisjs/ace/blob/14.x/src/debug.ts"
click node_command_formatter "https://github.com/adonisjs/ace/blob/14.x/src/formatters/command.ts"
click node_info_formatter "https://github.com/adonisjs/ace/blob/14.x/src/formatters/info.ts"
click node_list_formatter "https://github.com/adonisjs/ace/blob/14.x/src/formatters/list.ts"
click node_index_generator "https://github.com/adonisjs/ace/blob/14.x/src/generators/index_generator.ts"
click node_loader_stub "https://github.com/adonisjs/ace/blob/14.x/stubs/commands_loader.stub"
click node_package "https://github.com/adonisjs/ace/blob/14.x/package.json"

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_entry,node_examples toneBlue
class node_kernel,node_types,node_tracing,node_list_loader,node_fs_loader toneAmber
class node_parser,node_base_command,node_arg_decorators,node_flag_decorators,node_help_command,node_list_command toneMint
class node_exception_handler,node_errors,node_debug,node_command_formatter,node_info_formatter,node_list_formatter toneRose
class node_index_generator,node_loader_stub,node_package toneIndigo
```

## Components

### Public API

- [Package entry](https://github.com/adonisjs/ace/blob/14.x/index.ts): TypeScript entry · Exports the framework public surface. · `index.ts`
- [Consumer examples](https://github.com/adonisjs/ace/blob/14.x/examples/main.ts): Example commands · Demonstrate framework integration. · `examples/main.ts`

### CLI Runtime

- [Kernel](https://github.com/adonisjs/ace/blob/14.x/src/kernel.ts): CLI lifecycle · Bootstraps sources, resolves commands, and controls execution. · `src/kernel.ts`
- [Shared types](https://github.com/adonisjs/ace/blob/14.x/src/types.ts): Metadata contracts · Carries command metadata across runtime stages. · `src/types.ts`
- [Tracing channels](https://github.com/adonisjs/ace/blob/14.x/src/tracing_channels.ts): Observability · `src/tracing_channels.ts`
- [List loader](https://github.com/adonisjs/ace/blob/14.x/src/loaders/list_loader.ts): Command loader · Provides an in-memory command inventory. · `src/loaders/list_loader.ts`
- [Filesystem loader](https://github.com/adonisjs/ace/blob/14.x/src/loaders/fs_loader.ts): Command loader · Discovers commands from the filesystem. · `src/loaders/fs_loader.ts`

### Commands & Metadata

- [CLI parser](https://github.com/adonisjs/ace/blob/14.x/src/parser.ts): Token parser · Splits CLI input into command name, arguments, and flags. · `src/parser.ts`
- [Base command](https://github.com/adonisjs/ace/blob/14.x/src/commands/base.ts): Command abstraction · Defines declarations, validation, serialization, and execution contract. · `src/commands/base.ts`
- [Argument decorators](https://github.com/adonisjs/ace/blob/14.x/src/decorators/args.ts): Declaration API · `src/decorators/args.ts`
- [Flag decorators](https://github.com/adonisjs/ace/blob/14.x/src/decorators/flags.ts): Declaration API · `src/decorators/flags.ts`
- [Help command](https://github.com/adonisjs/ace/blob/14.x/src/commands/help.ts): Built-in command · `src/commands/help.ts`
- [List command](https://github.com/adonisjs/ace/blob/14.x/src/commands/list.ts): Built-in command · `src/commands/list.ts`

### Output & Diagnostics

- [Exception handler](https://github.com/adonisjs/ace/blob/14.x/src/exception_handler.ts): Failure boundary · Centralizes execution failure handling. · `src/exception_handler.ts`
- [Error definitions](https://github.com/adonisjs/ace/blob/14.x/src/errors.ts): Error model · `src/errors.ts`
- [Debug facilities](https://github.com/adonisjs/ace/blob/14.x/src/debug.ts): Diagnostics · `src/debug.ts`
- [Command formatter](https://github.com/adonisjs/ace/blob/14.x/src/formatters/command.ts): CLI formatter · Renders command, argument, and flag help. · `src/formatters/command.ts`
- [Info formatter](https://github.com/adonisjs/ace/blob/14.x/src/formatters/info.ts): CLI formatter · `src/formatters/info.ts`
- [List formatter](https://github.com/adonisjs/ace/blob/14.x/src/formatters/list.ts): CLI formatter · Renders discovered command lists. · `src/formatters/list.ts`

### Generation & Distribution

- [Index generator](https://github.com/adonisjs/ace/blob/14.x/src/generators/index_generator.ts): Build generator · Generates package index code. · `src/generators/index_generator.ts`
- [Command loader stub](https://github.com/adonisjs/ace/blob/14.x/stubs/commands_loader.stub): Consumer scaffold · Supports generated command-loading code. · `stubs/commands_loader.stub`
- [Package manifest](https://github.com/adonisjs/ace/blob/14.x/package.json): npm package · Defines the TypeScript Node.js distribution. · `package.json`

## Connections

- Package entry → Kernel: exports
- Consumer examples → Package entry: consumes
- Kernel → List loader: loads commands
- Kernel → Filesystem loader: discovers commands
- Kernel → CLI parser: parses input
- Kernel → Base command: resolves and executes
- Kernel → Exception handler: routes failures
- Kernel → Tracing channels: emits lifecycle traces
- CLI parser → Shared types: uses metadata contracts
- Base command → Shared types: defines metadata
- Argument decorators → Base command: declares arguments
- Flag decorators → Base command: declares flags
- Help command → Base command: extends
- List command → Base command: extends
- Help command → Command formatter: formats help
- Help command → Info formatter: formats metadata
- List command → List formatter: formats command list
- Exception handler → Error definitions: handles
- Exception handler → Debug facilities: reports diagnostics
- Index generator → Command loader stub: supports generated loader
- Package manifest → Package entry: publishes
