# 42paris/42header architecture

> Architecture diagram of the GitHub repository 42paris/42header, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/42paris/42header
- Repository: https://github.com/42paris/42header

## Overview

##### Project type & purpose (from README + tree)
This is a **Vim plugin** (single-plugin style, not a service/app) whose purpose is to **insert a “42 school” standard header** into the currently edited file. It exposes:
- A **Vim command** `:Stdheader`
- A **key mapping** (F1) to trigger the header insertion
- Some **configuration** to set `user` and `mail` via environment variables or Vim globals
- A helper script `set_header.sh` to simplify setup in 42 cluster environments

So the “system” is small and local: **Vim runtime + plugin script + user config**, not client/server.

Top-level:
- `plugin/stdheader.vim` — the **core plugin logic** loaded by Vim’s runtime (the `plugin/` directory implies “auto-loaded on startup”).
- `set_header.sh` — helper script for installation/config in certain environments.
- `img/` — documentation image(s), not runtime.
- `README.md`, `LICENSE` — documentation/legal.

Key architectural implication:
- **No backend, no database, no network dependencies**.
- Primary integration is **with Vim editor APIs** (commands, mappings, buffer manipulation, variable lookup, environment).

##### What the README reveals about runtime behavior
- **Inputs**
- User triggers (`:Stdheader` or `F1`)
- Configuration sources:
- Environment variables: `USER`, `MAIL`
- Vim variables: `g:user42`, `g:mail42`
- **Core action**
- The plugin generates the header content and **writes/inserts it into the current buffer**.
- **Installation paths**
- Copying `stdheader.vim` into `~/.vim/plugin/`
- Or via a plugin manager (still ends up on runtimepath)
- `set_header.sh` as an optional installer/config helper

##### Vim Editor
- *Vim runtime / plugin loader* (loads files from `~/.vim/plugin` / runtimepath)
- *Command & keymap dispatcher* (routes `:Stdheader` and `<F1>`)
- *Buffer / current file* (the text being edited)
##### 42 Header Plugin (`plugin/stdheader.vim`)
- *Entry points*: `:Stdheader`, `<F1>` mapping
- *Config resolver*: reads `g:user42`, `g:mail42` OR `$USER`, `$MAIL`
- *Header generator*: builds the formatted header block
- *Buffer writer*: inserts/updates header in buffer
##### User configuration
- `~/.vimrc` (defines `g:user42`, `g:mail42`)
- Shell config (`~/.zshrc`) exporting `USER`, `MAIL`
##### Setup helper (`set_header.sh`)
- Writes/copies plugin file or assists config (conceptually: “installation automation”)

- **Filesystem**
- `~/.vim/plugin/stdheader.vim`
- Project directory where `set_header.sh` is run

**Startup / installation flow**
- Filesystem → Vim runtime: “loads `plugin/stdheader.vim` on startup”
- `set_header.sh` → Filesystem: “installs plugin / sets up environment in cluster”

**Execution flow**
- User → Terminal/Keyboard → Vim: presses `<F1>` or types `:Stdheader`
- Vim dispatcher → Plugin entry point: calls plugin function/command handler
- Plugin config resolver → (Vim globals / Environment variables): fetch user/mail
- Plugin header generator → Plugin buffer writer
- Plugin buffer writer → Vim Buffer: inserts header text into current file

##### Architectural patterns
- **Event-driven / command-driven plugin architecture**: user action triggers command/mapping → handler executes.
- **Configuration precedence** (important detail):
- **Editor-integration boundary**: plugin uses **Vimscript API** for editing buffer content.

