# dwadp/twig architecture

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

- Interactive diagram: https://gitdiagram.com/dwadp/twig
- Repository: https://github.com/dwadp/twig

## Overview

##### Main Components

a) Core Components:
- CLI Interface Layer
- Configuration Management System
- Command Execution Engine
- Version Detection System
- File System Interface

b) External Dependencies:
- PHP Runtime(s)
- Composer
- Project's composer.json files

**┌─ User Interface Layer ─────────────────────┐**
- CLI Commands (cmd/twig/*.go)               │
- ┬─────────────────────────┘
- ↓
**┌─ Core Services Layer ──────────────────────┐**
- ┌─────────────┐  ┌──────────┐  ┌────────┐ │
- Config    │  │  Schema  │  │  Twig  │ │
- Management │  │  Parser  │  │ Engine │ │
- ┘  └──────────┘  └────────┘ │
- ┬─────────────────────────┘
- ↓
**┌─ External Interface Layer ─────────────────┐**
- PHP Version Management                     │
- Composer Integration                       │
- File System Operations                     │
- ┬─────────────────────────┘
- ↓
**┌─ External Dependencies ───────────────────┐**
- PHP Runtimes                             │
- Composer                                 │
- Project Files (composer.json)            │
- ┘

##### Component Details

a) Command Components (Rectangle, Blue):
- Root Command
- Config Commands (init, reload, set-default)
- PHP Command
- Composer Command

b) Core Services (Hexagon, Green):
- Configuration Management (/pkg/config)
- Schema Parsing (/pkg/schema)
- Twig Engine (/pkg/twig)

- Configuration Store (inmem_store)
- File System Interface

- PHP Runtimes
- Composer
- Project Files

##### Flow Indicators

- Command flow from CLI to core services
- Configuration reading/writing operations
- Version detection flow
- Command execution flow to external systems

##### Additional Notes

- Version information handling
- Configuration file locations
- How PHP version detection works
- Composer command proxying flow

##### External system interactions

Remember to include cross-platform considerations and how the system handles different operating systems, as indicated by the separate Unix and Windows implementations in the twig package.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI["CLI Interface Layer"]
        Root["Root Command"]:::cmd
        ConfigCmd["Config Commands"]:::cmd
        PHPCmd["PHP Command"]:::cmd
        ComposerCmd["Composer Command"]:::cmd
    end

    subgraph Core["Core Services Layer"]
        Config["Configuration Management"]:::core
        Schema["Schema Parser"]:::core
        TwigEngine["Twig Engine"]:::core

        subgraph ConfigSystem["Configuration System"]
            MainConfig["Main Config"]:::config
            VersionMgmt["Version Management"]:::config
            Store["Storage Interface"]:::config
            InMemStore["In-Memory Store"]:::config
        end
    end

    subgraph Platform["Platform-Specific Layer"]
        Unix["Unix Implementation"]:::platform
        Windows["Windows Implementation"]:::platform
    end

    subgraph External["External Interface Layer"]
        PHP["PHP Runtime"]:::external
        Composer["Composer"]:::external
        ProjectFiles["Project Files"]:::external
    end

    %% Relationships
    Root --> ConfigCmd
    Root --> PHPCmd
    Root --> ComposerCmd

    ConfigCmd --> Config
    PHPCmd --> TwigEngine
    ComposerCmd --> TwigEngine

    Config --> Schema
    Config --> ConfigSystem
    MainConfig --> Store
    Store --> InMemStore
    VersionMgmt --> Store

    TwigEngine --> Unix
    TwigEngine --> Windows
    Unix --> External
    Windows --> External

    %% Click Events
    click Root "https://github.com/dwadp/twig/blob/develop/cmd/twig/root.go"
    click ConfigCmd "https://github.com/dwadp/twig/blob/develop/cmd/twig/config.go"
    click PHPCmd "https://github.com/dwadp/twig/blob/develop/cmd/twig/php.go"
    click ComposerCmd "https://github.com/dwadp/twig/blob/develop/cmd/twig/composer.go"
    click Config "https://github.com/dwadp/twig/tree/develop/pkg/config"
    click Schema "https://github.com/dwadp/twig/blob/develop/pkg/schema/parser.go"
    click TwigEngine "https://github.com/dwadp/twig/blob/develop/pkg/twig/twig.go"
    click MainConfig "https://github.com/dwadp/twig/blob/develop/pkg/config/config.go"
    click VersionMgmt "https://github.com/dwadp/twig/blob/develop/pkg/config/version.go"
    click Store "https://github.com/dwadp/twig/blob/develop/pkg/config/store.go"
    click InMemStore "https://github.com/dwadp/twig/blob/develop/pkg/config/inmem_store.go"
    click Unix "https://github.com/dwadp/twig/blob/develop/pkg/twig/twig_unix.go"
    click Windows "https://github.com/dwadp/twig/blob/develop/pkg/twig/twig_windows.go"

    %% Styles
    classDef cmd fill:#2374ab,stroke:#2374ab,color:#fff
    classDef core fill:#57a773,stroke:#57a773,color:#fff
    classDef config fill:#484d6d,stroke:#484d6d,color:#fff
    classDef platform fill:#f7b267,stroke:#f7b267,color:#000
    classDef external fill:#d8d8d8,stroke:#808080,color:#000

    %% Legend
    subgraph Legend
        CMD["Command"]:::cmd
        CORE["Core Service"]:::core
        CONF["Configuration"]:::config
        PLAT["Platform Specific"]:::platform
        EXT["External System"]:::external
    end
```
