# crytic/slither architecture

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

- Interactive diagram: https://gitdiagram.com/crytic/slither
- Repository: https://github.com/crytic/slither

## Overview

##### Project Type and Purpose
- Slither is an open‑source, Python‑based static analysis framework and CLI tool for Solidity & Vyper smart contracts.
- Its goal is to parse smart‑contract source, build an intermediate representation (SlithIR), run vulnerability “detectors,” emit visual/printer reports, and offer an API for extensions.

##### High‑Level Architecture Components
A. CLI / Entry‑Point Layer
- `slither/__main__.py`, `slither/slither.py` define the `slither` console command.
- Subcommands under `slither/tools/*` (e.g., `slither-read-storage`, `slither-flat`) are separate entry points.
- `plugin_example` demonstrates how to add new detectors via Python entry_points.

B. Parsing Layer
- `slither/solc_parsing`: wraps the Solidity compiler AST, builds Solidity AST + basic CFG.
- `slither/vyper_parsing`: handles Vyper AST and CFG.
- Relies on external `solc` (or crytic‑compile) to produce JSON AST.

C. Core Model & IR
- `slither/core`: builds a unified object model (CompilationUnit, AST nodes, CFG, scoping, type information).
- `slither/slithir`: converts core model to SlithIR SSA, supports IR operations, SSA variables, dominator analysis.

D. Analysis & Detectors
- `slither/analyses/*`: built‑in analyses (data dependency, EVM CFG generation, write‐analysis).
- `slither/detectors/*`: a plugin‑style architecture where each detector inspects the core model or IR and emits findings.
- `slither/visitors`: AST/IR visitors to factor common traversal logic.

E. Formatters & Printers
- `slither/formatters`: transforms raw detector findings into human‑readable or SARIF formats.
- `slither/printers`: visual “printers” (call graph, CFG, inheritance graph) and summaries; these render dot files, plain text, or JSON.

F. Tools (Standalone Utilities)
- Under `slither/tools/*`: wrap detectors/printers for specialized workflows: upgradeability checks, property generation, flattening, ERC compliance, etc.
- Each has its own `__main__.py` and reuses core and detectors.

G. Utilities & Shared Code
- `slither/utils`: common helpers (command‑line parsing, code complexity, output capture).
- `scripts`, `Makefile`, Dockerfile, GitHub Actions workflows orchestrate CI, testing, packaging.

H. Tests & Documentation
- `tests/unit` and `tests/e2e`: verify core model, IR correctness, detector outputs, printer outputs.
- `docs/src`: user/docs, API references, how to write detectors/printers.

##### Data Flow and Interactions
1. User invokes `slither` (or one of the `slither-*` tools).
2. CLI layer calls Parsing Layer → obtains AST + basic CFG.
3. Core Model builds semantic objects; SlithIR converts to SSA IR.
4. Analyses run on core model and IR to produce dependency graphs, CFGs, call graphs.
5. Detectors execute against model/IR, emit vulnerabilities/warnings.
7. Tools wrap steps 2–6 for specialized commands.
8. Results go to console, files, or CI integrations (e.g., SARIF for GitHub code scanning).

##### Architectural Patterns & Principles
- Layered design: CLI → Parsing → Core Model → IR → Analyses/Detectors → Output
- Plugin architecture: detectors, printers, and tools are registered via Python entry points.
- Separation of concerns: parsing, modeling, analysis, and reporting are distinct modules.
- Extensibility: users can add new detectors/printers/tools without modifying core.

##### Technologies & External Services
- Python 3.8+
- External `solc` compiler or `crytic‑compile` backend
- Docker for containerized execution
- GitHub Actions for CI (lint, test, docs, publish)
- PyPI packaging (`setup.py`, `pyproject.toml`)
- Graphviz (dot) for graphs

