# mahmoud-khaled23/accident_intel architecture

> Architecture diagram of the GitHub repository mahmoud-khaled23/accident_intel, 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/mahmoud-khaled23/accident_intel
- Repository: https://github.com/mahmoud-khaled23/accident_intel

## Overview

Accident Intel is a collection of runnable accident-analysis workflows, not yet a unified upload-to-report service. The video workflow produces visual observations and vehicle trajectories; a separate law-analysis workflow extracts facts, retrieves New York traffic-law passages, and drafts a qualified assessment. A separate damage workflow reviews vehicle photos and estimates repair costs. The README documents intended integration; unsampled implementation details are not inferred, and the damage and law workflows remain distinct in this map.

Main entry points: [`app/main.py`](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/main.py) (Analysis UI), [`src/Car_damage_cost/app.py`](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/app.py) (Damage review UI), [`app/pages/1_video_analysis.py`](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/1_video_analysis.py) (Video page), [`src/Car_damage_cost/pipeline.py`](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/pipeline.py) (Photo analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interfaces"]
  node_webui["Analysis UI<br/>[main.py]"]
  node_video_page["Video page"]
  node_tracking_page["Tracking page"]
  node_law_page["Accident page"]
  node_damage_page["Damage page<br/>[4_damage_cost.py]"]
end

subgraph group_video["Video analysis"]
  node_vlm_video["Video VLM<br/>[analyze_video.py]"]
  node_prompts["Analysis prompts<br/>[prompts.py]"]
  node_tracker["Vehicle tracker<br/>[tracker.py]"]
  node_candidates["Accident candidates"]
end

subgraph group_law["Law retrieval"]
  node_law_analysis["Accident analysis"]
  node_retrieval["Hybrid retrieval"]
  node_expansion["Query expansion<br/>[query_expansion.py]"]
  node_chunk_builder["Law chunking<br/>[build_chunks.py]"]
  node_law_index[("Law index<br/>[build_index.py]")]
end

subgraph group_damage["Damage estimation"]
  node_damage_app["Damage review UI<br/>[app.py]"]
  node_damage_pipeline["Photo analysis<br/>[pipeline.py]"]
  node_detectors["Segmentation models<br/>[yolo_wrapper.py]"]
  node_damage_vlm["Photo VLM<br/>[vlm_client.py]"]
  node_fusion["Damage fusion<br/>[fusion.py]"]
  node_cost_engine["Cost estimation<br/>[cost_engine.py]"]
  node_price_agent["Part pricing<br/>[price_agent.py]"]
  node_review_logic["Review logic<br/>[review_logic.py]"]
end

subgraph group_shared["Analysis support"]
  node_session["Session state<br/>[session.py]"]
end

node_analyst(("Analyst"))
node_price_service(("Gemini pricing"))

node_analyst -->|"uses"| node_webui
node_webui -->|"opens"| node_video_page
node_webui -->|"opens"| node_tracking_page
node_webui -->|"opens"| node_law_page
node_webui -->|"opens"| node_damage_page
node_video_page -->|"runs"| node_vlm_video
node_video_page -->|"runs"| node_tracker
node_video_page -->|"checks candidates"| node_candidates
node_tracking_page -->|"runs"| node_tracker
node_law_page -->|"runs"| node_law_analysis
node_law_page -->|"searches laws"| node_retrieval
node_vlm_video -->|"uses prompts"| node_prompts
node_law_analysis -->|"retrieves passages"| node_retrieval
node_retrieval -->|"expands queries"| node_expansion
node_chunk_builder -.->|"builds index inputs"| node_law_index
node_retrieval -->|"searches index"| node_law_index
node_damage_page -.->|"opens estimator"| node_damage_app
node_analyst -->|"uploads photos"| node_damage_app
node_damage_app -->|"analyzes case"| node_damage_pipeline
node_damage_pipeline -->|"runs detection"| node_detectors
node_damage_pipeline -->|"checks photos"| node_damage_vlm
node_damage_pipeline -->|"fuses results"| node_fusion
node_damage_app -->|"supports review"| node_review_logic
node_damage_app -->|"estimates costs"| node_cost_engine
node_cost_engine -->|"requests pricing"| node_price_agent
node_price_agent -.->|"queries prices"| node_price_service

click node_webui "https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/main.py"
click node_video_page "https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/1_video_analysis.py"
click node_tracking_page "https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/2_vehicle_tracking.py"
click node_law_page "https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/3_accident_analysis.py"
click node_damage_page "https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/4_damage_cost.py"
click node_session "https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/utils/session.py"
click node_vlm_video "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/VLM/analyze_video.py"
click node_prompts "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/VLM/prompts.py"
click node_tracker "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/vehicle_tracking/tracker.py"
click node_candidates "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/vehicle_tracking/accident_candidates.py"
click node_law_analysis "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/retrieval/analyze_accident.py"
click node_retrieval "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/retrieval/index_and_retrieve.py"
click node_expansion "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/chunking/query_expansion.py"
click node_chunk_builder "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/chunking/build_chunks.py"
click node_law_index "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/retrieval/build_index.py"
click node_damage_app "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/app.py"
click node_damage_pipeline "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/pipeline.py"
click node_detectors "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/yolo_wrapper.py"
click node_damage_vlm "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/vlm_client.py"
click node_fusion "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/fusion.py"
click node_cost_engine "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/cost_engine.py"
click node_price_agent "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/price_agent.py"
click node_review_logic "https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/review_logic.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_webui,node_video_page,node_tracking_page,node_law_page,node_damage_page toneBlue
class node_vlm_video,node_prompts,node_tracker,node_candidates toneAmber
class node_law_analysis,node_retrieval,node_expansion,node_chunk_builder,node_law_index toneMint
class node_damage_app,node_damage_pipeline,node_detectors,node_damage_vlm,node_fusion,node_cost_engine,node_price_agent,node_review_logic toneRose
class node_session,node_analyst,node_price_service toneIndigo
```

## Components

### User interfaces

- [Analysis UI](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/main.py): `app/main.py`
- [Video page](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/1_video_analysis.py): `app/pages/1_video_analysis.py`
- [Tracking page](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/2_vehicle_tracking.py): `app/pages/2_vehicle_tracking.py`
- [Accident page](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/3_accident_analysis.py): `app/pages/3_accident_analysis.py`
- [Damage page](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/pages/4_damage_cost.py): `app/pages/4_damage_cost.py`

### Video analysis

- [Video VLM](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/VLM/analyze_video.py): `src/VLM/analyze_video.py`
- [Analysis prompts](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/VLM/prompts.py): `src/VLM/prompts.py`
- [Vehicle tracker](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/vehicle_tracking/tracker.py): `src/vehicle_tracking/tracker.py`
- [Accident candidates](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/vehicle_tracking/accident_candidates.py): `src/vehicle_tracking/accident_candidates.py`

### Law retrieval

- [Accident analysis](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/retrieval/analyze_accident.py): `src/rag/retrieval/analyze_accident.py`
- [Hybrid retrieval](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/retrieval/index_and_retrieve.py): `src/rag/retrieval/index_and_retrieve.py`
- [Query expansion](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/chunking/query_expansion.py): `src/rag/chunking/query_expansion.py`
- [Law chunking](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/chunking/build_chunks.py): `src/rag/chunking/build_chunks.py`
- [Law index](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/rag/retrieval/build_index.py): `src/rag/retrieval/build_index.py`

### Damage estimation

- [Damage review UI](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/app.py): `src/Car_damage_cost/app.py`
- [Photo analysis](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/pipeline.py): `src/Car_damage_cost/pipeline.py`
- [Segmentation models](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/yolo_wrapper.py): `src/Car_damage_cost/yolo_wrapper.py`
- [Photo VLM](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/vlm_client.py): `src/Car_damage_cost/vlm_client.py`
- [Damage fusion](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/fusion.py): `src/Car_damage_cost/fusion.py`
- [Cost estimation](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/cost_engine.py): `src/Car_damage_cost/cost_engine.py`
- [Part pricing](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/price_agent.py): `src/Car_damage_cost/price_agent.py`
- [Review logic](https://github.com/mahmoud-khaled23/accident_intel/blob/main/src/Car_damage_cost/review_logic.py): `src/Car_damage_cost/review_logic.py`

### Analysis support

- [Session state](https://github.com/mahmoud-khaled23/accident_intel/blob/main/app/utils/session.py): `app/utils/session.py`

### Other components

- **Analyst**
- **Gemini pricing**

## Connections

- Analyst → Analysis UI: uses (evidence: `README.md`)
- Analysis UI → Video page: opens (evidence: `app/main.py`)
- Analysis UI → Tracking page: opens (evidence: `app/main.py`)
- Analysis UI → Accident page: opens (evidence: `app/main.py`)
- Analysis UI → Damage page: opens (evidence: `app/main.py`)
- Video page → Video VLM: runs (evidence: `app/pages/1_video_analysis.py`)
- Video page → Vehicle tracker: runs (evidence: `app/pages/1_video_analysis.py`)
- Video page → Accident candidates: checks candidates (evidence: `app/pages/1_video_analysis.py`)
- Tracking page → Vehicle tracker: runs (evidence: `app/pages/2_vehicle_tracking.py`)
- Accident page → Accident analysis: runs (evidence: `app/pages/3_accident_analysis.py`)
- Accident page → Hybrid retrieval: searches laws (evidence: `app/pages/3_accident_analysis.py`)
- Video VLM → Analysis prompts: uses prompts (evidence: `src/VLM/analyze_video.py`)
- Accident analysis → Hybrid retrieval: retrieves passages (evidence: `src/rag/retrieval/analyze_accident.py`)
- Hybrid retrieval → Query expansion: expands queries (evidence: `src/rag/retrieval/index_and_retrieve.py`)
- Law chunking → Law index: builds index inputs (evidence: `README.md`)
- Hybrid retrieval → Law index: searches index (evidence: `src/rag/retrieval/index_and_retrieve.py`)
- Damage page → Damage review UI: opens estimator
- Analyst → Damage review UI: uploads photos (evidence: `README.md`)
- Damage review UI → Photo analysis: analyzes case (evidence: `src/Car_damage_cost/app.py`)
- Photo analysis → Segmentation models: runs detection (evidence: `src/Car_damage_cost/pipeline.py`)
- Photo analysis → Photo VLM: checks photos (evidence: `src/Car_damage_cost/pipeline.py`)
- Photo analysis → Damage fusion: fuses results (evidence: `src/Car_damage_cost/pipeline.py`)
- Damage review UI → Review logic: supports review (evidence: `src/Car_damage_cost/app.py`)
- Damage review UI → Cost estimation: estimates costs (evidence: `src/Car_damage_cost/app.py`)
- Cost estimation → Part pricing: requests pricing (evidence: `src/Car_damage_cost/cost_engine.py`)
- Part pricing → Gemini pricing: queries prices (evidence: `README.md`)
