# sourav-maji/auto-doc-generator architecture

> Architecture diagram of the GitHub repository sourav-maji/auto-doc-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sourav-maji/auto-doc-generator
- Repository: https://github.com/sourav-maji/auto-doc-generator

## Overview

##### Project type and purpose
- This is a Node.js backend service (“auto-doc-generator”) whose sole purpose is to automatically update project documentation on every code change.
- It exposes a CLI or script entry point (via npm scripts) that:
1. Computes a `git diff`
2. Feeds the diff and existing docs into Google Gemini AI
3. Receives a Markdown update
4. Writes to `docs/UPDATED_DOCUMENTATION.md`
5. Optionally commits & pushes the updated docs

##### File structure
- Top-level files:
- `app.js` – Express app setup & entry point
- `package.json` + `.env.example` – dependencies & env-config
- Folders:
- `routes/` – HTTP route definitions (e.g., `userRoutes.js`)
- `controllers/` – Business logic handlers (e.g., `userController.js`)
- `ai/` – Core AI logic (`autoDocAgent.js`) that calls Google Gemini
- `docs/` – The Markdown file being maintained
- CI/CD & automation: npm scripts in `package.json` to run `generate-docs`

##### README
- Confirms: Express + File System + Google Gemini + Git integration
- Usage pattern: run `npm start` for server; run `npm run generate-docs` for docs update
- Emphasizes integration points: Git CLI, Generative AI API, file writes, optional Git commit

a. Main components
1. CLI / Scheduler / CI Pipeline
2. Express Application (app.js)
– Routes layer (`routes/userRoutes.js`)
– Controllers layer (`controllers/userController.js`)
3. AI Agent Module (`ai/autoDocAgent.js`)
4. Git Subsystem (executes `git diff`, `git commit`)
5. File System (`docs/UPDATED_DOCUMENTATION.md`)
6. Google Gemini API (external service)
7. dotenv / Config store (environment variables)
b. Relationships & data flow
- The CLI or CI triggers the “Generate Docs” command →
- Express app (or direct script) loads .env →
- Calls Git Subsystem: fetch diff →
- Passes diff + existing docs to AI Agent →
- AI Agent issues API call to Google Gemini →
- Receives updated Markdown →
- Writes update to `docs/UPDATED_DOCUMENTATION.md` →
- Optionally invokes Git Subsystem again to commit & push
c. Architectural patterns & design principles
- MVC-style separation: Routes → Controllers
- Single-responsibility modules: AI logic isolated in `ai/autoDocAgent.js`
- Externalized configuration (dotenv) for API keys & flags
- Scriptable entry points (npm scripts) for integration into CI/CD
d. Key technologies & libraries
- Express.js (HTTP server)
- Node.js File System (fs)
- child_process or simple-git for Git operations
- Google Gemini 2.5 via Generative AI API
- dotenv for config

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Triggers
    CLI["CLI / CI Pipeline"]:::trigger
    %% Core Application
    subgraph "Express Application"
        Express["Express App"]:::core
        Routes["routes/userRoutes.js"]:::core
        Controllers["controllers/userController.js"]:::core
    end
    %% Modules
    Config["Config Store (.env)"]:::conf
    Git["Git Subsystem"]:::external
    AI["AI Agent Module"]:::core
    API["Google Gemini API"]:::external
    Docs["File System (docs/UPDATED_DOCUMENTATION.md)"]:::storage

    %% Flows
    CLI -->|"npm start (HTTP mode)"| Express
    CLI -->|"npm run generate-docs"| Express
    Express -->|imports| Config
    Express -->|handles routes| Routes
    Routes -->|calls| Controllers
    Express -->|"git diff"| Git
    Git -->|"diff + docs"| AI
    AI -->|"Generative AI Request"| API
    API -->|"Markdown Response"| AI
    AI -->|"write update"| Docs
    Docs -->|"git commit & push"| Git

    %% Click Events
    click CLI "https://github.com/sourav-maji/auto-doc-generator/blob/main/package.json"
    click Express "https://github.com/sourav-maji/auto-doc-generator/blob/main/app.js"
    click Routes "https://github.com/sourav-maji/auto-doc-generator/blob/main/routes/userRoutes.js"
    click Controllers "https://github.com/sourav-maji/auto-doc-generator/blob/main/controllers/userController.js"
    click Config "https://github.com/sourav-maji/auto-doc-generator/blob/main/.env.example"
    click AI "https://github.com/sourav-maji/auto-doc-generator/blob/main/ai/autoDocAgent.js"
    click Docs "https://github.com/sourav-maji/auto-doc-generator/blob/main/docs/UPDATED_DOCUMENTATION.md"

    %% Styles
    classDef core fill:#a2d2ff,stroke:#000,stroke-width:1px
    classDef external fill:#ffafcc,stroke:#000,stroke-width:1px
    classDef conf fill:#cdb4db,stroke:#000,stroke-width:1px
    classDef storage fill:#ffffd2,stroke:#000,stroke-width:1px
    classDef trigger fill:#bde0fe,stroke:#000,stroke-width:1px
```
