# narender-rk10/marketing-ai-studio architecture

> Architecture diagram of the GitHub repository narender-rk10/marketing-ai-studio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/narender-rk10/marketing-ai-studio
- Repository: https://github.com/narender-rk10/marketing-ai-studio

## Overview

1. **Overall shape**
   - This is a **monorepo** with a **React/Vite frontend** and a **FastAPI/Python backend**.
   - The backend is the system of record and orchestration layer; the frontend is primarily a visual control surface for managing campaigns, agents, assets, and workspace state.

2. **Frontend boundary**
   - The frontend lives under `frontend/src` and is organized around **workspace/canvas UX**, **agent configuration/forms**, **asset and prompt management**, and **analytics views**.
   - State is managed with **Zustand**, API calls go through `frontend/src/services/api.ts`, and realtime updates use `useWebSocket`.
   - The UI is built around many **agent-specific output components** and form definitions, which means the frontend is tightly coupled to the backend’s agent catalog and output schemas.

3. **Backend entrypoints and API surface**
   - `backend/app/main.py` is the application entrypoint.
   - The backend is split into routers for **auth**, **campaigns**, **workspaces**, **analytics**, **agents**, and **websocket** handling.
   - `backend/app/agents/api_router.py` and `v3_registry.py` suggest a dedicated agent API layer that dispatches requests into the agent system rather than embedding logic directly in generic CRUD endpoints.

4. **Core orchestration layer**
   - The heart of the system is the **agent orchestration stack** in `backend/app/agents`.
   - Key coordination pieces include:
     - `executor.py` for running agent tasks,
     - `registry.py` / `v3_registry.py` for agent discovery and routing,
     - `base.py` for shared agent behavior,
     - `control/` for intent detection, requirement discovery, and conversation state,
     - `fallback_forms.py` and `tools/dynamic_form.py` for structured input handling.
   - This layer is what turns a user request into a specific specialized agent invocation with the right prompt, tools, and output schema.

5. **Specialized agent domains**
   - The repository’s main functional breadth is in the large set of agent domains:
     - **Brand**, **creative**, **content**, **social**, **SEO**, **video**, **audio**, **ads**, **growth**, **image**, **visual**, and **adaptation**.
   - Each domain contains multiple focused agents, and the naming indicates a pattern: one agent per marketing task or channel-specific output.
   - This makes the architecture **catalog-driven**: the system is not one generic assistant, but a large collection of constrained, task-specific agent workflows.

6. **Prompt and tool architecture**
   - Agent behavior is heavily prompt-driven through `backend/app/prompts/agents/*.yaml` and `backend/app/prompts/tools/*.yaml`.
   - The tools layer in `backend/app/tools` and `backend/app/agents/tools` provides reusable capabilities such as **brand tools**, **creative tools**, **feedback tools**, **media tools**, and **scraping tools**.
   - This is an important boundary: prompts define the task logic and output contract, while tools provide the agent’s actionable capabilities.

7. **Model/provider integration**
   - External AI/model access is abstracted in `backend/app/providers`.
   - The provider set includes **Gemini**, **Veo**, **GCS**, and specialized adapters like **nano_banana**.
   - `backend/app/core/llm.py` and the config files indicate model selection is environment-driven, with separate models for text, image, video, edge/experimental use cases.
   - Architecturally, this is a **multi-model backend** where different agent classes route to different model capabilities depending on the task.

8. **Persistence and domain data**
   - MongoDB is the primary application database, as reflected by the README and the presence of model/repository layers.
   - `backend/app/models` defines the domain objects: **users, workspaces, campaigns, conversations, messages, assets, versions, prompt library, analytics logs, agent logs**, and related workspace/context records.
   - `backend/app/db/repositories.py` and `backend/app/database.py` indicate a repository-style persistence boundary between API/service logic and storage.
   - The data model suggests the platform keeps both **operational state** (workspace/campaign/user) and **observability/history** (logs, versions, analytics).

9. **Workspace, campaign, and asset flows**
   - `backend/app/workspaces` and `backend/app/campaigns` are separate product areas.
   - Workspaces appear to hold the “canvas” or operating environment: documents, prompts, scraper inputs, and assets.
   - Campaign services coordinate marketing deliverables, while the workspace/asset layers manage the artifacts produced by agents.
   - Google Cloud Storage (`providers/gcs.py`) is used for durable media storage, which is especially important for generated images, mockups, and videos.