##### Relevant technologies
- **Vimscript** for `plugin/stdheader.vim`
- **Shell** for `set_header.sh`
- **Vim** (and optionally “Vim runtimepath plugin loading semantics”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% =======================
    %% External Actors / Inputs
    %% =======================
    User["User"]:::actor
    KB["Terminal / Keyboard"]:::external

    subgraph "User Configuration"
        direction TB
        VimRC["~/.vimrc\n(g:user42, g:mail42)"]:::config
        ShellEnv["Shell Environment\n($USER, $MAIL)"]:::config
    end

    %% =======================
    %% Host Platform: Vim
    %% =======================
    subgraph "Vim Editor (Host Application)"
        direction TB

        Loader["Vim runtime / plugin loader\n(loads from runtimepath: ~/.vim/plugin/)"]:::platform

        subgraph "Command & Keymap Dispatcher"
            direction TB
            CmdStdheader[":Stdheader command"]:::entry
            KeyF1["<F1> mapping"]:::entry
        end

        Buffer["Current Buffer / File\n(text being edited)"]:::data
    end

    %% =======================
    %% Plugin: stdheader.vim
    %% =======================
    subgraph "42 Header Plugin (Vimscript)"
        direction TB

        PluginCore["plugin/stdheader.vim\n(Core plugin logic)"]:::plugin

        subgraph "Plugin Components"
            direction TB
            EntryPoints["Entry points\n(command + mapping handlers)"]:::plugin
            ConfigResolver["Config resolver\nprefers g:user42/g:mail42\nfallback $USER/$MAIL"]:::plugin
            HeaderGen["Header generator\n(builds formatted header)"]:::plugin
            BufferWriter["Buffer writer\n(inserts/updates header in buffer)"]:::plugin
        end
    end

    %% =======================
    %% Installation / Setup Helper
    %% =======================
    subgraph "Setup / Installation (Optional)"
        direction TB
        SetupScript["set_header.sh\n(install/config helper)"]:::script
        FSPluginLocation["Filesystem\n~/.vim/plugin/stdheader.vim"]:::fs
    end

    %% =======================
    %% Documentation (Non-runtime)
    %% =======================
    subgraph "Repository Docs (Non-runtime)"
        direction TB
        Readme["README.md"]:::doc
        License["LICENSE"]:::doc
        Images["img/"]:::doc
    end

    %% =======================
    %% Runtime / Execution Flow
    %% =======================
    User -->|"triggers"| KB
    KB -->|"types :Stdheader"| CmdStdheader
    KB -->|"presses <F1>"| KeyF1

    Loader -->|"loads on startup"| PluginCore
    CmdStdheader -->|"dispatches"| EntryPoints
    KeyF1 -->|"dispatches"| EntryPoints

    EntryPoints -->|"calls"| ConfigResolver
    ConfigResolver -.->|"reads"| VimRC
    ConfigResolver -.->|"reads"| ShellEnv

    ConfigResolver -->|"provides user/mail"| HeaderGen
    HeaderGen -->|"builds header block"| BufferWriter
    BufferWriter -->|"writes into"| Buffer

    %% =======================
    %% Installation Flow
    %% =======================
    SetupScript -->|"copies/installs"| FSPluginLocation
    FSPluginLocation -->|"available on runtimepath"| Loader

    %% =======================
    %% Click Events (from component_mapping)
    %% =======================
    click PluginCore "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click EntryPoints "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click CmdStdheader "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click KeyF1 "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click ConfigResolver "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click HeaderGen "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click BufferWriter "https://github.com/42paris/42header/blob/master/plugin/stdheader.vim"
    click SetupScript "https://github.com/42paris/42header/blob/master/set_header.sh"
    click Images "https://github.com/42paris/42header/tree/master/img/"
    click Readme "https://github.com/42paris/42header/blob/master/README.md"
    click License "https://github.com/42paris/42header/tree/master/LICENSE"

    %% =======================
    %% Styles
    %% =======================
    classDef actor fill:#1f2937,stroke:#111827,color:#ffffff,stroke-width:1.5px
    classDef external fill:#334155,stroke:#0f172a,color:#ffffff,stroke-width:1.2px
    classDef platform fill:#0b5cab,stroke:#083b6e,color:#ffffff,stroke-width:1.5px
    classDef entry fill:#2563eb,stroke:#1e40af,color:#ffffff,stroke-width:1.2px
    classDef plugin fill:#7c3aed,stroke:#4c1d95,color:#ffffff,stroke-width:1.3px
    classDef data fill:#10b981,stroke:#065f46,color:#ffffff,stroke-width:1.3px
    classDef config fill:#f59e0b,stroke:#92400e,color:#111827,stroke-width:1.3px
    classDef script fill:#ef4444,stroke:#7f1d1d,color:#ffffff,stroke-width:1.3px
    classDef fs fill:#64748b,stroke:#334155,color:#ffffff,stroke-width:1.2px
    classDef doc fill:#e5e7eb,stroke:#6b7280,color:#111827,stroke-width:1.1px
```
