# xampprocky/tokei architecture

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

- Interactive diagram: https://gitdiagram.com/xampprocky/tokei
- Repository: https://github.com/xampprocky/tokei

## Overview

Tokei is a Rust library and CLI for counting files and classifying lines as code, comments, or blanks by language. The CLI accepts paths and optional prior statistics, applies configuration and ignore rules, scans and analyzes source (including embedded languages), aggregates results, then sorts and prints or serializes them. The README documents broad language support, multiple output formats, and library use. Some implementation links rely on README workflow descriptions because the relevant source was not excerpted.

Main entry points: [`src/main.rs`](https://github.com/xampprocky/tokei/blob/master/src/main.rs) (CLI Entry), [`src/language/mod.rs`](https://github.com/xampprocky/tokei/blob/master/src/language/mod.rs) (Language Aggregation), [`src/language/syntax.rs`](https://github.com/xampprocky/tokei/blob/master/src/language/syntax.rs) (Syntax Counter), [`src/input.rs`](https://github.com/xampprocky/tokei/blob/master/src/input.rs) (Import and Export)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI and Output"]
  node_cli_entry["CLI Entry<br/>[main.rs]"]
  node_arguments["CLI Options<br/>[cli.rs]"]
  node_printer["Terminal Printer<br/>[cli_utils.rs]"]
  node_formats["Import and Export<br/>[input.rs]"]
  node_constants["Display Constants<br/>[consts.rs]"]
end

subgraph group_scan["File Discovery"]
  node_configuration["Configuration<br/>[config.rs]"]
  node_walker["File Walker<br/>[fs.rs]"]
end

subgraph group_analysis["Language Analysis"]
  node_language_catalog["Language Catalog<br/>[languages.rs]"]
  node_language_types["Language Types<br/>[language_type.rs]"]
  node_syntax_counter["Syntax Counter<br/>[syntax.rs]"]
  node_embedding["Embedded Languages<br/>[embedding.rs]"]
  node_text_helpers["Byte Helpers<br/>[ext.rs]"]
end

subgraph group_results["Statistics and API"]
  node_aggregation["Language Aggregation<br/>[mod.rs]"]
  node_statistics["File Statistics<br/>[stats.rs]"]
  node_sorting["Result Sorting<br/>[sort.rs]"]
  node_library["Library API<br/>[lib.rs]"]
  node_macros["Utility Macros<br/>[macros.rs]"]
end

node_user(("CLI User"))

node_user -->|"provides paths"| node_cli_entry
node_cli_entry -->|"parses options"| node_arguments
node_cli_entry -->|"loads prior stats"| node_formats
node_cli_entry -->|"loads settings"| node_configuration
node_cli_entry -->|"requests statistics"| node_aggregation
node_aggregation -.->|"discovers files"| node_walker
node_walker -.->|"uses scan rules"| node_configuration
node_aggregation -.->|"uses language definitions"| node_language_catalog
node_language_catalog -.->|"defines supported types"| node_language_types
node_aggregation -.->|"counts source"| node_syntax_counter
node_syntax_counter -->|"finds embedded regions"| node_embedding
node_syntax_counter -->|"uses byte helpers"| node_text_helpers
node_syntax_counter -->|"produces counts"| node_statistics
node_aggregation -.->|"stores reports"| node_statistics
node_cli_entry -->|"sorts results"| node_sorting
node_cli_entry -->|"prints results"| node_printer
node_cli_entry -->|"sets output widths"| node_constants
node_cli_entry -->|"serializes results"| node_formats
node_formats -->|"encodes reports"| node_statistics
node_library -->|"exports configuration"| node_configuration
node_library -->|"exports language API"| node_aggregation

click node_cli_entry "https://github.com/xampprocky/tokei/blob/master/src/main.rs"
click node_arguments "https://github.com/xampprocky/tokei/blob/master/src/cli.rs"
click node_printer "https://github.com/xampprocky/tokei/blob/master/src/cli_utils.rs"
click node_formats "https://github.com/xampprocky/tokei/blob/master/src/input.rs"
click node_constants "https://github.com/xampprocky/tokei/blob/master/src/consts.rs"
click node_configuration "https://github.com/xampprocky/tokei/blob/master/src/config.rs"
click node_walker "https://github.com/xampprocky/tokei/blob/master/src/utils/fs.rs"
click node_language_catalog "https://github.com/xampprocky/tokei/blob/master/src/language/languages.rs"
click node_language_types "https://github.com/xampprocky/tokei/blob/master/src/language/language_type.rs"
click node_syntax_counter "https://github.com/xampprocky/tokei/blob/master/src/language/syntax.rs"
click node_embedding "https://github.com/xampprocky/tokei/blob/master/src/language/embedding.rs"
click node_text_helpers "https://github.com/xampprocky/tokei/blob/master/src/utils/ext.rs"
click node_aggregation "https://github.com/xampprocky/tokei/blob/master/src/language/mod.rs"
click node_statistics "https://github.com/xampprocky/tokei/blob/master/src/stats.rs"
click node_sorting "https://github.com/xampprocky/tokei/blob/master/src/sort.rs"
click node_library "https://github.com/xampprocky/tokei/blob/master/src/lib.rs"
click node_macros "https://github.com/xampprocky/tokei/blob/master/src/utils/macros.rs"

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_entry,node_arguments,node_printer,node_formats,node_constants,node_user toneBlue
class node_configuration,node_walker toneAmber
class node_language_catalog,node_language_types,node_syntax_counter,node_embedding,node_text_helpers toneMint
class node_aggregation,node_statistics,node_sorting,node_library,node_macros toneRose
```

## Components

### CLI and Output

- [CLI Entry](https://github.com/xampprocky/tokei/blob/master/src/main.rs): `src/main.rs`
- [CLI Options](https://github.com/xampprocky/tokei/blob/master/src/cli.rs): `src/cli.rs`
- [Terminal Printer](https://github.com/xampprocky/tokei/blob/master/src/cli_utils.rs): `src/cli_utils.rs`
- [Import and Export](https://github.com/xampprocky/tokei/blob/master/src/input.rs): `src/input.rs`
- [Display Constants](https://github.com/xampprocky/tokei/blob/master/src/consts.rs): `src/consts.rs`

### File Discovery

- [Configuration](https://github.com/xampprocky/tokei/blob/master/src/config.rs): `src/config.rs`
- [File Walker](https://github.com/xampprocky/tokei/blob/master/src/utils/fs.rs): `src/utils/fs.rs`

### Language Analysis

- [Language Catalog](https://github.com/xampprocky/tokei/blob/master/src/language/languages.rs): `src/language/languages.rs`
- [Language Types](https://github.com/xampprocky/tokei/blob/master/src/language/language_type.rs): `src/language/language_type.rs`
- [Syntax Counter](https://github.com/xampprocky/tokei/blob/master/src/language/syntax.rs): `src/language/syntax.rs`
- [Embedded Languages](https://github.com/xampprocky/tokei/blob/master/src/language/embedding.rs): `src/language/embedding.rs`
- [Byte Helpers](https://github.com/xampprocky/tokei/blob/master/src/utils/ext.rs): `src/utils/ext.rs`

### Statistics and API

- [Language Aggregation](https://github.com/xampprocky/tokei/blob/master/src/language/mod.rs): `src/language/mod.rs`
- [File Statistics](https://github.com/xampprocky/tokei/blob/master/src/stats.rs): `src/stats.rs`
- [Result Sorting](https://github.com/xampprocky/tokei/blob/master/src/sort.rs): `src/sort.rs`
- [Library API](https://github.com/xampprocky/tokei/blob/master/src/lib.rs): `src/lib.rs`
- [Utility Macros](https://github.com/xampprocky/tokei/blob/master/src/utils/macros.rs): `src/utils/macros.rs`

### Other components

- **CLI User**

## Connections

- CLI User → CLI Entry: provides paths (evidence: `README.md`)
- CLI Entry → CLI Options: parses options (evidence: `src/main.rs`)
- CLI Entry → Import and Export: loads prior stats (evidence: `src/main.rs`)
- CLI Entry → Configuration: loads settings (evidence: `README.md`)
- CLI Entry → Language Aggregation: requests statistics (evidence: `src/main.rs`)
- Language Aggregation → File Walker: discovers files
- File Walker → Configuration: uses scan rules
- Language Aggregation → Language Catalog: uses language definitions (evidence: `src/language/mod.rs`)
- Language Catalog → Language Types: defines supported types
- Language Aggregation → Syntax Counter: counts source (evidence: `src/language/mod.rs`)
- Syntax Counter → Embedded Languages: finds embedded regions (evidence: `src/language/syntax.rs`)
- Syntax Counter → Byte Helpers: uses byte helpers (evidence: `src/language/syntax.rs`)
- Syntax Counter → File Statistics: produces counts (evidence: `src/language/syntax.rs`)
- Language Aggregation → File Statistics: stores reports (evidence: `src/language/mod.rs`)
- CLI Entry → Result Sorting: sorts results (evidence: `src/main.rs`)
- CLI Entry → Terminal Printer: prints results (evidence: `src/main.rs`)
- CLI Entry → Display Constants: sets output widths (evidence: `src/main.rs`)
- CLI Entry → Import and Export: serializes results (evidence: `src/main.rs`)
- Import and Export → File Statistics: encodes reports (evidence: `src/input.rs`)
- Library API → Configuration: exports configuration (evidence: `src/lib.rs`)
- Library API → Language Aggregation: exports language API (evidence: `src/lib.rs`)