10. **Realtime interaction and collaboration**
   - `backend/app/websocket` provides a realtime channel, likely used for streaming agent progress, workspace updates, and live UI synchronization.
   - `backend/app/core/context_vars.py`, `middleware.py`, and `session_manager.py` imply request/session scoping and conversational context tracking across agent runs.
   - This supports the product’s interactive feel: users can launch agent tasks and see results or partial progress without waiting for a purely synchronous request/response cycle.

11. **Analytics and feedback loop**
   - `backend/app/analytics` and `services/analytics.py` capture usage and performance data.
   - `backend/app/agents/feedback` includes optimizer, quality suggestion, and version management, which indicates a built-in improvement loop around generated outputs.
   - The architecture therefore includes not just generation, but **measurement and refinement** of agent outputs over time.

12. **Supporting services**
   - `backend/app/services` contains the operational glue:
     - `campaign_manager` and `context_manager` for orchestration,
     - `kb_processor` for knowledge base/document processing,
     - `scraper` for external content ingestion,
     - `image_generator`, `video_generator`, and `audio_generator` for media pipeline execution,
     - `prompt_utils` and `session_manager` for prompt/session handling.
   - These services sit between the API/router layer and the agents/providers, giving the system its domain-specific orchestration.

13. **Auth and security boundary**
   - `backend/app/auth` plus `backend/app/core/security.py` and `dependencies.py` define the authentication and authorization layer.
   - This protects workspace, campaign, and generation endpoints, and likely scopes data by user/workspace.
   - In an architecture diagram, auth should be shown as a cross-cutting gate in front of the product API, not as a separate subsystem.

14. **Deployment/runtime**
   - The project is containerized with Docker, including a root `Dockerfile`, backend Dockerfile, frontend Dockerfile, and `docker-compose.yml`.
   - The README indicates deployment on **Python 3.12**, **FastAPI**, **React 18**, and Google Cloud services.
   - The external infrastructure dependencies that materially affect architecture are **MongoDB**, **Google Cloud Storage**, and the **Google AI model APIs**.

15. **How to draw the main data flow**
   - A useful diagram would show:
     - **Frontend UI** → **FastAPI routers** → **agent orchestration / service layer** → **provider APIs and tools** → **MongoDB / GCS**
     - with **WebSocket** returning live status and generated results back to the UI.
   - The key architectural idea is that the system is a **marketing workflow platform** built around a **registry of specialized AI agents**, not a single chat interface.

