# google/meridian architecture

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

- Interactive diagram: https://gitdiagram.com/google/meridian
- Repository: https://github.com/google/meridian

## Overview

##### Project Context & Purpose
- Meridian is a marketing mix modeling (MMM) framework. It is designed to help advertisers run Bayesian causal inference-based MMM analyses. The system handles large-scale geo-level (and national-level) data, provides MCMC sampling (with GPU-supported No U Turn Sampler), and outputs analytical summaries and visualizations to aid budget planning and marketing optimization.

##### And Outline Main Components

a. Data Layer:
- Components: Located in the “meridian/data” directory.
- Responsibilities: Handling data input, sample data management, simulated data, time coordinates, and argument building. This part of the system is responsible for loading, preprocessing, and coordinating data extraction.

b. Analysis Module:
- Components: Found under “meridian/analysis”.
- Responsibilities: Implementing various analytics functions including summarization, optimization, formatting, visualization, and reporting. It also includes Jinja2 templates for generating reports and dashboards (HTML-based templates for cards, charts, tables, etc.).

c. Modeling Module:
- Components: Located in “meridian/model”.
- Responsibilities: Handling the core MMM methodologies. This includes building the marketing mix model, setting model specifications, performing MCMC sampling using NUTS, managing priors/posteriors, and implementing transformations (e.g., adstock, media functions).

d. External and Supporting Components:
- Build and Distribution: Files like “setup.py”, “pyproject.toml”, and “MANIFEST.in” indicate standard Python packaging. Note that these support the deployment and distribution of Meridian and are not runtime components but might be referenced as “Package & Environment Management” if needed.

##### Relationships and Data Flows
- Data Collection/Preprocessing → Model Core
- Model Core output → Analysis & Visualization (report generation, templating)

##### Architectural Patterns and Key Technologies
- That the framework leverages a modular design pattern by separating core functionalities into distinct packages (data, analysis, model).
- Use of templating (Jinja2) for report generation, and the integration with GPU acceleration for model sampling (indicate this with a note on “GPU Support”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Modules
    A["Data Ingestion & Preprocessing"]:::data
    B["MMM Modeling and Inference Engine"]:::model
    C["Analysis & Visualization Module"]:::analysis

    %% Side Modules
    D["Automated Testing & Deployment"]:::cicd
    E["User Demo / Notebook"]:::demo

    %% Package & Environment Management Subgraph
    subgraph "Package & Environment Management"
        F1["setup.py"]:::package
        F2["pyproject.toml"]:::package
        F3["MANIFEST.in"]:::package
    end

    %% Annotation for GPU Support in MMM Modeling
    G["GPU Support (via TensorFlow Probability)"]:::modelNote

    %% Data Flow Connections
    A -->|"preprocessedData"| B
    B -->|"modelOutput"| C
    C -->|"feedback"| B

    %% CI/CD and Deployment Pipeline
    D -->|"deploys"| F1
    D -->|"deploys"| F2
    D -->|"deploys"| F3

    %% User Interaction
    C -->|"userView"| E

    %% GPU Support Annotation
    B ---|"accelerates"| G

    %% Styles
    classDef data fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef model fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef analysis fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef cicd fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef demo fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef package fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef modelNote fill:#F8C471,stroke:#B9770E,stroke-dasharray:5,5,stroke-width:2px;

    %% Click Events (component mapping)
    click A "https://github.com/google/meridian/tree/main/meridian/data"
    click C "https://github.com/google/meridian/tree/main/meridian/analysis"
    click B "https://github.com/google/meridian/tree/main/meridian/model"
    click D "https://github.com/google/meridian/blob/main/.github"
    click E "https://github.com/google/meridian/tree/main/demo"
    click F1 "https://github.com/google/meridian/blob/main/setup.py"
    click F2 "https://github.com/google/meridian/blob/main/pyproject.toml"
    click F3 "https://github.com/google/meridian/blob/main/MANIFEST.in"
```
