# njk8/snowdbt architecture

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

- Interactive diagram: https://gitdiagram.com/njk8/snowdbt
- Repository: https://github.com/njk8/snowdbt

## Overview

##### Project type and purpose
- This is a dbt (data build tool) analytics engineering project. Its purpose is to extract and transform raw data into clean, tested, consumable data marts (fact tables) for downstream reporting or BI tools.

##### File structure
- Top-level files:
- dbt_project.yml – configuration for the entire dbt project
- packages.yml / package-lock.yml – external dbt packages and versions
- README.md – usage instructions
- Key directories:
- seeds/ – CSV files loaded as raw reference data (manual_book1.csv, manual_book2.csv)
- macros/ – reusable SQL snippets or Jinja macros (e.g., call_me_anything_you_want.sql)
- models/ – the heart of the transformations, subdivided into:
– example/ – sample starter models
– l10_staging/ – level 10 staging models (raw data ingestion and cleaning)
– l20_transform/ – level 20 business transformations (join, enrich, calculate)
– l30_mart/ – level 30 data marts (final fact tables and views)
– tests/ – YAML definitions for data quality tests
- snapshots/ – configurations for time-travel tables
- analyses/ – ad-hoc SQL for one-off analyses
- tests/ – generic test configurations (currently empty placeholder)

##### README for additional insights
- This is a standard starter project with instructions to run dbt and test.

