# mattermost/mattermost-data-warehouse architecture

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

- Interactive diagram: https://gitdiagram.com/mattermost/mattermost-data-warehouse
- Repository: https://github.com/mattermost/mattermost-data-warehouse

## Overview

##### Project type and purpose
- This is an ETL/ELT data-warehouse orchestration platform for Mattermost. It uses Airflow on Kubernetes to extract data from sources (S3, GitHub, Stripe, Salesforce, RudderStack, Snowflake raw tables, etc.), loads it into Snowflake staging, transforms it via two DBT projects (snowflake-dbt and mattermost-analytics), and exports processed data to downstream tools (Hightouch, Postgres, dashboards).
- Key goals: centralized orchestration (Airflow), robust transformations (DBT), role management (Snowflake roles), notifications (Mattermost), and utility scripts for edge-case ETL tasks.

##### File structure
- Top-level directories:
- airflow/ – Airflow DAGs, plugins (Mattermost hooks/operators), tests
- extract/ – Python scripts to pull data from S3 and APIs into Snowflake
- transform/ –
· snowflake-dbt/ – legacy DBT project of Snowflake models
· mattermost-analytics/ – new DBT project for analytics models (staging, intermediate, marts, reports)
· sql/ – standalone SQL scripts executed by DAGs (e.g., NPS feedback updates)
- load/ – Snowflake role definitions, Airflow DAG to apply permissions
- utils/ – Python CLI scripts for ad hoc ETL tasks and helpers (DB, GitHub, GeoLite, packets, etc.)
- Configuration & build artifacts: Dockerfiles, docker-compose yamls, Makefile, pyproject.toml, GitHub CI workflows
- Tests are co-located under airflow/tests/ and top-level tests/ and transform/mattermost-analytics/tests/

