# leonkohli/copy4ai architecture

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

- Interactive diagram: https://gitdiagram.com/leonkohli/copy4ai
- Repository: https://github.com/leonkohli/copy4ai

## Overview

Copy4AI is a VS Code extension that packages selected workspace files as a project tree plus file contents for pasting into an LLM. Users initiate copy commands from Explorer, editor tabs, Source Control, or the Command Palette; the extension resolves selections, applies exclusions, reads files or diffs, formats the result, and writes it to the clipboard. Separate documented branches support tree-only copies, force copy, repeat copy, and token warnings. The excerpts show key processing and utility behavior, but not the full command-registration and clipboard-writing code, so some orchestration links rely on README documentation.

Main entry points: [`src/extension.ts`](https://github.com/leonkohli/copy4ai/blob/master/src/extension.ts) (Command orchestrator), [`src/types.ts`](https://github.com/leonkohli/copy4ai/blob/master/src/types.ts) (Shared data types), [`src/utils/fileProcessor.ts`](https://github.com/leonkohli/copy4ai/blob/master/src/utils/fileProcessor.ts) (File processing), [`src/utils/uriUtils.ts`](https://github.com/leonkohli/copy4ai/blob/master/src/utils/uriUtils.ts) (URI resolution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commands["Commands and orchestration"]
  node_extension["Command orchestrator<br/>[extension.ts]"]
  node_lastcopy["Repeat selection state<br/>[lastCopy.ts]"]
end

subgraph group_selection["Selection and policy"]
  node_config["Copy settings<br/>[configuration.ts]"]
  node_migration["Settings migration"]
  node_tabs["Tab selection<br/>[tabSelection.ts]"]
  node_uri["URI resolution<br/>[uriUtils.ts]"]
  node_ignore["Exclusion rules<br/>[ignoreUtils.ts]"]
end

subgraph group_content["Content and presentation"]
  node_processor["File processing<br/>[fileProcessor.ts]"]
  node_tree["Project tree<br/>[projectTree.ts]"]
  node_formatter["Output formatting<br/>[formatters.ts]"]
  node_types["Shared data types<br/>[types.ts]"]
end

subgraph group_extras["SCM and assistance"]
  node_scm["SCM file contents<br/>[extension.ts]"]
  node_diff["Git change diffs<br/>[scmChanges.ts]"]
  node_tokens["Token estimate<br/>[tokenCounter.ts]"]
  node_feedback["Copy feedback<br/>[feedback.ts]"]
end

node_user(("VS Code user"))
node_clipboard["VS Code clipboard"]

node_user -->|"runs command"| node_extension
node_extension -->|"reads settings"| node_config
node_extension -.->|"migrates settings"| node_migration
node_extension -->|"resolves tabs"| node_tabs
node_extension -->|"resolves paths"| node_uri
node_extension -->|"applies exclusions"| node_ignore
node_extension -->|"reads files"| node_processor
node_extension -->|"generates tree"| node_tree
node_extension -->|"requests diffs"| node_diff
node_extension -->|"copies changed files"| node_scm
node_extension -->|"stores selection"| node_lastcopy
node_extension -->|"formats output"| node_formatter
node_extension -->|"writes result"| node_clipboard
node_extension -->|"checks token count"| node_tokens
node_extension -->|"reports completion"| node_feedback
node_processor -->|"checks exclusions"| node_ignore
node_processor -->|"builds relative paths"| node_uri
node_tree -->|"checks exclusions"| node_ignore
node_tree -->|"builds relative paths"| node_uri
node_diff -->|"gets file names"| node_uri
node_tokens -->|"reports warnings"| node_feedback
node_config -->|"uses settings types"| node_types
node_processor -->|"uses content types"| node_types
node_formatter -->|"formats content types"| node_types
node_tokens -->|"returns token data"| node_types
node_migration -->|"uses exclusion types"| node_types

click node_extension "https://github.com/leonkohli/copy4ai/blob/master/src/extension.ts"
click node_config "https://github.com/leonkohli/copy4ai/blob/master/src/utils/configuration.ts"
click node_migration "https://github.com/leonkohli/copy4ai/blob/master/src/utils/settingsMigration.ts"
click node_tabs "https://github.com/leonkohli/copy4ai/blob/master/src/utils/tabSelection.ts"
click node_uri "https://github.com/leonkohli/copy4ai/blob/master/src/utils/uriUtils.ts"
click node_ignore "https://github.com/leonkohli/copy4ai/blob/master/src/utils/ignoreUtils.ts"
click node_processor "https://github.com/leonkohli/copy4ai/blob/master/src/utils/fileProcessor.ts"
click node_tree "https://github.com/leonkohli/copy4ai/blob/master/src/utils/projectTree.ts"
click node_formatter "https://github.com/leonkohli/copy4ai/blob/master/src/utils/formatters.ts"
click node_lastcopy "https://github.com/leonkohli/copy4ai/blob/master/src/utils/lastCopy.ts"
click node_scm "https://github.com/leonkohli/copy4ai/blob/master/src/extension.ts"
click node_diff "https://github.com/leonkohli/copy4ai/blob/master/src/utils/scmChanges.ts"
click node_tokens "https://github.com/leonkohli/copy4ai/blob/master/src/utils/tokenCounter.ts"
click node_feedback "https://github.com/leonkohli/copy4ai/blob/master/src/utils/feedback.ts"
click node_types "https://github.com/leonkohli/copy4ai/blob/master/src/types.ts"

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_extension,node_lastcopy,node_user toneBlue
class node_config,node_migration,node_tabs,node_uri,node_ignore toneAmber
class node_processor,node_tree,node_formatter,node_types toneMint
class node_scm,node_diff,node_tokens,node_feedback toneRose
class node_clipboard toneIndigo
```

## Components

### Commands and orchestration

- [Command orchestrator](https://github.com/leonkohli/copy4ai/blob/master/src/extension.ts): `src/extension.ts`
- [Repeat selection state](https://github.com/leonkohli/copy4ai/blob/master/src/utils/lastCopy.ts): `src/utils/lastCopy.ts`

### Selection and policy

- [Copy settings](https://github.com/leonkohli/copy4ai/blob/master/src/utils/configuration.ts): `src/utils/configuration.ts`
- [Settings migration](https://github.com/leonkohli/copy4ai/blob/master/src/utils/settingsMigration.ts): `src/utils/settingsMigration.ts`
- [Tab selection](https://github.com/leonkohli/copy4ai/blob/master/src/utils/tabSelection.ts): `src/utils/tabSelection.ts`
- [URI resolution](https://github.com/leonkohli/copy4ai/blob/master/src/utils/uriUtils.ts): `src/utils/uriUtils.ts`
- [Exclusion rules](https://github.com/leonkohli/copy4ai/blob/master/src/utils/ignoreUtils.ts): `src/utils/ignoreUtils.ts`

### Content and presentation

- [File processing](https://github.com/leonkohli/copy4ai/blob/master/src/utils/fileProcessor.ts): `src/utils/fileProcessor.ts`
- [Project tree](https://github.com/leonkohli/copy4ai/blob/master/src/utils/projectTree.ts): `src/utils/projectTree.ts`
- [Output formatting](https://github.com/leonkohli/copy4ai/blob/master/src/utils/formatters.ts): `src/utils/formatters.ts`
- [Shared data types](https://github.com/leonkohli/copy4ai/blob/master/src/types.ts): `src/types.ts`

### SCM and assistance

- [SCM file contents](https://github.com/leonkohli/copy4ai/blob/master/src/extension.ts): `src/extension.ts`
- [Git change diffs](https://github.com/leonkohli/copy4ai/blob/master/src/utils/scmChanges.ts): `src/utils/scmChanges.ts`
- [Token estimate](https://github.com/leonkohli/copy4ai/blob/master/src/utils/tokenCounter.ts): `src/utils/tokenCounter.ts`
- [Copy feedback](https://github.com/leonkohli/copy4ai/blob/master/src/utils/feedback.ts): `src/utils/feedback.ts`

### Other components

- **VS Code user**
- **VS Code clipboard**

## Connections

- VS Code user → Command orchestrator: runs command (evidence: `README.md`)
- Command orchestrator → Copy settings: reads settings (evidence: `src/extension.ts`)
- Command orchestrator → Settings migration: migrates settings (evidence: `src/extension.ts`)
- Command orchestrator → Tab selection: resolves tabs (evidence: `README.md`)
- Command orchestrator → URI resolution: resolves paths (evidence: `src/extension.ts`)
- Command orchestrator → Exclusion rules: applies exclusions (evidence: `src/extension.ts`)
- Command orchestrator → File processing: reads files (evidence: `README.md`)
- Command orchestrator → Project tree: generates tree (evidence: `README.md`)
- Command orchestrator → Git change diffs: requests diffs (evidence: `README.md`)
- Command orchestrator → SCM file contents: copies changed files (evidence: `README.md`)
- Command orchestrator → Repeat selection state: stores selection (evidence: `README.md`)
- Command orchestrator → Output formatting: formats output (evidence: `README.md`)
- Command orchestrator → VS Code clipboard: writes result (evidence: `README.md`)
- Command orchestrator → Token estimate: checks token count (evidence: `README.md`)
- Command orchestrator → Copy feedback: reports completion (evidence: `src/extension.ts`)
- File processing → Exclusion rules: checks exclusions (evidence: `src/utils/fileProcessor.ts`)
- File processing → URI resolution: builds relative paths (evidence: `src/utils/fileProcessor.ts`)
- Project tree → Exclusion rules: checks exclusions (evidence: `src/utils/projectTree.ts`)
- Project tree → URI resolution: builds relative paths (evidence: `src/utils/projectTree.ts`)
- Git change diffs → URI resolution: gets file names (evidence: `src/utils/scmChanges.ts`)
- Token estimate → Copy feedback: reports warnings (evidence: `src/utils/tokenCounter.ts`)
- Copy settings → Shared data types: uses settings types (evidence: `src/utils/configuration.ts`)
- File processing → Shared data types: uses content types (evidence: `src/utils/fileProcessor.ts`)
- Output formatting → Shared data types: formats content types (evidence: `src/utils/formatters.ts`)
- Token estimate → Shared data types: returns token data (evidence: `src/utils/tokenCounter.ts`)
- Settings migration → Shared data types: uses exclusion types (evidence: `src/utils/settingsMigration.ts`)
