# google/lightweight_mmm architecture

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

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

## Overview

LightweightMMM is a Bayesian marketing-mix modeling library: users prepare and scale media, KPI, feature, and cost data; fit national or geo-level models; inspect predictions and channel effects; and optimize budget allocation. The graph keeps those product stages and the documented model components visible. Sampled source confirms the model-fitting interface, prior definitions, transformation and time-series components, and plotting behavior; some subsystem connections are based on README-described capabilities because their implementation excerpts were not supplied.

Main entry points: [`lightweight_mmm/models.py`](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/models.py) (MMM model forms), [`lightweight_mmm/lightweight_mmm.py`](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/lightweight_mmm.py) (Fit and predict), [`lightweight_mmm/optimize_media.py`](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/optimize_media.py) (Budget optimization), [`lightweight_mmm/media_transforms.py`](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/media_transforms.py) (Media transforms)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Analysis workflow"]
  node_prep["Scale and inspect<br/>[preprocessing.py]"]
  node_fit["Fit and predict<br/>[lightweight_mmm.py]"]
  node_optimizer["Budget optimization<br/>[optimize_media.py]"]
  node_utilities["Data utilities<br/>[utils.py]"]
end

subgraph group_inference["Bayesian inference"]
  node_media_effects["Media transforms"]
  node_lagging["Lag and carryover<br/>[lagging.py]"]
  node_saturation["Saturation<br/>[saturation.py]"]
  node_priors["Prior definitions<br/>[priors.py]"]
  node_baseline["Intercept<br/>[intercept.py]"]
  node_seasonality["Seasonality<br/>[seasonality.py]"]
  node_trend["Trend<br/>[trend.py]"]
  node_models["MMM model forms<br/>[models.py]"]
end

subgraph group_diagnostics["Analysis outputs"]
  node_plots["Model plots<br/>[plot.py]"]
  node_result["Effect and budget insights"]
end

node_analyst(("Analyst"))

node_analyst -->|"prepares data"| node_prep
node_analyst -->|"fits model"| node_fit
node_prep -->|"scaled inputs"| node_fit
node_fit -->|"runs inference"| node_models
node_models -->|"uses priors"| node_priors
node_models -->|"models baseline"| node_baseline
node_models -->|"models cycles"| node_seasonality
node_models -->|"models trend"| node_trend
node_models -->|"transforms media"| node_media_effects
node_media_effects -->|"applies lag"| node_lagging
node_media_effects -->|"applies saturation"| node_saturation
node_analyst -->|"optimizes spend"| node_optimizer
node_optimizer -->|"uses fitted model"| node_fit
node_analyst -->|"requests plots"| node_plots
node_plots -->|"reads fit results"| node_fit
node_plots -->|"visualizes effects"| node_result
node_optimizer -->|"returns allocation"| node_result
node_analyst -.->|"simulates data"| node_utilities

click node_prep "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/preprocessing.py"
click node_media_effects "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/media_transforms.py"
click node_lagging "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/transformations/lagging.py"
click node_saturation "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/transformations/saturation.py"
click node_priors "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/priors.py"
click node_baseline "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/baseline/intercept.py"
click node_seasonality "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/time/seasonality.py"
click node_trend "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/time/trend.py"
click node_models "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/models.py"
click node_fit "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/lightweight_mmm.py"
click node_optimizer "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/optimize_media.py"
click node_plots "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/plot.py"
click node_utilities "https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_prep,node_fit,node_optimizer,node_utilities toneBlue
class node_media_effects,node_lagging,node_saturation,node_priors,node_baseline,node_seasonality,node_trend,node_models toneAmber
class node_plots,node_result toneMint
class node_analyst toneIndigo
```

## Components

### Analysis workflow

- [Scale and inspect](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/preprocessing.py): `lightweight_mmm/preprocessing.py`
- [Fit and predict](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/lightweight_mmm.py): `lightweight_mmm/lightweight_mmm.py`
- [Budget optimization](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/optimize_media.py): `lightweight_mmm/optimize_media.py`
- [Data utilities](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/utils.py): `lightweight_mmm/utils.py`

### Bayesian inference

- [Media transforms](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/media_transforms.py): `lightweight_mmm/media_transforms.py`
- [Lag and carryover](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/transformations/lagging.py): `lightweight_mmm/core/transformations/lagging.py`
- [Saturation](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/transformations/saturation.py): `lightweight_mmm/core/transformations/saturation.py`
- [Prior definitions](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/priors.py): `lightweight_mmm/core/priors.py`
- [Intercept](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/baseline/intercept.py): `lightweight_mmm/core/baseline/intercept.py`
- [Seasonality](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/time/seasonality.py): `lightweight_mmm/core/time/seasonality.py`
- [Trend](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/core/time/trend.py): `lightweight_mmm/core/time/trend.py`
- [MMM model forms](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/models.py): `lightweight_mmm/models.py`

### Analysis outputs

- [Model plots](https://github.com/google/lightweight_mmm/blob/main/lightweight_mmm/plot.py): `lightweight_mmm/plot.py`
- **Effect and budget insights**

### Other components

- **Analyst**

## Connections

- Analyst → Scale and inspect: prepares data
- Analyst → Fit and predict: fits model
- Scale and inspect → Fit and predict: scaled inputs
- Fit and predict → MMM model forms: runs inference
- MMM model forms → Prior definitions: uses priors
- MMM model forms → Intercept: models baseline
- MMM model forms → Seasonality: models cycles
- MMM model forms → Trend: models trend
- MMM model forms → Media transforms: transforms media
- Media transforms → Lag and carryover: applies lag
- Media transforms → Saturation: applies saturation
- Analyst → Budget optimization: optimizes spend
- Budget optimization → Fit and predict: uses fitted model
- Analyst → Model plots: requests plots
- Model plots → Fit and predict: reads fit results
- Model plots → Effect and budget insights: visualizes effects
- Budget optimization → Effect and budget insights: returns allocation
- Analyst → Data utilities: simulates data