##### README for additional insights
- Describes a layered “Extract → Load → Transform → Export” architecture
- DBT runs on DBT Cloud, orchestrated via Airflow DAGs
- Environment variables drive Snowflake connections for different roles (SYSADMIN, LOADER, TRANSFORMER, PERMISSIONS)
- Utilities and billing/invoicing tasks are run as Airflow DAGs
- External systems: Kubernetes cluster, Snowflake, S3, DBT Cloud, Mattermost (for notifications), Hightouch, Postgres

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Sources
    subgraph "External Data Sources" 
        direction TB
        S3["AWS S3 Buckets"]:::dataStore
        GitHub["GitHub API"]:::external
        Stripe["Stripe API"]:::external
        Salesforce["Salesforce API"]:::external
        RudderStack["RudderStack"]:::external
        SnowflakeRaw["Snowflake Raw Tables"]:::dataStore
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        Airflow["Airflow (Kubernetes/Docker)"]:::orchestr
        AirflowDAGs["Airflow DAGs"]:::orchestr
        MattermostPlugins["Mattermost Notifications Plugins"]:::external
    end

    %% Extraction Services
    subgraph "Extraction Services"
        direction TB
        ExtractScripts["Extract Scripts (S3 & APIs)"]:::compute
        S3Extract["S3-Specific Extract Modules"]:::compute
        UtilsExtract["Ad-hoc ETL & Helpers"]:::compute
    end

    %% Data Warehouse
    subgraph "Data Warehouse (Snowflake)"
        direction TB
        Staging["Staging Schema"]:::dataStore
        Intermediate["Intermediate Schema"]:::dataStore
        Marts["Marts Schema"]:::dataStore
        Reports["Reports Schema"]:::dataStore
    end

    %% Transformation Services
    subgraph "Transformation Services"
        direction TB
        LegacyDBT["Legacy DBT Project"]:::compute
        AnalyticsDBT["Analytics DBT Project"]:::compute
        SQLJobs["Standalone SQL Scripts"]:::compute
        subgraph "DBT Models"
            direction TB
            StagingModels["Staging Models"]:::compute
            IntermediateModels["Intermediate Models"]:::compute
            MartsModels["Marts Models"]:::compute
            ReportsModels["Reports Models"]:::compute
        end
        subgraph "DBT Macros"
            direction TB
            Macros1["Analytics DBT Macros"]:::compute
            Macros2["Snowflake-DBT Macros"]:::compute
        end
    end

    %% Role Management
    subgraph "Role Management"
        direction TB
        Roles["Snowflake Role Definitions"]:::compute
    end

    %% Export Services
    subgraph "Export Services"
        direction TB
        Hightouch["Hightouch Exports"]:::external
        PostgresExport["Postgres Exports"]:::external
        Billing["Billing/Invoice DAGs"]:::compute
    end

    %% Monitoring & Notifications
    subgraph "Monitoring & Notifications"
        direction TB
        Notifications["Mattermost Notifications"]:::external
    end

    %% CI/CD & Config
    subgraph "CI/CD & Config"
        direction TB
        CI["GitHub Actions Workflows"]:::config
        DockerConfig["Docker & Compose Config"]:::config
        ProjectConfig["Project Config & Packaging"]:::config
    end

    %% Relationships: Data Flow
    S3 -->|REST API/COPY| ExtractScripts
    GitHub -->|REST API| ExtractScripts
    Stripe -->|REST API| ExtractScripts
    Salesforce -->|REST API| ExtractScripts
    RudderStack -->|REST API| ExtractScripts
    SnowflakeRaw -->|SELECT| ExtractScripts

    ExtractScripts -->|COPY INTO| Staging
    S3Extract -->|COPY INTO| Staging
    UtilsExtract -->|LOAD| Staging

    Staging -->|dbt run| StagingModels
    StagingModels -->|dbt run| IntermediateModels
    IntermediateModels -->|dbt run| MartsModels
    MartsModels -->|dbt run| ReportsModels

    ReportsModels -->|EXPORT| Hightouch
    ReportsModels -->|EXPORT| PostgresExport
    ReportsModels -->|EXPORT| Billing

    %% Control/Orchestration Flow
    Airflow -->|"Trigger DAGs"| ExtractScripts
    Airflow -->|"Trigger DAGs"| SQLJobs
    Airflow -->|"Trigger DBT Cloud"| AnalyticsDBT
    Airflow -->|"Trigger DBT Cloud"| LegacyDBT
    Airflow -->|"Run Role DAG"| Roles
    Airflow -->|"Run Export DAGs"| Billing
    Airflow -->|"Invoke Utils"| UtilsExtract

    %% Monitoring
    Airflow -->|"Alerts"| Notifications

    %% CI/CD & Config ties
    CI -.-> Airflow
    CI -.-> ExtractScripts
    DockerConfig -.-> Airflow
    ProjectConfig -.-> Airflow
    ProjectConfig -.-> AnalyticsDBT

    %% DBT Macros connections
    Macros1 -.-> AnalyticsDBT
    Macros2 -.-> LegacyDBT

    %% Click Events
    click Airflow "https://github.com/mattermost/mattermost-data-warehouse/tree/master/airflow/"
    click AirflowDAGs "https://github.com/mattermost/mattermost-data-warehouse/tree/master/airflow/dags/mattermost_dags/"
    click MattermostPlugins "https://github.com/mattermost/mattermost-data-warehouse/tree/master/airflow/plugins/mattermost/"
    click ExtractScripts "https://github.com/mattermost/mattermost-data-warehouse/tree/master/extract/"
    click S3Extract "https://github.com/mattermost/mattermost-data-warehouse/tree/master/extract/s3_extract/"
    click UtilsExtract "https://github.com/mattermost/mattermost-data-warehouse/tree/master/utils/"
    click Roles "https://github.com/mattermost/mattermost-data-warehouse/blob/master/load/snowflake/roles.yaml"
    click SQLJobs "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/sql/"
    click LegacyDBT "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/snowflake-dbt/"
    click AnalyticsDBT "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/mattermost-analytics/"
    click Macros1 "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/mattermost-analytics/macros/"
    click Macros2 "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/snowflake-dbt/macros/"
    click StagingModels "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/mattermost-analytics/models/staging/"
    click IntermediateModels "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/mattermost-analytics/models/intermediate/"
    click MartsModels "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/mattermost-analytics/models/marts/"
    click ReportsModels "https://github.com/mattermost/mattermost-data-warehouse/tree/master/transform/mattermost-analytics/models/reports/"
    click CI "https://github.com/mattermost/mattermost-data-warehouse/tree/master/.github/workflows/"
    click DockerConfig "https://github.com/mattermost/mattermost-data-warehouse/tree/master/build/"
    click ProjectConfig "https://github.com/mattermost/mattermost-data-warehouse/blob/master/pyproject.toml"

    %% Styles
    classDef dataStore fill:#a2d149,color:#000,stroke:#333,stroke-width:1px
    classDef orchestr fill:#6baed6,color:#000,stroke:#333,stroke-width:1px
    classDef compute fill:#f59e0b,color:#000,stroke:#333,stroke-width:1px
    classDef external fill:#9b5de5,color:#fff,stroke:#333,stroke-width:1px
    classDef config fill:#9ca3af,color:#000,stroke:#333,stroke-width:1px
```
