# sdf-labs/dbt-sdf architecture

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

- Interactive diagram: https://gitdiagram.com/sdf-labs/dbt-sdf
- Repository: https://github.com/sdf-labs/dbt-sdf

## Overview

##### Main Components
- CLI Component – Represented by the dbt_sdf/cli directory. This is the entry point for the tool (with main.py and params.py) and will handle user interaction via command-line inputs.
- Model Parser Component – Found under the dbt_sdf/model_parser directory. This module (mainly parser.py) likely takes care of parsing model definitions or files. It will be a key processing engine that interprets input.
- Schema Component – Located in the dbt_sdf/schema directory. This module manages schema logic by providing base functionality (via base.py) and handling generated code (in the schema/generated subdirectory with models.py).
- Support Scripts – The scripts directory contains helper scripts such as cleanup_codegen.py. Though not part of the core package, these support tasks like code generation maintenance.
- Testing Infrastructure – The tests directory contains unit tests (test_cli.py, test_model_parser.py, etc.) and common test setup (conftest.py) to ensure the tool’s functionality.

##### Relationships and Data Flow
- Within the CLI, the main.py and params.py handle input processing. Once parameters are collected, the CLI component should call the Model Parser.
- Optionally, a feedback loop or error outputs can be shown, flowing from the Schema back to the CLI for logging or result presentation.
- External support where scripts (like cleanup_codegen.py) interact with the generated code in the Schema component, perhaps drawn as a side process that “cleans up” or maintains the code generation output.
- The build/deployment tools (e.g., Makefile and setup.py) can be drawn in a separate “Infrastructure & DevOps” layer that supports packaging and deployment of the entire system.

##### Architectural Patterns and Design Principles
- Separation of concerns, as the CLI, Parser, and Schema components are clearly delineated. This modular design ensures that each component has a single responsibility.
- That the tool is architected as a command-line application with core business logic abstracted from user interaction.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Input
    User["User Input"]:::user

    %% CLI Component Subgraph
    subgraph "CLI Component"
        cli_main["main.py"]:::core
        cli_params["params.py"]:::core
    end

    %% Model Parser Component Subgraph
    subgraph "Model Parser Component"
        parser["parser.py"]:::core
    end

    %% Schema Component Subgraph
    subgraph "Schema Component"
        schema_base["base.py"]:::core
        schema_models["models.py (generated)"]:::core
    end

    %% Support Scripts
    support["Cleanup Script (cleanup_codegen.py)"]:::support

    %% Testing Infrastructure Subgraph
    subgraph "Testing Infrastructure"
        test_cli["test_cli.py"]:::testing
        test_model_parser["test_model_parser.py"]:::testing
        test_cli_exit["test_cli_exit_codes.py"]:::testing
        conftest["conftest.py"]:::testing
    end

    %% Build & Deployment Subgraph
    subgraph "Build & Deployment"
        setup["setup.py"]:::dev
        makefile["Makefile"]:::dev
        gitignore[".gitignore"]:::dev
    end

    %% Connections: Data Flow & Relationships
    User -->|"trigger"| cli_main
    cli_main -->|"collectsParams"| cli_params
    cli_main -->|"callsParser"| parser
    parser -->|"sendsData"| schema_base
    schema_base -->|"generates"| schema_models
    schema_models -->|"feedback"| cli_main

    support -->|"cleanupUpdate"| schema_models

    test_cli -->|"testsCLI"| cli_main
    test_model_parser -->|"testsParser"| parser
    test_cli_exit -->|"testsCLIExit"| cli_params
    conftest -->|"setupTests"| cli_main

    setup -->|"packages"| cli_main

    %% Click Events for Components
    click cli_main "https://github.com/sdf-labs/dbt-sdf/blob/main/dbt_sdf/cli/main.py"
    click cli_params "https://github.com/sdf-labs/dbt-sdf/blob/main/dbt_sdf/cli/params.py"
    click parser "https://github.com/sdf-labs/dbt-sdf/blob/main/dbt_sdf/model_parser/parser.py"
    click schema_base "https://github.com/sdf-labs/dbt-sdf/blob/main/dbt_sdf/schema/base.py"
    click schema_models "https://github.com/sdf-labs/dbt-sdf/blob/main/dbt_sdf/schema/generated/models.py"
    click support "https://github.com/sdf-labs/dbt-sdf/blob/main/scripts/cleanup_codegen.py"
    click test_cli "https://github.com/sdf-labs/dbt-sdf/blob/main/tests/test_cli.py"
    click test_model_parser "https://github.com/sdf-labs/dbt-sdf/blob/main/tests/test_model_parser.py"
    click test_cli_exit "https://github.com/sdf-labs/dbt-sdf/blob/main/tests/test_cli_exit_codes.py"
    click conftest "https://github.com/sdf-labs/dbt-sdf/blob/main/tests/conftest.py"
    click setup "https://github.com/sdf-labs/dbt-sdf/blob/main/setup.py"
    click makefile "https://github.com/sdf-labs/dbt-sdf/tree/main/Makefile"
    click gitignore "https://github.com/sdf-labs/dbt-sdf/blob/main/.gitignore"

    %% Styles
    classDef user fill:#D1BBFF,stroke:#333,stroke-width:2px;
    classDef core fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef support fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef testing fill:#CCE5FF,stroke:#333,stroke-width:2px,stroke-dasharray: 5, 5;
    classDef dev fill:#FFDDCC,stroke:#333,stroke-width:2px;
```
