# malkzidan/brandora-ai architecture

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

- Interactive diagram: https://gitdiagram.com/malkzidan/brandora-ai
- Repository: https://github.com/malkzidan/brandora-ai

## Overview

Brandora AI is an HTTP reply service called by the NestJS backend. Its implemented request path authenticates and validates input, then throttles, cleans, and short-circuits empty messages or exact greeting/thanks rules; remaining messages go to a provider and pass an output guard before returning contract-shaped JSON. The README also describes intent, FAQ, catalog, order, and product-media stages as planned capabilities, but their implementation files are absent from this tree. The mock provider replays scenario answers. Edges for undocumented or unsampled feature wiring are omitted; README-described capability links are identified as such.

Main entry points: [`app/pipeline/orchestrator.py`](https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/orchestrator.py) (Reply Orchestrator), [`app/main.py`](https://github.com/malkzidan/brandora-ai/blob/main/app/main.py) (HTTP API), [`app/providers/__init__.py`](https://github.com/malkzidan/brandora-ai/blob/main/app/providers/__init__.py) (Provider Factory), [`app/validation/output_guard.py`](https://github.com/malkzidan/brandora-ai/blob/main/app/validation/output_guard.py) (Output Guard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP Contract"]
  node_http["HTTP API<br/>[main.py]"]
  node_settings["Service Settings<br/>[config.py]"]
  node_request["Request Schema<br/>[request.py]"]
  node_response["Response Schema<br/>[response.py]"]
end

subgraph group_flow["Reply Flow"]
  node_orchestrator["Reply Orchestrator<br/>[orchestrator.py]"]
  node_throttle["Rate Throttle<br/>[throttle.py]"]
  node_preprocess["Text Preprocessor<br/>[preprocess.py]"]
  node_rules["Fixed Reply Rules<br/>[rules.py]"]
  node_text["Arabic Normalizer<br/>[text.py]"]
  node_guard["Output Guard<br/>[output_guard.py]"]
end

subgraph group_provider["Answer Providers"]
  node_factory["Provider Factory<br/>[__init__.py]"]
  node_provider_interface["Provider Interface<br/>[base.py]"]
  node_mock["Mock Provider<br/>[mock.py]"]
  node_scenarios["Golden Scenarios"]
end

subgraph group_features["AI Capabilities"]
  node_intent["Intent Detection"]
  node_faq["FAQ Answers"]
  node_catalog["Catalog Search"]
  node_order["Order Candidate"]
  node_media["Product Media"]
  node_observability["Redacted Logging"]
end

node_nestjs(("NestJS Backend"))
node_whatsapp(("WhatsApp Customer"))

node_nestjs -->|"posts request"| node_http
node_http -->|"validates input"| node_request
node_http -->|"loads settings"| node_settings
node_http -->|"builds provider"| node_factory
node_http -->|"dispatches request"| node_orchestrator
node_http -->|"validates response"| node_response
node_orchestrator -->|"checks limit"| node_throttle
node_orchestrator -->|"cleans message"| node_preprocess
node_orchestrator -->|"checks fixed rules"| node_rules
node_rules -->|"normalizes phrases"| node_text
node_orchestrator -->|"requests answer"| node_provider_interface
node_orchestrator -->|"validates answer"| node_guard
node_guard -->|"normalizes reply"| node_text
node_guard -->|"checks catalog context"| node_request
node_factory -->|"implements contract"| node_provider_interface
node_factory -->|"selects mock"| node_mock
node_settings -->|"configures provider"| node_factory
node_mock -->|"replays answers"| node_scenarios
node_nestjs -->|"sends reply"| node_whatsapp
node_orchestrator -.->|"planned feature stage"| node_intent
node_orchestrator -.->|"planned feature stage"| node_faq
node_orchestrator -.->|"planned feature stage"| node_catalog
node_orchestrator -.->|"planned feature stage"| node_order
node_orchestrator -.->|"planned feature stage"| node_media
node_orchestrator -.->|"planned feature stage"| node_observability

click node_http "https://github.com/malkzidan/brandora-ai/blob/main/app/main.py"
click node_settings "https://github.com/malkzidan/brandora-ai/blob/main/app/config.py"
click node_request "https://github.com/malkzidan/brandora-ai/blob/main/app/schemas/request.py"
click node_response "https://github.com/malkzidan/brandora-ai/blob/main/app/schemas/response.py"
click node_orchestrator "https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/orchestrator.py"
click node_throttle "https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/throttle.py"
click node_preprocess "https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/preprocess.py"
click node_rules "https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/rules.py"
click node_text "https://github.com/malkzidan/brandora-ai/blob/main/app/text.py"
click node_guard "https://github.com/malkzidan/brandora-ai/blob/main/app/validation/output_guard.py"
click node_factory "https://github.com/malkzidan/brandora-ai/blob/main/app/providers/__init__.py"
click node_provider_interface "https://github.com/malkzidan/brandora-ai/blob/main/app/providers/base.py"
click node_mock "https://github.com/malkzidan/brandora-ai/blob/main/app/providers/mock.py"
click node_scenarios "https://github.com/malkzidan/brandora-ai/tree/main/mock_data/scenarios"
click node_intent "https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline"
click node_faq "https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline"
click node_catalog "https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline"
click node_order "https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline"
click node_media "https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline"
click node_observability "https://github.com/malkzidan/brandora-ai/tree/main/app/observability"

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_http,node_settings,node_request,node_response toneBlue
class node_orchestrator,node_throttle,node_preprocess,node_rules,node_text,node_guard toneAmber
class node_factory,node_provider_interface,node_mock,node_scenarios toneMint
class node_intent,node_faq,node_catalog,node_order,node_media,node_observability toneRose
class node_nestjs,node_whatsapp toneIndigo
```

## Components

### HTTP Contract

- [HTTP API](https://github.com/malkzidan/brandora-ai/blob/main/app/main.py): `app/main.py`
- [Service Settings](https://github.com/malkzidan/brandora-ai/blob/main/app/config.py): `app/config.py`
- [Request Schema](https://github.com/malkzidan/brandora-ai/blob/main/app/schemas/request.py): `app/schemas/request.py`
- [Response Schema](https://github.com/malkzidan/brandora-ai/blob/main/app/schemas/response.py): `app/schemas/response.py`

### Reply Flow

- [Reply Orchestrator](https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/orchestrator.py): `app/pipeline/orchestrator.py`
- [Rate Throttle](https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/throttle.py): `app/pipeline/throttle.py`
- [Text Preprocessor](https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/preprocess.py): `app/pipeline/preprocess.py`
- [Fixed Reply Rules](https://github.com/malkzidan/brandora-ai/blob/main/app/pipeline/rules.py): `app/pipeline/rules.py`
- [Arabic Normalizer](https://github.com/malkzidan/brandora-ai/blob/main/app/text.py): `app/text.py`
- [Output Guard](https://github.com/malkzidan/brandora-ai/blob/main/app/validation/output_guard.py): `app/validation/output_guard.py`

### Answer Providers

- [Provider Factory](https://github.com/malkzidan/brandora-ai/blob/main/app/providers/__init__.py): `app/providers/__init__.py`
- [Provider Interface](https://github.com/malkzidan/brandora-ai/blob/main/app/providers/base.py): `app/providers/base.py`
- [Mock Provider](https://github.com/malkzidan/brandora-ai/blob/main/app/providers/mock.py): `app/providers/mock.py`
- [Golden Scenarios](https://github.com/malkzidan/brandora-ai/tree/main/mock_data/scenarios): `mock_data/scenarios`

### AI Capabilities

- [Intent Detection](https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline): `app/pipeline`
- [FAQ Answers](https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline): `app/pipeline`
- [Catalog Search](https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline): `app/pipeline`
- [Order Candidate](https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline): `app/pipeline`
- [Product Media](https://github.com/malkzidan/brandora-ai/tree/main/app/pipeline): `app/pipeline`
- [Redacted Logging](https://github.com/malkzidan/brandora-ai/tree/main/app/observability): `app/observability`

### Other components

- **NestJS Backend**
- **WhatsApp Customer**

## Connections

- NestJS Backend → HTTP API: posts request (evidence: `README.md`)
- HTTP API → Request Schema: validates input (evidence: `app/main.py`)
- HTTP API → Service Settings: loads settings (evidence: `app/main.py`)
- HTTP API → Provider Factory: builds provider (evidence: `app/main.py`)
- HTTP API → Reply Orchestrator: dispatches request (evidence: `app/main.py`)
- HTTP API → Response Schema: validates response (evidence: `app/main.py`)
- Reply Orchestrator → Rate Throttle: checks limit (evidence: `app/pipeline/orchestrator.py`)
- Reply Orchestrator → Text Preprocessor: cleans message (evidence: `app/pipeline/orchestrator.py`)
- Reply Orchestrator → Fixed Reply Rules: checks fixed rules (evidence: `app/pipeline/orchestrator.py`)
- Fixed Reply Rules → Arabic Normalizer: normalizes phrases (evidence: `app/pipeline/rules.py`)
- Reply Orchestrator → Provider Interface: requests answer (evidence: `app/pipeline/orchestrator.py`)
- Reply Orchestrator → Output Guard: validates answer (evidence: `app/pipeline/orchestrator.py`)
- Output Guard → Arabic Normalizer: normalizes reply (evidence: `app/validation/output_guard.py`)
- Output Guard → Request Schema: checks catalog context (evidence: `app/validation/output_guard.py`)
- Provider Factory → Provider Interface: implements contract (evidence: `app/providers/__init__.py`)
- Provider Factory → Mock Provider: selects mock (evidence: `app/providers/__init__.py`)
- Service Settings → Provider Factory: configures provider (evidence: `app/providers/__init__.py`)
- Mock Provider → Golden Scenarios: replays answers (evidence: `app/providers/mock.py`)
- NestJS Backend → WhatsApp Customer: sends reply (evidence: `README.md`)
- Reply Orchestrator → Intent Detection: planned feature stage (evidence: `README.md`)
- Reply Orchestrator → FAQ Answers: planned feature stage (evidence: `README.md`)
- Reply Orchestrator → Catalog Search: planned feature stage (evidence: `README.md`)
- Reply Orchestrator → Order Candidate: planned feature stage (evidence: `README.md`)
- Reply Orchestrator → Product Media: planned feature stage (evidence: `README.md`)
- Reply Orchestrator → Redacted Logging: planned feature stage (evidence: `README.md`)
