GitDiagram

repository·main·Indexed 12 days ago

https://github.com/ahmedkhaleel2004/gitdiagram

An AI-powered tool that transforms GitHub repositories into interactive, system-level architecture diagrams using Mermaid.js and LLMs. It analyzes repository trees and READMEs to generate logic-based graphs with interactive links to GitHub files. Supports public and private repositories via GitHub personal access tokens (PAT), streaming generation, and exports to PNG or Mermaid source.

Tokens
5.9K
Snippets
18
Records
28
Agent score
96%

What's inside GitDiagram

  1. Overview of GitDiagram

    main

    GitDiagram is a tool that converts public or private GitHub repositories into interactive architecture diagrams. Unlike simple folder visualizers, it uses AI to analyze the repository tree and README to generate a system-level graph.

    Key Capabilities:

    • Architecture-first diagrams: Generates a graph based on system logic rather than just folder structures.
    • Interactive links: Components in the diagram link directly to their real files or directories on GitHub.
    • Streaming generation: Provides real-time architecture explanations while the graph is being planned.
    • Export options: Users can copy the Mermaid source or download the diagram as a PNG.
    • Private repository support: Users can provide a GitHub personal access token (PAT) locally in the browser to diagram private repos.
  2. Recover GitDiagram on Railway

    main

    If the Vercel production deployment becomes unavailable, GitDiagram can be recovered using Railway. The repository contains a Dockerfile and railway.json configured to package the existing Next.js application (using output: "standalone") for Railway.

    Because the application is self-contained, recovery does not require a separate backend implementation, CORS configuration, or data migration. The application uses /api/healthz for deployment health checks and respects the platform-provided PORT.

  3. Set up GitDiagram for local development

    main

    To run GitDiagram locally, ensure you have bun installed. Follow these steps:

    1. Clone the repository:
      git clone https://github.com/ahmedkhaleel2004/gitdiagram.git
      cd gitdiagram
    2. Install dependencies:
      bun install
    3. Configure environment variables:
      cp .env.example .env
    4. Start the development server:
      bun run dev

    Access the application at http://localhost:3000.

    Required Configuration: You must configure Cloudflare R2, Upstash, and an AI provider (OpenAI or OpenRouter via AI_PROVIDER) in your .env file. While optional, providing a GitHub PAT or GitHub App is recommended to increase GitHub API limits.

    git clone https://github.com/ahmedkhaleel2004/gitdiagram.git
    cd gitdiagram
    bun install
    cp .env.example .env
    bun run dev
  4. Revert from Railway to Vercel

    main

    Once the incident is resolved and you wish to return to the primary Vercel deployment, follow these steps:

    1. Verify Vercel Health: Ensure https://gitdiagram.com/api/healthz is responsive and a small production generation works.
    2. Restore Routing: Restore gitdiagram.com to the intended Vercel deployment if any routing changes were made.
    3. Cleanup Railway: Remove temporary Railway domains and delete the Railway service.
    4. Final Audit: Confirm the Railway project has no active services and the DNS zone contains no Railway records.
  5. Deploy GitDiagram to Railway via CLI

    main

    To perform an offline recovery on Railway, follow these steps to link, configure, and deploy the application. Note that railway up does not automatically connect to GitHub or create a public domain.

    1. Initialize/Link Project: Link the directory to an empty Railway project or create a new one:
      railway link
      # OR
      railway init --name gitdiagram
    2. Create Service: Create an unconnected service for the API:
      railway add --service gitdiagram-api
    3. Configure Variables: Set required environment variables from .env.example. Use --stdin to prevent secrets from appearing in shell history:
      railway variable set VARIABLE_NAME --stdin --service gitdiagram-api
    4. Deploy: Upload and deploy the current checkout:
      railway up --service gitdiagram-api
    5. Verify: Add a temporary Railway domain and verify the health check, cost estimation, streamed generation, cancellation, and persisted diagram state.
    railway link
    railway add --service gitdiagram-api
    railway variable set VARIABLE_NAME --stdin --service gitdiagram-api
    railway up --service gitdiagram-api
  6. Deploy GitDiagram to Vercel

    main

    The primary deployment target is Vercel. The project uses Bun as both the package manager and the server runtime for Route Handlers.

    Key Deployment Details:

    • The project uses runtime = "nodejs" declarations for route-level server runtimes.
    • The project-level bunVersion setting ensures Vercel executes Functions with Bun.
    • Ensure all variables from .env.example are added to your Vercel project settings before deploying.

    Deployment Commands

    vercel deploy
    vercel deploy --prod
  7. Run GitDiagram locally

    main

    Once configured, you can start the application in development or production mode.

    Development Mode

    Run the following command to start the Next.js development server:

    bun run dev

    The application will be available at http://localhost:3000. Note that Next.js Route Handlers under /api/generate/* run within this same process.

    Production Mode (Local Check)

    To test the production build locally:

    bun run build
    bun run start
  8. How to use GitDiagram for private repositories

    main

    To diagram a private repository, select the Private Repos option in the application header. You must provide a fine-grained GitHub personal access token (PAT) that has read access to the target repository.

    Security Note: The token is sent only with the relevant same-origin request and is never embedded in public diagram links. Private artifacts are stored in a separate, protected R2 storage namespace derived with a server-side secret.

  9. Configure environment variables for GitDiagram

    main

    GitDiagram requires several environment variables for storage, coordination, and AI generation. These should be configured in your .env file.

    Storage and Coordination

    • R2_ACCOUNT_ID
    • R2_ACCESS_KEY_ID
    • R2_SECRET_ACCESS_KEY
    • R2_PUBLIC_BUCKET
    • R2_PRIVATE_BUCKET
    • CACHE_KEY_SECRET
    • UPSTASH_REDIS_REST_URL
    • UPSTASH_REDIS_REST_TOKEN

    AI Provider Configuration

    You must choose one AI provider:

    OpenAI

    • AI_PROVIDER=openai
    • OPENAI_API_KEY
    • Optional: OPENAI_MODEL, OPENAI_COMPLIMENTARY_GATE_ENABLED, OPENAI_COMPLIMENTARY_DAILY_LIMIT_TOKENS, OPENAI_COMPLIMENTARY_MODEL_FAMILY
    • Default configuration:
      AI_PROVIDER=openai
      OPENAI_MODEL=gpt-5.6-terra

    OpenRouter

    • AI_PROVIDER=openrouter
    • OPENROUTER_API_KEY
    • Optional: OPENROUTER_MODEL, OPENROUTER_SITE_URL, OPENROUTER_APP_NAME
    • Example configuration:
      AI_PROVIDER=openrouter
      OPENROUTER_API_KEY=... 
      OPENROUTER_MODEL=openai/gpt-5.6-terra
      OPENROUTER_SITE_URL=http://localhost:3000
      OPENROUTER_APP_NAME=GitDiagram

    GitHub Authentication (Optional)

    • GITHUB_PAT: Single token.
    • GITHUB_PATS: Comma- or newline-separated token pool.
    • GITHUB_APP_ID, GITHUB_CLIENT_ID, GITHUB_PRIVATE_KEY, and GITHUB_INSTALLATION_ID: For GitHub App authentication.

    Analytics (Optional)

    • NEXT_PUBLIC_POSTHOG_KEY
    AI_PROVIDER=openai
    OPENAI_MODEL=gpt-5.6-terra
  10. Understand the GenerationSessionAudit structure

    main

    The GenerationSessionAudit interface provides a complete audit trail of a diagram generation attempt. It tracks the lifecycle from idle through running to succeeded or failed.

    Key fields for debugging or monitoring include:

    • status: Current state (idle | running | succeeded | failed).
    • graphAttempts: An array of GraphAttemptAudit objects, useful for seeing how many retries were required to produce a valid graph.
    • validationError: Contains error details if the generated graph failed schema validation.
    • stageUsages: Detailed usage metrics for different generation stages.
    • timeline: A chronological list of GenerationTimelineEvent entries.