# droopytersen/ts-engineer architecture

> Architecture diagram of the GitHub repository droopytersen/ts-engineer, 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/droopytersen/ts-engineer
- Repository: https://github.com/droopytersen/ts-engineer

## Overview

Key Components to Include in the System Design:

##### Core Application Layers
- Frontend Layer (React/Remix)
- Backend API Layer (Hono)
- Database Layer (PGLite)
- File System Integration Layer
- AI/LLM Integration Layer

##### Main Architectural Patterns
- Model-View-Controller (MVC) pattern in the routes structure
- Service-based architecture for AI operations
- Repository pattern for database operations
- Event-driven architecture for streaming responses

##### Key Flows to Highlight

a. Code Task Flow:

##### Important Elements

- Blue: Frontend components
- Green: Backend services
- Yellow: AI/LLM services
- Purple: Data storage
- Gray: External services

- Connection Types:

##### Key Integration Points to Emphasize

- File System Integration:
- How the system interacts with local files
- Context selection mechanism
- File watching and updating processes

- AI Provider Integration:
- Routing logic based on project classification
- Model selection process
- Streaming response handling

##### Data Flow Patterns

- How data flows from:
- Frontend user interactions
- Through the API layer
- To the AI services
- Back to the user interface
- Into the persistent storage

## Diagram (Mermaid)

```mermaid
graph TD
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef ai fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        UI["UI Components"]:::frontend
        Routes["Remix Routes"]:::frontend
        Toolkit["UI Toolkit"]:::frontend
        ChatUI["Chat Interface"]:::frontend
        TaskUI["Task Interface"]:::frontend
    end

    %% Backend Layer
    subgraph Backend
        APIServer["API Server"]:::backend
        Middleware["API Middleware"]:::backend
        FSCore["File System Core"]:::backend
        FileEdit["File Editor"]:::backend
        FileFilter["File Filter"]:::backend
        Telemetry["Telemetry System"]:::backend
    end

    %% AI Services Layer
    subgraph AIServices
        LLMCore["LLM Integration"]:::ai
        CodeAnalysis["Code Analysis"]:::ai
        Specifications["Specifications Generator"]:::ai
        AIToolkit["AI Toolkit"]:::ai
        AIStreams["AI Streams"]:::ai
    end

    %% Data Layer
    subgraph DataStorage
        PGLite["PGLite Database"]:::data
        Migrations["DB Migrations"]:::data
        DBOps["Database Operations"]:::data
        FileStore["Local File Storage"]:::data
    end

    %% External Services
    subgraph External
        OpenAI["OpenAI"]:::external
        Anthropic["Anthropic"]:::external
        OtherAI["Other AI Providers"]:::external
    end

    %% Relationships
    UI --> Routes
    Routes --> APIServer
    APIServer --> LLMCore
    APIServer --> FSCore
    FSCore --> FileStore
    LLMCore --> External
    LLMCore --> PGLite
    FileEdit --> FileStore
    FileFilter --> FileStore
    Telemetry --> DBOps
    ChatUI --> Routes
    TaskUI --> Routes
    CodeAnalysis --> FSCore
    AIStreams --> LLMCore
    DBOps --> PGLite

    %% Click Events
    click UI "https://github.com/DroopyTersen/ts-engineer/tree/main/app/components"
    click Routes "https://github.com/DroopyTersen/ts-engineer/tree/main/app/routes"
    click Toolkit "https://github.com/DroopyTersen/ts-engineer/tree/main/app/shadcn/components/ui"
    click APIServer "https://github.com/DroopyTersen/ts-engineer/blob/main/api/server.ts"
    click Middleware "https://github.com/DroopyTersen/ts-engineer/blob/main/api/middleware/telemetryMiddleware.ts"
    click FSCore "https://github.com/DroopyTersen/ts-engineer/tree/main/api/aiEngineer/fs"
    click FileEdit "https://github.com/DroopyTersen/ts-engineer/tree/main/api/aiEngineer/fs/applyFileEdit"
    click FileFilter "https://github.com/DroopyTersen/ts-engineer/blob/main/api/aiEngineer/fs/filterFilePaths.ts"
    click LLMCore "https://github.com/DroopyTersen/ts-engineer/tree/main/api/aiEngineer/llm"
    click CodeAnalysis "https://github.com/DroopyTersen/ts-engineer/tree/main/api/aiEngineer/llm/codingPlan"
    click Specifications "https://github.com/DroopyTersen/ts-engineer/tree/main/api/aiEngineer/llm/specfications"
    click AIToolkit "https://github.com/DroopyTersen/ts-engineer/tree/main/app/toolkit/ai/llm"
    click AIStreams "https://github.com/DroopyTersen/ts-engineer/tree/main/app/toolkit/ai/streams"
    click PGLite "https://github.com/DroopyTersen/ts-engineer/blob/main/api/aiEngineer/db/pglite/pglite.server.ts"
    click Migrations "https://github.com/DroopyTersen/ts-engineer/tree/main/api/aiEngineer/db/pglite/migrations"
    click DBOps "https://github.com/DroopyTersen/ts-engineer/blob/main/api/aiEngineer/db/db.server.ts"
    click Telemetry "https://github.com/DroopyTersen/ts-engineer/blob/main/api/telemetry/telemetry.server.ts"
    click ChatUI "https://github.com/DroopyTersen/ts-engineer/blob/main/app/routes/projects.$id.chat.$conversationId"
    click TaskUI "https://github.com/DroopyTersen/ts-engineer/blob/main/app/routes/projects.$id.codeTasks.$codeTaskId"
```
