# calchiwo/etr architecture

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

- Interactive diagram: https://gitdiagram.com/calchiwo/etr
- Repository: https://github.com/calchiwo/etr

## Overview

1. This repository is a multi-distribution product centered on a **Python analysis engine** called `explain_this_repo`, with a **Node.js wrapper/binary distribution** and a separate **Next.js marketing/docs site** under `apps/web`.

2. The main architectural boundary is between **input normalization + repository inspection** and **LLM-backed explanation generation**. The tool accepts GitHub repositories, GitHub file paths, local directories, or single files, then converts those inputs into a normalized repository/file view before generating an explanation.

3. In the Python core, `cli.py` and `__main__.py` are the command entrypoints. `config.py`, `init.py`, and `github.py` handle user setup, model/provider selection, and GitHub access concerns such as private repos and API tokens.

4. Repository and file ingestion is split across dedicated readers: `repo_reader.py`, `local_reader.py`, and `file_reader.py`. This suggests a clear separation between remote GitHub analysis, local filesystem analysis, and single-file analysis, with `generate.py` orchestrating the downstream flow.

5. The analysis pipeline builds a structured prompt from repo signals. `stack_detector.py` and `stack_printer.py` infer the technology stack from manifests, configs, entrypoints, and other high-signal files, while `prompt.py` packages those signals into the model input that drives the explanation.

6. LLM integration is abstracted behind `providers/`. There is a provider interface plus concrete adapters for **Anthropic, Gemini, Groq, Ollama, OpenAI, and OpenRouter**, with `providers/registry.py` handling provider lookup/selection. This makes model choice a pluggable runtime concern rather than something hardcoded into the analysis pipeline.

7. Output is handled separately from generation. `writer.py` is responsible for formatting and emitting the result to `EXPLAIN.md`, stdout, or alternate output targets, which keeps the analysis engine independent from presentation and file-writing concerns.

8. The Node.js side in `node_version/` mirrors the Python capabilities and serves as the packaging layer for npm users and standalone binaries. The `_legacy/` subtree indicates a previous TypeScript implementation retained for compatibility or reference, while `cli.ts` is the current Node entrypoint.

9. `scripts/build_pyinstaller.py` and `scripts/pyinstaller_entry.py` show that the Python application is also packaged into standalone executables. Combined with the release workflows, this repo supports three distribution modes: Python package, npm package/binary, and direct downloadable release assets.

10. `apps/web` is a separate Next.js application used for the public site. Its component structure (`hero`, `features`, `downloads`, `install`, `terminal-demo`, etc.) indicates a marketing/documentation frontend rather than part of the core analysis engine.

11. The GitHub Actions workflows reflect the repo’s release-oriented architecture. `ci.yml` covers validation, while `release-binaries.yml` builds and publishes binaries, supporting the cross-runtime distribution strategy described in the README.

12. Overall, the system is organized as: **input normalization → repo/file signal extraction → stack detection → prompt construction → LLM provider call → formatted output**. The key diagram boundaries are between the analysis core, provider adapters, output/writer layer, and the separate packaging/frontend surfaces.

