# ismail-seleit/revitgeminirag architecture

> Architecture diagram of the GitHub repository ismail-seleit/revitgeminirag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ismail-seleit/revitgeminirag
- Repository: https://github.com/ismail-seleit/revitgeminirag

## Overview

##### Main Components
a. Revit Host Application
- Autodesk Revit 2025 process (loads add-in via `.addin` manifest)
b. -in Loader & Manifest
- `RevitGeminiRAG.addin` loads `RevitGeminiRAG.dll` into Revit’s AppDomain
c. C# Plugin Backend
- RunRAGCommand.cs (command entry point)
- PromptForm.cs/Designer (WinForms UI for user input and response display)
- App.config, NuGet-managed assemblies (`Google.Cloud.AIPlatform.V1`, gRPC, IronPython, Newtonsoft.Json, etc.)
d. RAG Prompt Generator (Python)
- `python/generate_rag_prompt.py` invoked in-process via IronPython/DLR
- Local knowledge store (embeddings + API docs) or vector database (abstracted)
e. External LLM Service
- Google Gemini API over gRPC (via Google.Cloud.AIPlatform.V1 client)
- Protos folder for service definitions
f. Dynamic Script Execution
- IronPython engine interprets both RAG script and LLM-generated Python
- `GeneratedSuccessfulCode/` folder: archive of one-shot scripts
g. Revit API
- `RevitAPI.dll`, `RevitAPIUI.dll` invoked by either C# or Python code to manipulate the model

##### Relationships & Data Flows
- User clicks button in Revit ribbon → RunRAGCommand is invoked
- RunRAGCommand opens PromptForm and captures user’s natural-language query
- PromptForm passes query to RAG generator (IronPython calls `generate_rag_prompt.py`)
- RAG generator retrieves relevant API context from local store, combines with query → forms prompt
- C# backend sends prompt to Google Gemini via gRPC → receives LLM response (Python code + plain text)
- C# backend hands generated Python to IronPython engine for execution in Revit context
- Executed script calls Revit API to perform operations (e.g., hide walls, export CSV)
- Results or exceptions are returned to PromptForm and displayed to the user
- Optionally, successful code is saved under `GeneratedSuccessfulCode/`

##### Architectural Patterns & Principles
- Plugin Architecture: in-process extension loaded by host application via add-in manifest
- Mediator Pattern: RunRAGCommand orchestrates between UI, Python RAG, LLM client, and Revit API
- RAG Pattern: retrieval of API docs + LLM generation for accurate domain-specific code
- Embedded Interpreter: IronPython (Dynamic Language Runtime) for Python integration inside .NET
- gRPC Microservice: external LLM service interaction via Google AIPlatform client

