# wildberry-source/open-repoprompt architecture

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

- Interactive diagram: https://gitdiagram.com/wildberry-source/open-repoprompt
- Repository: https://github.com/wildberry-source/open-repoprompt

## Overview

##### Project Type and Purpose
- OpenPrompt is a command-line tool (with a terminal UI) that:
- Scans a local directory tree
- Applies include/exclude filters
- Presents a checkbox-style file selector
- Generates an XML “prompt” of the selected files
- Copies that XML to the OS clipboard
- Enables pasting into any LLM interface
- It’s a modular monolith: a single binary composed of internal packages.

##### File Structure
- Entry Point: cmd/main.go
- Internal Packages:
- fileutils: recursively read directories, handle include/exclude filters
- preferences: persist/set user preferences (e.g. “last-used filters”)
- prompt: assemble the XML structure, serialize file contents
- prompt/clipboard.go: abstract OS clipboard operations
- ui: terminal UI components (app orchestration, filetree widget)
- Tooling & CI:
- build.sh: local build script
- .github/workflows/release.yml: automated build & release pipeline
- go.mod/go.sum: dependency management

##### Key README Insights
- Fastest Serialization into XML
- Workflow: Select Dir → Set Filters → Select Files → Add Instructions → Generate & Copy
- External interactions: OS clipboard, target LLM via manual paste

##### Main Components
a. CLI Entrypoint (cmd/main.go)
b. Terminal UI Layer (internal/ui)
– App orchestrator
– Filetree widget
c. File System Scanner (internal/fileutils)
d. Preferences Manager (internal/preferences)
e. Prompt Generator (internal/prompt)
– XML builder
– Clipboard service
f. Operating System (File System, Clipboard)
g. Developer/User (drives the CLI; pastes into LLM)

##### Relationships & Data Flow
1. User invokes OpenPrompt via CLI → cmd/main.go
2. Main loads Preferences
↔ internal/preferences
3. UI Layer queries File System Scanner
→ internal/fileutils reads disk
4. UI presents directory tree & filters
↔ internal/ui
5. User selects files & enters instructions
→ internal/ui
6. UI calls Prompt Generator
→ internal/prompt assembles XML
7. Prompt Generator writes to OS Clipboard
→ clipboard.go → OS
8. User pastes XML into target LLM UI

##### Architectural Patterns & Principles
- Modular Monolith: clearly delineated packages, no cross-dependencies back into cmd
- Layered design:
- Presentation (ui)
- Business logic (fileutils, preferences, prompt)
- Infrastructure (clipboard, file system)
- Single Responsibility per package; DI via simple function calls

##### Checklist
[ ] Clear labels on every component

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actor
    User["User"]:::actor
    LLM["LLM Interface"]:::external

    %% External Resources
    OSFS["Local File System"]:::external
    OSClip["OS Clipboard"]:::external

    %% OpenPrompt Binary Boundary
    subgraph "OpenPrompt Binary"
        CLI["cmd/main.go\n(CLI Entrypoint)"]:::internal
        Pref["internal/preferences/preferences.go\n(Preferences Manager)"]:::internal
        UIApp["internal/ui/app.go\n(UI Orchestrator)"]:::internal
        UIFT["internal/ui/filetree.go\n(Filetree Widget)"]:::internal
        FSScanner["internal/fileutils/fileutils.go\n(File System Scanner)"]:::internal
        PromptGen["internal/prompt/generator.go\n(XML Builder)"]:::internal
        Clip["internal/prompt/clipboard.go\n(Clipboard Service)"]:::internal
    end

    %% Tooling & CI
    subgraph "Tooling & CI"
        Build["build.sh"]:::external
        CI[".github/workflows/release.yml"]:::external
        Mod["go.mod & go.sum"]:::external
    end

    %% Data Flow
    User -->|"invokes CLI"| CLI
    CLI -->|"load preferences"| Pref
    CLI -->|"start UI"| UIApp
    UIApp -->|"read disk"| FSScanner
    UIApp -->|"render filetree"| UIFT
    UIFT -->|"scan on expand"| FSScanner
    UIApp -->|"file selection"| PromptGen
    PromptGen -->|"write XML"| Clip
    FSScanner --> OSFS
    Clip --> OSClip
    User -->|"pastes XML"| LLM

    %% Click Events
    click CLI "https://github.com/wildberry-source/open-repoprompt/blob/main/cmd/main.go"
    click Pref "https://github.com/wildberry-source/open-repoprompt/blob/main/internal/preferences/preferences.go"
    click UIApp "https://github.com/wildberry-source/open-repoprompt/blob/main/internal/ui/app.go"
    click UIFT "https://github.com/wildberry-source/open-repoprompt/blob/main/internal/ui/filetree.go"
    click FSScanner "https://github.com/wildberry-source/open-repoprompt/blob/main/internal/fileutils/fileutils.go"
    click PromptGen "https://github.com/wildberry-source/open-repoprompt/blob/main/internal/prompt/generator.go"
    click Clip "https://github.com/wildberry-source/open-repoprompt/blob/main/internal/prompt/clipboard.go"
    click Build "https://github.com/wildberry-source/open-repoprompt/blob/main/build.sh"
    click CI "https://github.com/wildberry-source/open-repoprompt/blob/main/.github/workflows/release.yml"
    click Mod "https://github.com/wildberry-source/open-repoprompt/blob/main/go.mod"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px
    classDef actor fill:#F9F,stroke:#000,stroke-width:1px,font-weight:bold
```
