# snowplow/dbt-snowplow-unified architecture

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

- Interactive diagram: https://gitdiagram.com/snowplow/dbt-snowplow-unified
- Repository: https://github.com/snowplow/dbt-snowplow-unified

## Overview

##### Main Components

a. Data Sources Layer:
- Snowplow JavaScript Tracker (Web)
- iOS Tracker (Mobile)
- Android Tracker (Mobile)
- React Native Tracker (Mobile)

b. Raw Data Layer:
- Web Events
- Mobile Events
- Context Data (webpage, geolocation, user agent, etc.)

c. Processing Layer (Core dbt Models):
- Base Models (/models/base/)
- Scratch Models (intermediate transformations)
- Incremental Processing Framework

d. Output Models Layer:
- Views Model (snowplow_unified_views)
- Sessions Model (snowplow_unified_sessions)
- Users Model (snowplow_unified_users)
- User Mapping Model (snowplow_unified_user_mapping)

e. Optional Modules Layer:
- App Errors
- Consent Management
- Conversions
- Core Web Vitals

##### Relationships and Data Flow

- Event flow from trackers to raw data
- Incremental processing flow through the models
- Dependencies between models (base → scratch → final models)
- Optional module integration points

##### Technical Details

- Supported Databases (Snowflake, BigQuery, Databricks, Redshift & Postgres)
- dbt version requirement (≥1.6.0)
- Required contexts (webpage context)
- Incremental processing indicators

##### Additional Elements

- Notes about incremental processing
- Integration points for custom models
- Test coverage points

##### Key Architectural Patterns to Emphasize

- Modular design pattern
- Incremental processing pattern
- Data transformation pipeline
- Identity stitching framework

Remember to include a version indicator and any relevant configuration dependencies, as this package requires specific setup for different warehouse platforms.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef source fill:#90EE90,stroke:#333,stroke-width:2px
    classDef raw fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef processing fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef output fill:#9370DB,stroke:#333,stroke-width:2px
    classDef optional fill:#FFD700,stroke:#333,stroke-width:2px
    classDef support fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% Data Sources
    subgraph DataSources["Data Collection Layer"]
        JS["JavaScript Tracker"]:::source
        iOS["iOS Tracker"]:::source
        Android["Android Tracker"]:::source
        ReactNative["React Native Tracker"]:::source
    end

    %% Raw Data Layer
    subgraph RawData["Raw Data Layer"]
        WebEvents["Web Events"]:::raw
        MobileEvents["Mobile Events"]:::raw
        ContextData["Context Data"]:::raw
    end
    click RawData "https://github.com/snowplow/dbt-snowplow-unified/tree/main/integration_tests/data/source/"

    %% Processing Layer
    subgraph Processing["Processing Layer"]
        BaseModels["Base Models"]:::processing
        ScratchModels["Scratch Models"]:::processing
        IncrementalFramework["Incremental Processing Framework"]:::processing
    end
    click BaseModels "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/base/"
    click IncrementalFramework "https://github.com/snowplow/dbt-snowplow-unified/blob/main/models/base/manifest/snowplow_unified_incremental_manifest.sql"

    %% Scratch Processing
    subgraph ScratchProcessing["Scratch Processing"]
        SessionProc["Session Processing"]:::processing
        UserProc["User Processing"]:::processing
        ViewsProc["Views Processing"]:::processing
    end
    click SessionProc "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/sessions/scratch/"
    click UserProc "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/users/scratch/"
    click ViewsProc "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/views/scratch/"

    %% Output Models
    subgraph OutputModels["Output Models Layer"]
        Views["Views Model"]:::output
        Sessions["Sessions Model"]:::output
        Users["Users Model"]:::output
        UserMapping["User Mapping Model"]:::output
    end
    click Views "https://github.com/snowplow/dbt-snowplow-unified/blob/main/models/views/snowplow_unified_views.sql"
    click Sessions "https://github.com/snowplow/dbt-snowplow-unified/blob/main/models/sessions/snowplow_unified_sessions.sql"
    click Users "https://github.com/snowplow/dbt-snowplow-unified/blob/main/models/users/snowplow_unified_users.sql"
    click UserMapping "https://github.com/snowplow/dbt-snowplow-unified/blob/main/models/user_mapping/snowplow_unified_user_mapping.sql"

    %% Optional Modules
    subgraph OptionalModules["Optional Modules"]
        AppErrors["App Errors"]:::optional
        ConsentMgmt["Consent Management"]:::optional
        Conversions["Conversions"]:::optional
        WebVitals["Core Web Vitals"]:::optional
    end
    click AppErrors "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/optional_modules/app_errors/"
    click ConsentMgmt "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/optional_modules/consent/"
    click Conversions "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/optional_modules/conversions/"
    click WebVitals "https://github.com/snowplow/dbt-snowplow-unified/tree/main/models/optional_modules/core_web_vitals/"

    %% Support Components
    subgraph Support["Supporting Components"]
        FieldDefs["Field Definitions"]:::support
        FieldExtracts["Field Extractions"]:::support
    end
    click FieldDefs "https://github.com/snowplow/dbt-snowplow-unified/tree/main/macros/field_definitions/"
    click FieldExtracts "https://github.com/snowplow/dbt-snowplow-unified/tree/main/macros/field_extractions/"

    %% Relationships
    JS & iOS & Android & ReactNative --> WebEvents & MobileEvents
    WebEvents & MobileEvents --> ContextData
    ContextData --> BaseModels
    BaseModels --> IncrementalFramework
    IncrementalFramework --> ScratchModels
    ScratchModels --> SessionProc & UserProc & ViewsProc
    SessionProc --> Sessions
    UserProc --> Users
    ViewsProc --> Views
    Users --> UserMapping
    
    %% Optional Module Integration
    BaseModels --> OptionalModules
    Support --> BaseModels

    %% Legend
    subgraph Legend
        SourceLegend["Data Sources"]:::source
        RawLegend["Raw Data"]:::raw
        ProcessingLegend["Processing"]:::processing
        OutputLegend["Output Models"]:::output
        OptionalLegend["Optional Modules"]:::optional
        SupportLegend["Support Components"]:::support
    end
```
