# zeybek/camouflage architecture

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

- Interactive diagram: https://gitdiagram.com/zeybek/camouflage
- Repository: https://github.com/zeybek/camouflage

## Overview

##### Main Project Type and Purpose
- Project: A VS Code extension.
- Purpose: To protect sensitive environment variable values by replacing them with masked strings (using various styles) when .env files are opened.
- Key functional areas include auto-hiding, selective key hiding, toggling modes, and customizable appearance of masked values.

##### File Structure to Determine Key Components
- Top-Level and Configuration: Notice the configuration files (.env, .prettierrc, tsconfig.json, eslint.config.mjs, package.json, etc.) and CI/CD workflows (under .github/workflows) which indicate standard practices and automated builds/tests.
- Core and Extension Entry Points:
- "src/extension.ts": Likely the main entry point where VS Code loads the extension.
- "src/core": Contains the core functionality, e.g., camouflage.ts and associated types.
- Modules for Cross-Cutting Behaviors: The “src/decorators” folder holds a collection of decorators for adding functionality like debouncing, error handling, performance measurement, validation, and logging. This demonstrates separation of concerns using decorator patterns.
- Utility and Library Functions:
- "src/lib": Contains logic like text generation (e.g., text-generator.ts) which is probably essential for creating the various styles of masked text.
- "src/utils": Contains helper functions for managing configurations and file operations.
- Testing: There is an organized test suite in each module’s __tests__ folders.

a. VS Code Extension Host (External Environment):
- The environment where the extension is loaded (i.e., VS Code).
- User interactions, such as opening a .env file, clicking on the status bar, or right-click context menu selections.
b. Extension Main Module:
- Entry point (src/extension.ts). This module hooks into VS Code APIs and initializes the extension.
c. Core Engine:
- “src/core/camouflage.ts” which implements the primary logic to mask environment variable values.
- “src/core/types.ts” for defining types and interfaces.
d. Decorators Layer:
- Decorator (debounce, handle errors, log, measure performance, validate config) and how they wrap or enhance the core functionality.
e. Library and Utility Modules:
- “src/lib/text-generator.ts”: Generates various masking patterns.
- “src/utils”: For handling config and file operations that support both core and decorator logic.
f. Configuration & Settings:
- How user settings (from VS Code configuration) are fed into the extension, especially controls for enabling/disabling the extension, selective toggling, and style preferences.
g. Testing & Development Support:
- You may optionally include nodes representing tests (Jest configuration and __tests__ directories) showing that they validate the behavior of both core and decorator functionalities.

##### Relationships and Interactions
- From the core module, show the data flow to utility functions (for retrieving and parsing the .env file, configuration, etc.).
- How output (the masked environment variables) is rendered back in VS Code’s editor.

##### Architectural Patterns and Design Principles
- Use of Decorator Pattern: Clearly denote the layers of decorators enhancing core behaviors.
- Separation of Concerns: Distinct folders for core logic, decorators, utilities, and libraries.
- Extensibility: Indicate configuration modules that allow for customization (hiding styles, selective key patterns).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Environment
    A["VS Code Extension Host"]:::external

    %% Main Extension Entry
    B["Main Extension Entry (extension.ts)"]:::core

    %% Core Logic Components
    C["Masking Engine (camouflage.ts)"]:::core
    D["Type Definitions (types.ts)"]:::core

    %% Decorators Layer Subgraph
    subgraph "Decorators Layer"
        E["Debounce (debounce.ts)"]:::decorator
        F["Handle Errors (handle-errors.ts)"]:::decorator
        G["Log (log.ts)"]:::decorator
        H["Measure Performance (measure-performance.ts)"]:::decorator
        I["Validate Config (validate-config.ts)"]:::decorator
    end

    %% Library Module
    J["Text Generator (text-generator.ts)"]:::library

    %% Utility Modules Subgraph
    subgraph "Configuration & Utilities"
        K["Config Utility (config.ts)"]:::utility
        L["File Utility (file.ts)"]:::utility
    end

    %% Interactions
    A -->|"userAction"| B
    B -->|"initiateExtension"| C
    C -->|"usesTypes"| D

    %% Decorator Wrapping (illustrative - decorators enhance core behavior)
    C -->|"decoratedBy"| E
    C -->|"decoratedBy"| F
    C -->|"decoratedBy"| G
    C -->|"decoratedBy"| H
    C -->|"decoratedBy"| I

    %% Core calling library and utilities
    C -->|"generateMask"| J
    C -->|"readConfig"| K
    C -->|"fileOps"| L

    %% Output back to VS Code Host
    C -->|"updateEditor"| A

    %% Click Events
    click B "https://github.com/zeybek/camouflage/blob/main/src/extension.ts"
    click C "https://github.com/zeybek/camouflage/blob/main/src/core/camouflage.ts"
    click D "https://github.com/zeybek/camouflage/blob/main/src/core/types.ts"
    click E "https://github.com/zeybek/camouflage/blob/main/src/decorators/debounce.ts"
    click F "https://github.com/zeybek/camouflage/blob/main/src/decorators/handle-errors.ts"
    click G "https://github.com/zeybek/camouflage/blob/main/src/decorators/log.ts"
    click H "https://github.com/zeybek/camouflage/blob/main/src/decorators/measure-performance.ts"
    click I "https://github.com/zeybek/camouflage/blob/main/src/decorators/validate-config.ts"
    click J "https://github.com/zeybek/camouflage/blob/main/src/lib/text-generator.ts"
    click K "https://github.com/zeybek/camouflage/blob/main/src/utils/config.ts"
    click L "https://github.com/zeybek/camouflage/blob/main/src/utils/file.ts"

    %% Styles
    classDef external fill:#C3E88D,stroke:#333,stroke-width:2px;
    classDef core fill:#82AAFF,stroke:#333,stroke-width:2px;
    classDef decorator fill:#C792EA,stroke:#333,stroke-width:2px;
    classDef library fill:#FFCB6B,stroke:#333,stroke-width:2px;
    classDef utility fill:#89DDFF,stroke:#333,stroke-width:2px;
```
