# xnacly/sqleibniz architecture

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

- Interactive diagram: https://gitdiagram.com/xnacly/sqleibniz
- Repository: https://github.com/xnacly/sqleibniz

## Overview

##### Main Components Identification
The system should be divided into these primary components:

a. Core Analysis Engine:
- Lexer (src/lexer/)
- Parser (src/parser/)
- Type System (src/types/)

b. Integration Layers:
- LSP Server (src/lsp/)
- CLI Interface (src/main.rs)
- Lua Scripting Engine (leibniz.lua)

##### Component Relationships

**┌─────────────────────────────────────────────┐**
- Client Interfaces              │
- (CLI Interface / LSP Server)         │
- ┤
- Analysis Pipeline                │
- ┌─────────┐    ┌────────┐    ┌────────┐  │
- Lexer  │ -> │ Parser │ -> │ Rules  │  │
- ┘    └────────┘    └────────┘  │
- ┤
- Extension System                 │
- (Lua Scripting Interface)           │
- ┤
- Type System                    │
- (Keywords, Rules, Context, Storage)      │
- ┘

##### Specific Implementation Details

a. Analysis Pipeline:
- Token flow: Source Code → Lexer → Tokens → Parser → AST → Rules
- Error handling paths (src/error.rs)
- How the tracer system integrates (parser/tracer.rs)

b. Configuration System:
- How leibniz.lua configuration integrates
- Demonstrate rule system configuration flow
- Storage and context management

##### Key Architectural Patterns to Highlight

- Pipeline Pattern: The main analysis flow
- Plugin Architecture: Lua scripting integration
- Visitor Pattern: For AST traversal
- Factory Pattern: For token and node creation

##### External Dependencies

- SQLite (for dynamic analysis)
- Lua Runtime
- LSP Protocol

##### Implementation Notes

- The modular nature of the codebase
- Clear separation between analysis and interface layers
- Extensibility through Lua scripting
- Error handling and reporting mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef core fill:#a8d1f0,stroke:#333
    classDef interface fill:#90EE90,stroke:#333
    classDef extension fill:#FFE5B4,stroke:#333
    classDef support fill:#E6E6E6,stroke:#333
    classDef pipeline fill:#FFF,stroke:#333,stroke-dasharray: 5 5
    
    %% Client Interface Layer
    subgraph ClientLayer
        CLI["CLI Interface"]:::interface
        LSP["LSP Server"]:::interface
    end

    %% Analysis Pipeline
    subgraph AnalysisPipeline
        direction TB
        Input["Source Code Input"]:::pipeline
        Lexer["Lexer Engine"]:::core
        Parser["Parser Engine"]:::core
        AST["AST Node System"]:::core
        Rules["Rules Engine"]:::core
        ErrorHandler["Error Handling System"]:::support
        Tracer["Tracer System"]:::support
    end

    %% Extension System
    subgraph ExtensionSystem
        LuaEngine["Lua Scripting Engine"]:::extension
        Config["Configuration System"]:::extension
    end

    %% Type System Layer
    subgraph TypeSystem
        TypeMgr["Type System"]:::support
        Keywords["Keyword Management"]:::support
        Context["Context Management"]:::support
        Storage["Storage System"]:::support
    end

    %% Relationships
    Input --> Lexer
    Lexer --> Parser
    Parser --> AST
    AST --> Rules
    Parser --> ErrorHandler
    Parser --> Tracer
    
    CLI --> Input
    LSP --> Input
    
    LuaEngine --> Rules
    Config --> TypeMgr
    
    Rules --> TypeMgr
    TypeMgr --> Keywords
    TypeMgr --> Context
    TypeMgr --> Storage

    %% Click Events
    click CLI "https://github.com/xNaCly/sqleibniz/blob/master/src/main.rs"
    click LSP "https://github.com/xNaCly/sqleibniz/blob/master/src/lsp/mod.rs"
    click Lexer "https://github.com/xNaCly/sqleibniz/blob/master/src/lexer/mod.rs"
    click Parser "https://github.com/xNaCly/sqleibniz/blob/master/src/parser/mod.rs"
    click AST "https://github.com/xNaCly/sqleibniz/blob/master/src/parser/nodes.rs"
    click Rules "https://github.com/xNaCly/sqleibniz/blob/master/src/types/rules.rs"
    click ErrorHandler "https://github.com/xNaCly/sqleibniz/blob/master/src/error.rs"
    click Tracer "https://github.com/xNaCly/sqleibniz/blob/master/src/parser/tracer.rs"
    click LuaEngine "https://github.com/xNaCly/sqleibniz/blob/master/leibniz.lua"
    click Config "https://github.com/xNaCly/sqleibniz/blob/master/src/types/config.rs"
    click TypeMgr "https://github.com/xNaCly/sqleibniz/blob/master/src/types/mod.rs"
    click Keywords "https://github.com/xNaCly/sqleibniz/blob/master/src/types/keyword.rs"
    click Context "https://github.com/xNaCly/sqleibniz/blob/master/src/types/ctx.rs"
    click Storage "https://github.com/xNaCly/sqleibniz/blob/master/src/types/storage.rs"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Interface Layer"]:::interface
        L3["Extension System"]:::extension
        L4["Support Systems"]:::support
        L5["Pipeline Flow"]:::pipeline
    end
```
