# macbeth1501/v-neuron architecture

> Architecture diagram of the GitHub repository macbeth1501/v-neuron, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/macbeth1501/v-neuron
- Repository: https://github.com/macbeth1501/v-neuron

## Overview

1. **Repository shape**
   - This is a two-tier application: a **Python backend** that builds and serves a multimodal routing engine, and a **React/Vite frontend** that visualizes routes and provides interactive controls.
   - The core domain is **Nagpur urban routing**, with road, metro, bus, and walking modes unified into one graph.

2. **Backend responsibility boundary**
   - `backend/` is the system-of-record for routing logic and data preparation.
   - It contains both the **offline data pipeline** (`pipeline.py`) and the **online API** (`api.py`), so the backend owns graph generation, route computation, geocoding, and chatbot orchestration.

3. **Routing engine core**
   - `routing_engine.py` is the heart of the system: it computes shortest paths over a **NetworkX** graph using multimodal edges.
   - The graph encodes different transport modes and transfer penalties, so the engine is not just geographic routing; it is **mode-aware pathfinding** with walking, road, metro, and bus segments.

4. **Configuration as a shared control layer**
   - `config.py` centralizes all routing assumptions and spatial constants: Nagpur center, search radius, projected CRS, walking speed, metro speed, boarding penalty, and traffic-speed tables.
   - This file is the main boundary for tuning behavior without changing the routing logic itself.

5. **Offline data pipeline**
   - `pipeline.py` is an ingestion and calibration workflow that turns OpenStreetMap-derived data into usable routing assets.
   - It produces the GraphML and GeoJSON artifacts stored under `backend/data/`, including projected roads, multimodal base graphs, and the final calibrated network.
   - The pipeline also handles spatial projection, snapping transit stops to roads, and adding metro rail structure for the Orange and Aqua lines.

6. **Persisted spatial assets**
   - The backend relies on precomputed files rather than building everything at request time.
   - Important artifacts include road graphs, multimodal GraphML files, and transit GeoJSON layers; these are loaded by the backend to keep route computation fast.
   - `locations.json` acts as a curated location index for search/autocomplete and fuzzy matching.

7. **API and orchestration layer**
   - `api.py` exposes the runtime interface consumed by the frontend.
   - The key responsibilities are: route requests, marker/location data, session-aware chatbot interaction, CORS, and geocoding fallback behavior.
   - This layer sits between the UI and the routing engine, translating user intent into graph queries and response payloads.

8. **Agentic chatbot integration**
   - The `/chat` flow is a separate interaction path from direct route calculation.
   - It uses **Groq LLaMA 3.1** for natural-language parsing of source, destination, and travel preferences, then reuses the same routing backend to compute the actual path when enough information is available.
   - This means AI is not the routing system itself; it is an **input interpretation layer** over deterministic route computation.

9. **Frontend presentation layer**
   - `frontend/` is a single-page React app built with Vite.
   - `App.jsx` appears to combine the major UI surfaces: map display, route controls, simulation/telemetry panels, and chat interaction.
   - The frontend does not own routing logic; it is primarily a **visualization and interaction client** for backend services.

10. **Map and simulation flow**
   - The frontend uses **Leaflet / React-Leaflet** to render the city map and markers.
   - It consumes marker datasets and route responses from the backend, then draws route geometry, transfer points, and vehicle movement along the selected path.
   - The live vehicle tracking is a UI simulation driven by backend route outputs, including mode, ETA, distance remaining, and speed.

11. **External services and data sources**
   - **OpenStreetMap / OSMnx** is the upstream source for the road network and spatial context.
   - **Nominatim** is used as a fallback geocoder when local matching does not resolve a place.
   - **Groq** is the external inference service for the assistant.
   - These external dependencies affect the architecture because the system combines offline ingestion with runtime fallback lookups and AI-assisted query parsing.

12. **Request/data lifecycle**
   - The main runtime path is: user action in the React app → API request to FastAPI → route lookup in the prebuilt multimodal graph → response with geometry and metrics → map/simulation update in the browser.
   - The separate offline path is: OSM/transit data → pipeline processing → persisted graph files → backend runtime loading.
   - These two paths are intentionally separated so expensive geospatial processing happens ahead of time, not during interactive use.