##### Essential Elements
- Component names and responsibilities
- Notes on extensibility (entry_points, plugin_example)
- External dependencies/services clearly outside core boundary

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        Solc["solc / crytic-compile"]:::external
        Docker["Docker"]:::external
        CI["GitHub Actions"]:::external
    end

    %% CLI / Entry-Point Layer
    subgraph "CLI / Entry-Point Layer"
        MainCLI["slither/__main__.py"]:::cli
        CLIImpl["slither/slither.py"]:::cli
    end

    %% Tools Layer
    subgraph "Tools (Standalone Utilities)"
        FlattenTool["Flattening Tool (__main__.py)"]:::tools
        DoctorTool["Doctor Tool (__main__.py)"]:::tools
        ReadStorageTool["Read-Storage Tool"]:::tools
    end

    %% Parsing Layer
    subgraph "Parsing Layer"
        solcParsingDir["slither/solc_parsing/"]:::parsing
        solithirCompUnit["slither/solc_parsing/slither_compilation_unit_solc.py"]:::parsing
        solcCfgNode["slither/solc_parsing/cfg/node.py"]:::parsing
        vyperParsingDir["slither/vyper_parsing/"]:::parsing
    end

    %% Core Model & IR
    subgraph "Core Model & IR"
        coreDir["slither/core/"]:::core
        coreCU["slither/core/compilation_unit.py"]:::core
        slithirDir["slither/slithir/"]:::ir
        slithirConvert["slither/slithir/convert.py"]:::ir
    end

    %% Analysis & Detectors
    subgraph "Analysis & Detectors"
        analysesDir["slither/analyses/"]:::analysis
        detectorsDir["slither/detectors/"]:::detectors
    end

    %% Formatters & Printers
    subgraph "Formatters & Printers"
        formattersDir["slither/formatters/"]:::formatters
        printersDir["slither/printers/"]:::printers
    end

    %% Utilities & Shared Code
    utilsDir["slither/utils/"]:::external

    %% Tests & Documentation
    subgraph "Tests & Documentation"
        Tests["tests/unit & tests/e2e"]:::external
        Docs["docs/src/"]:::external
    end

    %% Data Flow Connections
    MainCLI -->|invoke| solcParsingDir
    CLIImpl -->|start parsing| solcParsingDir
    FlattenTool -->|wraps steps| solcParsingDir
    DoctorTool -->|wraps steps| solcParsingDir
    ReadStorageTool -->|wraps steps| solcParsingDir

    solcParsingDir --> solithirCompUnit
    solcParsingDir --> solcCfgNode
    solcParsingDir --> vyperParsingDir
    Solc --> solcParsingDir

    solithirCompUnit --> coreDir
    solcCfgNode --> coreDir
    vyperParsingDir --> coreDir

    coreDir --> coreCU
    coreDir --> slithirDir
    coreCU --> slithirConvert
    slithirDir --> slithirConvert

    slithirConvert --> analysesDir
    slithirConvert --> detectorsDir
    analysesDir --> detectorsDir

    detectorsDir --> formattersDir
    formattersDir --> printersDir

    printersDir -->|output artifacts| Tests
    printersDir -->|output artifacts| Docs

    Docker --> MainCLI
    CI --> Tests
    CI --> Docs

    %% Click Events
    click MainCLI "https://github.com/crytic/slither/blob/master/slither/__main__.py"
    click CLIImpl "https://github.com/crytic/slither/blob/master/slither/slither.py"
    click FlattenTool "https://github.com/crytic/slither/blob/master/slither/tools/flattening/__main__.py"
    click DoctorTool "https://github.com/crytic/slither/blob/master/slither/tools/doctor/__main__.py"
    click ReadStorageTool "https://github.com/crytic/slither/blob/master/slither/tools/read_storage/read_storage.py"
    click solcParsingDir "https://github.com/crytic/slither/tree/master/slither/solc_parsing/"
    click solithirCompUnit "https://github.com/crytic/slither/blob/master/slither/solc_parsing/slither_compilation_unit_solc.py"
    click solcCfgNode "https://github.com/crytic/slither/blob/master/slither/solc_parsing/cfg/node.py"
    click vyperParsingDir "https://github.com/crytic/slither/tree/master/slither/vyper_parsing/"
    click coreDir "https://github.com/crytic/slither/tree/master/slither/core/"
    click coreCU "https://github.com/crytic/slither/blob/master/slither/core/compilation_unit.py"
    click slithirDir "https://github.com/crytic/slither/tree/master/slither/slithir/"
    click slithirConvert "https://github.com/crytic/slither/blob/master/slither/slithir/convert.py"
    click analysesDir "https://github.com/crytic/slither/tree/master/slither/analyses/"
    click detectorsDir "https://github.com/crytic/slither/tree/master/slither/detectors/"
    click formattersDir "https://github.com/crytic/slither/tree/master/slither/formatters/"
    click printersDir "https://github.com/crytic/slither/tree/master/slither/printers/"
    click utilsDir "https://github.com/crytic/slither/tree/master/slither/utils/"

    %% Styles
    classDef cli fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef tools fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef parsing fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef ir fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef analysis fill:#98FB98,stroke:#333,stroke-width:1px
    classDef detectors fill:#98FB98,stroke:#333,stroke-width:1px
    classDef formatters fill:#FFA500,stroke:#333,stroke-width:1px
    classDef printers fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
