# raghu-reddy-rs/ai-diagram-generator architecture

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

- Interactive diagram: https://gitdiagram.com/raghu-reddy-rs/ai-diagram-generator
- Repository: https://github.com/raghu-reddy-rs/ai-diagram-generator

## Overview

#### Purpose and Entry Points
Diagram Generator is a Node.js CLI that analyzes a local directory or Git repository and writes Markdown architecture documentation containing Mermaid diagrams. The executable command surface is `analyze`, `clone`, and `test`, implemented in `src/cli.js`; `src/index.js` is the package/module export boundary.

#### Command Dispatch and User Inputs
The CLI parses target paths/URLs, branch selection, output path, prompt, Gemini model/API-key overrides, clone lifecycle, and verbosity. `analyze` orchestrates the full pipeline; `clone` exposes repository acquisition independently; `test` verifies Gemini connectivity.
- `src/cli.js`
- `src/index.js`

#### Repository Acquisition Boundary
For URL targets, the analysis workflow invokes Git cloning into a configurable temporary directory, optionally selects a branch, then cleans up unless retention is requested. Local paths bypass this boundary. Git is therefore a required host/container runtime dependency rather than an internal data store.
- `src/cli.js`
- `setup.sh`
- `Dockerfile`

#### Analysis and Prompt-Construction Stage
The core workflow reads the selected codebase and combines its contents/context with either a supplied request or a generated domain-aware prompt. This is the boundary where filesystem/repository data becomes an AI request, intended to identify system structure, flows, and appropriate Mermaid diagram types.
- `src/cli.js`
- `example-prompts.md`
- `example-outputs/example-output.md`

#### Gemini Execution Boundary
Analysis is delegated to Google Gemini—by default Gemini 2.5 Pro—through the Gemini CLI/API-key configuration. Credentials originate from `GEMINI_API_KEY` or a command-line override. The external AI service produces the initial documentation and diagrams; network availability and Gemini CLI installation are material runtime dependencies.
- `src/cli.js`
- `.env.example`
- `setup.sh`

#### Diagram Validation and Output
Generated Mermaid-bearing Markdown passes a validation/correction stage before being persisted to the requested output file (default `analysis-output.md`). The intended control flow is: input → prompt enhancement → Gemini analysis → Mermaid validation/correction → Markdown output.
- `src/cli.js`
- `example-outputs/example-output.md`
- `example-outputs/example-output-2.md`

#### Runtime and Deployment
The application targets Node.js 22+ and can run locally or in Docker. The container setup packages Node, Git, and Gemini-related prerequisites; Compose provides the operational environment and maps generated output to the host for persistence. Local setup installs package dependencies and configures Gemini CLI access.
- `package.json`
- `Dockerfile`
- `docker-compose.yml`

Main entry points: [`src/cli.js`](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js) (Command dispatcher), [`docker-compose.yml`](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/docker-compose.yml) (Compose environment), [`setup.sh`](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/setup.sh) (Local runtime setup), [`Dockerfile`](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/Dockerfile) (Docker image)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI application"]
  node_cli["Command dispatcher<br/>Node.js CLI<br/>[cli.js]"]
  node_module["Package exports<br/>module boundary<br/>[index.js]"]
end

subgraph group_pipeline["Analysis pipeline"]
  node_local["Local directory<br/>repository input"]
  node_git["Git repository URL<br/>remote input"]
  node_clone["Clone lifecycle<br/>repository acquisition<br/>[cli.js]"]
  node_codebase["Selected codebase<br/>filesystem context"]
  node_prompt["Prompt construction<br/>analysis request<br/>[cli.js]"]
  node_gemini{{"Google Gemini<br/>external AI service"}}
  node_validation["Mermaid validation<br/>correction stage<br/>[cli.js]"]
  node_output["Markdown output<br/>generated documentation"]
end

subgraph group_runtime["Runtime &amp; deployment"]
  node_credentials["Gemini credentials<br/>API-key configuration<br/>[.env.example]"]
  node_localruntime["Local runtime setup<br/>Node.js 22+ environment<br/>[setup.sh]"]
  node_container["Docker image<br/>container runtime"]
  node_compose["Compose environment<br/>container orchestration<br/>[docker-compose.yml]"]
  node_package["Package manifest<br/>Node.js package<br/>[package.json]"]
