# nateyjaybee/fanuctpp architecture

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

- Interactive diagram: https://gitdiagram.com/nateyjaybee/fanuctpp
- Repository: https://github.com/nateyjaybee/fanuctpp

## Overview

##### Project type and purpose
- This is a Visual Studio Code extension named CodeFanuc TP Assist.
- Its purpose is to enhance the experience of editing Fanuc Teach Pendant programs by providing:
- Custom syntax definitions & theme for .ls, .kl, .dt, .cf files
- Code-editing utilities (auto-renumbering, auto-semicolon)
- Interactive commands and Webview panels for labels, I/O registers, backups
- Ctrl+Click navigation to other programs in the same folder

##### File structure
- Top-level directories:
- src/ – TypeScript source, organized into commands/, utils/, webviews/, types/
- syntaxes/ – TextMate grammar files (.tmLanguage.json) for each Fanuc file type
- themes/ – Custom VS Code theme (.tmTheme.json)
- completions/ & langs/ – JSON files for completions & language configurations
- package.json, tsconfig.json – Extension manifest and compiler config
- out/ directory is the compiled JavaScript (ignored when diagramming source)
- Key modules:
- extension.ts – Activation entrypoint
- commands/*.ts – Command handlers registered with VS Code
- webviews/*.ts – Code to spin up and update VS Code WebviewPanels
- utils/*.ts – Shared helper functions (editing, file I/O, navigation, networking)
- state.ts & constants.ts – Global state management and constant definitions

##### README for additional insights
- Lists features (auto-renumber, webview commands, theme)
- Describes interaction patterns (commands invoked via Ctrl+Shift+P, webviews that allow jumping to lines or replacing identifiers)
- No external services or databases—purely a client-side extension executing inside VS Code

##### Main components & their interactions
a. VS Code Host
- Activation:
- On startup, VS Code loads extension.ts
- Registers commands, language configurations, theme, syntax
- Event listeners:
- TextDocument change events trigger auto-renumber & semicolon logic
- Ctrl+Click handlers for program navigation
b. Commands layer (labelCommands, nameCommands, backupCommands, openProgramCommands)
- Exposed via package.json command IDs
- Each opens a WebviewPanel or triggers an edit operation
c. Webview UIs (LabelView, NameView, BackupView)
- Run HTML/JS sandboxed in VS Code
- Communicate with the extension via postMessage to request data or navigation commands
d. Utilities & shared modules
- helpers for debounce, decorate, extractors (parsing code), file I/O, navigation, network
- state.ts stores intermediate data between events and UI
e. Language features
- Syntax grammars in syntaxes/ loaded by VS Code for highlighting
- completions/ & langs/ provide IntelliSense and language configurations

##### Architectural patterns & design principles
- Plugin architecture: extension host ↔ VS Code core UI
- Modular separation:
- Commands (trigger → action → UI)
- Webviews (presentation layer)
- Utils (business logic and file manipulation)
- Event-driven model: document changes and command invocations
- Message-passing interface between extension process and Webview content

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Top-level host
    VSCodeCore["VS Code Host"]:::host

    %% Extension Host Process
    subgraph "Extension Host Process"
        direction TB
        Activation["Extension Activation\n(src/extension.ts)"]:::core
        subgraph "Commands Layer"
            direction TB
            BackupCmds["Backup Commands"]:::core
            LabelCmds["Label Commands"]:::core
            NameCmds["Name Commands"]:::core
            OpenProgramCmds["Open-Program Commands"]:::core
        end
        subgraph "Webview UIs"
            direction TB
            BackupView["Backup View"]:::webview
            LabelView["Label View"]:::webview
            NameView["Name View"]:::webview
        end
        subgraph "Utilities"
            direction TB
            Debounce["Debounce Helper"]:::utils
            Decorate["Decoration Helper"]:::utils
            EditOps["Editor/Edit Operations"]:::utils
            Extractors["Code Extractors/Parsers"]:::utils
            FileIO["File I/O Helpers"]:::utils
            Navigation["Navigation Helpers"]:::utils
            Network["Network Helpers"]:::utils
        end
        subgraph "State & Types"
            direction TB
            State["State Management"]:::core
            Constants["Constants Definitions"]:::core
            Types["Type Declarations"]:::core
        end
        subgraph "Language & Theme Assets"
            direction TB
            CF_Syntax[".cf Syntax"]:::assets
            DT_Syntax[".dt Syntax"]:::assets
            KL_Syntax[".kl Syntax"]:::assets
            LS_Syntax[".ls Syntax"]:::assets
            Theme["Theme Definition"]:::assets
            Completions["Completions Data"]:::assets
            LangCF[".cf Lang Config"]:::assets
            LangDT[".dt Lang Config"]:::assets
            LangKL[".kl Lang Config"]:::assets
            LangLS[".ls Lang Config"]:::assets
        end
    end

    %% File System
    FileSystem[(File System)]:::host

    %% Interactions
    FileSystem -->|"document events"| Activation
    VSCodeCore -->|"command palette/Ctrl+Click"| BackupCmds
    VSCodeCore --> LabelCmds
    VSCodeCore --> NameCmds
    VSCodeCore --> OpenProgramCmds

    Activation --> BackupCmds
    Activation --> LabelCmds
    Activation --> NameCmds
    Activation --> OpenProgramCmds
    Activation --> CF_Syntax
    Activation --> DT_Syntax
    Activation --> KL_Syntax
    Activation --> LS_Syntax
    Activation --> Theme
    Activation --> Completions
    Activation --> LangCF
    Activation --> LangDT
    Activation --> LangKL
    Activation --> LangLS

    BackupCmds --> BackupView
    LabelCmds --> LabelView
    NameCmds --> NameView
    OpenProgramCmds -->|"edit operations"| EditOps

    BackupView <--> BackupCmds
    LabelView <--> LabelCmds
    NameView <--> NameCmds

    BackupCmds --> Debounce
    BackupCmds --> Decorate
    BackupCmds --> Extractors
    BackupCmds --> FileIO
    BackupCmds --> Navigation
    BackupCmds --> Network

    LabelCmds --> Debounce
    LabelCmds --> Decorate
    LabelCmds --> Extractors
    LabelCmds --> FileIO
    LabelCmds --> Navigation

    NameCmds --> Debounce
    NameCmds --> Decorate
    NameCmds --> Extractors
    NameCmds --> FileIO
    NameCmds --> Navigation

    OpenProgramCmds --> Navigation
    OpenProgramCmds --> FileIO

    %% State and constants usage
    BackupCmds --> State
    LabelCmds --> State
    NameCmds --> State
    OpenProgramCmds --> State

    %% Click Events
    click Activation "https://github.com/nateyjaybee/fanuctpp/blob/master/src/extension.ts"
    click BackupCmds "https://github.com/nateyjaybee/fanuctpp/blob/master/src/commands/backupCommands.ts"
    click LabelCmds "https://github.com/nateyjaybee/fanuctpp/blob/master/src/commands/labelCommands.ts"
    click NameCmds "https://github.com/nateyjaybee/fanuctpp/blob/master/src/commands/nameCommands.ts"
    click OpenProgramCmds "https://github.com/nateyjaybee/fanuctpp/blob/master/src/commands/openProgramCommands.ts"
    click BackupView "https://github.com/nateyjaybee/fanuctpp/blob/master/src/webviews/backupWebview.ts"
    click LabelView "https://github.com/nateyjaybee/fanuctpp/blob/master/src/webviews/labelWebview.ts"
    click NameView "https://github.com/nateyjaybee/fanuctpp/blob/master/src/webviews/nameWebview.ts"
    click Debounce "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/debounce.ts"
    click Decorate "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/decorate.ts"
    click EditOps "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/edit.ts"
    click Extractors "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/extractors.ts"
    click FileIO "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/files.ts"
    click Navigation "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/navigation.ts"
    click Network "https://github.com/nateyjaybee/fanuctpp/blob/master/src/utils/network.ts"
    click State "https://github.com/nateyjaybee/fanuctpp/blob/master/src/state.ts"
    click Constants "https://github.com/nateyjaybee/fanuctpp/blob/master/src/constants.ts"
    click Types "https://github.com/nateyjaybee/fanuctpp/blob/master/src/types/index.ts"
    click CF_Syntax "https://github.com/nateyjaybee/fanuctpp/blob/master/syntaxes/fanuctp_cf.tmLanguage.json"
    click DT_Syntax "https://github.com/nateyjaybee/fanuctpp/blob/master/syntaxes/fanuctp_dt.tmLanguage.json"
    click KL_Syntax "https://github.com/nateyjaybee/fanuctpp/blob/master/syntaxes/fanuctp_kl.tmLanguage.json"
    click LS_Syntax "https://github.com/nateyjaybee/fanuctpp/blob/master/syntaxes/fanuctp_ls.tmLanguage.json"
    click Theme "https://github.com/nateyjaybee/fanuctpp/blob/master/themes/codefanuc_theme.tmTheme.json"
    click Completions "https://github.com/nateyjaybee/fanuctpp/blob/master/completions/fanuctp_kl_completions.json"
    click LangCF "https://github.com/nateyjaybee/fanuctpp/blob/master/langs/fanuc_cf_lang_config.json"
    click LangDT "https://github.com/nateyjaybee/fanuctpp/blob/master/langs/fanuc_dt_lang_config.json"
    click LangKL "https://github.com/nateyjaybee/fanuctpp/blob/master/langs/fanuc_kl_lang_config.json"
    click LangLS "https://github.com/nateyjaybee/fanuctpp/blob/master/langs/fanuc_ls_lang_config.json"

    %% Styles
    classDef host fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef core fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef webview fill:#c8e6c9,stroke:#43a047,stroke-width:1px
    classDef utils fill:#ffe0b2,stroke:#fb8c00,stroke-width:1px
    classDef assets fill:#e1bee7,stroke:#8e24aa,stroke-width:1px
```
