How to build a Strava alternative
How to build a Strava alternative with manual activities, weekly totals, and a calendar. Store units carefully; test date boundaries before deploying the log.
How to build a Strava alternative starts with an activity log you can keep using after the first week. We will build Lapbook with manual entries, weekly totals, and a month calendar. The Strava catalog page has the wider build prompt. The Strava post explains the scope choice.
We will enter runs, rides, and walks ourselves. A route map, social feed, wearable import, and training recommendations all stay outside this version. The goal is to record what happened and read a consistent total. You can add integrations after you trust the ledger.
How to build a Strava alternative with manual activities
Use Astro server rendering for pages and mutations, D1 for records, HTMX for refreshing the month panel, and Alpine for small editor interactions. Start with HTML forms so an entry can be saved even if the calendar enhancement fails. Authentication can come from a maintained library or an access layer suitable for your deployment.
The initial screens are Today, Activities, Month, and Settings. Today has an Add activity button and a recent list. Activities lets you filter by sport. Month shows each day’s entries and totals. Settings stores a display timezone and preferred distance unit. Avoid adding a second dashboard until these screens answer your questions.
Step 1 Define units and dates before the form
An activity needs an id, owner id, sport, local activity date, distance in integer meters, duration in integer seconds, optional notes, and a revision number. Creation and update timestamps are UTC instants. A date-only activity is a calendar date, not midnight in the server’s timezone.
Keep the date the owner selected even if they later change their display timezone. This is a manual diary. Automatically moving an old run to yesterday because of a settings change makes the history confusing. If you later import timestamped activities, define that separate conversion policy at the import boundary.
Build Lapbook's migrations and server repository. Activities belong to one
owner and have sport, local_date, distance_m, duration_s, notes, revision,
created_at, and updated_at. Require nonnegative distance and positive
duration. Validate the calendar date strictly. Index owner and local_date.
Authorize every query by the signed-in owner. Include isolated seed data.
Check February 29 in a leap year and a non-leap year. Reject impossible dates instead of letting a date parser normalize them. Try a negative distance, zero duration, and a very large number. Show the entered values again when validation fails so the user can correct one field without retyping everything.
Step 2 Save an activity through a real form
Show distance with an explicit unit beside the input. If someone enters kilometers, convert once at the server boundary and store meters. Decide the supported decimal precision. For example, accepting three decimal places in kilometers maps cleanly to integer meters. Reject extra precision with a clear message rather than silently altering the distance.
Duration can use hours, minutes, and seconds fields. Normalize them into seconds on the server. Show the formatted duration after save. Keep a short upper bound on the notes field and escape it on display. A diary entry should never render stored HTML supplied through a form.
Add an activity form with sport, local date, distance plus unit, duration,
and notes. Parse decimals without depending on binary floating-point
rounding. Save canonical meters and seconds. Preserve form values after
errors. Use a unique submission token so a retried POST creates one row.
Redirect after success and show the saved activity in the recent list.
Submit twice with the same token and confirm one activity exists. Refresh after the success redirect. Change the unit selector and verify that an existing typed value is either converted visibly or cleared with an explanation. Quietly relabeling 5 kilometers as 5 miles is an easy way to corrupt the diary.
Step 3 Calculate totals from the same selection
Choose Monday as the first day of the week and show that choice beside the total. Compute the week containing the selected local date as a half-open range. Include the first Monday and exclude the following Monday. Query by owner and date range before grouping by sport.
Display distance and duration separately. A single combined pace for walking and cycling is rarely useful. For running, pace can be derived from total duration divided by total distance. When distance is zero, show an unavailable pace label instead of infinity or a divide-by-zero error.
| Example entry | Stored distance | Weekly effect |
|---|---|---|
| Monday run, 5 km | 5000 m | Adds to run distance |
| Sunday walk, 2 km | 2000 m | Adds to walk distance |
| Next Monday ride, 8 km | 8000 m | Belongs to next week |
| Indoor session, no distance | 0 m | Adds duration only |
Build weekly summaries from the persisted activity query. Use Monday-start
local date ranges and separate sport totals. Format canonical units at
render time. Derive pace only for a meaningful nonzero distance. Add
fixtures spanning Sunday, Monday, month-end, and year-end. Make the list
and summary use identical owner and date filters.
Check that changing a filter updates both the count and the totals. Enter the same fixture distances by hand and compare the displayed sum. If a summary differs, inspect the selected rows before changing formatting code. Rounding each row before summing can create a discrepancy even when storage is correct.
Step 4 Build a calendar that includes empty days
Generate the calendar from the selected year and month. Fill leading and trailing cells as needed for the Monday-start grid. Keep the selected month in the URL so reloading or sharing a private bookmark returns to the same view. Each populated day links to that day’s activities.
An empty month should say that no activities were recorded and offer Add activity. An empty day is a valid result. A failed database request should show an error with Retry. Reusing the empty state for a failed query can persuade someone that their records disappeared.
Render a server-backed month calendar. Put year and month in the query
string and validate their ranges. Include days with zero activities and
label out-of-month cells. Link a day to its filtered list. Enhance month
navigation with HTMX while preserving ordinary links. On query failure,
keep the current month visible and show a retryable error.
Navigate from December to January, then reload. Disable client JavaScript and repeat. Use the keyboard to reach the previous-month link, next-month link, and an activity day. A grid made entirely from clickable divs will need extra accessibility work; links and buttons provide sensible behavior from the start.
Step 5 Edit without losing another tab’s change
Use the revision number in update and delete requests. An update matches the activity id, owner id, and revision. If another tab changed the row, return a conflict and show both the saved values and the attempted edit. Let the owner choose what to keep.
Deletion needs a deliberate confirmation naming the sport and date. Preserve enough context to understand the action, then redirect to the same filtered list. Derive summaries from the remaining records so an edit or deletion cannot leave a stale accumulated total.
Implement revision-checked edits and deletes. A stale update returns a
conflict without overwriting stored values. Show a reload option and the
unsaved attempt. Require confirmation for deletion. Recompute summary
queries after changes. Test two owners and two simultaneous editor tabs.
Try a guessed activity id as a different owner. Test the list, detail, update, delete, and export routes separately. Authorization in the navigation alone cannot protect a direct request. Return a consistent unavailable response for records the current owner cannot read.
Step 6 Export a diary you can read elsewhere
Export the selected owner’s activities as CSV with a stable header. Include canonical distance and duration columns, the local date, sport, and notes. Escape quotes and multiline notes correctly. If offering spreadsheet-oriented export, address cells beginning with formula characters rather than relying on CSV quotation to neutralize them.
Download an export containing accented text and a multiline note. Read it with a CSV parser and compare the parsed fields to the original rows. Keep the Todoist guide nearby for another example of date-centered private records.
Stop here before adding segments or GPX imports. Manual entry, trustworthy totals, and a portable history give you a complete first application to maintain.
Deploy the private application
Keep production credentials in the deployment platform’s secret store. Use separate databases for local development, preview, and production. An agent should never point destructive seed commands at the production binding. Ask it to print the selected environment name before a migration, without printing secret values.
Commit versioned migrations alongside the application. Rehearse applying them to a copy of the database before release. After building, check that the production schema has the required columns. Document the migration and deployment order in the README so a later update follows the same path.
For a Cloudflare deployment, use the official Astro adapter and current platform documentation for the installed versions. Deploy the server application to Workers, bind D1 explicitly, and keep public static assets separate from private data. Check the generated deployment configuration rather than copying an old command from a different Astro project.
Open the deployed application in a fresh browser session. Sign in, create one record, reload, and confirm it survived. Sign out and try its private URL. Repeat the core edit from another tab and verify the conflict behavior. Also open an unavailable route and confirm that it produces an understandable missing-page response.
Make a backup you can restore
Export the database before changing its schema. Keep the export outside the live application’s storage. Restore it into an isolated database and check record counts, ownership, and a few meaningful relationships. A file named backup is useful only after you have read the restored records through the application.
Write down the restore command, required bindings, and the release revision that matches the schema. If the application stores private files, include their object keys and a separate recovery plan. Database recovery cannot recreate a deleted original file.
Keep logs small and useful. Record request ids, route names, error categories, and revision ids. Leave passwords, access tokens, private bodies, and complete exports out. When a request fails, show the user a retry path and a request id they can match to the server log.