How to build a MyFitnessPal alternative
How to build a MyFitnessPal alternative with a focused v1, clear data rules and practical checks. Keep your saved work portable and handle failed writes.
How to build a MyFitnessPal alternative starts with a private food diary with daily totals. We will build one complete path, save its result, and check that the next page request shows the same data. Use the MyFitnessPal catalog prompt to compare this scope with the wider product.
How to build a MyFitnessPal alternative with a clear v1
The owner signs in, creates the main record and opens its detail page. They make a valid change and read the result after refreshing. The first release also includes an export and a documented restore procedure. Keep barcode scanning, nutritional advice, weight-loss targets and a commercial food database outside this build.
Write that boundary into the README before generating screens. Ask the agent to list every route that reads or changes data. A list page, detail page, create form, edit form and export endpoint are enough to begin. Avoid adding an administration dashboard until there is a real setting to administer.
Use fictional records during development. Real personal or company information can wait until authorization, backups and restore checks work. A convincing interface is easier to generate than a dependable write path, so we will check persistence at each stage.
Step 1 choose the runtime and create the schema
Use Astro for server-rendered routes, HTMX for partial form updates and Alpine.js for local controls. SQL stores the records. Start on a Node host with persistent SQLite storage, or choose a hosted relational database if the host has no durable disk. Keep the database client inside server modules.
These are proposed records for our replacement:
Food(id, owner_id, name, serving_label, calories_per_serving)
Entry(id, owner_id, food_id, local_date, servings, calorie_snapshot, revision)
Every child must lead back to an owner. Use foreign keys and indexes that support that lookup. A route accepting a child identifier should join through its parent before returning data. UUIDs make guessing harder, but authorization still decides whether the request succeeds.
Send the first prompt:
Create an Astro server application with HTMX and Alpine.js.
Implement the proposed schema with versioned SQL migrations.
Add two fixture owners with separate records and development sessions.
Keep all database access in server modules.
Document the migration, seed and test commands in the README.
Do not generate external service integrations.
Run the migration against an empty test database. Seed both owners, stop the process and start it again. Check that each record still exists. Then run the migration command again and confirm that already-applied migrations are skipped rather than replayed.
Step 2 implement the domain rule before the layout
Save the nutrition values used by each diary entry. Editing the food library should affect future additions while keeping past totals explainable. Store a local diary date separately from creation time.
Use this acceptance fixture:
Create oats with 150 calories per serving. Log two servings for 2026-11-17 and expect 300 calories. Change the food definition to 160 calories. The original entry stays at 300 until the owner explicitly edits that entry.
Keep that fixture beside the domain function as a readable test. It should call the same code as the server mutation. A test that only reproduces a calculation in a second function cannot catch a defect in the actual save path.
Implement the domain rule and fixture described above.
Validate all fields on the server before opening the transaction.
Reject invalid changes without altering the current saved record.
Return field errors alongside the attempted values.
Test successful writes, invalid inputs and transaction rollback.
After this step, inspect saved rows directly. Confirm the expected state, values and revision. Simulate a database error after the first write in a multi-row operation. Either all required records should commit or all should roll back. Document the transaction guarantees of the selected SQL driver.
Calculate diary totals from saved serving values
Keep the initial food library manual. Enter a food name, a serving label and calories for that serving from a label you can inspect. This avoids pretending the app has a licensed nutrition database. Include the source text or an optional note so the owner knows where their entry came from.
Serving labels need a clear quantity. “One bowl” means little after you switch bowls. Prefer a label such as “40 g dry oats” and store how many servings the diary entry represents. Make the field accept only positive quantities within a documented range.
| Food fixture | Servings | Saved calories |
|---|---|---|
| Oats, 150 per serving | 2 | 300 |
| Milk, 100 per serving | 0.5 | 50 |
| Total for selected date | 350 | |
| Oats definition changes later | Original day remains 350 |
Use scaled integers or a decimal library for fractional quantities. Choose a rounding rule for the displayed total and apply it consistently. Keep sufficient precision in the entry snapshot to avoid a visible total that differs from summing the displayed rows.
Add the oats and milk fixture to the diary tests.
Keep serving quantity and nutrition snapshot on each entry.
Group totals by the entry's explicit local diary date.
Editing a food changes future entries only.
Require an explicit entry edit to recalculate a historical snapshot.
Reject negative quantities, invalid dates and non-finite numbers.
Let the owner choose the diary date directly. They may record yesterday’s breakfast after midnight. Save the creation timestamp for history, but avoid changing the diary date when they travel or change their account timezone. A daily report reads the selected date field.
A deleted food definition also needs a policy. Archive it so old entries retain a readable reference, while new-entry search hides archived foods by default. Keep the snapshot name and serving label with historical entries so an export can stand alone.
Check the diary with no entries. Show zero recorded calories and an add action. Keep this phrasing descriptive: an empty diary means nothing was recorded. It does not establish what the person ate. This tool records values the owner enters and provides no dietary recommendations.
Step 3 build the create and detail forms
Start with ordinary HTML forms that submit to server routes. Make every field label explicit and show the expected unit beside numeric inputs. A blank field and a zero value may have different meanings; decide which fields permit either before accepting submissions.
The form posts data, the server validates it, and a successful response redirects to the detail page. The detail page reads committed rows. HTMX can shorten that round trip later, but the first version should work with JavaScript disabled.
Build create, list and detail routes for the saved records.
Use accessible labels and field-level validation messages.
Preserve submitted values when validation or persistence fails.
Redirect after successful ordinary form submissions.
Show an empty list with one create action and no sample production data.
Create the fixture through the interface. Refresh its detail page, open the list and follow the record link back. Compare displayed values with the saved rows. Enter angle brackets in a text field and confirm they render as plain text. Try a very long title and check that the server enforces the documented limit.
Step 4 protect edits from retries and conflicts
Two browser tabs can load the same revision. The first saves a valid change. The second must receive a conflict instead of silently replacing that change. Include the expected revision in the form and match it inside the mutation query.
A retry needs another rule. Generate a submission key when displaying a new operation, then retain it through recoverable failures. Store that key with its result. When a response is lost after commit, retrying the key returns the original result instead of creating another operation.
Add expected-revision checks to every edit.
Persist request keys for operations that create records or decisions.
Return a conflict with the current saved revision and attempted input.
Keep request-key lookup scoped to the authenticated owner.
Test a lost response followed by a retry with the same key.
Open the same record in two tabs and perform the stale edit sequence. The newer data must survive. Then submit the same create payload twice with one key and count the records. Repeat with a different owner’s session: no saved result or private field should leak through the retry response.
| Request | Expected outcome |
|---|---|
| Valid current revision | Saved result with a new revision |
| Older revision | Conflict and retained input |
| Repeated request key | Original result |
| Wrong owner | No private record contents |
| Failed transaction | Previous state remains |
Step 5 connect the useful views
A secondary view should derive from saved records. Keep its filters in the URL where practical so a reload preserves the view. Include a clear way to remove the filters. An empty filtered result should explain that records may exist outside the current selection.
Input → authorized validation → transaction → saved rows
↓
detail, list and export
Failure → retain input and show a retry action
For this build, the useful outcome is a private food diary with daily totals. Keep labels consistent between the detail view and list. A change that appears successful in a local preview should display a pending indicator until the server returns its committed result. On failure, restore the saved presentation while retaining the attempted value for correction.
Ask the agent to add keyboard navigation and a small-screen layout. Use the interface at a narrow width, tab through the controls, and activate the main action without a mouse. Check long titles and validation text so they remain readable without covering the save button.
Step 6 export records and prove restoration
Export stable identifiers and a schema version. Include the fields needed to reconstruct ownership relationships and history. Describe whether archived records are included. A CSV can help with inspection, but JSON is usually easier for restoring related records without losing types.
Add an authenticated JSON export with a schema version.
Write a restore command targeting an empty development database.
Validate the whole archive before inserting any records.
Refuse duplicate identifiers and missing parent references.
Compare restored records with the exported fixture.
Download an export as the first owner. Confirm that the second owner’s records are absent. Restore into a fresh database, sign in and open the restored detail page. Check the domain fixture again. Count records, compare identifiers and inspect a historical value rather than relying on a success message from the importer.
Keep the original export until the restored application passes these checks. If import fails midway, roll back the operation and report which record failed without printing private contents into shared logs. Never test restoration by overwriting the only production database.
Step 7 deploy the server and its storage together
A static site build can display pages, but these mutations require a server runtime. For Cloudflare, configure the current Astro adapter and bind D1 to the server routes. For a Node deployment, verify durable storage or connect the hosted database before serving traffic. Put secret values in the host’s secret settings.
Create a staging database and apply migrations there first. Seed fictional records, deploy the app and repeat the fixture through the public staging URL. Verify that sessions use secure cookies and state-changing forms reject cross-site requests. Disable any development session shortcuts before production.
Document staging and production deployment for the chosen host.
List required secret names without including secret values.
Add a health route that reveals no records or credentials.
Document backup, restore and migration rollback procedures.
Run the acceptance fixture against staging before production.
Use separate database bindings for staging and production. Check the actual binding after deployment by creating a fictional staging record and confirming it never appears in production. Test expired sessions by opening an edit form, expiring the session, then submitting. The response should ask for sign-in while explaining how to preserve unsaved input.
Handle the failures you will see first
A missing record should show a useful unavailable page with a route back to the list. An empty workspace should offer creation. A database outage should show a recoverable error and a request identifier, with details confined to server logs. Keep private record contents out of those logs.
Test a failed export and a rejected stale edit separately. A successful page load says little about either operation. Check other views after every important mutation: the list, detail page and downloaded export should agree about the committed result.
A basic prototype covers one owner’s happy path. A maintained version adds authorization tests, conflict handling and tested restoration. Replacing the whole commercial product adds support and compatibility obligations far beyond this scope. Finish the fixture and export before extending the feature list.
Use the scope article and prompt article when changing the build request. The Trello guide offers another example of a saved workflow with ordered records.