# seungyeop-lee/directory-watcher architecture

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

- Interactive diagram: https://gitdiagram.com/seungyeop-lee/directory-watcher
- Repository: https://github.com/seungyeop-lee/directory-watcher

## Overview

##### Main Components

a. Core Components:
- File System Watcher Engine
- Configuration Manager
- Command Execution Engine
- Event Handler
- Lifecycle Manager

b. Supporting Components:
- Logger System
- Error Handler
- Command Manager

**┌─ Directory Watcher System ──────────────────────────────────┐**

- ┌─ Configuration Layer ─────┐                             │
- Config Parser          │                             │
- YAML Handler           │                             │
- Config Validator       │                             │
- ┘                             │

- ┌─ Core Watch Engine ───────┐    ┌─ Event Pipeline ────┐  │
- FSNotify Integration   │───▶│ - Event Filter      │  │
- Directory Monitor      │    │ - Event Debouncer   │  │
- Path Manager          │    │ - Event Router      │  │
- ┘    └──────────────────────┘  │

- ┌─ Command Management ──────┐    ┌─ Execution Engine ──┐  │
- Command Parser         │───▶│ - Runner            │  │
- Command Builder        │    │ - Process Manager   │  │
- Variable Interpolator  │    │ - Interrupt Handler │  │
- ┘    └──────────────────────┘  │

- ┌─ Lifecycle Hooks ─────────┐    ┌─ Output Handling ───┐  │
- Before Change         │    │ - Logger            │  │
- After Change          │    │ - Error Reporter    │  │
- Finish Watch          │    └──────────────────────┘  │
- ┘                             │
- ┘

##### Key Relationships to Highlight

- Command execution flow (bold lines)

##### Implementation Details

- FSNotify integration point
- Command execution environment
- Platform-specific components (Unix/Windows)
- Error handling paths
- Logging system integration

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Legend
        direction TB
        L1[Component]:::core --- L2[Relationship]
        L3[/API/]:::api --- L4[Event Flow]
        L5[(Database)]:::db --- L6[Config Flow]
        style L2 stroke-width:2px
        style L4 stroke-dasharray: 5 5
        style L6 stroke-width:1px,stroke-dasharray: 1 1
    end

    subgraph ConfigLayer["Configuration Layer"]
        direction TB
        ConfigMgr[Configuration Manager]:::config
        YAMLHandler[YAML Handler]:::config
        ConfigValidator[Config Validator]:::config
        
        ConfigMgr --> YAMLHandler
        YAMLHandler --> ConfigValidator
    end

    subgraph CoreEngine["Core Watch Engine"]
        direction TB
        FSNotify[FSNotify Integration]:::core
        DirMonitor[Directory Monitor]:::core
        PathMgr[Path Manager]:::core
        
        FSNotify --> DirMonitor
        DirMonitor --> PathMgr
    end

    subgraph EventPipeline["Event Pipeline"]
        direction TB
        EventFilter[Event Filter]:::event
        EventDebouncer[Event Debouncer]:::event
        EventRouter[Event Router]:::event
        
        EventFilter --> EventDebouncer
        EventDebouncer --> EventRouter
    end

    subgraph CmdMgmt["Command Management"]
        direction TB
        CmdParser[Command Parser]:::cmd
        CmdBuilder[Command Builder]:::cmd
        VarInterpolator[Variable Interpolator]:::cmd
        
        CmdParser --> CmdBuilder
        CmdBuilder --> VarInterpolator
    end

    subgraph ExecEngine["Execution Engine"]
        direction TB
        Runner[Runner]:::exec
        ProcMgr[Process Manager]:::exec
        IntHandler[Interrupt Handler]:::exec
        
        Runner --> ProcMgr
        ProcMgr --> IntHandler
    end

    subgraph LifecycleHooks["Lifecycle Hooks"]
        direction TB
        StartWatch[Start Watch]:::lifecycle
        BeforeChange[Before Change]:::lifecycle
        AfterChange[After Change]:::lifecycle
        FinishWatch[Finish Watch]:::lifecycle
        
        StartWatch --> BeforeChange
        BeforeChange --> AfterChange
        AfterChange --> FinishWatch
    end

    subgraph OutputHandling["Output Handling"]
        direction TB
        ColorWriter[Color Writer]:::output
        Logger[Logger]:::output
        ErrorReporter[Error Reporter]:::output
        
        ColorWriter --> Logger
        Logger --> ErrorReporter
    end

    ConfigLayer -.-> CoreEngine
    CoreEngine --> EventPipeline
    EventPipeline --> CmdMgmt
    CmdMgmt ==> ExecEngine
    ExecEngine --> OutputHandling
    LifecycleHooks -.-> ExecEngine

    %% Click events for component mapping
    click ConfigMgr "https://github.com/seungyeop-lee/directory-watcher/tree/master/internal/config/"
    click YAMLHandler "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/config/yaml/config.go"
    click CmdParser "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/domain/cmd/cmd_manager.go"
    click CmdBuilder "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/domain/cmd/cmds.go"
    click EventRouter "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/domain/watch_event.go"
    click EventFilter "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/domain/event.go"
    click Runner "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/service/runner.go"
    click ProcMgr "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/service/runner_global.go"
    click ColorWriter "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/domain/cmd/color_writer.go"
    click Logger "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/helper/logger.go"
    click ErrorReporter "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/helper/error.go"
    click PathMgr "https://github.com/seungyeop-lee/directory-watcher/blob/master/internal/app/domain/path.go"

    %% Styling
    classDef core fill:#2374ab
    classDef config fill:#57a773
    classDef event fill:#4392f1
    classDef cmd fill:#f1c40f
    classDef exec fill:#e67e22
    classDef lifecycle fill:#9b59b6
    classDef output fill:#95a5a6
    classDef api fill:#3498db
    classDef db fill:#34495e
```
