# tscircuit/cli architecture

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

- Interactive diagram: https://gitdiagram.com/tscircuit/cli
- Repository: https://github.com/tscircuit/cli

## Overview

##### Main Components Identification

a) CLI Interface Layer
- Entry point through cli/main.ts
- Type installation handling (cli/installTypes.ts)

b) Core Library Layer (lib/)
- Configuration management (lib/config.ts)
- Dependency analysis system
- File server integration
- Site rendering

c) External Dependencies
- @tscircuit/file-server
- @tscircuit/runframe
- Browser preview system

##### Component Relationships

**[CLI Layer] → [Core Library Layer] → [External Services]**

Use these specific elements:

a) Primary Components (Use rectangles):
- CLI Interface
- Dependency Analyzer
- File Server
- Events Watcher
- Browser Preview

- Command flow from CLI to library
- File watching events
- Browser updates
- Dependency resolution paths

##### Specific Implementation Details

a) Development Flow:
**[Source Files] → [Events Watcher] → [Dependency Analyzer] → [File Server] → [Browser Preview]**

b) Configuration Flow:
**[CLI Commands] → [Config Manager] → [External Authentication]**

##### Important Elements to Highlight

- Connection between the local development server and browser preview
- Dependency analysis flow
- Demonstrate the file watching mechanism
- Integration points with external @tscircuit services

##### Technical Stack Indicators

Technology badges or labels for:
- TypeScript
- Bun runtime
- CommanderJS
- Browser preview system

##### Architectural Patterns

Emphasize:
- Event-driven architecture for file watching
- Plugin system for type installation
- Service-oriented architecture for external integrations

##### Browser preview generation

Keep the focus on the interaction between local development tools and the browser preview system, as this appears to be the primary use case based on the README and file structure.

- Component type representations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef cli fill:#2196F3,color:white
    classDef core fill:#4CAF50,color:white
    classDef external fill:#FF9800,color:white
    classDef preview fill:#9C27B0,color:white
    classDef config fill:#607D8B,color:white

    %% Main Components
    CLI["CLI Interface"]:::cli
    TIH["Type Installation Handler"]:::cli
    CM["Configuration Manager"]:::config
    DA["Dependency Analyzer"]:::core
    LFD["Local File Dependency System"]:::core
    EW["Events Watcher"]:::core
    FS["File Server"]:::core
    SR["Site Renderer"]:::core
    CL["Core Library Entry"]:::core

    %% External Services
    TFS["@tscircuit/file-server"]:::external
    TRF["@tscircuit/runframe"]:::external
    BP["Browser Preview"]:::preview

    %% Development Flow
    subgraph Development
        SF["Source Files"]
        EW --> SF
        SF --> DA
        DA --> LFD
        LFD --> FS
    end

    %% CLI Flow
    subgraph CLI
        CLI --> TIH
        CLI --> CM
        CLI --> CL
    end

    %% Core Operations
    subgraph Core
        CL --> DA
        DA --> FS
        FS --> SR
        EW --> DA
    end

    %% External Integrations
    FS <--> TFS
    SR --> BP
    BP <--> TRF

    %% Click Events
    click CLI "https://github.com/tscircuit/cli/blob/main/cli/main.ts"
    click TIH "https://github.com/tscircuit/cli/blob/main/cli/installTypes.ts"
    click CM "https://github.com/tscircuit/cli/blob/main/lib/config.ts"
    click DA "https://github.com/tscircuit/cli/blob/main/lib/dependency-analysis/DependencyAnalyzer.ts"
    click LFD "https://github.com/tscircuit/cli/blob/main/lib/dependency-analysis/getLocalFileDependencies.ts"
    click EW "https://github.com/tscircuit/cli/blob/main/lib/server/EventsWatcher.ts"
    click FS "https://github.com/tscircuit/cli/blob/main/lib/server/createServer.ts"
    click SR "https://github.com/tscircuit/cli/blob/main/lib/site/getIndex.ts"
    click CL "https://github.com/tscircuit/cli/blob/main/lib/index.ts"

    %% Legend
    subgraph Legend
        L1["CLI Components"]:::cli
        L2["Core Components"]:::core
        L3["External Services"]:::external
        L4["Preview System"]:::preview
        L5["Configuration"]:::config
    end
```
