# adtechthai/adtop-agent-template-suebphatt architecture

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

- Interactive diagram: https://gitdiagram.com/adtechthai/adtop-agent-template-suebphatt
- Repository: https://github.com/adtechthai/adtop-agent-template-suebphatt

## Overview

This repository is a client-agnostic Meta ads optimization and campaign-launch engine. Its main daily path pulls ad insights, scores performance against configured KPIs, and takes kill actions; separate budget-allocation paths enforce guarded writes and rollback. The Temporal runtime runs recurring measurement and scale/cut policy workflows, while launch and naming modules build campaigns and maintain canonical object names. The README documents additional warehouse, reporting, and notification capabilities whose implementation is not sampled here; those branches are included without inferring internal call chains.

Main entry points: [`engine/strict_allocator.py`](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_allocator.py) (Strict allocator), [`engine/temporal/activities.py`](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/activities.py) (Policy activities), [`engine/pull_v2.py`](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/pull_v2.py) (Insights pull), [`engine/strict_runtime.py`](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_runtime.py) (Write execution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_optimization["Daily optimization"]
  node_pull["Insights pull<br/>[pull_v2.py]"]
  node_score["KPI scoring<br/>[score.py]"]
  node_act["Kill actions<br/>[act.py]"]
end

subgraph group_allocation["Budget safety"]
  node_allocator["Strict allocator"]
  node_portfolio["Portfolio controls"]
  node_runtime["Write execution<br/>[strict_runtime.py]"]
  node_ledger["Action ledger<br/>[action_ledger.py]"]
end

subgraph group_temporal["Temporal policy"]
  node_temporal_worker["Temporal worker<br/>[worker.py]"]
  node_workflows["Policy workflows<br/>[workflows.py]"]
  node_activities["Policy activities<br/>[activities.py]"]
  node_policy["Scale-cut policy<br/>[policy.py]"]
  node_measure["Campaign measurement<br/>[measure.py]"]
  node_writer["Policy writer<br/>[writer.py]"]
  node_purchase_metrics["Purchase metrics"]
end

subgraph group_launch["Launch and naming"]
  node_launch_builder["Campaign builders<br/>[create_funnel.py]"]
  node_leadgen_builder["Leadgen builder<br/>[create_leadgen.py]"]
  node_creative_upload["Creative upload<br/>[upload_creative.py]"]
  node_placements["Placement policy<br/>[placements.py]"]
  node_naming["Naming contract<br/>[naming_contract.py]"]
  node_naming_inventory["Naming inventory"]
  node_naming_migration["Naming migration"]
end

subgraph group_dataops["Data and operations"]
  node_warehouse_reader["Warehouse evidence"]
  node_warehouse[("Supabase warehouse")]
  node_sync["Warehouse sync<br/>[supabase_sync.py]"]
  node_reports["Daily reports<br/>[publish_report.py]"]
  node_lark["Lark notifications<br/>[lark_notify.py]"]
end

node_operator(("Operator or scheduler"))
node_meta["Meta Marketing API"]

node_operator -->|"starts pull"| node_pull
node_pull -->|"reads insights"| node_meta
node_pull -->|"provides data"| node_score
node_score -->|"provides scores"| node_act
node_act -->|"applies kills"| node_meta
node_operator -->|"requests allocation"| node_allocator
node_allocator -->|"checks portfolio"| node_portfolio
node_allocator -->|"reads evidence"| node_warehouse_reader
node_allocator -->|"dispatches writes"| node_runtime
node_runtime -->|"records actions"| node_ledger
node_runtime -->|"writes and verifies"| node_meta
node_warehouse -->|"supplies evidence"| node_warehouse_reader
node_temporal_worker -->|"registers workflows"| node_workflows
node_temporal_worker -->|"registers activities"| node_activities
node_workflows -->|"executes activities"| node_activities
node_workflows -->|"uses policy"| node_policy
node_activities -->|"measures campaigns"| node_measure
node_activities -->|"requests writes"| node_writer
node_measure -->|"normalizes purchases"| node_purchase_metrics
node_writer -->|"appends actions"| node_ledger
node_writer -->|"writes and reads back"| node_meta
node_operator -->|"requests launch"| node_launch_builder
node_operator -->|"requests launch"| node_leadgen_builder
node_operator -->|"requests upload"| node_creative_upload
node_leadgen_builder -->|"applies placements"| node_placements
node_operator -->|"requests inventory"| node_naming_inventory
node_naming_inventory -->|"validates names"| node_naming
node_operator -->|"requests migration"| node_naming_migration
node_naming_migration -->|"uses contract"| node_naming
node_sync -->|"syncs data"| node_warehouse
node_reports -->|"publishes digest"| node_operator
node_lark -->|"sends notifications"| node_operator

click node_pull "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/pull_v2.py"
click node_score "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/score.py"
click node_act "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/act.py"
click node_allocator "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_allocator.py"
click node_portfolio "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_portfolio.py"
click node_runtime "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_runtime.py"
click node_ledger "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/action_ledger.py"
click node_warehouse_reader "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/warehouse_reader.py"
click node_temporal_worker "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/worker.py"
click node_workflows "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/workflows.py"
click node_activities "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/activities.py"
click node_policy "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/policy.py"
click node_measure "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/measure.py"
click node_writer "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/writer.py"
click node_purchase_metrics "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/purchase_metrics.py"
click node_launch_builder "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/create_funnel.py"
click node_leadgen_builder "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/create_leadgen.py"
click node_creative_upload "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/upload_creative.py"
click node_placements "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/placements.py"
click node_naming "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/naming_contract.py"
click node_naming_inventory "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/naming_inventory.py"
click node_naming_migration "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/naming_migration.py"
click node_sync "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/scripts/supabase_sync.py"
click node_reports "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/scripts/publish_report.py"
click node_lark "https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/scripts/lark_notify.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_pull,node_score,node_act toneBlue
class node_allocator,node_portfolio,node_runtime,node_ledger toneAmber
class node_temporal_worker,node_workflows,node_activities,node_policy,node_measure,node_writer,node_purchase_metrics,node_meta toneMint
class node_launch_builder,node_leadgen_builder,node_creative_upload,node_placements,node_naming,node_naming_inventory,node_naming_migration,node_operator toneRose
class node_warehouse_reader,node_warehouse,node_sync,node_reports,node_lark toneIndigo
```

## Components

### Daily optimization

- [Insights pull](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/pull_v2.py): `engine/pull_v2.py`
- [KPI scoring](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/score.py): `engine/score.py`
- [Kill actions](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/act.py): `engine/act.py`

### Budget safety

- [Strict allocator](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_allocator.py): `engine/strict_allocator.py`
- [Portfolio controls](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_portfolio.py): `engine/strict_portfolio.py`
- [Write execution](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/strict_runtime.py): `engine/strict_runtime.py`
- [Action ledger](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/action_ledger.py): `engine/action_ledger.py`

### Temporal policy

- [Temporal worker](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/worker.py): `engine/temporal/worker.py`
- [Policy workflows](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/workflows.py): `engine/temporal/workflows.py`
- [Policy activities](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/activities.py): `engine/temporal/activities.py`
- [Scale-cut policy](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/policy.py): `engine/temporal/policy.py`
- [Campaign measurement](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/measure.py): `engine/temporal/measure.py`
- [Policy writer](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/temporal/writer.py): `engine/temporal/writer.py`
- [Purchase metrics](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/purchase_metrics.py): `engine/purchase_metrics.py`

### Launch and naming

- [Campaign builders](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/create_funnel.py): `engine/create_funnel.py`
- [Leadgen builder](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/create_leadgen.py): `engine/create_leadgen.py`
- [Creative upload](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/upload_creative.py): `engine/upload_creative.py`
- [Placement policy](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/placements.py): `engine/placements.py`
- [Naming contract](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/naming_contract.py): `engine/naming_contract.py`
- [Naming inventory](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/naming_inventory.py): `engine/naming_inventory.py`
- [Naming migration](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/naming_migration.py): `engine/naming_migration.py`

### Data and operations

- [Warehouse evidence](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/engine/warehouse_reader.py): `engine/warehouse_reader.py`
- **Supabase warehouse**
- [Warehouse sync](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/scripts/supabase_sync.py): `scripts/supabase_sync.py`
- [Daily reports](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/scripts/publish_report.py): `scripts/publish_report.py`
- [Lark notifications](https://github.com/adtechthai/adtop-agent-template-suebphatt/blob/main/scripts/lark_notify.py): `scripts/lark_notify.py`

### Other components

- **Operator or scheduler**
- **Meta Marketing API**

## Connections

- Operator or scheduler → Insights pull: starts pull
- Insights pull → Meta Marketing API: reads insights
- Insights pull → KPI scoring: provides data
- KPI scoring → Kill actions: provides scores
- Kill actions → Meta Marketing API: applies kills
- Operator or scheduler → Strict allocator: requests allocation
- Strict allocator → Portfolio controls: checks portfolio (evidence: `engine/strict_allocator.py`)
- Strict allocator → Warehouse evidence: reads evidence (evidence: `engine/strict_allocator.py`)
- Strict allocator → Write execution: dispatches writes (evidence: `engine/strict_allocator.py`)
- Write execution → Action ledger: records actions (evidence: `engine/strict_runtime.py`)
- Write execution → Meta Marketing API: writes and verifies
- Supabase warehouse → Warehouse evidence: supplies evidence
- Temporal worker → Policy workflows: registers workflows (evidence: `engine/temporal/worker.py`)
- Temporal worker → Policy activities: registers activities (evidence: `engine/temporal/worker.py`)
- Policy workflows → Policy activities: executes activities (evidence: `engine/temporal/workflows.py`)
- Policy workflows → Scale-cut policy: uses policy (evidence: `engine/temporal/workflows.py`)
- Policy activities → Campaign measurement: measures campaigns (evidence: `engine/temporal/activities.py`)
- Policy activities → Policy writer: requests writes (evidence: `engine/temporal/activities.py`)
- Campaign measurement → Purchase metrics: normalizes purchases (evidence: `engine/temporal/measure.py`)
- Policy writer → Action ledger: appends actions (evidence: `engine/temporal/writer.py`)
- Policy writer → Meta Marketing API: writes and reads back (evidence: `engine/temporal/writer.py`)
- Operator or scheduler → Campaign builders: requests launch
- Operator or scheduler → Leadgen builder: requests launch
- Operator or scheduler → Creative upload: requests upload
- Leadgen builder → Placement policy: applies placements (evidence: `engine/create_leadgen.py`)
- Operator or scheduler → Naming inventory: requests inventory
- Naming inventory → Naming contract: validates names (evidence: `engine/naming_inventory.py`)
- Operator or scheduler → Naming migration: requests migration
- Naming migration → Naming contract: uses contract (evidence: `engine/naming_migration.py`)
- Warehouse sync → Supabase warehouse: syncs data
- Daily reports → Operator or scheduler: publishes digest
- Lark notifications → Operator or scheduler: sends notifications
