# eneelkant/marketing-database-agent architecture

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

- Interactive diagram: https://gitdiagram.com/eneelkant/marketing-database-agent
- Repository: https://github.com/eneelkant/marketing-database-agent

## Overview

Marketing Database Agent lets a Gemini Enterprise user request a prospect list, then returns a CSV download rather than displaying prospect rows in chat. The primary flow queries BigQuery and exports to Cloud Storage; a bucket-triggered helper renames the file, looks up export-job details, logs usage, and requests an admin email. A scheduled BigQuery procedure refreshes the clean prospect view. The repository also contains an optional MCP export server, documented as blocked by organization policy. Relationships for unsampled agent, SQL, and Apps Script behavior follow README documentation; implementation detail is limited to the supplied excerpts.

Main entry points: [`csv-helper/index.js`](https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js) (CSV event handler), [`agent/agent_instructions.md`](https://github.com/eneelkant/marketing-database-agent/blob/main/agent/agent_instructions.md) (Gemini agent), [`mcp-server-optional/index.js`](https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js) (MCP HTTP endpoint), [`bigquery/setup_auto_view.sh`](https://github.com/eneelkant/marketing-database-agent/blob/main/bigquery/setup_auto_view.sh) (Prospect view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prospecting["Prospect Generation"]
  node_agent["Gemini agent"]
  node_title_rules["Title matching"]
  node_bq_connector["BigQuery connector"]
  node_export_bucket[("Export bucket")]
end

subgraph group_data["Data Preparation"]
  node_prospect_data[("Prospect view<br/>[setup_auto_view.sh]")]
  node_scheduled_query["Hourly refresh<br/>[setup_auto_view.sh]"]
end

subgraph group_audit["Audit and Email"]
  node_csv_trigger["CSV event handler<br/>[index.js]"]
  node_rename_file["Download naming<br/>[index.js]"]
  node_job_lookup["Export job lookup<br/>[index.js]"]
  node_row_count["Delivered row count<br/>[index.js]"]
  node_usage_log[("Generation log")]
  node_monthly_totals["Monthly totals<br/>[index.js]"]
  node_mail_sender["Email sender<br/>[Code.gs]"]
end

subgraph group_optional["Optional MCP Export"]
  node_mcp_endpoint["MCP HTTP endpoint<br/>[index.js]"]
  node_mcp_search["Prospect search<br/>[index.js]"]
  node_mcp_csv["CSV and signed link<br/>[index.js]"]
  node_mcp_storage[("Cloud Storage")]
end

node_user(("Gemini user"))
node_admins(("Admin recipients"))
node_mcp_client(("MCP client"))

node_user -->|"requests list"| node_agent
node_agent -->|"queries and exports"| node_bq_connector
node_agent -->|"applies matching"| node_title_rules
node_bq_connector -->|"queries"| node_prospect_data
node_bq_connector -->|"exports CSV"| node_export_bucket
node_agent -->|"returns download link"| node_user
node_scheduled_query -->|"refreshes view"| node_prospect_data
node_export_bucket -->|"triggers on new file"| node_csv_trigger
node_csv_trigger -->|"sets download name"| node_rename_file
node_csv_trigger -->|"looks up export"| node_job_lookup
node_csv_trigger -->|"counts rows"| node_row_count
node_csv_trigger -->|"inserts generation"| node_usage_log
node_csv_trigger -->|"queries totals"| node_monthly_totals
node_csv_trigger -->|"posts email data"| node_mail_sender
node_mail_sender -->|"emails"| node_admins
node_mcp_client -->|"calls tool"| node_mcp_endpoint
node_mcp_endpoint -->|"dispatches search"| node_mcp_search
node_mcp_search -.->|"queries prospects"| node_prospect_data
node_mcp_endpoint -->|"builds CSV"| node_mcp_csv
node_mcp_csv -->|"uploads and signs"| node_mcp_storage

click node_agent "https://github.com/eneelkant/marketing-database-agent/blob/main/agent/agent_instructions.md"
click node_title_rules "https://github.com/eneelkant/marketing-database-agent/blob/main/agent/agent_instructions.md"
click node_prospect_data "https://github.com/eneelkant/marketing-database-agent/blob/main/bigquery/setup_auto_view.sh"
click node_scheduled_query "https://github.com/eneelkant/marketing-database-agent/blob/main/bigquery/setup_auto_view.sh"
click node_csv_trigger "https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js"
click node_rename_file "https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js"
click node_job_lookup "https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js"
click node_row_count "https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js"
click node_monthly_totals "https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js"
click node_mail_sender "https://github.com/eneelkant/marketing-database-agent/blob/main/apps-script/Code.gs"
click node_mcp_endpoint "https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js"
click node_mcp_search "https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js"
click node_mcp_csv "https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js"

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_agent,node_title_rules,node_bq_connector,node_export_bucket,node_user,node_mcp_client toneBlue
class node_prospect_data,node_scheduled_query toneAmber
class node_csv_trigger,node_rename_file,node_job_lookup,node_row_count,node_usage_log,node_monthly_totals,node_mail_sender toneMint
class node_mcp_endpoint,node_mcp_search,node_mcp_csv,node_mcp_storage toneRose
class node_admins toneIndigo
```

## Components

### Prospect Generation

- [Gemini agent](https://github.com/eneelkant/marketing-database-agent/blob/main/agent/agent_instructions.md): `agent/agent_instructions.md`
- [Title matching](https://github.com/eneelkant/marketing-database-agent/blob/main/agent/agent_instructions.md): `agent/agent_instructions.md`
- **BigQuery connector**
- **Export bucket**

### Data Preparation

- [Prospect view](https://github.com/eneelkant/marketing-database-agent/blob/main/bigquery/setup_auto_view.sh): `bigquery/setup_auto_view.sh`
- [Hourly refresh](https://github.com/eneelkant/marketing-database-agent/blob/main/bigquery/setup_auto_view.sh): `bigquery/setup_auto_view.sh`

### Audit and Email

- [CSV event handler](https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js): `csv-helper/index.js`
- [Download naming](https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js): `csv-helper/index.js`
- [Export job lookup](https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js): `csv-helper/index.js`
- [Delivered row count](https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js): `csv-helper/index.js`
- **Generation log**
- [Monthly totals](https://github.com/eneelkant/marketing-database-agent/blob/main/csv-helper/index.js): `csv-helper/index.js`
- [Email sender](https://github.com/eneelkant/marketing-database-agent/blob/main/apps-script/Code.gs): `apps-script/Code.gs`

### Optional MCP Export

- [MCP HTTP endpoint](https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js): `mcp-server-optional/index.js`
- [Prospect search](https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js): `mcp-server-optional/index.js`
- [CSV and signed link](https://github.com/eneelkant/marketing-database-agent/blob/main/mcp-server-optional/index.js): `mcp-server-optional/index.js`
- **Cloud Storage**

### Other components

- **Gemini user**
- **Admin recipients**
- **MCP client**

## Connections

- Gemini user → Gemini agent: requests list (evidence: `README.md`)
- Gemini agent → BigQuery connector: queries and exports (evidence: `README.md`)
- Gemini agent → Title matching: applies matching (evidence: `README.md`)
- BigQuery connector → Prospect view: queries (evidence: `README.md`)
- BigQuery connector → Export bucket: exports CSV (evidence: `README.md`)
- Gemini agent → Gemini user: returns download link (evidence: `README.md`)
- Hourly refresh → Prospect view: refreshes view (evidence: `README.md`)
- Export bucket → CSV event handler: triggers on new file (evidence: `README.md`)
- CSV event handler → Download naming: sets download name (evidence: `csv-helper/index.js`)
- CSV event handler → Export job lookup: looks up export (evidence: `csv-helper/index.js`)
- CSV event handler → Delivered row count: counts rows (evidence: `csv-helper/index.js`)
- CSV event handler → Generation log: inserts generation (evidence: `csv-helper/index.js`)
- CSV event handler → Monthly totals: queries totals (evidence: `csv-helper/index.js`)
- CSV event handler → Email sender: posts email data (evidence: `csv-helper/index.js`)
- Email sender → Admin recipients: emails (evidence: `README.md`)
- MCP client → MCP HTTP endpoint: calls tool (evidence: `mcp-server-optional/index.js`)
- MCP HTTP endpoint → Prospect search: dispatches search (evidence: `mcp-server-optional/index.js`)
- Prospect search → Prospect view: queries prospects
- MCP HTTP endpoint → CSV and signed link: builds CSV (evidence: `mcp-server-optional/index.js`)
- CSV and signed link → Cloud Storage: uploads and signs (evidence: `mcp-server-optional/index.js`)
