How raghu-reddy-rs/ai-diagram-generator works
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: cli.js Command dispatcher · docker-compose.yml Compose environment · setup.sh Local runtime setup · Dockerfile Docker image
Components 16
CLI application
- Command dispatcher · Implements analyze, clone, and test commands.
src/cli.js - Package exports
src/index.js
Analysis pipeline
- Local directory
- Git repository URL
- Clone lifecycle · Clones a selected branch to temporary storage and optionally cleans it up.
src/cli.js - Selected codebase
- Prompt construction · Combines codebase context with a supplied or domain-aware prompt.
src/cli.js - Google Gemini · Produces initial Markdown and Mermaid diagrams.
- Mermaid validation · Validates and corrects generated Mermaid-bearing Markdown.
src/cli.js - Markdown output · Persists to the requested path, defaulting to analysis-output.md.
Runtime & deployment
- Gemini credentials · Uses GEMINI_API_KEY or a command-line override.
.env.example - Local runtime setup · Installs dependencies and configures Gemini CLI access.
setup.sh - Docker image · Packages Node, Git, and Gemini prerequisites.
Dockerfile - Compose environment · Maps generated output to the host.
docker-compose.yml - Package manifest · Declares the Node.js 22+ application runtime.
package.json
Other components
- User / automation
Connections 18
- 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