# justinmk/vim-dirvish architecture

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

- Interactive diagram: https://gitdiagram.com/justinmk/vim-dirvish
- Repository: https://github.com/justinmk/vim-dirvish

## Overview

##### Project Type and Purpose
- Dirvish is a Vim plugin (an open-source tool) that provides a filesystem navigator inside Vim.
- It’s not a client-server or full-stack app—it lives entirely in the Vim process, leveraging Vimscript, Vim’s conceal/syntax engine, buffer/arglist APIs, and occasional shell calls.

##### Main Components
a. Vim Core
- Buffer management, conceal, syntax engine, command/arglist infrastructure, shell (`:!`) support.
b. Dirvish Plugin Modules
1. plugin/dirvish.vim – plugin entrypoint; defines commands, mappings, autoload hooks.
2. autoload/dirvish.vim – pure Vimscript business logic (read directory, format lines, manage state).
3. ftplugin/dirvish.vim – filetype setup (buffer options, keybindings local to Dirvish buffers).
5. doc/dirvish.txt & README.md – user documentation.
c. File System
– Underlying filesystem from which directories are listed.
d. Shell
– Invoked via `:!` or `:Shdo` to execute batch operations.
e. External Plugins (optional)
– vim-eunuch, vim-unimpaired, dirvish-git, etc., which hook into Dirvish via exposed functions or filetype.

##### Relationships and Data Flows
1. User Issues a Dirvish Command or Mapping →
plugin/dirvish.vim
↓ calls
autoload/dirvish#open()
↓ reads
File System
↓ returns file list
autoload formats list → fills Vim buffer
↓ buffer rendered with
syntax/dirvish.vim (conceal) + ftplugin/dirvish.vim (keymaps)
↓ user navigates/selects → plugin invokes
arglist/global/Shdo → optionally Shell
↓ shell performs filesystem mutation or outputs script.

##### Architectural Patterns & Design Principles
- Modularity: clear separation between “entrypoint” (plugin/) and “logic” (autoload/).
- Filetype-driven behavior: ftplugin + syntax rules trigger automatically on `set ft=dirvish`.
- Minimalism: no persistent state beyond buffer contents; pure functions in autoload.
- Extensibility: autoload functions and filetype hooks serve as integration points for other plugins.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Core
    User["User"]:::external
    subgraph "Vim Core"
        VimCore["Vim Core\n(buffer mgmt, conceal, syntax engine,\ncommand/arglist APIs, shell support)"]:::core
    end

    %% Dirvish Plugin Modules
    subgraph "Dirvish Plugin Modules"
        PE["Dirvish Entrypoint"]:::plugin
        AL["Autoload Logic\n(public API)"]:::plugin
        FT["Filetype Setup\n(public API)"]:::plugin
        SY["Syntax & Conceal Rules"]:::plugin
    end

    %% I/O Systems
    subgraph "External Systems"
        FS["Filesystem"]:::io
        SH["Shell"]:::io
    end

    %% Documentation
    subgraph "Documentation"
        Doc1["doc/dirvish.txt"]:::doc
        Readme["README.md"]:::doc
        License["LICENSE"]:::doc
    end

    %% External Plugins
    External["External Plugins\n(vim-eunuch, vim-unimpaired,\ndirvish-git)"]:::ext

    %% Buffer & Commands
    Buffer["Vim Buffer\n(rendered Dirvish view)"]:::core
    Arglist["Arglist / :Shdo"]:::core

    %% Flows
    User -->|"command/mapping"| PE
    PE -->|"function call"| AL
    AL -->|"I/O read directory"| FS
    FS -->|"returns file list"| AL
    AL -->|"render"| Buffer
    Buffer -->|"apply syntax"| SY
    Buffer -->|"apply filetype hooks"| FT
    Buffer -->|"user selects"| PE
    PE -->|"arglist/Shdo"| Arglist
    Arglist -->|"shell invocation"| SH
    SH -->|"filesystem mutation/output"| FS

    External -.->|"hook into public API"| AL
    External -.->|"hook into filetype"| FT

    %% Click Events
    click PE "https://github.com/justinmk/vim-dirvish/blob/master/plugin/dirvish.vim"
    click AL "https://github.com/justinmk/vim-dirvish/blob/master/autoload/dirvish.vim"
    click FT "https://github.com/justinmk/vim-dirvish/blob/master/ftplugin/dirvish.vim"
    click SY "https://github.com/justinmk/vim-dirvish/blob/master/syntax/dirvish.vim"
    click Doc1 "https://github.com/justinmk/vim-dirvish/blob/master/doc/dirvish.txt"
    click Readme "https://github.com/justinmk/vim-dirvish/blob/master/README.md"
    click License "https://github.com/justinmk/vim-dirvish/tree/master/LICENSE"

    %% Styles
    classDef core fill:#f2f2f2,stroke:#666,stroke-width:1px;
    classDef plugin fill:#cce5ff,stroke:#339,stroke-width:1px;
    classDef io fill:#d4edda,stroke:#2d662d,stroke-width:1px;
    classDef ext fill:none,stroke:orange,stroke-dasharray:5 5,stroke-width:1px;
    classDef doc fill:#fff3cd,stroke:#997a00,stroke-width:1px;
    class User external
    class External ext
    class User,VimCore,Buffer,Arglist core
```
