# anujtambake936-ctrl/azure_video_compliance_analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/anujtambake936-ctrl/azure_video_compliance_analyzer
- Repository: https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer

## Overview

#### Purpose and Entry Points
Video Compliance Analyzer audits a submitted YouTube URL against brand/regulatory guidance. It extracts video evidence, retrieves relevant rules, and returns a structured PASS/FAIL compliance report with risk score and violations.

Runtime entry points:
- CLI local audit: `main.py`
- FastAPI service (`GET /health`, `POST /audit`): `backend/src/api/server.py`
- One-time knowledge-base ingestion: `backend/scripts/index_documents.py`

#### API and Request Boundary
`backend/src/api/server.py` owns HTTP validation, audit invocation, and response delivery. It is the external boundary for clients: callers submit a YouTube URL and receive a session-scoped report. Telemetry initialization is separated in `backend/src/api/telemetry.py`, allowing API request traces and failures to be exported without embedding observability logic in workflow nodes.

#### Workflow Orchestration
The audit is a LangGraph `StateGraph` defined in `backend/src/graph/workflow.py`. It coordinates a linear two-stage DAG:
1. video indexing/evidence extraction;
2. compliance auditing/report generation.

Shared execution context is formalized by `backend/src/graph/state.py` as `VideoAuditState`, carrying the URL/session identity, extracted content, retrieved rules, report fields, and accumulated errors across node boundaries.

#### Video Evidence Extraction
The first graph stage is implemented in `backend/src/graph/nodes.py` and delegates Azure Video Indexer integration to `backend/src/services/video_indexer.py`. The service boundary encapsulates downloading the YouTube asset with yt-dlp and submitting/reading analysis from Azure Video Indexer. Its output—transcript plus on-screen OCR text—is the evidence passed to the auditor rather than exposing video-provider mechanics to graph orchestration.

#### Retrieval and AI Audit
The auditor node in `backend/src/graph/nodes.py` uses Azure OpenAI embeddings and Azure AI Search vector retrieval to find compliance guidance relevant to extracted video evidence. It then calls an Azure OpenAI chat deployment to generate the structured audit: status, risk score, summary, violations, cited/retrieved rules, and final narrative. Azure AI Search is therefore the policy knowledge boundary; the LLM consumes retrieved rule context rather than relying only on model knowledge.

#### Knowledge-Base Ingestion
Source regulations and ad guidance reside in `backend/data/1001a-influencer-guide-508_1.pdf` and `backend/data/youtube-ad-specs.pdf`. `backend/scripts/index_documents.py` is the offline ingestion path that chunks these documents, embeds them with Azure OpenAI, and populates the Azure AI Search index. Re-running it after adding PDFs refreshes/extends the corpus used by live audits.

#### Infrastructure and Observability
The system is Python-based, with dependencies managed by `pyproject.toml` and `uv.lock`. Required managed services are Azure OpenAI (chat and embeddings), Azure AI Search, and Azure Video Indexer; Azure credentials/endpoints are environment-driven via `.env.example`. Optional Azure Monitor/Application Insights instrumentation is wired through `backend/src/api/telemetry.py`; LangSmith traces LangGraph executions when configured.

