# m-izadmehr/deadfile architecture

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

- Interactive diagram: https://gitdiagram.com/m-izadmehr/deadfile
- Repository: https://github.com/m-izadmehr/deadfile

## Overview

##### Project type and purpose
- deadfile is a Node.js-based CLI utility for detecting dead code and unused files in JavaScript/TypeScript/Vue/React projects.
- It parses source files (via AST plugins), resolves imports/exports, and reports unused modules either as a JSON/CI report or via a simple HTTP report server with Mustache templates.

##### File structure
- Top level
- bin.js – CLI entry point
- src/ – core application code
- • ASTPlugins/ – modular parsers and walkers for import/export detection
- • cli/ – classes for argument parsing, logging, and writing report files
- • handlers/ – business-logic units (AllAssets, UsedAssets, fileResolver)
- • models/ – data abstractions (Parsables, Source, Types)
- • reportServer/ – lightweight server offering a web UI (scripts, views, server.js)
- • index.js – orchestrates the analysis pipeline
- example/ – sample projects demonstrating different import syntaxes
- docs/ – static site assets and generated documentation
- test/ – integration and unit test suites, fixtures for various babel configurations

##### README for additional insights
- Highlights loose parsing strategy and broad syntax support (ES5/ES6, dynamic import, React/Vue).
- Describes CLI options (`--dir`, `--exclude`, `--output`, `--ci`) and output modes (JSON vs. report server).

##### Detail
- Explicitly show the filesystem and package.json as the ultimate source of truth for resolving imports and identifying unused dependencies.
- Plugin points for future extension.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "CLI & Orchestration"
        CLI["CLI Launcher"]:::cli
        Options["Argument Parser"]:::cli
        Logger["Logger"]:::cli
        Greet["Greeting"]:::cli
    end

    subgraph "Core Analysis"
        Index["Analysis Pipeline Orchestrator"]:::core
        Resolver["File Resolver (module graph builder)"]:::core
        subgraph "AST Plugins"
            Registry["AST Plugin Registry"]:::core
            Parsable["AST Parsability Checker"]:::core
            Require["CommonJS Require Detector"]:::core
            ImportExport["Import/Export Parser"]:::core
            JSX["JSX Syntax Parser"]:::core
            Walker["AST Walker Utility"]:::core
        end
        subgraph "Handlers"
            AllAssets["All Assets Collector"]:::core
            UsedAssets["Used Assets Analyzer"]:::core
        end
        subgraph "Models"
            Parsables["Parsable File Model"]:::core
            Source["Source File Model"]:::core
            Types["Type Definitions Model"]:::core
        end
    end

    subgraph "Reporting"
        WriteReport["JSON/CI Report Writer"]:::report
        subgraph "Report Server"
            Server["HTTP Report Server Controller"]:::report
            Scripts["Report Server Scripts"]:::report
            Styles["Report Server Stylesheet"]:::report
            View["Report Server View Template"]:::report
        end
    end

    subgraph "External Systems"
        User((User)):::external
        FS["Filesystem"]:::external
        Package["package.json"]:::external
        Browser["Browser UI"]:::external
    end

    User -->|invokes| CLI
    CLI -->|"reads args"| Options
    CLI -->|"initial message"| Greet
    CLI -->|"logs"| Logger
    CLI -->|"passes entry paths"| Index
    Index -->|"resolve modules"| Resolver
    Resolver --> FS
    Resolver --> Package
    Index -->|"register plugins"| Registry
    Registry --> Parsable
    Registry --> Require
    Registry --> ImportExport
    Registry --> JSX
    Registry --> Walker
    Index -->|"AST walk"| Walker
    Walker -->|"extract imports/exports"| ImportExport
    ImportExport --> AllAssets
    Require --> AllAssets
    Parsable --> AllAssets
    AllAssets -->|"assets list"| UsedAssets
    UsedAssets --> Parsables
    UsedAssets --> Source
    UsedAssets --> Types
    Index -->|"write report"| WriteReport
    WriteReport --> FS
    WriteReport -->|"output JSON/CI"| CLI
    Index -->|"serve web UI"| Server
    Server --> Scripts
    Server --> Styles
    Server --> View
    View --> Browser
    Scripts --> Browser

    click CLI "https://github.com/m-izadmehr/deadfile/blob/master/src/bin.js"
    click Options "https://github.com/m-izadmehr/deadfile/blob/master/src/cli/options.js"
    click Logger "https://github.com/m-izadmehr/deadfile/blob/master/src/cli/Logger.js"
    click Greet "https://github.com/m-izadmehr/deadfile/blob/master/src/cli/Greeting.js"
    click WriteReport "https://github.com/m-izadmehr/deadfile/blob/master/src/cli/WriteReportFile.js"
    click Index "https://github.com/m-izadmehr/deadfile/blob/master/src/index.js"
    click Registry "https://github.com/m-izadmehr/deadfile/blob/master/src/ASTPlugins/index.js"
    click Parsable "https://github.com/m-izadmehr/deadfile/blob/master/src/ASTPlugins/isParsable.js"
    click Require "https://github.com/m-izadmehr/deadfile/blob/master/src/ASTPlugins/isRequire.js"
    click ImportExport "https://github.com/m-izadmehr/deadfile/blob/master/src/ASTPlugins/parseImportFromExport.js"
    click JSX "https://github.com/m-izadmehr/deadfile/blob/master/src/ASTPlugins/parseJsx.js"
    click Walker "https://github.com/m-izadmehr/deadfile/blob/master/src/ASTPlugins/walk.js"
    click Resolver "https://github.com/m-izadmehr/deadfile/blob/master/src/handlers/fileResolver.js"
    click AllAssets "https://github.com/m-izadmehr/deadfile/blob/master/src/handlers/AllAssets.js"
    click UsedAssets "https://github.com/m-izadmehr/deadfile/blob/master/src/handlers/UsedAssets.js"
    click Parsables "https://github.com/m-izadmehr/deadfile/blob/master/src/models/Parsables.js"
    click Source "https://github.com/m-izadmehr/deadfile/blob/master/src/models/Source.js"
    click Types "https://github.com/m-izadmehr/deadfile/blob/master/src/models/Types.js"
    click Server "https://github.com/m-izadmehr/deadfile/blob/master/src/reportServer/server.js"
    click Scripts "https://github.com/m-izadmehr/deadfile/blob/master/src/reportServer/scripts/funnel.js"
    click Styles "https://github.com/m-izadmehr/deadfile/blob/master/src/reportServer/scripts/table.css"
    click View "https://github.com/m-izadmehr/deadfile/blob/master/src/reportServer/views/index/index.mustache"
    click Package "https://github.com/m-izadmehr/deadfile/blob/master/package.json"

    classDef cli fill:#FFA500,stroke:#333,stroke-width:1px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef report fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
