# dsherret/ts-morph architecture

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

- Interactive diagram: https://gitdiagram.com/dsherret/ts-morph
- Repository: https://github.com/dsherret/ts-morph

## Overview

##### Main Components

a) Core Components:
- Project Layer
- Compiler Layer
- File System Layer
- Manipulation Layer
- Structure Layer

b) Supporting Components:
- Utils
- Factory System
- Type System

##### Component Relationships

**┌─────────────────────────────────────────────────────┐**
- Project Layer                    │
- ┤
- Project Management                                │
- Configuration Handling                            │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Compiler Layer                    │
- ┤
- AST Manipulation                                  │
- Node Handling                                     │
- Type Checking                                     │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Manipulation & Structure               │
- ┤
- Code Manipulation                                 │
- Structure Printing                                │
- Node Transformation                               │
- ┬─────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- File System Layer                  │
- ┤
- File Operations                                   │
- Directory Management                              │
- ┘

##### Detailed Component Breakdown

Project Layer:
- Project initialization
- Configuration management
- Source file coordination

Compiler Layer:
- AST handling
- Node management
- Type checking
- Symbol management

Manipulation & Structure Layer:
- Code manipulation
- Structure printing
- Node transformation
- Text manipulation

File System Layer:
- File operations
- Directory management
- Path resolution
- Transaction handling

##### Integration Points

Integration points with:
- TypeScript Compiler API
- File System
- External Tools

##### Data Flow

- Source files → Project Layer
- Project Layer → Compiler Layer
- Compiler Layer → Manipulation Layer
- Manipulation Layer → File System Layer

##### Key Features to Highlight

- AST manipulation capabilities
- Type system integration
- Code generation features
- File system abstraction

##### Implementation Details

- Factory patterns
- Caching mechanisms
- Event handling
- Error management

##### Notes

Notes for:
- Version compatibility
- Performance considerations
- Extension points
- Common use cases

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Core Component]:::core
        L2[File System Component]:::filesystem
        L3[Manipulation Component]:::manipulation
        L4[Support Component]:::support
        L5[Data Flow]-- Flow -->L6
    end

    subgraph "Project Layer"
        Project["Project Management"]:::core
        ProjectContext["Configuration Handling"]:::core
        Project --> ProjectContext
    end

    subgraph "Compiler Layer"
        AST["AST Handling"]:::core
        Tools["Compiler Tools"]:::core
        Symbols["Symbol Management"]:::core
        TypeSystem["Type System"]:::core
        AST --> Tools
        Tools --> Symbols
        Symbols --> TypeSystem
    end

    subgraph "Manipulation & Structure"
        Manipulation["Code Manipulation"]:::manipulation
        Structures["Structure Management"]:::manipulation
        StructurePrinters["Structure Printing"]:::manipulation
        Manipulation --> Structures
        Structures --> StructurePrinters
    end

    subgraph "File System Layer"
        Directory["Directory Management"]:::filesystem
        DirectoryCoord["Directory Coordinator"]:::filesystem
        DirectoryEmit["Directory Emit"]:::filesystem
        Directory --> DirectoryCoord
        DirectoryCoord --> DirectoryEmit
    end

    subgraph "Support Systems"
        CompilerFactory["Compiler Factory"]:::support
        StructurePrinterFactory["Structure Printer Factory"]:::support
        DirectoryCache["Directory Cache"]:::support
        Utils["Utilities"]:::support
        Types["Type Definitions"]:::support
        Options["Options Management"]:::support
    end

    Project --> AST
    ProjectContext --> Tools
    AST --> Manipulation
    TypeSystem --> Structures
    Manipulation --> Directory
    StructurePrinters --> DirectoryEmit
    CompilerFactory --> AST
    StructurePrinterFactory --> StructurePrinters
    DirectoryCache --> Directory
    Utils --> Project
    Types --> TypeSystem
    Options --> ProjectContext

    classDef core fill:#3498db,stroke:#2980b9,color:#fff
    classDef filesystem fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef manipulation fill:#e67e22,stroke:#d35400,color:#fff
    classDef support fill:#95a5a6,stroke:#7f8c8d,color:#fff

    click Project "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/Project.ts"
    click ProjectContext "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/ProjectContext.ts"
    click AST "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/compiler/ast"
    click Tools "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/compiler/tools"
    click Symbols "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/compiler/symbols"
    click TypeSystem "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/compiler/types"
    click Manipulation "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/manipulation"
    click Structures "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/structures"
    click StructurePrinters "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/structurePrinters"
    click Directory "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/fileSystem/Directory.ts"
    click DirectoryCoord "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/fileSystem/DirectoryCoordinator.ts"
    click DirectoryEmit "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/fileSystem/DirectoryEmitResult.ts"
    click CompilerFactory "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/factories/CompilerFactory.ts"
    click StructurePrinterFactory "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/factories/StructurePrinterFactory.ts"
    click DirectoryCache "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/factories/DirectoryCache.ts"
    click Utils "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/utils"
    click Types "https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/types.ts"
    click Options "https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph/src/options"
```