Main entry points: [`frontend/src/App.tsx`](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/App.tsx) (App shell), [`backend/app/main.py`](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/main.py) (API app), [`backend/app/agents/executor.py`](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/executor.py) (Orchestrator), [`backend/app/agents/api_router.py`](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/api_router.py) (Agent API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>React/Vite<br/>[App.tsx]"]
  node_frontend_canvas["Canvas UX<br/>workspace UI<br/>[CanvasPanel.tsx]"]
  node_frontend_forms["Agent forms<br/>input UI<br/>[AgentForm.tsx]"]
  node_frontend_outputs["Agent outputs<br/>renderers<br/>[GenericOutput.tsx]"]
  node_frontend_state["App state<br/>Zustand store<br/>[appStore.ts]"]
  node_frontend_api["API client<br/>HTTP client<br/>[api.ts]"]
  node_frontend_ws["Realtime hook<br/>WebSocket hook<br/>[useWebSocket.ts]"]
end

subgraph group_backend["Backend"]
  node_backend_main["API app<br/>FastAPI entrypoint<br/>[main.py]"]
  node_backend_auth["Auth<br/>security layer<br/>[router.py]"]
  node_backend_products["Product APIs<br/>routers<br/>[router.py]"]
  node_backend_ws["WebSocket<br/>realtime channel<br/>[handlers.py]"]
  node_backend_agents_api["Agent API<br/>dispatch layer<br/>[api_router.py]"]
  node_backend_orchestrator["Orchestrator<br/>agent runtime<br/>[executor.py]"]
  node_backend_registry["Agent registry<br/>catalog<br/>[v3_registry.py]"]
  node_backend_domains["Agent domains<br/>specialized agents<br/>[brand_identity.py]"]
  node_backend_prompts_tools["Prompts & tools<br/>prompt/tool layer"]
  node_backend_services["Services"]
  node_backend_data["Data layer<br/>models/repositories<br/>[repositories.py]"]
end

subgraph group_external["External"]
  node_external_llm["Model APIs<br/>LLM/providers<br/>[gemini.py]"]
  node_external_storage["Storage<br/>GCS<br/>[gcs.py]"]
  node_external_db[("MongoDB<br/>database<br/>[database.py]")]
end

node_frontend_app -->|"renders"| node_frontend_canvas
node_frontend_app -->|"uses"| node_frontend_forms
node_frontend_app -->|"shows"| node_frontend_outputs
node_frontend_app -->|"reads/writes"| node_frontend_state
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_app -->|"subscribes"| node_frontend_ws
node_frontend_api -->|"HTTP"| node_backend_main
node_frontend_ws -->|"WS"| node_backend_ws
node_backend_main -->|"protects"| node_backend_auth
node_backend_main -->|"mounts"| node_backend_products
node_backend_main -->|"mounts"| node_backend_agents_api
node_backend_main -->|"mounts"| node_backend_ws
node_backend_agents_api -->|"dispatches to"| node_backend_registry
node_backend_agents_api -->|"executes via"| node_backend_orchestrator
node_backend_orchestrator -->|"coordinates"| node_backend_services
node_backend_orchestrator -->|"loads"| node_backend_prompts_tools
node_backend_registry -->|"indexes"| node_backend_domains
node_backend_domains -->|"invokes"| node_external_llm
node_backend_services -->|"stores media"| node_external_storage
node_backend_services -->|"persists"| node_backend_data
node_backend_data -->|"writes/reads"| node_external_db
node_backend_products -->|"loads"| node_backend_data
node_backend_ws -->|"streams"| node_backend_orchestrator

click node_frontend_app "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/App.tsx"
click node_frontend_canvas "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/components/ReactFlow/CanvasPanel.tsx"
click node_frontend_forms "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/components/Core/AgentForm.tsx"
click node_frontend_outputs "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/components/Core/agents/GenericOutput.tsx"
click node_frontend_state "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/store/appStore.ts"
click node_frontend_api "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/services/api.ts"
click node_frontend_ws "https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/hooks/useWebSocket.ts"
click node_backend_main "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/main.py"
click node_backend_auth "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/auth/router.py"
click node_backend_products "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/workspaces/router.py"
click node_backend_ws "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/websocket/handlers.py"
click node_backend_agents_api "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/api_router.py"
click node_backend_orchestrator "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/executor.py"
click node_backend_registry "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/v3_registry.py"
click node_backend_domains "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/brand/brand_identity.py"
click node_backend_prompts_tools "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/prompts/agents/brand_identity.yaml"
click node_backend_services "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/services/campaign_manager.py"
click node_backend_data "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/db/repositories.py"
click node_external_llm "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/providers/gemini.py"
click node_external_storage "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/providers/gcs.py"
click node_external_db "https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/core/database.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_frontend_app,node_frontend_canvas,node_frontend_forms,node_frontend_outputs,node_frontend_state,node_frontend_api,node_frontend_ws toneBlue
class node_backend_main,node_backend_auth,node_backend_products,node_backend_ws,node_backend_agents_api,node_backend_orchestrator,node_backend_registry,node_backend_domains,node_backend_prompts_tools,node_backend_services,node_backend_data toneAmber
class node_external_llm,node_external_storage,node_external_db toneMint
```

## Components

### Frontend

React/Vite control surface

- [App shell](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/App.tsx): React/Vite · Top-level UI composition and route switching · `frontend/src/App.tsx`
- [Canvas UX](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/components/ReactFlow/CanvasPanel.tsx): workspace UI · Workspace, canvas, and panel interactions · `frontend/src/components/ReactFlow/CanvasPanel.tsx`
- [Agent forms](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/components/Core/AgentForm.tsx): input UI · Shared forms and prompt selection for agent runs · `frontend/src/components/Core/AgentForm.tsx`
- [Agent outputs](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/components/Core/agents/GenericOutput.tsx): renderers · Agent-specific output views and result formatting · `frontend/src/components/Core/agents/GenericOutput.tsx`
- [App state](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/store/appStore.ts): Zustand store · Client-side workspace, agent, and UI state · `frontend/src/store/appStore.ts`
- [API client](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/services/api.ts): HTTP client · Frontend service layer for backend requests · `frontend/src/services/api.ts`
- [Realtime hook](https://github.com/narender-rk10/marketing-ai-studio/blob/main/frontend/src/hooks/useWebSocket.ts): WebSocket hook · Streams live task progress and workspace updates · `frontend/src/hooks/useWebSocket.ts`

### Backend

FastAPI orchestration layer

- [API app](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/main.py): FastAPI entrypoint · Application bootstrap and router wiring · `backend/app/main.py`
- [Auth](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/auth/router.py): security layer · Authentication and authorization boundary · `backend/app/auth/router.py`
- [Product APIs](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/workspaces/router.py): routers · Campaign and workspace API surface · `backend/app/workspaces/router.py`
- [WebSocket](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/websocket/handlers.py): realtime channel · Streaming and live session handlers · `backend/app/websocket/handlers.py`
- [Agent API](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/api_router.py): dispatch layer · Routes requests into the specialized agent system · `backend/app/agents/api_router.py`
- [Orchestrator](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/executor.py): agent runtime · Executes agent tasks and manages conversation state · `backend/app/agents/executor.py`
- [Agent registry](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/v3_registry.py): catalog · Agent discovery, routing, and versioned registration · `backend/app/agents/v3_registry.py`
- [Agent domains](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/agents/brand/brand_identity.py): specialized agents · Brand, content, creative, social, SEO, video, image, and growth agents · `backend/app/agents/brand/brand_identity.py`
- [Prompts & tools](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/prompts/agents/brand_identity.yaml): prompt/tool layer · YAML prompts and reusable tool definitions · `backend/app/prompts/agents/brand_identity.yaml`
- [Services](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/services/campaign_manager.py): orchestration services · Campaign, context, media, scraping, and session helpers · `backend/app/services/campaign_manager.py`
- [Data layer](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/db/repositories.py): models/repositories · Mongo-style domain models, repositories, and seed data · `backend/app/db/repositories.py`

### External

Model, storage, and database dependencies

- [Model APIs](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/providers/gemini.py): LLM/providers · Gemini, Veo, and other AI provider integrations · `backend/app/providers/gemini.py`
- [Storage](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/providers/gcs.py): GCS · Durable media and artifact storage · `backend/app/providers/gcs.py`
- [MongoDB](https://github.com/narender-rk10/marketing-ai-studio/blob/main/backend/app/core/database.py): database · Primary persistence for users, workspaces, campaigns, assets, logs, and versions · `backend/app/core/database.py`

## Connections

- App shell → Canvas UX: renders · Main application mounts workspace and canvas views
- App shell → Agent forms: uses · Agent launch and configuration forms
- App shell → Agent outputs: shows · Result rendering for agent outputs
- App shell → App state: reads/writes · UI state and selection state flow through Zustand
- App shell → API client: calls · Primary backend HTTP client
- App shell → Realtime hook: subscribes · Realtime updates from backend
- API client → API app: HTTP · Frontend requests land in FastAPI
- Realtime hook → WebSocket: WS · Live streaming and progress events
- API app → Auth: protects · Auth gate in front of product routes
- API app → Product APIs: mounts · Workspace and campaign endpoints
- API app → Agent API: mounts · Agent invocation surface
- API app → WebSocket: mounts · Realtime endpoint registration
- Agent API → Agent registry: dispatches to · Resolves agent handlers from catalog
- Agent API → Orchestrator: executes via · Runs specialized agent workflows
- Orchestrator → Services: coordinates · Uses shared services for campaign, media, scraper, and session work
- Orchestrator → Prompts & tools: loads · Prompt templates and tool contracts
- Agent registry → Agent domains: indexes · Specialized marketing agent implementations
- Agent domains → Model APIs: invokes · Model-backed generation and reasoning
- Services → Storage: stores media · Generated assets and large artifacts
- Services → Data layer: persists · Operational and historical domain records
- Data layer → MongoDB: writes/reads · Primary application database
- Product APIs → Data layer: loads · Workspace and campaign state
- WebSocket → Orchestrator: streams · Emits progress from running agents
