# Self-hosted OSRM The app defaults to the FOSSGIS community routing server. That server is free and keyless, but it is donation-funded infrastructure with a fair-use policy — fine for development, **not** appropriate for a production delivery fleet. Run your own before shipping. Everything below is open source and costs nothing but the machine it runs on. ## 1. Pick a region Nearle operates around Coimbatore, so the **southern zone** extract is enough — it covers Tamil Nadu, Kerala, Karnataka, Andhra Pradesh and Telangana. | Extract | Download size | | --- | --- | | `asia/india/southern-zone` | **0.52 GB** ← use this | | `asia/india` (all of India) | 1.58 GB | Using the regional extract rather than all-India cuts preprocessing time and roughly a third of the memory. ## 2. Preprocess (one-off, ~15–40 min) ```sh mkdir -p data && cd data wget https://download.geofabrik.de/asia/india/southern-zone-latest.osm.pbf REGION=southern-zone-latest IMG=ghcr.io/project-osrm/osrm-backend:latest docker run -t -v "$PWD:/data" $IMG osrm-extract -p /opt/car.lua /data/$REGION.osm.pbf docker run -t -v "$PWD:/data" $IMG osrm-partition /data/$REGION.osrm docker run -t -v "$PWD:/data" $IMG osrm-customize /data/$REGION.osrm ``` `osrm-extract` is the memory-hungry step — give the machine **~8 GB RAM** for the southern zone. Serving afterwards needs far less (the compose file caps at 4 GB). If extraction is killed, that is OOM, not corruption: retry with more RAM or a smaller extract. Use `/opt/bicycle.lua` instead of `car.lua` if riders are mostly on two-wheelers in pedestrianised areas — but `car.lua` is the right default for motorbike delivery on Indian roads. ## 3. Serve ```sh cd .. && docker compose up -d curl "http://localhost:5000/route/v1/driving/76.9558,11.0168;76.9776,10.9984?overview=full" ``` A healthy response starts with `{"code":"Ok"`. ## 4. Point the app at it ```sh flutter build apk --dart-define=OSRM_BASE_URL=https://osrm.your-domain.in ``` Put it behind TLS and restrict it to your own backend or app — OSRM has **no authentication of its own**. An open OSRM instance is a free compute service for anyone who finds it. If you already proxy other services, route this through the same gateway. ## 5. Keep it current OSM data drifts as roads change. Re-run step 2 monthly-ish and restart the container. There is no live-update path in OSRM — reprocessing is the only way. ## Optional: also self-host tiles The app's default tile source, [OpenFreeMap](https://openfreemap.org), is a free public instance with no key and no request limits, so self-hosting tiles is not required. If you ever want to, the options are OpenFreeMap's own self-host instructions or serving a [Protomaps](https://protomaps.com) `.pmtiles` extract from the MinIO instance this project already uses. Then: ```sh --dart-define=MAP_STYLE_URL=https://tiles.your-domain.in/styles/liberty ```