# bradleyboy/tuql architecture

> Architecture diagram of the GitHub repository bradleyboy/tuql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bradleyboy/tuql
- Repository: https://github.com/bradleyboy/tuql

## Overview

##### Main Components

a) Input Layer:
- SQLite Database File Input
- SQL File Input (for in-memory database)
- Command-line Interface (CLI)

b) Core Processing Components:
- Schema Builder
- Query Builder
- Relationship Inference Engine
- Mutation Generator

c) Output Layer:
- GraphQL Server
- GraphiQL Interface (optional)
- Schema Export Functionality

**┌─ Input Layer ─┐**
- CLI Args   │
- SQLite/SQL  │
- ┬───────┘
- ▼
**┌─ Core Layer ──────────────────┐**
- ┌─ Schema Builder ─┐          │
- Definitions    │          │
- Arguments     │──┐       │
- Associations  │  │       │
- ┘  │       │
- ┌─ Query Engine ─┐  │       │
- Resolvers     │◄─┘       │
- Mutations     │          │
- ┘          │
- ┬─────────────────┘
- ▼
**┌─ Output Layer ─┐**
- GraphQL API  │
- GraphiQL    │
- ┘

##### Component Details

Schema Builder Section:
- Three main builders (definitions.js, arguments.js, associations.js)
- Relationship inference logic
- Supported relationship types (belongsTo, hasMany, belongsToMany)

Query Engine Section:
- CRUD operation support
- Mutation capabilities
- Relationship resolution logic

##### Additional Elements

- The relationship inference rules (id naming conventions)
- Table naming conventions for many-to-many relationships
- Foreign key detection capabilities

##### Technical Details

Integration points:
- CLI argument processing
- Database connection handling
- GraphQL server setup
- Schema export functionality

##### Implementation Notes

- The modular builder pattern used
- The separation of concerns between builders
- The utility functions support
- The test coverage for each component

Remember to include a note about the tool's flexibility in handling both foreign key-based and naming convention-based relationship inference, as this is a key feature of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        CLI["Command Line Interface"]:::cli
        DB[(SQLite Database)]:::db
        SQL[("SQL File<br/>(In-Memory)")]:::db
    end

    subgraph Core["Core Processing Layer"]
        SB["Schema Builder"]:::core
        
        subgraph Builders["Builder Components"]
            direction TB
            DEF["Definitions Builder"]:::builder
            ARG["Arguments Builder"]:::builder
            REL["Relationship Inference<br/>Engine"]:::builder
        end
        
        subgraph QueryEngine["Query Engine"]
            direction TB
            RES["Resolvers"]:::engine
            MUT["Mutations"]:::engine
        end

        UTIL["Utility Functions"]:::util
    end

    subgraph Output
        GQL["GraphQL API"]:::output
        GUI["GraphiQL Interface"]:::output
        EXP["Schema Export"]:::output
    end

    %% Connections
    CLI --> SB
    DB --> SB
    SQL --> SB

    SB --> DEF
    SB --> ARG
    SB --> REL
    
    DEF --> RES
    ARG --> RES
    REL --> RES
    
    UTIL -.-> DEF
    UTIL -.-> ARG
    UTIL -.-> REL
    
    RES --> GQL
    MUT --> GQL
    GQL --> GUI
    GQL --> EXP

    %% Styles
    classDef cli fill:#a8d5ff,stroke:#333,stroke-width:1px
    classDef db fill:#ffcdb2,stroke:#333,stroke-width:1px
    classDef core fill:#b5e48c,stroke:#333,stroke-width:1px
    classDef builder fill:#99d98c,stroke:#333,stroke-width:1px
    classDef engine fill:#76c893,stroke:#333,stroke-width:1px
    classDef util fill:#52b69a,stroke:#333,stroke-width:1px
    classDef output fill:#ff9f1c,stroke:#333,stroke-width:1px

    %% Click events
    click CLI "https://github.com/bradleyboy/tuql/blob/master/src/bin/index.js"
    click SB "https://github.com/bradleyboy/tuql/blob/master/src/builders/schema.js"
    click DEF "https://github.com/bradleyboy/tuql/blob/master/src/builders/definitions.js"
    click ARG "https://github.com/bradleyboy/tuql/blob/master/src/builders/arguments.js"
    click REL "https://github.com/bradleyboy/tuql/blob/master/src/builders/associations.js"
    click UTIL "https://github.com/bradleyboy/tuql/blob/master/src/utils/index.js"
```
