# mercenarya/castravision architecture

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

- Interactive diagram: https://gitdiagram.com/mercenarya/castravision
- Repository: https://github.com/mercenarya/castravision

## Overview

CastraVision is an early-stage marketing strategy assistant for SMEs. Its evidenced workflow is business-profile and campaign-data entry in the React app, followed by a strategy request validated and handled by Django, which retrieves relevant knowledge and generates a recommendation. Account and import endpoints persist profile and normalized campaign data; knowledge ingestion and embedding tasks support retrieval. The README also describes content generation, budget optimization, ad-platform integrations, dashboards, and exports, but the sampled implementation does not establish those runtime paths. The graph preserves the implemented workflow and notes that evidence limit.

Main entry points: [`CastraServices/rag.py`](https://github.com/mercenarya/castravision/blob/main/CastraServices/rag.py) (Knowledge search), [`CastraView/src/App.jsx`](https://github.com/mercenarya/castravision/blob/main/CastraView/src/App.jsx) (Web application), [`CastraServices/strategy.py`](https://github.com/mercenarya/castravision/blob/main/CastraServices/strategy.py) (Strategy generation), [`CastraServices/views.py`](https://github.com/mercenarya/castravision/blob/main/CastraServices/views.py) (Strategy endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_webapp["Web application<br/>[App.jsx]"]
end

subgraph group_backend["Application API"]
  node_account_api["Account API<br/>[account_api.py]"]
  node_campaign_import["Campaign import<br/>[account_api.py]"]
  node_strategy_api["Strategy endpoint<br/>[views.py]"]
  node_business_store[("Business and imports<br/>[models.py]")]
  node_csv_tools["CSV preprocessing"]
end

subgraph group_strategy["Strategy services"]
  node_request_schema["Request validation<br/>[schemas.py]"]
  node_strategy_engine["Strategy generation<br/>[strategy.py]"]
  node_prompt_builder["Prompt construction<br/>[prompts.py]"]
end

subgraph group_knowledge["Knowledge retrieval"]
  node_rag["Knowledge search<br/>[rag.py]"]
  node_knowledge_store[("Knowledge chunks<br/>[models.py]")]
  node_knowledge_ingest["Knowledge ingestion"]
  node_embedding_task["Embedding worker<br/>[tasks.py]"]
  node_celery_app["Task runtime<br/>[celery.py]"]
end

node_user(("SME user"))
node_llm{{"OpenAI service"}}

node_user -->|"enters profile"| node_webapp
node_webapp -->|"sends account requests"| node_account_api
node_webapp -->|"uploads campaign data"| node_campaign_import
node_webapp -->|"requests strategy"| node_strategy_api
node_strategy_api -->|"validates request"| node_request_schema
node_strategy_api -->|"generates recommendation"| node_strategy_engine
node_account_api -->|"saves profile"| node_business_store
node_campaign_import -->|"saves normalized rows"| node_business_store
node_strategy_engine -->|"builds prompt"| node_prompt_builder
node_strategy_engine -->|"searches context"| node_rag
node_strategy_engine -->|"requests completion"| node_llm
node_prompt_builder -.->|"uses search results"| node_rag
node_rag -->|"queries chunks"| node_knowledge_store
node_rag -->|"creates embeddings"| node_llm
node_knowledge_ingest -->|"ingests documents"| node_rag
node_embedding_task -->|"gets embedding provider"| node_rag
node_embedding_task -->|"updates embeddings"| node_knowledge_store
node_celery_app -.->|"provides task runtime"| node_embedding_task

click node_webapp "https://github.com/mercenarya/castravision/blob/main/CastraView/src/App.jsx"
click node_account_api "https://github.com/mercenarya/castravision/blob/main/CastraServices/account_api.py"
click node_campaign_import "https://github.com/mercenarya/castravision/blob/main/CastraServices/account_api.py"
click node_strategy_api "https://github.com/mercenarya/castravision/blob/main/CastraServices/views.py"
click node_request_schema "https://github.com/mercenarya/castravision/blob/main/CastraServices/schemas.py"
click node_strategy_engine "https://github.com/mercenarya/castravision/blob/main/CastraServices/strategy.py"
click node_prompt_builder "https://github.com/mercenarya/castravision/blob/main/CastraServices/prompts.py"
click node_rag "https://github.com/mercenarya/castravision/blob/main/CastraServices/rag.py"
click node_knowledge_store "https://github.com/mercenarya/castravision/blob/main/CastraServices/models.py"
click node_business_store "https://github.com/mercenarya/castravision/blob/main/CastraServices/models.py"
click node_knowledge_ingest "https://github.com/mercenarya/castravision/blob/main/CastraServices/management/commands/ingest_knowledge.py"
click node_embedding_task "https://github.com/mercenarya/castravision/blob/main/CastraServices/tasks.py"
click node_celery_app "https://github.com/mercenarya/castravision/blob/main/CastraVision/celery.py"
click node_csv_tools "https://github.com/mercenarya/castravision/blob/main/Utils/data_preprocessing.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_webapp,node_user toneBlue
class node_account_api,node_campaign_import,node_strategy_api,node_business_store,node_csv_tools toneAmber
class node_request_schema,node_strategy_engine,node_prompt_builder toneMint
class node_rag,node_knowledge_store,node_knowledge_ingest,node_embedding_task,node_celery_app toneRose
class node_llm toneIndigo
```

## Components

### User interface

- [Web application](https://github.com/mercenarya/castravision/blob/main/CastraView/src/App.jsx): `CastraView/src/App.jsx`

### Application API

- [Account API](https://github.com/mercenarya/castravision/blob/main/CastraServices/account_api.py): `CastraServices/account_api.py`
- [Campaign import](https://github.com/mercenarya/castravision/blob/main/CastraServices/account_api.py): `CastraServices/account_api.py`
- [Strategy endpoint](https://github.com/mercenarya/castravision/blob/main/CastraServices/views.py): `CastraServices/views.py`
- [Business and imports](https://github.com/mercenarya/castravision/blob/main/CastraServices/models.py): `CastraServices/models.py`
- [CSV preprocessing](https://github.com/mercenarya/castravision/blob/main/Utils/data_preprocessing.py): `Utils/data_preprocessing.py`

### Strategy services

- [Request validation](https://github.com/mercenarya/castravision/blob/main/CastraServices/schemas.py): `CastraServices/schemas.py`
- [Strategy generation](https://github.com/mercenarya/castravision/blob/main/CastraServices/strategy.py): `CastraServices/strategy.py`
- [Prompt construction](https://github.com/mercenarya/castravision/blob/main/CastraServices/prompts.py): `CastraServices/prompts.py`

### Knowledge retrieval

- [Knowledge search](https://github.com/mercenarya/castravision/blob/main/CastraServices/rag.py): `CastraServices/rag.py`
- [Knowledge chunks](https://github.com/mercenarya/castravision/blob/main/CastraServices/models.py): `CastraServices/models.py`
- [Knowledge ingestion](https://github.com/mercenarya/castravision/blob/main/CastraServices/management/commands/ingest_knowledge.py): `CastraServices/management/commands/ingest_knowledge.py`
- [Embedding worker](https://github.com/mercenarya/castravision/blob/main/CastraServices/tasks.py): `CastraServices/tasks.py`
- [Task runtime](https://github.com/mercenarya/castravision/blob/main/CastraVision/celery.py): `CastraVision/celery.py`

### Other components

- **SME user**
- **OpenAI service**

## Connections

- SME user → Web application: enters profile (evidence: `CastraView/src/App.jsx`)
- Web application → Account API: sends account requests (evidence: `CastraView/src/App.jsx`)
- Web application → Campaign import: uploads campaign data (evidence: `CastraView/src/App.jsx`)
- Web application → Strategy endpoint: requests strategy (evidence: `CastraView/src/App.jsx`)
- Strategy endpoint → Request validation: validates request (evidence: `CastraServices/views.py`)
- Strategy endpoint → Strategy generation: generates recommendation (evidence: `CastraServices/views.py`)
- Account API → Business and imports: saves profile (evidence: `CastraServices/account_api.py`)
- Campaign import → Business and imports: saves normalized rows (evidence: `CastraServices/account_api.py`)
- Strategy generation → Prompt construction: builds prompt (evidence: `CastraServices/strategy.py`)
- Strategy generation → Knowledge search: searches context (evidence: `CastraServices/strategy.py`)
- Strategy generation → OpenAI service: requests completion (evidence: `CastraServices/strategy.py`)
- Prompt construction → Knowledge search: uses search results (evidence: `CastraServices/prompts.py`)
- Knowledge search → Knowledge chunks: queries chunks (evidence: `CastraServices/rag.py`)
- Knowledge search → OpenAI service: creates embeddings (evidence: `CastraServices/rag.py`)
- Knowledge ingestion → Knowledge search: ingests documents (evidence: `CastraServices/management/commands/ingest_knowledge.py`)
- Embedding worker → Knowledge search: gets embedding provider (evidence: `CastraServices/tasks.py`)
- Embedding worker → Knowledge chunks: updates embeddings (evidence: `CastraServices/tasks.py`)
- Task runtime → Embedding worker: provides task runtime (evidence: `CastraServices/tasks.py`)
