I wanted a simple, privacy-first way to see all of my Strava GPS activities in one place — both as individual routes and as a combined heatmap — without sending my location history to another third-party web app.
So I built StravaHeatmap: a self-hosted web application that connects to your Strava account via OAuth 2.0, stores your activities locally in SQLite, and renders interactive routes and heatmaps on OpenStreetMap.
- GitHub Repository: beriltzcn/strava-heatmap (MIT License)
Why Self-Hosted?
Strava restricts new API applications to a single athlete by default, which actually fits the self-hosted model really well: your own instance, your own API credentials, and your own SQLite database.
Once activities are synced, the map loads directly from your local database without hitting Strava on every page load.
Tech Stack
- Backend: ASP.NET Core (.NET 10), Entity Framework Core, SQLite
-
Frontend: React 19, TypeScript, Vite, Leaflet (
react-leaflet+leaflet.heat) - Maps & Geocoding: OpenStreetMap tiles + Nominatim reverse geocoding
-
Deployment & CI: Multi-stage Docker + Docker Compose, GitHub Actions (
.NETbuild/test + ESLint + Vite build)
Key Features & Architecture
1. Strava OAuth 2.0 & Concurrency-Safe Token Refresh
The backend handles the full OAuth 2.0 flow:
-
/api/strava/connectgenerates a random CSRFstatetoken stored in the ASP.NET Core session and redirects to Strava. -
/api/strava/callbackvalidatesstate, exchanges the authorization code for access and refresh tokens, persists them in SQLite, and redirects cleanly back to the React app. -
/api/strava/statuslets the frontend display the connected athlete badge and disable syncing when disconnected.
Because Strava access tokens expire every 6 hours, StravaConnectionService checks expiry with a 5-minute buffer before any Strava API call and guards refresh requests with a SemaphoreSlim lock (reloading the entity inside the lock) so concurrent requests never race to refresh the same token.
2. N+1-Free Activity Sync
When you click Sync, StravaSyncService fetches pages of activities from /api/v3/athlete/activities. Instead of querying SQLite one activity at a time inside the loop, it fetches all matching StravaActivityIds for the current page in a single ToDictionaryAsync query and either inserts or updates them in batch.
Network timeouts, upstream 5xx errors, and Strava 429 rate limits are mapped cleanly via a shared HTTP helper so the UI gets actionable feedback.
3. Decoding Polylines & Rendering Maps in React
Strava returns compressed route geometry as Google-encoded summary_polyline strings. The frontend decodes those 5-bit delta-encoded coordinates in TypeScript (decodePolyline) and renders two views:
-
Routes view: Interactive Leaflet
<Polyline>layers with hover tooltips and click-to-select highlighting. -
Heatmap view: A
leaflet.heatdensity canvas layer projecting all filtered GPS points.
4. Interactive Sidebar, Filters & Instant Search
When your activities span multiple cities or countries, zooming out to fit everything makes individual walks tiny. To solve that:
-
Server & client filtering: Filter by sport type (
Run,Walk,Hike,Ride, etc.) and date range (From/To), or search instantly by activity name, sport, or location. - Click-to-zoom sidebar: Clicking any activity in the left sidebar (or directly on the map) highlights it and automatically zooms the Leaflet viewport right onto that route.
-
SQLite
DateTimeOffsetquirk: EF Core cannot translateORDER BYor range comparisons onDateTimeOffsetcolumns in SQLite, soActivitiesControllerappliesSportTypeandSummaryPolylinefilters in SQL first, then runs date filtering, sorting, andlimitin memory.
5. Background Reverse Geocoding (with Polite Rate Limiting)
Summary activities from Strava don't reliably include city/country names, even though we already have the route's GPS start point.
A background BackgroundService (LocationEnrichmentService) decodes the first coordinate of each new route and resolves a clean City, COUNTRY label (like Quedlinburg, DE or Berlin, DE) using OpenStreetMap Nominatim:
- Respects Nominatim's 1 request/second policy (
1100msspacing) and customUser-Agent. - Caches resolved locations in a rounded
~1 kmcoordinate grid before calling Nominatim, so multiple walks starting in the same neighborhood trigger zero extra API calls. - Persists
Activity.Locationin SQLite so lookups only happen once per area.
6. Single-Container Docker Setup
In production, the multi-stage Dockerfile builds the Vite frontend into wwwroot inside the ASP.NET Core image:
- Single container, single origin, no CORS configuration needed.
- SQLite database and ASP.NET Core DataProtection keys live on a mounted
/datavolume so OAuth sessions and data survive container restarts. - Pending EF Core migrations run automatically at startup (
Database.MigrateAsync()).
Try It Yourself
git clone https://github.com/beriltzcn/strava-heatmap.git
cd strava-heatmap
cp .env.example .env
# Add your Strava Client ID & Client Secret to .env
docker compose up --build
Then open http://localhost:8080, click Connect Strava, and hit Sync.
What's Next?
I'm planning to add:
- A statistics panel (total distance, elevation gain, moving time, and breakdowns per sport/month)
- Automated unit & integration tests for the sync and token refresh logic
Feedback, ideas, and PRs are always welcome on GitHub!

Top comments (0)