##### Technologies & Frameworks
- .NET Framework 4.8 host for Revit plugin
- WinForms (`PromptForm.cs`) for user interaction
- IronPython/DLR (`Microsoft.Scripting` packages) for Python execution
- Google.Cloud.AIPlatform.V1 + gRPC/*.Proto for LLM communication
- Vector store or file-based embeddings for RAG context
- NuGet packages (Newtonsoft.Json for serialization, DI abstractions, logging, etc.)

##### Elements
- User → UI → Controller → RAG Generator → LLM → Controller → Interpreter → Revit API → UI
- Blue for on-host/plugin
- Green for local data stores
- Orange for external cloud service
- Annotations for build/deploy artifacts (e.g., `.addin` manifest, `.dll`, Python scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Revit Host (Autodesk Revit 2025)"
        RevitProcess["Revit Process\n(Autodesk Revit 2025)"]:::host
        AddinLoader["Add-in Loader & Manifest\nRevitGeminiRAG.addin"]:::plugin
    end

    subgraph "C# Plugin Backend"
        RunCommand["RunRAGCommand.cs\n(Orchestrator)"]:::plugin
        PromptForm["WinForms UI\nPromptForm.cs\nPromptForm.Designer.cs\nPromptForm.resx"]:::plugin
        DotNetConfig[".NET Project & Configuration\nRevitGeminiRAG.csproj\napp.config\npackages.config"]:::plugin
        LLMClientLib["LLM Client Library\nGoogle.Cloud.AIPlatform.V1"]:::plugin
        IronPythonEngine["IronPython Engine\n(DLR)"]:::plugin
    end

    subgraph "Python RAG Prompt Generator"
        RAGGen["generate_rag_prompt.py"]:::plugin
    end

    subgraph "Local Data Stores"
        KnowledgeStore["API Docs & Embeddings"]:::store
        GeneratedCode["GeneratedSuccessfulCode/"]:::store
    end

    subgraph "Protos Definitions"
        Protos["protos/"]:::plugin
    end

    LLMService["Google Gemini API\n(gRPC Service)"]:::external
    RevitAPI["RevitAPI.dll & RevitAPIUI.dll\n(Revit API)"]:::host

    %% Flows
    User["User"]:::external -->|"click Ribbon button"| RunCommand
    RunCommand -->|"opens"| PromptForm
    PromptForm -->|"user query"| RunCommand
    RunCommand -->|"IronPython call"| RAGGen
    RAGGen -->|"retrieves context"| KnowledgeStore
    RAGGen -->|"prompt text"| RunCommand
    RunCommand -->|"gRPC"| LLMClientLib
    LLMClientLib -->|"gRPC"| LLMService
    LLMService -->|"LLM response"| LLMClientLib
    LLMClientLib -->|"code + text"| RunCommand
    RunCommand -->|"IronPython execute"| IronPythonEngine
    IronPythonEngine -->|"executes script"| RevitAPI
    RevitAPI -->|"results/exceptions"| IronPythonEngine
    IronPythonEngine -->|"output"| RunCommand
    RunCommand -->|"display result"| PromptForm
    RunCommand -->|"archive code"| GeneratedCode

    %% Click Events
    click AddinLoader "https://github.com/ismail-seleit/revitgeminirag/blob/main/RevitGeminiRAG.addin"
    click RunCommand "https://github.com/ismail-seleit/revitgeminirag/blob/main/RunRAGCommand.cs"
    click PromptForm "https://github.com/ismail-seleit/revitgeminirag/blob/main/PromptForm.cs"
    click PromptForm "https://github.com/ismail-seleit/revitgeminirag/blob/main/PromptForm.Designer.cs"
    click PromptForm "https://github.com/ismail-seleit/revitgeminirag/blob/main/PromptForm.resx"
    click DotNetConfig "https://github.com/ismail-seleit/revitgeminirag/blob/main/RevitGeminiRAG.csproj"
    click DotNetConfig "https://github.com/ismail-seleit/revitgeminirag/blob/main/app.config"
    click DotNetConfig "https://github.com/ismail-seleit/revitgeminirag/blob/main/packages.config"
    click RAGGen "https://github.com/ismail-seleit/revitgeminirag/blob/main/python/generate_rag_prompt.py"
    click Protos "https://github.com/ismail-seleit/revitgeminirag/tree/main/protos/"
    click LLMClientLib "https://github.com/ismail-seleit/revitgeminirag/blob/main/packages/Google.Cloud.AIPlatform.V1.3.25.0"
    click GeneratedCode "https://github.com/ismail-seleit/revitgeminirag/tree/main/GeneratedSuccessfulCode/"
    click IronPythonEngine "https://github.com/ismail-seleit/revitgeminirag/tree/main/packages/DynamicLanguageRuntime.1.3.5/"
    click IronPythonEngine "https://github.com/ismail-seleit/revitgeminirag/tree/main/packages/IronPython.3.4.2/"

    %% Styles
    classDef host fill:#CFE2F3,stroke:#036,COLOR:#000;
    classDef plugin fill:#BDD7EE,stroke:#036,COLOR:#000;
    classDef store fill:#D9EAD3,stroke:#090,COLOR:#000;
    classDef external fill:#FCE5CD,stroke:#E80,COLOR:#000;
```
