# yanquankun/forbid-lint architecture

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

- Interactive diagram: https://gitdiagram.com/yanquankun/forbid-lint
- Repository: https://github.com/yanquankun/forbid-lint

## Overview

##### Project Type and Purpose
- This is a Node.js-based CLI tool meant to integrate with typical front-end development workflows. It primarily works by “forbidding” changes to certain lint configuration files during git operations (via husky pre-commit hooks).
- The tool offers a couple of CLI commands (e.g., “forbid-lint init” to initialize configuration and “forbid-lint check” to inspect staged changes) and supports both global and project-level installation.
- In essence, it manages file integrity for lint configurations by scanning for modifications and erroring out on forbidden changes.

##### File Structure
- Top-level project files: Include configuration files (e.g., .eslintrc, tsconfig*, package.json, etc.) and scripts (gulpfile.ts, jest.config.ts) used for development, testing, and publishing.
- The "src" folder contains the core implementation:
▪ src/index.ts – the main entry point.
▪ src/lib – houses helper libraries; for example, inquirer.ts deals with command-line prompts.
▪ src/task – has modularized tasks like:
- checkTask.ts: performs checks for modifications in the lint files.
- forbidden-related tasks such as huskyTask.ts and initTask.ts.
- types.ts defining structure for tasks.
▪ src/template – stores default configuration templates and husky hook template files.
▪ src/utils – supports file and directory operations, logging, error catching, etc.
- A “demo” folder shows an example usage scenario, including its own husky configuration (with pre-commit hooks) and a simplified setup to illustrate how the plugin works.
- Additional scripts in the “scripts” folder manage publishing and utility functions.

##### Key Components
a. CLI Entry Point:
- CLI interface as the user’s starting component. This would be the “forbid-lint” command which resolves to src/index.ts.
b. Task Manager / Executor:
- A “Task/Command Handler” component that dispatches tasks based on CLI commands. Tasks here include initialization, checking file modifications, and possibly configuration validation.
c. Configuration Manager:
- A component dedicated to handling configuration files (i.e., reading and writing “.forbidrc.json”) where forbidden files are specified.
d. Integration with Husky:
- Connection where the CLI is integrated with husky’s pre-commit hook. This integration ensures “forbid-lint check” is called during git commit procedures.
e. Utility Modules:
- Support modules for IO, file system operations, logging, prompting (via inquirer), error handling, etc.
f. Template Repository:
g. Demo Application:
- A reference to the “demo” folder that models an example project integration.

##### Relationships and Data Flow
- Client (developer using CLI) → CLI Entry Point: User enters a CLI command.
- CLI passes the command to Task Manager → Task Manager selects an appropriate module (initTask, checkTask, etc.).
- Task Manager interacts with Configuration Manager: It reads default config if none provided or generates a configuration file.
- Task Manager uses Utility Modules for file checks (e.g., reading files from the project root) and logs results.
- For the “check” command, the chain includes: scanning file changes → validating changes against listed forbidden lint files → triggering success/failure responses.
- Integration with external systems (i.e., Git/Husky):
- The pre-commit hook in husky (set up using the husky template from “src/template/husky_tpl”) calls “forbid-lint check”, linking back into the Task Manager.

##### Architectural Patterns and Important Technologies
- Modular design: Each type of task (init, check, etc.) is separated into its own module.
- CLI pattern: The tool leverages a command-line interface using modules like inquirer for interactive prompts.
- Integration with a Git workflow by automatically setting up Husky hooks.
- Use of Node.js’s file system operations and logging utilities encapsulated in the utils folder.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        Developer["Developer(Input Command)"]:::external
    end

    subgraph "CLI Operation"
        CLI["forbid-lint (CLI Entry Point)"]:::cli
    end

    subgraph "Processing Layer"
        TM["Task Manager/Executor"]:::processor
        CM["Configuration Manager"]:::config
        UT["Utility Modules"]:::utils
        TR["Template Repository"]:::template
    end

    subgraph "External Integration"
        HI["Husky Integration"]:::external
        DA["Demo Application"]:::demo
    end

    subgraph "Husky Details"
        HST["Husky Template"]:::integration
        DH["Demo Husky Hook"]:::integration
    end

    subgraph "Utility Details"
        CLP["CLI Prompts"]:::prompt
    end

    %% Data Flow
    Developer -->|"enters command"| CLI
    CLI -->|"dispatches command"| TM
    TM -->|"reads configuration"| CM
    CM -->|"loads defaults"| TR
    CM -->|"provides config defaults"| ConfigTemplate["Config Default Template"]:::config
    TM -->|"invokes utilities"| UT
    UT -->|"uses prompting"| CLP
    HI -->|"triggers check pre-commit"| CLI
    DA -->|"integrates usage"| TM
    HI --> HST
    HI --> DH
    DA -->|"runs demo CLI"| DemoCLI["Demo CLI Entry"]:::demo

    %% Click Events
    click CLI "https://github.com/yanquankun/forbid-lint/blob/master/src/index.ts"
    click TM "https://github.com/yanquankun/forbid-lint/tree/master/src/task"
    click CM "https://github.com/yanquankun/forbid-lint/blob/master/src/task/forbidrcTask.ts"
    click ConfigTemplate "https://github.com/yanquankun/forbid-lint/blob/master/src/template/.forbidrc.json"
    click HST "https://github.com/yanquankun/forbid-lint/tree/master/src/template/husky_tpl"
    click DH "https://github.com/yanquankun/forbid-lint/blob/master/demo/.husky"
    click CLP "https://github.com/yanquankun/forbid-lint/blob/master/src/lib/inquirer.ts"
    click UT "https://github.com/yanquankun/forbid-lint/tree/master/src/utils"
    click TR "https://github.com/yanquankun/forbid-lint/tree/master/src/template"
    click DA "https://github.com/yanquankun/forbid-lint/tree/master/demo"
    click DemoCLI "https://github.com/yanquankun/forbid-lint/blob/master/demo/src/index.ts"

    %% Styles
    classDef cli fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef processor fill:#ccffff,stroke:#333,stroke-width:2px;
    classDef config fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef utils fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef template fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef external fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef demo fill:#e6ffe6,stroke:#333,stroke-width:2px;
    classDef integration fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef prompt fill:#ccffff,stroke:#333,stroke-width:2px;
```