Main entry points: [`backend/src/graph/workflow.py`](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/workflow.py) (Audit StateGraph), [`backend/src/graph/nodes.py`](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/nodes.py) (Generate compliance report), [`backend/scripts/index_documents.py`](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/scripts/index_documents.py) (Document indexer), [`backend/src/services/video_indexer.py`](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/services/video_indexer.py) (Video Indexer service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_cli["Local audit CLI<br/>Python entry point<br/>[main.py]"]
  node_api["FastAPI audit API<br/>HTTP boundary<br/>[server.py]"]
end

subgraph group_workflow["Audit Workflow"]
  node_state["VideoAuditState<br/>shared graph state<br/>[state.py]"]
  node_workflow_graph["Audit StateGraph<br/>LangGraph orchestration<br/>[workflow.py]"]
  node_index_video["Index video evidence<br/>graph stage<br/>[nodes.py]"]
  node_audit_video["Generate compliance report<br/>graph stage<br/>[nodes.py]"]
  node_video_service["Video Indexer service<br/>provider adapter<br/>[video_indexer.py]"]
end

subgraph group_knowledge["Knowledge Pipeline"]
  node_ingestion["Document indexer<br/>offline ingestion job<br/>[index_documents.py]"]
  node_influencer_pdf["Influencer guidance<br/>source regulation PDF"]
  node_youtube_specs_pdf["YouTube ad specs<br/>source guidance PDF"]
end

subgraph group_azure["Managed Services"]
  node_azure_video{{"Azure Video Indexer<br/>video analysis service"}}
  node_azure_openai{{"Azure OpenAI<br/>embeddings and chat"}}
  node_azure_search[("Azure AI Search<br/>policy vector index")]
end

subgraph group_observability["Observability"]
  node_telemetry["API telemetry<br/>instrumentation setup<br/>[telemetry.py]"]
  node_azure_monitor{{"Azure Monitor / App Insights<br/>optional telemetry sink"}}
  node_langsmith{{"LangSmith<br/>optional graph tracing"}}
end

node_youtube["YouTube video URL<br/>external media source"]

node_cli -->|"starts audit"| node_workflow_graph
node_api -->|"validates URL and invokes"| node_workflow_graph
node_api -->|"initializes"| node_telemetry
node_telemetry -.->|"exports API telemetry"| node_azure_monitor
node_workflow_graph -->|"uses"| node_state
node_workflow_graph -->|"stage 1"| node_index_video
node_index_video -->|"extracts evidence"| node_video_service
node_video_service -->|"downloads"| node_youtube
node_video_service -->|"submits and reads analysis"| node_azure_video
node_index_video -->|"transcript and OCR"| node_audit_video
node_workflow_graph -->|"stage 2"| node_audit_video
node_audit_video -->|"embeds evidence and generates report"| node_azure_openai
node_audit_video -->|"retrieves relevant rules"| node_azure_search
node_influencer_pdf -->|"source"| node_ingestion
node_youtube_specs_pdf -->|"source"| node_ingestion
node_ingestion -->|"creates embeddings"| node_azure_openai
node_ingestion -->|"populates index"| node_azure_search
node_workflow_graph -.->|"traces when configured"| node_langsmith
node_workflow_graph -->|"session-scoped report"| node_api

click node_cli "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/main.py"
click node_api "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/api/server.py"
click node_telemetry "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/api/telemetry.py"
click node_state "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/state.py"
click node_workflow_graph "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/workflow.py"
click node_index_video "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/nodes.py"
click node_audit_video "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/nodes.py"
click node_video_service "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/services/video_indexer.py"
click node_ingestion "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/scripts/index_documents.py"
click node_influencer_pdf "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/data/1001a-influencer-guide-508_1.pdf"
click node_youtube_specs_pdf "https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/data/youtube-ad-specs.pdf"

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_cli,node_api toneBlue
class node_state,node_workflow_graph,node_index_video,node_audit_video,node_video_service toneAmber
class node_ingestion,node_influencer_pdf,node_youtube_specs_pdf toneMint
class node_azure_video,node_azure_openai,node_azure_search toneRose
class node_telemetry,node_azure_monitor,node_langsmith toneIndigo
class node_youtube toneNeutral
```

## Components

### Entry Points

- [Local audit CLI](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/main.py): Python entry point · `main.py`
- [FastAPI audit API](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/api/server.py): HTTP boundary · Serves health checks and URL audit requests. · `backend/src/api/server.py`

### Audit Workflow

- [VideoAuditState](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/state.py): shared graph state · Carries session, evidence, rules, report fields, and errors. · `backend/src/graph/state.py`
- [Audit StateGraph](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/workflow.py): LangGraph orchestration · Runs evidence extraction followed by compliance auditing. · `backend/src/graph/workflow.py`
- [Index video evidence](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/nodes.py): graph stage · `backend/src/graph/nodes.py`
- [Generate compliance report](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/graph/nodes.py): graph stage · `backend/src/graph/nodes.py`
- [Video Indexer service](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/services/video_indexer.py): provider adapter · Downloads YouTube media and obtains transcript and OCR evidence. · `backend/src/services/video_indexer.py`

### Knowledge Pipeline

- [Document indexer](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/scripts/index_documents.py): offline ingestion job · Chunks PDFs, embeds them, and refreshes the policy index. · `backend/scripts/index_documents.py`
- [Influencer guidance](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/data/1001a-influencer-guide-508_1.pdf): source regulation PDF · `backend/data/1001a-influencer-guide-508_1.pdf`
- [YouTube ad specs](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/data/youtube-ad-specs.pdf): source guidance PDF · `backend/data/youtube-ad-specs.pdf`

### Managed Services

- **Azure Video Indexer**: video analysis service
- **Azure OpenAI**: embeddings and chat · Embeds corpus/query content and produces the structured audit.
- **Azure AI Search**: policy vector index · Retrieves relevant compliance guidance.

### Observability

- [API telemetry](https://github.com/anujtambake936-ctrl/azure_video_compliance_analyzer/blob/main/backend/src/api/telemetry.py): instrumentation setup · `backend/src/api/telemetry.py`
- **Azure Monitor / App Insights**: optional telemetry sink
- **LangSmith**: optional graph tracing

### Other components

- **YouTube video URL**: external media source

## Connections

- Local audit CLI → Audit StateGraph: starts audit
- FastAPI audit API → Audit StateGraph: validates URL and invokes
- FastAPI audit API → API telemetry: initializes
- API telemetry → Azure Monitor / App Insights: exports API telemetry
- Audit StateGraph → VideoAuditState: uses
- Audit StateGraph → Index video evidence: stage 1
- Index video evidence → Video Indexer service: extracts evidence
- Video Indexer service → YouTube video URL: downloads
- Video Indexer service → Azure Video Indexer: submits and reads analysis
- Index video evidence → Generate compliance report: transcript and OCR
- Audit StateGraph → Generate compliance report: stage 2
- Generate compliance report → Azure OpenAI: embeds evidence and generates report
- Generate compliance report → Azure AI Search: retrieves relevant rules
- Influencer guidance → Document indexer: source
- YouTube ad specs → Document indexer: source
- Document indexer → Azure OpenAI: creates embeddings
- Document indexer → Azure AI Search: populates index
- Audit StateGraph → LangSmith: traces when configured
- Audit StateGraph → FastAPI audit API: session-scoped report