Main entry points: [`explain_this_repo/generate.py`](https://github.com/calchiwo/etr/blob/main/explain_this_repo/generate.py) (Generate), [`.github/workflows`](https://github.com/calchiwo/etr/blob/main/.github/workflows) (CI / release), [`apps/web`](https://github.com/calchiwo/etr/tree/main/apps/web) (Next.js app), [`explain_this_repo/config.py`](https://github.com/calchiwo/etr/blob/main/explain_this_repo/config.py) (Config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_python_core["Python core"]
  node_python_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_python_main["Module run<br/>entrypoint<br/>[__main__.py]"]
  node_python_config["Config<br/>setup<br/>[config.py]"]
  node_python_init["Init<br/>bootstrap<br/>[init.py]"]
  node_python_github[("GitHub access<br/>integration<br/>[github.py]")]
  node_python_readers["Readers<br/>ingestion"]
  node_python_generate{{"Generate<br/>orchestration<br/>[generate.py]"}}
  node_python_stack_detector["Stack detect<br/>analysis<br/>[stack_detector.py]"]
  node_python_stack_printer["Stack print<br/>presentation<br/>[stack_printer.py]"]
  node_python_prompt["Prompt<br/>[prompt.py]"]
  node_python_providers["Providers<br/>llm adapters"]
  node_python_writer["Writer<br/>output<br/>[writer.py]"]
end

subgraph group_node_dist["Node distribution"]
  node_node_cli["Node CLI<br/>entrypoint<br/>[cli.ts]"]
  node_node_legacy["Legacy TS<br/>legacy impl"]
end

subgraph group_web_site["Web site"]
  node_web_app["Next.js app<br/>frontend"]
  node_web_components["Site sections<br/>ui"]
  node_web_pages["App shell<br/>ui"]
end

subgraph group_release_infra["Release infra"]
  node_build_pyinstaller{{"PyInstaller build<br/>packaging"}}
  node_pyinstaller_entry["PyInstaller entry<br/>packaging"]
  node_ci_workflows["CI / release<br/>automation<br/>[workflows]"]
end

node_python_cli -->|"starts"| node_python_generate
node_python_main -->|"starts"| node_python_generate
node_python_generate -->|"loads input"| node_python_readers
node_python_readers -->|"uses"| node_python_github
node_python_generate -->|"analyzes"| node_python_stack_detector
node_python_stack_detector -->|"formats"| node_python_stack_printer
node_python_generate -->|"builds"| node_python_prompt
node_python_generate -->|"calls"| node_python_providers
node_python_providers -->|"returns output"| node_python_writer
node_python_config -->|"configures"| node_python_generate
node_python_init -->|"boots"| node_python_config
node_node_cli -.->|"mirrors"| node_node_legacy
node_web_app -->|"composes"| node_web_components
node_web_app -->|"renders"| node_web_pages
node_build_pyinstaller -->|"packages"| node_pyinstaller_entry
node_ci_workflows -->|"builds"| node_build_pyinstaller
node_ci_workflows -->|"releases"| node_node_cli
node_ci_workflows -.->|"publishes"| node_web_app

click node_python_cli "https://github.com/calchiwo/etr/blob/main/explain_this_repo/cli.py"
click node_python_main "https://github.com/calchiwo/etr/blob/main/explain_this_repo/__main__.py"
click node_python_config "https://github.com/calchiwo/etr/blob/main/explain_this_repo/config.py"
click node_python_init "https://github.com/calchiwo/etr/blob/main/explain_this_repo/init.py"
click node_python_github "https://github.com/calchiwo/etr/blob/main/explain_this_repo/github.py"
click node_python_generate "https://github.com/calchiwo/etr/blob/main/explain_this_repo/generate.py"
click node_python_stack_detector "https://github.com/calchiwo/etr/blob/main/explain_this_repo/stack_detector.py"
click node_python_stack_printer "https://github.com/calchiwo/etr/blob/main/explain_this_repo/stack_printer.py"
click node_python_prompt "https://github.com/calchiwo/etr/blob/main/explain_this_repo/prompt.py"
click node_python_providers "https://github.com/calchiwo/etr/tree/main/explain_this_repo/providers"
click node_python_writer "https://github.com/calchiwo/etr/blob/main/explain_this_repo/writer.py"
click node_node_cli "https://github.com/calchiwo/etr/blob/main/node_version/cli.ts"
click node_node_legacy "https://github.com/calchiwo/etr/tree/main/node_version/_legacy"
click node_web_app "https://github.com/calchiwo/etr/tree/main/apps/web"
click node_web_components "https://github.com/calchiwo/etr/tree/main/apps/web/components"
click node_web_pages "https://github.com/calchiwo/etr/tree/main/apps/web/app"
click node_build_pyinstaller "https://github.com/calchiwo/etr/blob/main/scripts/build_pyinstaller.py"
click node_pyinstaller_entry "https://github.com/calchiwo/etr/blob/main/scripts/pyinstaller_entry.py"
click node_ci_workflows "https://github.com/calchiwo/etr/blob/main/.github/workflows"

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_python_cli,node_python_main,node_python_config,node_python_init,node_python_github,node_python_readers,node_python_generate,node_python_stack_detector,node_python_stack_printer,node_python_prompt,node_python_providers,node_python_writer toneBlue
class node_node_cli,node_node_legacy toneAmber
class node_web_app,node_web_components,node_web_pages toneMint
class node_build_pyinstaller,node_pyinstaller_entry,node_ci_workflows toneRose
```

## Components

### Python core

Main analysis engine and CLI.

- [CLI](https://github.com/calchiwo/etr/blob/main/explain_this_repo/cli.py): entrypoint · Python command entrypoints for the tool. · `explain_this_repo/cli.py`
- [Module run](https://github.com/calchiwo/etr/blob/main/explain_this_repo/__main__.py): entrypoint · Python package execution entrypoint. · `explain_this_repo/__main__.py`
- [Config](https://github.com/calchiwo/etr/blob/main/explain_this_repo/config.py): setup · User configuration and model/provider selection. · `explain_this_repo/config.py`
- [Init](https://github.com/calchiwo/etr/blob/main/explain_this_repo/init.py): bootstrap · Initialization and first-run setup flow. · `explain_this_repo/init.py`
- [GitHub access](https://github.com/calchiwo/etr/blob/main/explain_this_repo/github.py): integration · GitHub repo access, auth, and private repo handling. · `explain_this_repo/github.py`
- **Readers**: ingestion · Repository, local, and single-file input normalization.
- [Generate](https://github.com/calchiwo/etr/blob/main/explain_this_repo/generate.py): orchestration · Coordinates ingestion, analysis, provider calls, and result assembly. · `explain_this_repo/generate.py`
- [Stack detect](https://github.com/calchiwo/etr/blob/main/explain_this_repo/stack_detector.py): analysis · Infers technology stack from repo signals. · `explain_this_repo/stack_detector.py`
- [Stack print](https://github.com/calchiwo/etr/blob/main/explain_this_repo/stack_printer.py): presentation · Formats detected stack information for prompts/output. · `explain_this_repo/stack_printer.py`
- [Prompt](https://github.com/calchiwo/etr/blob/main/explain_this_repo/prompt.py): prompting · Builds structured LLM input from repo signals. · `explain_this_repo/prompt.py`
- [Providers](https://github.com/calchiwo/etr/tree/main/explain_this_repo/providers): llm adapters · Provider implementations and runtime selection. · `explain_this_repo/providers`
- [Writer](https://github.com/calchiwo/etr/blob/main/explain_this_repo/writer.py): output · Writes results to files or stdout. · `explain_this_repo/writer.py`

### Node distribution

npm/binary packaging layer and legacy implementation.

- [Node CLI](https://github.com/calchiwo/etr/blob/main/node_version/cli.ts): entrypoint · Current Node.js command entrypoint. · `node_version/cli.ts`
- [Legacy TS](https://github.com/calchiwo/etr/tree/main/node_version/_legacy): legacy impl · Previous TypeScript implementation kept under _legacy. · `node_version/_legacy`

### Web site

Next.js marketing and docs frontend.

- [Next.js app](https://github.com/calchiwo/etr/tree/main/apps/web): frontend · Public marketing and documentation site. · `apps/web`
- [Site sections](https://github.com/calchiwo/etr/tree/main/apps/web/components): ui · Hero, features, install, downloads, terminal demo, and related sections. · `apps/web/components`
- [App shell](https://github.com/calchiwo/etr/tree/main/apps/web/app): ui · Root app layout and landing page. · `apps/web/app`

### Release infra

Build, packaging, and CI automation.

- [PyInstaller build](https://github.com/calchiwo/etr/blob/main/scripts/build_pyinstaller.py): packaging · Builds standalone Python executables. · `scripts/build_pyinstaller.py`
- [PyInstaller entry](https://github.com/calchiwo/etr/blob/main/scripts/pyinstaller_entry.py): packaging · Entry shim used by the executable build. · `scripts/pyinstaller_entry.py`
- [CI / release](https://github.com/calchiwo/etr/blob/main/.github/workflows): automation · Validation and binary release workflows. · `.github/workflows`

## Connections

- CLI → Generate: starts · CLI dispatches into the main analysis pipeline.
- Module run → Generate: starts · Module execution enters the same pipeline.
- Generate → Readers: loads input · Normalizes repository, directory, file, or GitHub input.
- Readers → GitHub access: uses · GitHub-based ingestion relies on auth and access helpers.
- Generate → Stack detect: analyzes · Derives stack and framework signals from the ingested tree.
- Stack detect → Stack print: formats · Detected stack information is rendered for prompt use.
- Generate → Prompt: builds · Assembles the model prompt from repo signals and stack data.
- Generate → Providers: calls · Sends the prompt through the selected LLM provider.
- Providers → Writer: returns output · Provider response is handed to the output layer for emission.
- Config → Generate: configures · Controls provider choice and runtime settings.
- Init → Config: boots · Initialization prepares configuration for first use.
- Node CLI → Legacy TS: mirrors · Node package retains the prior implementation as a legacy subtree.
- Next.js app → Site sections: composes · Landing page is assembled from section components.
- Next.js app → App shell: renders · Next.js app shell provides layout and home page.
- PyInstaller build → PyInstaller entry: packages · Executable build uses the dedicated entry shim.
- CI / release → PyInstaller build: builds · Release automation produces standalone binaries.
- CI / release → Node CLI: releases · CI/release workflows support the Node distribution path.
- CI / release → Next.js app: publishes · Repository automation supports the public web site surface.