13. **Key architectural boundaries for a diagram**
   - Boundary 1: **Offline preprocessing vs online serving**
   - Boundary 2: **Deterministic routing engine vs AI assistant**
   - Boundary 3: **Backend computation vs frontend rendering**
   - Boundary 4: **Local curated spatial assets vs external data/services**
   - Those four boundaries capture the repository’s real architecture more accurately than a simple “frontend/backend” split.

14. **Operational footprint**
   - The system is designed to run locally with a Python API and a browser client, but it depends on large precomputed geospatial assets.
   - The architecture favors **fast interactive queries** over real-time graph construction, which is why the data pipeline and persisted graph files are central to the design.

Main entry points: [`backend/api.py`](https://github.com/macbeth1501/v-neuron/blob/main/backend/api.py) (API), [`frontend/src/App.jsx`](https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/App.jsx) (App), [`backend/pipeline.py`](https://github.com/macbeth1501/v-neuron/blob/main/backend/pipeline.py) (Pipeline), [`backend/routing_engine.py`](https://github.com/macbeth1501/v-neuron/blob/main/backend/routing_engine.py) (Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_config["Config<br/>routing settings<br/>[config.py]"]
  node_backend_pipeline["Pipeline<br/>offline ingestion<br/>[pipeline.py]"]
  node_backend_engine["Router<br/>pathfinding engine<br/>[routing_engine.py]"]
  node_backend_api["API<br/>runtime service<br/>[api.py]"]
  node_backend_locations["Locations<br/>location index<br/>[locations.json]"]
  node_offline_assets[("Spatial assets<br/>persisted graphs")]
  node_multimodal_graph{{"Route graph<br/>multimodal network"}}
end

subgraph group_frontend["Frontend"]
  node_frontend_app["App<br/>spa shell<br/>[App.jsx]"]
  node_frontend_main["Bootstrap<br/>entrypoint<br/>[main.jsx]"]
  node_frontend_map["Map view<br/>leaflet UI"]
  node_frontend_controls["Controls<br/>interaction UI"]
  node_frontend_chat["Chat panel<br/>assistant UI"]
  node_frontend_style["Styles<br/>ui styling<br/>[index.css]"]
end

subgraph group_external["External"]
  node_osm_source(("OSM data<br/>external source"))
  node_nominatim(("Nominatim<br/>geocoder"))
  node_groq_llm(("Groq LLM<br/>assistant model"))
end

node_osm_source -->|"feeds"| node_backend_pipeline
node_backend_pipeline -->|"builds"| node_offline_assets
node_backend_pipeline -->|"uses"| node_backend_config
node_offline_assets -->|"loads"| node_backend_api
node_backend_api -->|"queries"| node_backend_engine
node_backend_engine -->|"runs on"| node_multimodal_graph
node_backend_engine -->|"tuned by"| node_backend_config
node_backend_api -->|"searches"| node_backend_locations
node_backend_api -.->|"falls back to"| node_nominatim
node_frontend_app -->|"renders"| node_frontend_map
node_frontend_app -->|"contains"| node_frontend_controls
node_frontend_app -->|"contains"| node_frontend_chat
node_frontend_app -->|"styled by"| node_frontend_style
node_frontend_main -->|"mounts"| node_frontend_app
node_frontend_map -->|"requests routes"| node_backend_api
node_frontend_controls -->|"submits"| node_backend_api
node_frontend_chat -->|"parses intent"| node_groq_llm
node_frontend_chat -->|"executes routes"| node_backend_api
node_backend_api -->|"orchestrates"| node_groq_llm
node_backend_api -->|"returns geometry"| node_frontend_map

click node_backend_config "https://github.com/macbeth1501/v-neuron/blob/main/backend/config.py"
click node_backend_pipeline "https://github.com/macbeth1501/v-neuron/blob/main/backend/pipeline.py"
click node_backend_engine "https://github.com/macbeth1501/v-neuron/blob/main/backend/routing_engine.py"
click node_backend_api "https://github.com/macbeth1501/v-neuron/blob/main/backend/api.py"
click node_backend_locations "https://github.com/macbeth1501/v-neuron/blob/main/backend/locations.json"
click node_frontend_app "https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/App.jsx"
click node_frontend_main "https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/main.jsx"
click node_frontend_style "https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/index.css"

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_backend_config,node_backend_pipeline,node_backend_engine,node_backend_api,node_backend_locations,node_offline_assets,node_multimodal_graph toneBlue
class node_frontend_app,node_frontend_main,node_frontend_map,node_frontend_controls,node_frontend_chat,node_frontend_style toneAmber
class node_osm_source,node_nominatim,node_groq_llm toneMint
```

## Components

### Backend

Python routing system-of-record: offline pipeline, runtime API, and core engine.

- [Config](https://github.com/macbeth1501/v-neuron/blob/main/backend/config.py): routing settings · Central constants for Nagpur-centered routing, speeds, penalties, and spatial thresholds. · `backend/config.py`
- [Pipeline](https://github.com/macbeth1501/v-neuron/blob/main/backend/pipeline.py): offline ingestion · Builds and calibrates multimodal routing assets from geospatial and transit data. · `backend/pipeline.py`
- [Router](https://github.com/macbeth1501/v-neuron/blob/main/backend/routing_engine.py): pathfinding engine · Computes shortest paths over the multimodal NetworkX graph with transfer penalties. · `backend/routing_engine.py`
- [API](https://github.com/macbeth1501/v-neuron/blob/main/backend/api.py): runtime service · Serves routes, locations, geocoding fallback, and chatbot orchestration to the client. · `backend/api.py`
- [Locations](https://github.com/macbeth1501/v-neuron/blob/main/backend/locations.json): location index · Curated place index for search, autocomplete, and fuzzy matching. · `backend/locations.json`
- **Spatial assets**: persisted graphs · Precomputed GraphML and GeoJSON routing artifacts loaded by the backend at runtime.
- **Route graph**: multimodal network · Unified road, metro, bus, and walking graph used for deterministic route computation.

### Frontend

React/Vite client for map visualization, controls, and chat interaction.

- [App](https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/App.jsx): spa shell · Top-level React application wiring together the map, controls, simulation, and chat surfaces. · `frontend/src/App.jsx`
- [Bootstrap](https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/main.jsx): entrypoint · Vite/React entry module that mounts the application. · `frontend/src/main.jsx`
- **Map view**: leaflet UI · Renders the city map, markers, and route geometry in the browser.
- **Controls**: interaction UI · Captures route inputs, preferences, and simulation controls.
- **Chat panel**: assistant UI · Natural-language interface for route intent and travel preferences.
- [Styles](https://github.com/macbeth1501/v-neuron/blob/main/frontend/src/index.css): ui styling · Global CSS styling for the single-page app. · `frontend/src/index.css`

### External

Upstream data sources and hosted services used by the app.

- **OSM data**: external source · OpenStreetMap and OSMnx-derived road and spatial context for offline graph building.
- **Nominatim**: geocoder · Fallback geocoding service used when local matching does not resolve a place.
- **Groq LLM**: assistant model · LLaMA-based service that parses chat intent into structured route requests.

## Connections

- OSM data → Pipeline: feeds · Provides roads, geometry, and spatial context for offline preprocessing.
- Pipeline → Spatial assets: builds · Produces calibrated GraphML and GeoJSON routing artifacts.
- Pipeline → Config: uses · Applies shared spatial constants and routing assumptions during calibration.
- Spatial assets → API: loads · Runtime service reads precomputed assets instead of rebuilding graphs on request.
- API → Router: queries · Delegates route computation to the deterministic routing engine.
- Router → Route graph: runs on · Performs shortest-path search over the multimodal network.
- Router → Config: tuned by · Uses walking speed, metro speed, penalties, and search bounds.
- API → Locations: searches · Uses curated place data for lookup and autocomplete.
- API → Nominatim: falls back to · Resolves unresolved places through external geocoding.
- App → Map view: renders · Composes the main map surface.
- App → Controls: contains · Hosts route input and simulation controls.
- App → Chat panel: contains · Hosts the conversational route assistant UI.
- App → Styles: styled by · Applies shared page styling.
- Bootstrap → App: mounts · Bootstraps the React application.
- Map view → API: requests routes · Fetches route geometries, metrics, and marker data.
- Controls → API: submits · Sends user route preferences and destination inputs.
- Chat panel → Groq LLM: parses intent · Uses the model to structure natural-language travel requests.
- Chat panel → API: executes routes · Hands off parsed source/destination details for deterministic routing.
- API → Groq LLM: orchestrates · Coordinates chatbot flow and response generation.
- API → Map view: returns geometry · Delivers route shapes, transfer points, and ETA/distance data for visualization.