##### Elements
- Clear labels for each component (e.g., “l10_staging: base_fe_fx_rates.sql”)
- Blue rectangles = source systems & seeds
- Orange rectangles = staging models
- Green rectangles = transformation models
- Purple rectangles = data marts / fact tables
- Gray ovals = macros & tests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Sources & Seeds
    subgraph "Sources & Seeds"
        ED["External Data Sources"]:::source
        Seeds1["manual_book1.csv"]:::seed
        Seeds2["manual_book2.csv"]:::seed
    end

    %% Staging Layer
    subgraph "Staging Layer (l10_staging)"
        S1["base_fe_fx_rates.sql"]:::staging
        S2["base_fe_stock_history.sql"]:::staging
    end

    %% Transform Layer
    subgraph "Transform Layer (l20_transform)"
        T1["tfm_book.sql"]:::transform
        T2["tfm_daily_position.sql"]:::transform
        T3["tfm_daily_position_with_trades.sql"]:::transform
        T4["tfm_fe_stock_history.sql"]:::transform
        T5["tfm_fe_stock_history_alt.sql"]:::transform
        T6["tfm_fx_rates.sql"]:::transform
        T7["tfm_stock_history.sql"]:::transform
        T8["tfm_stock_history_major_currency.sql"]:::transform
        T9["tfm_trading_pnl.sql"]:::transform
    end

    %% Mart Layer
    subgraph "Mart Layer (l30_mart)"
        M1["fct_trading_pnl.sql"]:::mart
        M2["fct_trading_pnl_finance_view.sql"]:::mart
        M3["fct_trading_pnl_risk_view.sql"]:::mart
        M4["fct_trading_pnl_treasury_view.sql"]:::mart
    end

    %% Snapshots
    subgraph "Snapshots"
        SP[".gitkeep"]:::snapshot
    end

    %% Macros & Tests
    subgraph "Macros & Tests"
        MAC["call_me_anything_you_want.sql"]:::macro
        TEST["data_quality_tests.yml"]:::test
    end

    %% Docs & Config
    subgraph "Docs & Config"
        CFG1["dbt_project.yml"]:::macro
        CFG2["packages.yml"]:::macro
        CFG3["package-lock.yml"]:::macro
        DOC["README.md"]:::macro
    end

    %% Examples & Analyses
    subgraph "Examples & Analyses"
        EX1["my_first_dbt_model.sql"]:::staging
        EX2["my_second_dbt_model.sql"]:::staging
        EX3["schema.yml"]:::staging
        AN[".gitkeep"]:::macro
    end

    %% Downstream Consumers
    subgraph "Downstream"
        BI["BI Tools / Dashboards"]:::mart
    end

    %% Data Flow
    ED --> S1
    ED --> S2
    Seeds1 --> S1
    Seeds2 --> S2
    S1 --> T6
    S2 --> T4
    S1 --> T1
    S2 --> T1
    T1 --> M1
    T9 --> M1
    M1 --> BI

    %% Snapshots Dashed
    SP -.-> S1
    SP -.-> S2

    %% Macros & Tests Usage
    MAC --> S1
    MAC --> T1
    MAC --> M1
    TEST --> S1
    TEST --> T1
    TEST --> M1

    %% Click Events
    click ED "https://github.com/njk8/snowdbt/blob/main/models/l10_staging/sources.yml"
    click Seeds1 "https://github.com/njk8/snowdbt/blob/main/seeds/manual_book1.csv"
    click Seeds2 "https://github.com/njk8/snowdbt/blob/main/seeds/manual_book2.csv"
    click S1 "https://github.com/njk8/snowdbt/blob/main/models/l10_staging/base_fe_fx_rates.sql"
    click S2 "https://github.com/njk8/snowdbt/blob/main/models/l10_staging/base_fe_stock_history.sql"
    click T1 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_book.sql"
    click T2 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_daily_position.sql"
    click T3 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_daily_position_with_trades.sql"
    click T4 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_fe_stock_history.sql"
    click T5 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_fe_stock_history_alt.sql"
    click T6 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_fx_rates.sql"
    click T7 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_stock_history.sql"
    click T8 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_stock_history_major_currency.sql"
    click T9 "https://github.com/njk8/snowdbt/blob/main/models/l20_transform/tfm_trading_pnl.sql"
    click M1 "https://github.com/njk8/snowdbt/blob/main/models/l30_mart/fct_trading_pnl.sql"
    click M2 "https://github.com/njk8/snowdbt/blob/main/models/l30_mart/fct_trading_pnl_finance_view.sql"
    click M3 "https://github.com/njk8/snowdbt/blob/main/models/l30_mart/fct_trading_pnl_risk_view.sql"
    click M4 "https://github.com/njk8/snowdbt/blob/main/models/l30_mart/fct_trading_pnl_treasury_view.sql"
    click SP "https://github.com/njk8/snowdbt/blob/main/snapshots/.gitkeep"
    click MAC "https://github.com/njk8/snowdbt/blob/main/macros/call_me_anything_you_want.sql"
    click TEST "https://github.com/njk8/snowdbt/blob/main/models/tests/data_quality_tests.yml"
    click CFG1 "https://github.com/njk8/snowdbt/blob/main/dbt_project.yml"
    click CFG2 "https://github.com/njk8/snowdbt/blob/main/packages.yml"
    click CFG3 "https://github.com/njk8/snowdbt/blob/main/package-lock.yml"
    click DOC "https://github.com/njk8/snowdbt/blob/main/README.md"
    click EX1 "https://github.com/njk8/snowdbt/blob/main/models/example/my_first_dbt_model.sql"
    click EX2 "https://github.com/njk8/snowdbt/blob/main/models/example/my_second_dbt_model.sql"
    click EX3 "https://github.com/njk8/snowdbt/blob/main/models/example/schema.yml"
    click AN "https://github.com/njk8/snowdbt/blob/main/analyses/.gitkeep"

    %% Styles
    classDef source fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef seed fill:#B3E6B0,stroke:#2E8B57,color:#2E8B57
    classDef staging fill:#FFD8B1,stroke:#FF8C00,color:#FF8C00
    classDef transform fill:#D5FFD0,stroke:#32CD32,color:#228B22
    classDef mart fill:#E7D0FF,stroke:#8A2BE2,color:#800080
    classDef macro fill:#F0F0F0,stroke:#696969,color:#696969
    classDef test fill:#F5F5F5,stroke:#808080,color:#808080
    classDef snapshot stroke-dasharray: 5 5,fill:#FFFFFF,stroke:#A9A9A9,color:#A9A9A9
```
