# azula1a89/mindmap architecture

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

- Interactive diagram: https://gitdiagram.com/azula1a89/mindmap
- Repository: https://github.com/azula1a89/mindmap

## Overview

Based on our analysis of the file tree and the README, we know that this project is a standalone mindmap editor written in C++ with support for both manual and auto layout (with graph routing) and an optional integration with a locally running LLM (via Ollama) for idea generation. The application is Windows-only and uses a combination of third-party libraries (such as imgui for GUI, glfw/glew for graphics, fmt for formatting, inja for template-based output generation, and others for JSON handling, base64 encoding, file dialogs, and image support).

##### Main Components
- User Interface (UI):
- This component handles canvas interaction (node creation, edge manipulation, zoom/pan, editing), theme switching (dark/light/classic), and managing input events.
- It is implemented with the help of the third-party libraries imgui (with its backends for glfw and OpenGL3), glfw, and glew.
- Core Mindmap Engine:
- The “src” folder contains files like main.cpp, mindmap.cpp, mindmap_state_machine.h, and several components related to graph layout and commands. These together form the core engine, processing user actions, applying state machines, managing undo/redo operations, and coordinating graph layout and editing logic.
- Template and Export Engine:
- The “templates” directory houses various template files (for SVG, HTML, JSON outputs, and even configuration files like imgui.ini). This engine uses inja and json libraries so that the export formats can be customized.
- LLM Integration Module:
- While not a separate folder, the README and references to "LLM" and "Ollama" suggest that part of the system can call an LLM (if run locally) to generate ideas. This functionality is likely integrated in the core logic (perhaps triggered via UI, with configurable prompts using a template system) and uses the httplib for API calls.
- Third-Party Libraries & Build Infrastructure:
- The “thirdparty” directory holds many libraries that provide rendering (imgui, glfw, glew), templating (inja), JSON processing (json), layout (libavoid, libcola, libvpsc), and support utilities (base64, fmt, stb_image, native file dialog).
- The CMakeLists.txt at the top level and within some subdirectories indicate a CMake-based build system.

##### Relationships and Data Flow
- UI Layer:
- Connects directly with the Mindmap engine – capturing user events (mouse clicks, drags, keyboard shortcuts) and propagating commands.
- Communicates with the rendering libraries (imgui, OpenGL via glfw/glew) to update what the user sees.
- Core Engine:
- Processes commands from the UI.
- Updates the mindmap state (nodes, edges, groups, animations, layout positions) and invokes the auto-layout algorithms (provided partly via libavoid/libcola/libvpsc).
- Orchestrates exporting operations by calling the Template Engine when the user requests an export action.
- May trigger the LLM integration to supply inspiration by formatting an API call via httplib.
- Export/Template Engine:
- Reads template files and uses inja along with the json library to generate final outputs (SVG, HTML) based on the current mindmap state.
- LLM Integration:
- When the user selects a trigger (for example, by right-clicking the “ai.” button), the module prepares an API call to a local Ollama instance, using a configurable prompt (possibly set by templates) and then integrates the returned ideas back into the mindmap.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- UI, business logic (mindmap editing), and export processing are well-separated.
- Third-party libraries are encapsulated within their own directories, supporting modular design.
- Event-Driven & Command Patterns:
- The operations like node selection, editing, and undo/redo indicate a command-based pattern.
- Template-Driven Customization:
- The use of an external template engine (via files in the templates directory) allows for customizable export formats.
- Integration with External Services:
- The integration with an LLM via HTTP calls is abstracted and made configurable, showing principles of loosely-coupled design.

##### Additional Elements
- A Build/Deployment block that indicates the CMake-based build process and that the application is compiled for Windows (MSYS2-UCRT64).
- Notes on how the state machine and command patterns support undo/redo and interactive editing (this might be a sub-component of the Core Engine).

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer"
        UI_Main["User Interface (UI)"]:::ui
        UI_Backend1["Backend: imgui_impl_glfw.cpp"]:::ui
        UI_Backend2["Backend: imgui_impl_opengl3.cpp"]:::ui
    end

    %% Core Mindmap Engine
    subgraph "Core Mindmap Engine"
        CE["Core Engine (src)"]:::core
        M_Main["main.cpp"]:::core
        M_Mindmap["mindmap.cpp"]:::core
        M_State["mindmap_state_machine.h"]:::core
        M_Command["mindmap_command.h"]:::core
        M_Graph["mindmap_graph*.h"]:::core
    end

    %% Template & Export Engine
    subgraph "Template & Export Engine"
        TE["Template & Export Engine (templates)"]:::export
        SVG["SVG Template (svg.txt)"]:::export
        HTML["HTML Template (html.txt)"]:::export
    end

    %% LLM Integration Module
    subgraph "LLM Integration Module"
        LLM["LLM Integration Module"]:::llm
    end

    %% Dependencies & Build
    subgraph "Dependencies & Build"
        TP["Third-Party Libraries (thirdparty)"]:::thirdparty
        Build["Build System (CMakeLists.txt)"]:::build
    end

    %% Connections
    UI_Main -->|"sends_commands"| CE
    CE -->|"composes"| M_Main
    CE -->|"composes"| M_Mindmap
    CE -->|"composes"| M_State
    CE -->|"composes"| M_Command
    CE -->|"composes"| M_Graph

    CE -->|"triggers_export"| TE
    CE -->|"calls_for_ideas"| LLM
    TE -->|"updates_UI"| UI_Main

    UI_Main -- "uses" --> TP
    CE -- "utilizes" --> TP
    TE -- "processes_templates" --> TP
    LLM -- "API_calls_via_httplib" --> TP

    Build -- "builds" --> CE
    Build -- "builds" --> TP

    %% Styling
    classDef ui fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef core fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef export fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef llm fill:#cc99ff,stroke:#333,stroke-width:2px;
    classDef build fill:#cccccc,stroke:#333,stroke-width:2px;
    classDef thirdparty fill:#ff99cc,stroke:#333,stroke-width:2px;

    %% Click Events
    click UI_Main "https://github.com/azula1a89/mindmap/tree/main/thirdparty/imgui"
    click UI_Backend1 "https://github.com/azula1a89/mindmap/blob/main/thirdparty/imgui/backend/imgui_impl_glfw.cpp"
    click UI_Backend2 "https://github.com/azula1a89/mindmap/blob/main/thirdparty/imgui/backend/imgui_impl_opengl3.cpp"
    click CE "https://github.com/azula1a89/mindmap/tree/main/src"
    click M_Main "https://github.com/azula1a89/mindmap/blob/main/src/main.cpp"
    click M_Mindmap "https://github.com/azula1a89/mindmap/blob/main/src/mindmap.cpp"
    click M_State "https://github.com/azula1a89/mindmap/blob/main/src/mindmap_state_machine.h"
    click M_Command "https://github.com/azula1a89/mindmap/blob/main/src/mindmap_command.h"
    click M_Graph "https://github.com/azula1a89/mindmap/blob/main/src/mindmap_graph*.h"
    click TE "https://github.com/azula1a89/mindmap/tree/main/templates"
    click SVG "https://github.com/azula1a89/mindmap/blob/main/templates/svg.txt"
    click HTML "https://github.com/azula1a89/mindmap/blob/main/templates/html.txt"
    click LLM "https://github.com/azula1a89/mindmap/tree/main/thirdparty/httplib"
    click Build "https://github.com/azula1a89/mindmap/blob/main/CMakeLists.txt"
    click TP "https://github.com/azula1a89/mindmap/tree/main/thirdparty"
```
