How macbeth1501/v-neuron works
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: api.py API · App.jsx App · pipeline.py Pipeline · routing_engine.py Router
Components 16
Backend
Python routing system-of-record: offline pipeline, runtime API, and core engine.
- Config · Central constants for Nagpur-centered routing, speeds, penalties, and spatial thresholds.
backend/config.py - Pipeline · Builds and calibrates multimodal routing assets from geospatial and transit data.
backend/pipeline.py - Router · Computes shortest paths over the multimodal NetworkX graph with transfer penalties.
backend/routing_engine.py - API · Serves routes, locations, geocoding fallback, and chatbot orchestration to the client.
backend/api.py - Locations · Curated place index for search, autocomplete, and fuzzy matching.
backend/locations.json - Spatial assets · Precomputed GraphML and GeoJSON routing artifacts loaded by the backend at runtime.
- Route graph · Unified road, metro, bus, and walking graph used for deterministic route computation.
Frontend
React/Vite client for map visualization, controls, and chat interaction.
- App · Top-level React application wiring together the map, controls, simulation, and chat surfaces.
frontend/src/App.jsx - Bootstrap · Vite/React entry module that mounts the application.
frontend/src/main.jsx - Map view · Renders the city map, markers, and route geometry in the browser.
- Controls · Captures route inputs, preferences, and simulation controls.
- Chat panel · Natural-language interface for route intent and travel preferences.
- Styles · 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 · OpenStreetMap and OSMnx-derived road and spatial context for offline graph building.
- Nominatim · Fallback geocoding service used when local matching does not resolve a place.
- Groq LLM · LLaMA-based service that parses chat intent into structured route requests.
Connections 20
- 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.