# antfu/eslint-config architecture

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

- Interactive diagram: https://gitdiagram.com/antfu/eslint-config
- Repository: https://github.com/antfu/eslint-config

## Overview

##### Project type and purpose
- This is an open-source Node.js/TypeScript tool and library published as `@antfu/eslint-config`.
- It provides a factory-based API to generate ESLint Flat Configs, plus a CLI to scaffold or migrate configs in user projects.
- It ships opinionated defaults, per-language and per-framework presets, optional plugins/formatters, and a plugin-renaming mechanism.

##### High-level components
a. CLI layer
- bin/index.js ↔ src/cli/run.ts → orchestrates the “starter wizard” and migration commands
- Reads user input/options, invokes factory, writes `eslint.config.mjs`
b. Core library/API
- src/index.ts & src/factory.ts
– Exposes `antfu()` factory function returning a FlatConfigComposer
– Chains presets, overrides, plugin renames, etc.
c. Preset modules
- src/configs/*.ts
– Each file exports one ESLint Flat Config fragment (javascript, typescript, vue, astro, style, markdown, etc.)
d. Utilities & helpers
- src/utils.ts, src/globs.ts, src/plugins.ts, src/types.ts
- Vendored types in src/vender/prettier-types.ts
e. Scripts & build
- scripts/typegen.ts, scripts/versiongen.ts → generate type definitions and version metadata
- tsconfig.json, vitest.config.ts, eslint.config.ts, pnpm-workspace.yaml
f. CI/CD & release
- .github/workflows/ci.yml → lint, test, build
- .github/workflows/release.yml → npm publish, changelog
g. Tests & fixtures
- test/*.ts → unit tests for CLI, fixtures, types
- fixtures/input & fixtures/output → sample files and expected transformed outputs

##### Relationships & data flow
- User calls `npx @antfu/eslint-config` (CLI)
- CLI parses flags → invokes factory with options → loads needed preset modules
- Factory composes flat config(s) → applies plugin renaming, overrides → returns JSON/MJS AST
- CLI writes the config file or prints to stdout
- Tests exercise the CLI and core: read fixtures/input, run transform, compare to fixtures/output

##### Architectural patterns & principles
- Factory Method: `antfu()` constructs and composes configs
- Plugin/Module Pattern: Each language/framework support is a self-contained module under src/configs
- Composable Flat Config: uses ESLint’s new flat config API to merge multiple config fragments
- Extensibility: users can override, prepend, rename, or replace any preset via the composer API
- Automated code generation for types & versions (scripts folder)

##### Diagramming details
- Title: “@antfu/eslint-config Architecture”
- Layered view:
- Top: User & CLI
- Middle: Factory → Presets → Utilities
- Bottom: Output (config file), External: ESLint, npm
- Side: Tests & CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Title
    subgraph "@antfu/eslint-config Architecture"
    end

    %% User Layer
    User["User"]:::external

    %% CLI Layer
    subgraph "CLI Layer" 
        direction TB
        bin["bin/index.js"]:::runtime
        cliIndex["src/cli/index.ts"]:::runtime
        cliRun["src/cli/run.ts"]:::runtime
        cliConsts["src/cli/constants.ts<br/>src/cli/constants-generated.ts"]:::runtime
        cliUtils["src/cli/utils.ts"]:::runtime
        cliTypes["src/cli/types.ts"]:::runtime
        stage1["src/cli/stages/update-eslint-files.ts"]:::runtime
        stage2["src/cli/stages/update-package-json.ts"]:::runtime
        stage3["src/cli/stages/update-vscode-settings.ts"]:::runtime
    end

    %% Core Library / API
    subgraph "Core Library / API"
        direction TB
        coreIndex["src/index.ts"]:::runtime
        factory["src/factory.ts"]:::runtime
    end

    %% Preset Modules
    subgraph "Preset Modules" 
        direction TB
        configs["src/configs"]:::runtime
    end

    %% Utilities & Helpers
    subgraph "Utilities & Helpers"
        direction TB
        utils["src/utils.ts"]:::runtime
        globs["src/globs.ts"]:::runtime
        plugins["src/plugins.ts"]:::runtime
        types["src/types.ts"]:::runtime
        vender["src/vender/prettier-types.ts"]:::runtime
    end

    %% Scripts & Build Configuration
    subgraph "Scripts & Build"
        direction TB
        typegen["scripts/typegen.ts"]:::tooling
        versiongen["scripts/versiongen.ts"]:::tooling
        configFiles["tsconfig.json<br/>vitest.config.ts<br/>eslint.config.ts<br/>tsdown.config.ts<br/>pnpm-workspace.yaml<br/>package.json<br/>pnpm-lock.yaml<br/>netlify.toml"]:::tooling
    end

    %% CI/CD & Release
    subgraph "CI/CD & Release"
        direction TB
        ci[".github/workflows/ci.yml"]:::external
        release[".github/workflows/release.yml"]:::external
    end

    %% Tests & Fixtures
    subgraph "Tests & Fixtures"
        direction TB
        tests["test/*.ts"]:::tooling
        fixturesIn["fixtures/input/**"]:::tooling
        fixturesOut["fixtures/output/**"]:::tooling
    end

    %% External Systems
    subgraph "External Services"
        direction TB
        eslintEngine["ESLint Engine"]:::external
        npmRegistry["npm Registry"]:::external
        githubActions["GitHub Actions"]:::external
    end

    %% Output
    output["eslint.config.mjs"]:::runtime

    %% Relationships
    User -->|"runs npx"| bin
    bin -->|"calls CLI"| cliRun
    cliRun -->|"invoke antfu(options)"| coreIndex
    coreIndex --> factory
    factory -->|"load config fragment"| configs
    factory -->|"resolve globs & plugins"| utils
    utils --> globs
    utils --> plugins
    factory -->|"generate flat config AST"| output
    output -->|"used by"| eslintEngine

    typegen --> coreIndex
    versiongen --> coreIndex

    ci --> tests
    ci --> configFiles
    ci -->|"on success"| release
    release -->|"publish"| npmRegistry

    tests --> fixturesIn
    tests --> fixturesOut

    githubActions --> ci

    %% Click Events
    click bin "https://github.com/antfu/eslint-config/blob/main/bin/index.js"
    click cliIndex "https://github.com/antfu/eslint-config/blob/main/src/cli/index.ts"
    click cliRun "https://github.com/antfu/eslint-config/blob/main/src/cli/run.ts"
    click cliConsts "https://github.com/antfu/eslint-config/blob/main/src/cli/constants.ts"
    click cliConsts "https://github.com/antfu/eslint-config/blob/main/src/cli/constants-generated.ts"
    click cliUtils "https://github.com/antfu/eslint-config/blob/main/src/cli/utils.ts"
    click cliTypes "https://github.com/antfu/eslint-config/blob/main/src/cli/types.ts"
    click stage1 "https://github.com/antfu/eslint-config/blob/main/src/cli/stages/update-eslint-files.ts"
    click stage2 "https://github.com/antfu/eslint-config/blob/main/src/cli/stages/update-package-json.ts"
    click stage3 "https://github.com/antfu/eslint-config/blob/main/src/cli/stages/update-vscode-settings.ts"

    click coreIndex "https://github.com/antfu/eslint-config/blob/main/src/index.ts"
    click factory "https://github.com/antfu/eslint-config/blob/main/src/factory.ts"

    click configs "https://github.com/antfu/eslint-config/tree/main/src/configs"

    click utils "https://github.com/antfu/eslint-config/blob/main/src/utils.ts"
    click globs "https://github.com/antfu/eslint-config/blob/main/src/globs.ts"
    click plugins "https://github.com/antfu/eslint-config/blob/main/src/plugins.ts"
    click types "https://github.com/antfu/eslint-config/blob/main/src/types.ts"
    click vender "https://github.com/antfu/eslint-config/blob/main/src/vender/prettier-types.ts"

    click typegen "https://github.com/antfu/eslint-config/blob/main/scripts/typegen.ts"
    click versiongen "https://github.com/antfu/eslint-config/blob/main/scripts/versiongen.ts"

    click ci "https://github.com/antfu/eslint-config/blob/main/.github/workflows/ci.yml"
    click release "https://github.com/antfu/eslint-config/blob/main/.github/workflows/release.yml"

    click tests "https://github.com/antfu/eslint-config/blob/main/test/cli.spec.ts"
    click fixturesIn "https://github.com/antfu/eslint-config/tree/main/fixtures/input"
    click fixturesOut "https://github.com/antfu/eslint-config/tree/main/fixtures/output"

    %% Styles
    classDef runtime fill:#cce5ff,stroke:#007bff,color:#000;
    classDef tooling fill:#d4edda,stroke:#28a745,color:#000;
    classDef external fill:#ffe5b4,stroke:#ff8c00,color:#000;
```
