# renan-michelao/crash-map-sp architecture

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

- Interactive diagram: https://gitdiagram.com/renan-michelao/crash-map-sp
- Repository: https://github.com/renan-michelao/crash-map-sp

## Overview

Crash Map SP is an interactive São Paulo traffic-accident map: the backend reads the accident CSV, validates and indexes points in a server-side QuadTree, and exposes spatial-query and summary endpoints. The React frontend loads data, filters it, builds a local QuadTree, and lets users select a map region to compare indexed results with a linear scan; map overlays and sidebar controls expose the index and query measurements. The README documents bounding-box querying and a Leaflet map. Frontend-to-backend HTTP wiring is not shown in the excerpts, so that link is marked unverified.

Main entry points: [`frontend/src/App.tsx`](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/App.tsx) (Map workflow), [`backend/src/loader.ts`](https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/loader.ts) (CSV loader), [`backend/src/server.ts`](https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/server.ts) (HTTP API), [`frontend/src/api/index.ts`](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/api/index.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend data and spatial API"]
  node_csv["Accident CSV<br/>[acidentes.csv]"]
  node_loader["CSV loader<br/>[loader.ts]"]
  node_serverqt["Server QuadTree<br/>[quadtree.ts]"]
  node_server["HTTP API<br/>[server.ts]"]
end

subgraph group_frontend["Frontend workflow"]
  node_api["API client<br/>[index.ts]"]
  node_app["Map workflow<br/>[App.tsx]"]
  node_clientqt["Client QuadTree<br/>[index.ts]"]
  node_types["Frontend data types<br/>[index.ts]"]
  node_entry["React entry point<br/>[main.tsx]"]
end

subgraph group_map["Map visualization and controls"]
  node_selectioncontrol["Region selection"]
  node_qtoverlay["Tree overlay"]
  node_selectionoverlay["Selection overlay"]
  node_gravitybadge["Gravity badge<br/>[GravityBadge.tsx]"]
end

subgraph group_ui["Sidebar controls"]
  node_sidebar["Filters and metrics<br/>[Sidebar.tsx]"]
  node_uicontrols["Sidebar UI controls"]
end

node_visitor(("Map user"))

node_server -->|"loads data"| node_loader
node_loader -->|"reads CSV"| node_csv
node_loader -->|"builds index"| node_serverqt
node_server -->|"queries index"| node_serverqt
node_visitor -->|"uses map"| node_app
node_entry -->|"renders"| node_app
node_app -->|"loads data"| node_api
node_api -.->|"requests API"| node_server
node_app -->|"builds and queries"| node_clientqt
node_app -->|"handles selection"| node_selectioncontrol
node_selectioncontrol -->|"reports region"| node_app
node_app -->|"renders index"| node_qtoverlay
node_app -->|"renders selection"| node_selectionoverlay
node_app -->|"renders details"| node_gravitybadge
node_app -->|"supplies controls"| node_sidebar
node_sidebar -->|"renders controls"| node_uicontrols
node_app -->|"uses data types"| node_types
node_clientqt -->|"uses point types"| node_types

click node_csv "https://github.com/renan-michelao/crash-map-sp/blob/main/backend/data/acidentes.csv"
click node_loader "https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/loader.ts"
click node_serverqt "https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/quadtree.ts"
click node_server "https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/server.ts"
click node_api "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/api/index.ts"
click node_app "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/App.tsx"
click node_clientqt "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/quadtree/index.ts"
click node_selectioncontrol "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/SelectionControl.tsx"
click node_qtoverlay "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/QuadTreeOverlay.tsx"
click node_selectionoverlay "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/SelectionOverlay.tsx"
click node_gravitybadge "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/GravityBadge.tsx"
click node_sidebar "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/Sidebar.tsx"
click node_uicontrols "https://github.com/renan-michelao/crash-map-sp/tree/main/frontend/src/components/ui"
click node_types "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/types/index.ts"
click node_entry "https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/main.tsx"

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_csv,node_loader,node_serverqt,node_server,node_visitor toneBlue
class node_api,node_app,node_clientqt,node_types,node_entry toneAmber
class node_selectioncontrol,node_qtoverlay,node_selectionoverlay,node_gravitybadge toneMint
class node_sidebar,node_uicontrols toneRose
```

## Components

### Backend data and spatial API

- [Accident CSV](https://github.com/renan-michelao/crash-map-sp/blob/main/backend/data/acidentes.csv): `backend/data/acidentes.csv`
- [CSV loader](https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/loader.ts): `backend/src/loader.ts`
- [Server QuadTree](https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/quadtree.ts): `backend/src/quadtree.ts`
- [HTTP API](https://github.com/renan-michelao/crash-map-sp/blob/main/backend/src/server.ts): `backend/src/server.ts`

### Frontend workflow

- [API client](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/api/index.ts): `frontend/src/api/index.ts`
- [Map workflow](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Client QuadTree](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/quadtree/index.ts): `frontend/src/quadtree/index.ts`
- [Frontend data types](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/types/index.ts): `frontend/src/types/index.ts`
- [React entry point](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/main.tsx): `frontend/src/main.tsx`

### Map visualization and controls

- [Region selection](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/SelectionControl.tsx): `frontend/src/components/SelectionControl.tsx`
- [Tree overlay](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/QuadTreeOverlay.tsx): `frontend/src/components/QuadTreeOverlay.tsx`
- [Selection overlay](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/SelectionOverlay.tsx): `frontend/src/components/SelectionOverlay.tsx`
- [Gravity badge](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/GravityBadge.tsx): `frontend/src/components/GravityBadge.tsx`

### Sidebar controls

- [Filters and metrics](https://github.com/renan-michelao/crash-map-sp/blob/main/frontend/src/components/Sidebar.tsx): `frontend/src/components/Sidebar.tsx`
- [Sidebar UI controls](https://github.com/renan-michelao/crash-map-sp/tree/main/frontend/src/components/ui): `frontend/src/components/ui`

### Other components

- **Map user**

## Connections

- HTTP API → CSV loader: loads data (evidence: `backend/src/server.ts`)
- CSV loader → Accident CSV: reads CSV (evidence: `backend/src/loader.ts`)
- CSV loader → Server QuadTree: builds index (evidence: `backend/src/loader.ts`)
- HTTP API → Server QuadTree: queries index (evidence: `backend/src/server.ts`)
- Map user → Map workflow: uses map (evidence: `README.md`)
- React entry point → Map workflow: renders (evidence: `frontend/src/main.tsx`)
- Map workflow → API client: loads data (evidence: `frontend/src/App.tsx`)
- API client → HTTP API: requests API
- Map workflow → Client QuadTree: builds and queries (evidence: `frontend/src/App.tsx`)
- Map workflow → Region selection: handles selection (evidence: `frontend/src/App.tsx`)
- Region selection → Map workflow: reports region (evidence: `frontend/src/components/SelectionControl.tsx`)
- Map workflow → Tree overlay: renders index (evidence: `frontend/src/App.tsx`)
- Map workflow → Selection overlay: renders selection (evidence: `frontend/src/App.tsx`)
- Map workflow → Gravity badge: renders details (evidence: `frontend/src/App.tsx`)
- Map workflow → Filters and metrics: supplies controls (evidence: `frontend/src/App.tsx`)
- Filters and metrics → Sidebar UI controls: renders controls (evidence: `frontend/src/components/Sidebar.tsx`)
- Map workflow → Frontend data types: uses data types (evidence: `frontend/src/App.tsx`)
- Client QuadTree → Frontend data types: uses point types (evidence: `frontend/src/quadtree/index.ts`)
