# eclipse-langium/langium architecture

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

- Interactive diagram: https://gitdiagram.com/eclipse-langium/langium
- Repository: https://github.com/eclipse-langium/langium

## Overview

##### Main Components (Core Architecture)

a) Core Language Processing Layer:
- Grammar Processing (packages/langium/src/grammar)
- Parser System (packages/langium/src/parser)
- AST Management (packages/langium/src/syntax-tree.ts)
- Type System (packages/langium/src/grammar/type-system)

b) Language Server Protocol (LSP) Layer:
- LSP Services (packages/langium/src/lsp)
- Document Management (packages/langium/src/workspace)
- Validation System (packages/langium/src/validation)

c) Generation & Tools:
- Code Generator (packages/langium/src/generate)
- CLI Tools (packages/langium-cli)
- VS Code Integration (packages/langium-vscode)

##### Component Relationships

- Grammar → Parser (Grammar definitions feed into parser generation)
- Parser → AST (Parser produces Abstract Syntax Trees)
- AST → LSP Services (AST provides basis for language services)
- LSP Services → IDE Integration (Services connect to IDE features)

##### Architectural Patterns to Highlight

a) Service Layer Pattern:
- Dependency injection system
- Service registry connections
- Module system organization

b) Pipeline Pattern:
- Text Input → Lexer → Parser → AST → Validation → IDE Services

##### Integration Points

External integration points:
- VS Code Extension Host
- Language Server Protocol
- Web Browser Runtime
- CLI Environment

- Source Text → Tokenization → Parsing → AST Building → Validation → IDE Features

##### Implementation Details

Technical details in notes:
- Built on TypeScript
- Uses Chevrotain for parsing
- LSP protocol implementation
- Web/Node.js runtime support

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Language Processing"]
        Grammar["Grammar Processing"]:::core
        Parser["Parser System"]:::core
        AST["AST Management"]:::core
        TypeSystem["Type System"]:::core
        
        Grammar --> Parser
        Parser --> AST
        AST --> TypeSystem
    end

    subgraph LSP["Language Server Protocol Layer"]
        LSPServices["LSP Services"]:::lsp
        DocManagement["Document Management"]:::lsp
        Validation["Validation System"]:::lsp
        
        DocManagement --> LSPServices
        Validation --> LSPServices
    end

    subgraph Tools["Generation & Tools"]
        Generator["Code Generator"]:::tools
        CLI["CLI Tools"]:::tools
        VSCode["VS Code Integration"]:::tools
    end

    subgraph External["Integration Points"]
        VSCodeHost["VS Code Extension Host"]:::external
        LSPProtocol["Language Server Protocol"]:::external
        WebRuntime["Web Browser Runtime"]:::external
        CLIEnv["CLI Environment"]:::external
    end

    %% Core relationships
    AST --> LSPServices
    TypeSystem --> Validation
    Grammar --> Generator
    
    %% Tool relationships
    LSPServices --> VSCode
    VSCode --> VSCodeHost
    LSPServices --> LSPProtocol
    Generator --> CLI
    CLI --> CLIEnv
    LSPServices --> WebRuntime

    %% Click events for file navigation
    click Grammar "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/grammar/"
    click Parser "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/parser/"
    click AST "https://github.com/eclipse-langium/langium/blob/main/packages/langium/src/syntax-tree.ts"
    click TypeSystem "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/grammar/type-system/"
    click LSPServices "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/lsp/"
    click DocManagement "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/workspace/"
    click Validation "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/validation/"
    click Generator "https://github.com/eclipse-langium/langium/tree/main/packages/langium/src/generate/"
    click CLI "https://github.com/eclipse-langium/langium/tree/main/packages/langium-cli/"
    click VSCode "https://github.com/eclipse-langium/langium/tree/main/packages/langium-vscode/"

    %% Styling
    classDef core fill:#2374ab
    classDef lsp fill:#2a9d8f
    classDef tools fill:#e76f51
    classDef external fill:#8338ec
    
    %% Legend
    subgraph Legend
        CoreLegend["Core Components"]:::core
        LSPLegend["LSP Components"]:::lsp
        ToolsLegend["Tools & Generation"]:::tools
        ExtLegend["External Integration"]:::external
    end
```