end

node_user(("User / automation<br/>caller"))

node_user -->|"runs commands"| node_cli
node_module -->|"exports CLI surface"| node_cli
node_cli -->|"accepts path"| node_local
node_cli -->|"accepts URL"| node_git
node_git -->|"clone command or analyze"| node_clone
node_clone -->|"temporary checkout"| node_codebase
node_local -->|"bypasses cloning"| node_codebase
node_cli -->|"analyze orchestrates"| node_prompt
node_codebase -->|"provides contents and context"| node_prompt
node_prompt -->|"AI request"| node_gemini
node_credentials -.->|"authenticates"| node_gemini
node_gemini -->|"Markdown with Mermaid"| node_validation
node_validation -->|"validated documentation"| node_output
node_package -.->|"dependencies and runtime"| node_localruntime
node_localruntime -.->|"runs locally"| node_cli
node_container -.->|"runs in container"| node_cli
node_compose -->|"operates image"| node_container
node_compose -.->|"persists to host"| node_output

click node_cli "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js"
click node_module "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/index.js"
click node_clone "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js"
click node_prompt "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js"
click node_validation "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js"
click node_credentials "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/.env.example"
click node_localruntime "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/setup.sh"
click node_container "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/Dockerfile"
click node_compose "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/docker-compose.yml"
click node_package "https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/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_cli,node_module toneBlue
class node_local,node_git,node_clone,node_codebase,node_prompt,node_gemini,node_validation,node_output toneAmber
class node_credentials,node_localruntime,node_container,node_compose,node_package toneMint
class node_user toneNeutral
```

## Components

### CLI application

- [Command dispatcher](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js): Node.js CLI · Implements analyze, clone, and test commands. · `src/cli.js`
- [Package exports](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/index.js): module boundary · `src/index.js`

### Analysis pipeline

- **Local directory**: repository input
- **Git repository URL**: remote input
- [Clone lifecycle](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js): repository acquisition · Clones a selected branch to temporary storage and optionally cleans it up. · `src/cli.js`
- **Selected codebase**: filesystem context
- [Prompt construction](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js): analysis request · Combines codebase context with a supplied or domain-aware prompt. · `src/cli.js`
- **Google Gemini**: external AI service · Produces initial Markdown and Mermaid diagrams.
- [Mermaid validation](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/src/cli.js): correction stage · Validates and corrects generated Mermaid-bearing Markdown. · `src/cli.js`
- **Markdown output**: generated documentation · Persists to the requested path, defaulting to analysis-output.md.

### Runtime & deployment

- [Gemini credentials](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/.env.example): API-key configuration · Uses GEMINI_API_KEY or a command-line override. · `.env.example`
- [Local runtime setup](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/setup.sh): Node.js 22+ environment · Installs dependencies and configures Gemini CLI access. · `setup.sh`
- [Docker image](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/Dockerfile): container runtime · Packages Node, Git, and Gemini prerequisites. · `Dockerfile`
- [Compose environment](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/docker-compose.yml): container orchestration · Maps generated output to the host. · `docker-compose.yml`
- [Package manifest](https://github.com/raghu-reddy-rs/ai-diagram-generator/blob/main/package.json): Node.js package · Declares the Node.js 22+ application runtime. · `package.json`

### Other components

- **User / automation**: caller

## Connections

- User / automation → Command dispatcher: runs commands
- Package exports → Command dispatcher: exports CLI surface
- Command dispatcher → Local directory: accepts path
- Command dispatcher → Git repository URL: accepts URL
- Git repository URL → Clone lifecycle: clone command or analyze
- Clone lifecycle → Selected codebase: temporary checkout
- Local directory → Selected codebase: bypasses cloning
- Command dispatcher → Prompt construction: analyze orchestrates
- Selected codebase → Prompt construction: provides contents and context
- Prompt construction → Google Gemini: AI request
- Gemini credentials → Google Gemini: authenticates
- Google Gemini → Mermaid validation: Markdown with Mermaid
- Mermaid validation → Markdown output: validated documentation
- Package manifest → Local runtime setup: dependencies and runtime
- Local runtime setup → Command dispatcher: runs locally
- Docker image → Command dispatcher: runs in container
- Compose environment → Docker image: operates image
- Compose environment → Markdown output: persists to host
