# auxin-io/agentic-marketing-agency architecture

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

- Interactive diagram: https://gitdiagram.com/auxin-io/agentic-marketing-agency
- Repository: https://github.com/auxin-io/agentic-marketing-agency

## Overview

Marketing Agency Demo is an agentic lead-prospecting system with a streamed web workflow and a separate MCP interface for invoking agents. The main workflow finds companies, researches and enriches them, scores and ranks leads, exports a CSV, and optionally emails it after policy checks and human approval. It also includes a free-form assistant and standalone generation and qualification workflows. The graph follows README-documented stages and SOURCE INDEX references; some UI-to-route and unsampled subsystem wiring is not shown, so those relationships are omitted.

Main entry points: [`src/mastra/workflows/integrated-lead-pipeline.ts`](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/integrated-lead-pipeline.ts) (Integrated pipeline), [`src/mastra/index.ts`](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/index.ts) (Mastra registry), [`src/mastra/agents/lead-research-agent.ts`](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/lead-research-agent.ts) (Research agent), [`src/mastra/tools/lead-generation-tool.ts`](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/lead-generation-tool.ts) (Lead generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_channels["User channels"]
  node_web["Web UI<br/>[page.tsx]"]
  node_stream_api["Streaming API<br/>[route.ts]"]
  node_approval_api["Approval API<br/>[route.ts]"]
  node_mcp["MCP server<br/>[mcp-server.ts]"]
end

subgraph group_workflow["Lead workflow"]
  node_registry["Mastra registry<br/>[index.ts]"]
  node_pipeline["Integrated pipeline"]
  node_schemas["Lead schemas<br/>[schemas.ts]"]
  node_generation_workflow["Generation workflow"]
  node_qualification_workflow["Qualification workflow"]
end

subgraph group_intelligence["Agents and tools"]
  node_generation["Lead generation"]
  node_research["Lead research"]
  node_research_agent["Research agent"]
  node_enrichment["Company enrichment"]
  node_scoring["Lead scoring<br/>[score-lead.ts]"]
  node_scoring_agent["Scoring agent"]
  node_csv["CSV export<br/>[csv-export-tool.ts]"]
  node_email["Email delivery<br/>[email-tool.ts]"]
  node_assistant["Simple assistant"]
  node_http["HTTP helpers<br/>[http.ts]"]
  node_model["Model configuration<br/>[model.ts]"]
end

subgraph group_controls["Security and delivery"]
  node_injection["Injection defense"]
  node_egress["Egress policy<br/>[egress-policy.ts]"]
  node_approval["Approval gate<br/>[approval.ts]"]
  node_events["Security events<br/>[events.ts]"]
end

node_user(("Prospecting user"))
node_exa["Exa search"]
node_smtp["SMTP service"]

node_user -->|"submits brief"| node_web
node_web -.->|"streams progress"| node_stream_api
node_stream_api -->|"uses registry"| node_registry
node_mcp -->|"uses registry"| node_registry
node_registry -->|"registers workflow"| node_pipeline
node_registry -->|"registers agent"| node_assistant
node_pipeline -->|"searches leads"| node_generation
node_generation -->|"searches companies"| node_exa
node_pipeline -->|"gets context"| node_research
node_research_agent -->|"uses tool"| node_research
node_pipeline -->|"classifies leads"| node_research_agent
node_pipeline -->|"scans context"| node_injection
node_pipeline -->|"enriches leads"| node_enrichment
node_research -->|"fetches sources"| node_http
node_enrichment -->|"fetches websites"| node_http
node_pipeline -->|"scores leads"| node_scoring
node_scoring -->|"requests score"| node_scoring_agent
node_pipeline -->|"exports results"| node_csv
node_pipeline -->|"sends report"| node_email
node_email -->|"delivers email"| node_smtp
node_pipeline -->|"checks recipient"| node_egress
node_pipeline -->|"requests approval"| node_approval
node_approval_api -->|"resolves decision"| node_approval
node_pipeline -->|"records controls"| node_events
node_generation_workflow -->|"runs search"| node_generation
node_qualification_workflow -->|"enriches leads"| node_enrichment
node_qualification_workflow -->|"scores leads"| node_scoring
node_pipeline -->|"builds summary"| node_schemas
node_research_agent -->|"uses model"| node_model
node_scoring_agent -->|"uses model"| node_model

click node_web "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/app/page.tsx"
click node_stream_api "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/app/api/run-pipeline-stream/route.ts"
click node_approval_api "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/app/api/approve/route.ts"
click node_mcp "https://github.com/auxin-io/agentic-marketing-agency/blob/main/mcp-server.ts"
click node_registry "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/index.ts"
click node_pipeline "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/integrated-lead-pipeline.ts"
click node_schemas "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/schemas.ts"
click node_generation_workflow "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/lead-generation-workflow.ts"
click node_qualification_workflow "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/lead-qualification-workflow.ts"
click node_generation "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/lead-generation-tool.ts"
click node_research "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/lead-research-tool.ts"
click node_research_agent "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/lead-research-agent.ts"
click node_enrichment "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/company-enrichment-tool.ts"
click node_scoring "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/score-lead.ts"
click node_scoring_agent "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/lead-scoring-agent.ts"
click node_csv "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/csv-export-tool.ts"
click node_email "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/email-tool.ts"
click node_assistant "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/simple-assistant-agent.ts"
click node_http "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/http.ts"
click node_injection "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/prompt-injection.ts"
click node_egress "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/egress-policy.ts"
click node_approval "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/approval.ts"
click node_events "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/events.ts"
click node_model "https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/model.ts"

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_web,node_stream_api,node_approval_api,node_mcp,node_user toneBlue
class node_registry,node_pipeline,node_schemas,node_generation_workflow,node_qualification_workflow toneAmber
class node_generation,node_research,node_research_agent,node_enrichment,node_scoring,node_scoring_agent,node_csv,node_email,node_assistant,node_http,node_model toneMint
class node_injection,node_egress,node_approval,node_events toneRose
class node_exa,node_smtp toneIndigo
```

## Components

### User channels

- [Web UI](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Streaming API](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/app/api/run-pipeline-stream/route.ts): `src/app/api/run-pipeline-stream/route.ts`
- [Approval API](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/app/api/approve/route.ts): `src/app/api/approve/route.ts`
- [MCP server](https://github.com/auxin-io/agentic-marketing-agency/blob/main/mcp-server.ts): `mcp-server.ts`

### Lead workflow

- [Mastra registry](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/index.ts): `src/mastra/index.ts`
- [Integrated pipeline](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/integrated-lead-pipeline.ts): `src/mastra/workflows/integrated-lead-pipeline.ts`
- [Lead schemas](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/schemas.ts): `src/mastra/workflows/schemas.ts`
- [Generation workflow](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/lead-generation-workflow.ts): `src/mastra/workflows/lead-generation-workflow.ts`
- [Qualification workflow](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/lead-qualification-workflow.ts): `src/mastra/workflows/lead-qualification-workflow.ts`

### Agents and tools

- [Lead generation](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/lead-generation-tool.ts): `src/mastra/tools/lead-generation-tool.ts`
- [Lead research](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/lead-research-tool.ts): `src/mastra/tools/lead-research-tool.ts`
- [Research agent](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/lead-research-agent.ts): `src/mastra/agents/lead-research-agent.ts`
- [Company enrichment](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/company-enrichment-tool.ts): `src/mastra/tools/company-enrichment-tool.ts`
- [Lead scoring](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/workflows/score-lead.ts): `src/mastra/workflows/score-lead.ts`
- [Scoring agent](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/lead-scoring-agent.ts): `src/mastra/agents/lead-scoring-agent.ts`
- [CSV export](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/csv-export-tool.ts): `src/mastra/tools/csv-export-tool.ts`
- [Email delivery](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/email-tool.ts): `src/mastra/tools/email-tool.ts`
- [Simple assistant](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/simple-assistant-agent.ts): `src/mastra/agents/simple-assistant-agent.ts`
- [HTTP helpers](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/tools/http.ts): `src/mastra/tools/http.ts`
- [Model configuration](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/agents/model.ts): `src/mastra/agents/model.ts`

### Security and delivery

- [Injection defense](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/prompt-injection.ts): `src/mastra/security/prompt-injection.ts`
- [Egress policy](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/egress-policy.ts): `src/mastra/security/egress-policy.ts`
- [Approval gate](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/approval.ts): `src/mastra/security/approval.ts`
- [Security events](https://github.com/auxin-io/agentic-marketing-agency/blob/main/src/mastra/security/events.ts): `src/mastra/security/events.ts`

### Other components

- **Prospecting user**
- **Exa search**
- **SMTP service**

## Connections

- Prospecting user → Web UI: submits brief (evidence: `README.md`)
- Web UI → Streaming API: streams progress
- Streaming API → Mastra registry: uses registry (evidence: `src/app/api/run-pipeline-stream/route.ts`)
- MCP server → Mastra registry: uses registry (evidence: `mcp-server.ts`)
- Mastra registry → Integrated pipeline: registers workflow (evidence: `src/mastra/index.ts`)
- Mastra registry → Simple assistant: registers agent (evidence: `src/mastra/index.ts`)
- Integrated pipeline → Lead generation: searches leads (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Lead generation → Exa search: searches companies (evidence: `README.md`)
- Integrated pipeline → Lead research: gets context (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Research agent → Lead research: uses tool (evidence: `src/mastra/agents/lead-research-agent.ts`)
- Integrated pipeline → Research agent: classifies leads (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Integrated pipeline → Injection defense: scans context (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Integrated pipeline → Company enrichment: enriches leads (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Lead research → HTTP helpers: fetches sources (evidence: `src/mastra/tools/lead-research-tool.ts`)
- Company enrichment → HTTP helpers: fetches websites (evidence: `src/mastra/tools/company-enrichment-tool.ts`)
- Integrated pipeline → Lead scoring: scores leads (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Lead scoring → Scoring agent: requests score (evidence: `src/mastra/workflows/score-lead.ts`)
- Integrated pipeline → CSV export: exports results (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Integrated pipeline → Email delivery: sends report (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Email delivery → SMTP service: delivers email (evidence: `README.md`)
- Integrated pipeline → Egress policy: checks recipient (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Integrated pipeline → Approval gate: requests approval (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Approval API → Approval gate: resolves decision (evidence: `src/app/api/approve/route.ts`)
- Integrated pipeline → Security events: records controls (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Generation workflow → Lead generation: runs search (evidence: `src/mastra/workflows/lead-generation-workflow.ts`)
- Qualification workflow → Company enrichment: enriches leads (evidence: `src/mastra/workflows/lead-qualification-workflow.ts`)
- Qualification workflow → Lead scoring: scores leads (evidence: `src/mastra/workflows/lead-qualification-workflow.ts`)
- Integrated pipeline → Lead schemas: builds summary (evidence: `src/mastra/workflows/integrated-lead-pipeline.ts`)
- Research agent → Model configuration: uses model (evidence: `src/mastra/agents/lead-research-agent.ts`)
- Scoring agent → Model configuration: uses model (evidence: `src/mastra/agents/lead-scoring-agent.ts`)
