# ahmed0elsawy/pharaoh-gurad architecture

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

- Interactive diagram: https://gitdiagram.com/ahmed0elsawy/pharaoh-gurad
- Repository: https://github.com/ahmed0elsawy/pharaoh-gurad

## Overview

PHARAOH-Guard is a crowd-risk and heritage-protection system for Egyptian archaeological sites. Its operational workflow accepts a site reading, scores risk, applies deterministic escalation policy, generates guidance, and—when escalated—dispatches actions and records an audit trail. Operators can also ask questions through RAG, a single tool-using agent, or a multi-agent team; historical data can be indexed for retrieval. The graph reflects documented calls and imports in the excerpts and SOURCE INDEX. Several API, agent, and ingestion internals were not sampled, so uncertain links are omitted.

Main entry points: [`pharaoh_guard/services/case_service.py`](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/case_service.py) (Reading Triage), [`pharaoh_guard/api/app.py`](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/api/app.py) (FastAPI), [`pharaoh_guard/core/llm.py`](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/llm.py) (Groq LLM Factory), [`pharaoh_guard/services/query_service.py`](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/query_service.py) (Assistant Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operations["Operations Workflow"]
  node_case_service["Reading Triage<br/>[case_service.py]"]
  node_risk_model["Risk Scoring<br/>[model.py]"]
  node_policy["Escalation Policy<br/>[policy.py]"]
  node_guidance["Guidance Generator<br/>[generator.py]"]
  node_rewriter["Briefing Rewriter<br/>[rewriter.py]"]
  node_dispatcher["Action Dispatcher<br/>[dispatcher.py]"]
  node_case_store[("Cases and Audit<br/>[store.py]")]
end

subgraph group_knowledge["Knowledge Archive"]
  node_rag_chain["RAG Answers<br/>[chain.py]"]
  node_retriever["Archive Retriever<br/>[retriever.py]"]
  node_vectorstore[("FAISS Archive<br/>[vectorstore.py]")]
  node_ingestion_service["Index Ingestion"]
  node_indexer["Document Indexer<br/>[indexer.py]"]
  node_loaders["Archive Loaders<br/>[loaders.py]"]
end

subgraph group_assistants["AI Assistants"]
  node_query_service["Assistant Router<br/>[query_service.py]"]
  node_operations_agent["Operations Agent"]
  node_tool_wrappers["Agent Tools<br/>[risk_tool.py]"]
  node_team_graph["Team Orchestrator<br/>[graph.py]"]
  node_team_workers["Team Workers<br/>[workers.py]"]
end

subgraph group_platform["Application Platform"]
  node_dashboard["Web Dashboard<br/>[app.js]"]
  node_api["FastAPI<br/>[app.py]"]
end

subgraph group_foundation["Core Services"]
  node_llm["Groq LLM Factory<br/>[llm.py]"]
  node_settings["Configuration<br/>[settings.py]"]
end

node_operator(("Site Operator"))
node_groq{{"Groq Service"}}

node_operator -->|"uses"| node_dashboard
node_dashboard -.->|"requests"| node_api
node_operator -->|"submits reading"| node_api
node_api -->|"processes reading"| node_case_service
node_api -->|"routes questions"| node_query_service
node_api -->|"reads cases"| node_case_store
node_case_service -->|"scores situation"| node_risk_model
node_case_service -->|"decides action"| node_policy
node_case_service -->|"generates guidance"| node_guidance
node_case_service -->|"rewrites briefing"| node_rewriter
node_case_service -->|"dispatches action"| node_dispatcher
node_case_service -->|"records case"| node_case_store
node_case_service -->|"records steps"| node_case_store
node_query_service -->|"answers with RAG"| node_rag_chain
node_query_service -->|"runs agent"| node_operations_agent
node_query_service -->|"runs team"| node_team_graph
node_rag_chain -->|"retrieves passages"| node_retriever
node_retriever -->|"loads archive"| node_vectorstore
node_ingestion_service -->|"builds index"| node_indexer
node_indexer -->|"loads documents"| node_loaders
node_indexer -->|"persists index"| node_vectorstore
node_operations_agent -->|"uses tools"| node_tool_wrappers
node_team_graph -->|"routes work"| node_team_workers
node_team_workers -->|"invokes tools"| node_tool_wrappers
node_llm -->|"creates client"| node_groq
node_llm -->|"reads settings"| node_settings
node_rewriter -->|"requests rewrite"| node_llm
node_rag_chain -->|"generates answer"| node_llm
node_team_workers -->|"generates notes"| node_llm

click node_dashboard "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/api/static/app.js"
click node_api "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/api/app.py"
click node_case_service "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/case_service.py"
click node_risk_model "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/model.py"
click node_policy "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/guidance/policy.py"
click node_guidance "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/guidance/generator.py"
click node_rewriter "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/guidance/rewriter.py"
click node_dispatcher "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/dispatch/dispatcher.py"
click node_case_store "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/dispatch/store.py"
click node_query_service "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/query_service.py"
click node_rag_chain "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/rag/chain.py"
click node_retriever "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/rag/retriever.py"
click node_vectorstore "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/vectorstore.py"
click node_ingestion_service "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/ingestion_service.py"
click node_indexer "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/ingestion/indexer.py"
click node_loaders "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/ingestion/loaders.py"
click node_operations_agent "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/agents/operations_agent.py"
click node_tool_wrappers "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/tools/risk_tool.py"
click node_team_graph "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/multi_agent/graph.py"
click node_team_workers "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/multi_agent/workers.py"
click node_llm "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/llm.py"
click node_settings "https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/config/settings.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_case_service,node_risk_model,node_policy,node_guidance,node_rewriter,node_dispatcher,node_case_store toneBlue
class node_rag_chain,node_retriever,node_vectorstore,node_ingestion_service,node_indexer,node_loaders toneAmber
class node_query_service,node_operations_agent,node_tool_wrappers,node_team_graph,node_team_workers toneMint
class node_dashboard,node_api toneRose
class node_llm,node_settings,node_operator,node_groq toneIndigo
```

## Components

### Operations Workflow

- [Reading Triage](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/case_service.py): `pharaoh_guard/services/case_service.py`
- [Risk Scoring](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/model.py): `pharaoh_guard/core/model.py`
- [Escalation Policy](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/guidance/policy.py): `pharaoh_guard/guidance/policy.py`
- [Guidance Generator](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/guidance/generator.py): `pharaoh_guard/guidance/generator.py`
- [Briefing Rewriter](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/guidance/rewriter.py): `pharaoh_guard/guidance/rewriter.py`
- [Action Dispatcher](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/dispatch/dispatcher.py): `pharaoh_guard/dispatch/dispatcher.py`
- [Cases and Audit](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/dispatch/store.py): `pharaoh_guard/dispatch/store.py`

### Knowledge Archive

- [RAG Answers](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/rag/chain.py): `pharaoh_guard/rag/chain.py`
- [Archive Retriever](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/rag/retriever.py): `pharaoh_guard/rag/retriever.py`
- [FAISS Archive](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/vectorstore.py): `pharaoh_guard/core/vectorstore.py`
- [Index Ingestion](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/ingestion_service.py): `pharaoh_guard/services/ingestion_service.py`
- [Document Indexer](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/ingestion/indexer.py): `pharaoh_guard/ingestion/indexer.py`
- [Archive Loaders](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/ingestion/loaders.py): `pharaoh_guard/ingestion/loaders.py`

### AI Assistants

- [Assistant Router](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/services/query_service.py): `pharaoh_guard/services/query_service.py`
- [Operations Agent](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/agents/operations_agent.py): `pharaoh_guard/agents/operations_agent.py`
- [Agent Tools](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/tools/risk_tool.py): `pharaoh_guard/tools/risk_tool.py`
- [Team Orchestrator](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/multi_agent/graph.py): `pharaoh_guard/multi_agent/graph.py`
- [Team Workers](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/multi_agent/workers.py): `pharaoh_guard/multi_agent/workers.py`

### Application Platform

- [Web Dashboard](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/api/static/app.js): `pharaoh_guard/api/static/app.js`
- [FastAPI](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/api/app.py): `pharaoh_guard/api/app.py`

### Core Services

- [Groq LLM Factory](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/core/llm.py): `pharaoh_guard/core/llm.py`
- [Configuration](https://github.com/ahmed0elsawy/pharaoh-gurad/blob/main/pharaoh_guard/config/settings.py): `pharaoh_guard/config/settings.py`

### Other components

- **Site Operator**
- **Groq Service**

## Connections

- Site Operator → Web Dashboard: uses
- Web Dashboard → FastAPI: requests
- Site Operator → FastAPI: submits reading
- FastAPI → Reading Triage: processes reading (evidence: `pharaoh_guard/api/app.py`)
- FastAPI → Assistant Router: routes questions (evidence: `pharaoh_guard/api/app.py`)
- FastAPI → Cases and Audit: reads cases (evidence: `pharaoh_guard/api/app.py`)
- Reading Triage → Risk Scoring: scores situation (evidence: `pharaoh_guard/services/case_service.py`)
- Reading Triage → Escalation Policy: decides action (evidence: `pharaoh_guard/services/case_service.py`)
- Reading Triage → Guidance Generator: generates guidance (evidence: `pharaoh_guard/services/case_service.py`)
- Reading Triage → Briefing Rewriter: rewrites briefing (evidence: `pharaoh_guard/services/case_service.py`)
- Reading Triage → Action Dispatcher: dispatches action (evidence: `pharaoh_guard/services/case_service.py`)
- Reading Triage → Cases and Audit: records case (evidence: `pharaoh_guard/services/case_service.py`)
- Reading Triage → Cases and Audit: records steps (evidence: `pharaoh_guard/services/case_service.py`)
- Assistant Router → RAG Answers: answers with RAG (evidence: `pharaoh_guard/services/query_service.py`)
- Assistant Router → Operations Agent: runs agent (evidence: `pharaoh_guard/services/query_service.py`)
- Assistant Router → Team Orchestrator: runs team (evidence: `pharaoh_guard/services/query_service.py`)
- RAG Answers → Archive Retriever: retrieves passages (evidence: `pharaoh_guard/rag/chain.py`)
- Archive Retriever → FAISS Archive: loads archive (evidence: `pharaoh_guard/rag/retriever.py`)
- Index Ingestion → Document Indexer: builds index (evidence: `pharaoh_guard/services/ingestion_service.py`)
- Document Indexer → Archive Loaders: loads documents (evidence: `pharaoh_guard/ingestion/indexer.py`)
- Document Indexer → FAISS Archive: persists index (evidence: `pharaoh_guard/ingestion/indexer.py`)
- Operations Agent → Agent Tools: uses tools (evidence: `pharaoh_guard/agents/operations_agent.py`)
- Team Orchestrator → Team Workers: routes work (evidence: `pharaoh_guard/multi_agent/graph.py`)
- Team Workers → Agent Tools: invokes tools (evidence: `pharaoh_guard/multi_agent/workers.py`)
- Groq LLM Factory → Groq Service: creates client (evidence: `pharaoh_guard/core/llm.py`)
- Groq LLM Factory → Configuration: reads settings (evidence: `pharaoh_guard/core/llm.py`)
- Briefing Rewriter → Groq LLM Factory: requests rewrite (evidence: `pharaoh_guard/guidance/rewriter.py`)
- RAG Answers → Groq LLM Factory: generates answer (evidence: `pharaoh_guard/rag/chain.py`)
- Team Workers → Groq LLM Factory: generates notes (evidence: `pharaoh_guard/multi_agent/workers.py`)
