Diastora
Photograph the display of a blood pressure monitor you already own, check the numbers a vision model copied off it, and keep a morning and evening log. The stages, the averages, a seven day home series and a one page sheet for the clinic are all worked out on the phone, every time, from the readings you confirmed.
Flutter and Material 3Light and dark Laravel key proxy includedLanding page included
AI-assisted tools were used to help write and review the source code and the documentation of this item. The author reviewed, tested and finalized every part before release. The photographs are licensed Pexels stock images, each listed with its photographer in assets/images/clinic/LICENSES.txt; the illustrations, including the six sample display graphics, are SVG drawings written as code for this item; no image-generation model was used. The app also has an AI-powered feature; the last chapter, AI disclosure, says what it does.
Reading a display bills the chosen AI provider (OpenAI, Anthropic or Google Gemini) for every request, whether it runs on a key pasted in Settings or through the included key proxy on your own server; push notifications and analytics need their own Firebase project once switched on. None of it is included in the purchase price.
1What it reads, what it works out
Diastora is a Flutter app for keeping a blood pressure log from a photograph. The person photographs the display of a blood pressure monitor they already own; a vision model copies the three printed numbers; the person checks every digit the model was unsure of before the reading is saved. The stage, the morning and evening averages, a seven day home series and a one page sheet for the clinic are all worked out afterward, on the phone, by a small Dart engine that never touches the network.
The download holds three folders. diastora_ai_app/ is the Flutter app (7
named routes, 102 tests). backend/ is a Laravel key proxy with a Filament admin
panel: it keeps the AI provider keys on your server, runs only this app's two reading jobs, meters
each phone and keeps the photos people chose to keep (121 tests of its own,
10 API routes). landing/ is a one page product website already in the
app's colors.
One idea is worth knowing before you read on: the model only transcribes. It never decides a stage, never averages two readings and never gives advice. Every one of those is a plain calculation over numbers the person confirmed, so it gives the same answer offline, in the tests and on every AI route.

The first run

How the parts fit together
What talks to what, and over which line. Every arrow is a network call; anything without an arrow stays on the phone.
+--------------------------------------------+
| diastora_ai_app/ (Flutter) |
| iOS and Android app |
| keeps its own data on the phone |
+--------------------------------------------+
| HTTPS, JSON under /api, Bearer token
v
+--------------------------------------------+
| Laravel key proxy (backend/) |
| holds the AI provider keys |
| per-device limits and usage |
| admin panel at /admin |
+--------------------------------------------+
|
+--> MySQL / MariaDB (or SQLite to try it)
+--> OpenAI / Anthropic / Google Gemini (your keys)
+--> Firebase Cloud Messaging (push)
The app also talks straight to:
- Firebase (push, analytics and crash reports)
- an AI provider directly, when the person types their own key into Settings
Out of the box the app runs on sample data with no server at all; giving it the address of your copy of backend/ is what switches the server arrows on. The server never calls a phone first; push messages reach it through Firebase.
2Run it in five minutes
You need Flutter on your machine (any current stable release; flutter doctor should be
clean) and a simulator, an emulator or a phone. Nothing else: the app opens in demo mode on six
drawn sample displays, so no key, server or network is needed for a first look.
From the diastora_ai_app folder of the download:
flutter pub get
flutter run # pick a simulator or a connected phone
The app opens straight on the Read tab - there is no account and nothing to sign in to. Tap Read the display, choose one of the six drawn sample displays, and watch the three numbers power up in the display well; the lower number on the first sample is underlined and waits for you to confirm it. Save to log drops a stage tag onto the reading and files it in the Log tab.
To check the project itself:
flutter analyze # expect: No issues found!
flutter test # expect: All tests passed! (102 tests)
To read your own display, turn demo mode off in Settings and open Who reads the photo: paste a Gemini, OpenAI or Claude key, or point the app at the included server (chapter "Setting up the admin panel, step by step").
3No command line needed
Everything in this manual can be done without typing a command.
- Android Studio or IntelliJ: File → Open the
diastora_ai_appfolder, accept "Get dependencies" in the banner, choose a device in the toolbar and press Run. Build → Flutter → Build APK / App Bundle makes a release build. - VS Code with the Flutter extension: File → Open Folder, then Run → Start Debugging; the device picker is in the status bar.
- Xcode (for an iPhone build): open
ios/Runner.xcworkspaceafter one "Get dependencies" in an IDE, choose the Runner target and press Run. - The server goes online through a hosting control panel (cPanel, Plesk) and phpMyAdmin; the section Shared hosting with no terminal in the production chapter has the seven steps.
4A glossary of the commands this manual uses
This glossary lists every command the manual uses. Commands that destroy data say so in bold.
| Command | What it does |
|---|---|
flutter pub get | Downloads the app's packages. Run it once after unzipping and after editing pubspec.yaml. |
flutter run | Builds and starts the app on the chosen device, in debug mode. |
flutter analyze | Static checks over the whole project. It should say No issues found! |
flutter test | Runs the 102 tests: the stage, average, protocol and reminder engines, the backup round trip, the two AI jobs against the server's prompts, the screens. |
flutter run --dart-define=API_BASE_URL=https://<your-server> | Starts the app pointed at your key proxy: the server route is chosen and demo mode starts off. |
flutter build appbundle --dart-define=API_BASE_URL=https://<your-server> | The Android App Bundle for Google Play, in build/app/outputs/bundle/release/; signed with your upload key from android/key.properties, without which it stops (chapter Demo builds and release builds). |
flutter build ipa --dart-define=API_BASE_URL=https://<your-server> | The iOS archive for App Store Connect, in build/ios/ipa/. |
dart run flutter_launcher_icons | Rebuilds every launcher icon from assets/icon/ after you replace the artwork. |
composer install | Installs the server's PHP packages (in backend/). |
./install.sh | First-time server setup in one go: packages, .env, app key, database, sample data. |
php artisan migrate | Adds any new tables to your database. Additive: it never drops a table that holds data. |
php artisan demo:seed | Fills the panel with sample devices and usage so it is not empty on day one. |
php artisan demo:clear | Removes the sample devices and usage; asks before it deletes (add --force to skip the question). |
php artisan migrate:fresh --seed | Deletes every table and builds them again with sample data. Every device, usage row, setting and kept photo record is gone, and there is no confirmation and no undo. Only for a test copy. |
docker compose up -d | Starts the server, its database and its scheduler in Docker. |
docker compose down -v | Stops Docker and deletes its database volume: everything stored in it is gone. Without -v the data is kept. |
composer test | Runs the server's 121 tests on a throwaway database. |
5Where the pieces live
diastora_ai_app/
lib/
main.dart settings first, feature packs, the services, start-up
app/core/ theme, colors, fonts, shared widgets
widgets/display_well.dart the inset reading panel and its power-up animation
widgets/stage_tag.dart the arrow-point stage label
widgets/twin_trace.dart the two-line trend chart and its target rail
widgets/cuff_band.dart the cuff record card
widgets/tally_bar.dart the seven day protocol strip
widgets/chart_paper.dart the clinic sheet's paper
app/data/
engines/ stages, averages, the protocol, cuff sizing, reminders, the sheet; plain Dart
providers/ the two AI jobs: prompt, schema, demo answer
models/ the reading, its context and the monitor
mock/sample_data.dart the sample readings, monitors and drawn displays; screens never import it
services/ stores, the AI route, photos, reminders, backup
app/modules/ one folder per screen
l10n/ English, Spanish, Arabic
assets/images/clinic/ the sample photographs (Pexels) and LICENSES.txt
assets/images/demo_displays/ the six drawn sample displays and their SVG sources
packages/ the feature packs and the AI routes package
backend/ the Laravel key proxy and admin panel
landing/ the product website
The rule that keeps it easy to change: no screen in app/modules imports a store, an engine
or the sample data. Screens ask ReadingService and ReaderService, and those two
are the only places that know where data lives and which AI route answers.
6Read: today's two slots
The first tab. Today's two slots sit at the top, each counting toward two: Morning @n of 2 and Evening @n of 2 fill in as readings come in, and the last reading saved (its numbers, its time and its stage tag) sits underneath. A large Read the display button is the way in to a photograph; tapping the last reading opens its full detail.

Which slot a new reading falls into is not chosen by hand: the clock decides (04:00–11:59 is morning, 17:00 through 03:59 is evening, everything else is neither), the same rule the averages and the protocol tracker use. In demo mode the clock is pinned to a Wednesday morning before the day's first reading, which is why the sample always opens on an empty morning slot.
7Reading the display
Tapping Read the display opens the capture screen: the camera, the photo library, one of six drawn sample displays in demo mode, or Type the numbers in for no photo at all. Every photo is resized as it is picked (long edge 14 px, JPEG quality 85), which keeps it under the server's per-image limit and still large enough to make out seven-segment digits.

What comes back is never trusted outright. The job returns a confidence of high, medium or low
for each of the systolic, diastolic and pulse numbers; a number the model read as low, or
did not read at all, is underlined and opens a large number pad on a tap - every key at least
56 points, for a hand that may not be steady. Save to log
stays off until every underlined number is confirmed or corrected, and a number outside what any
cuff monitor can show (for example a diastolic reading over 200) cannot be saved either, confirmed
or not.
Below the well sit the circumstances a clinician asks about: which slot the reading belongs to (it follows the clock, and can be changed), which arm, sitting or lying down, a Took my tablets toggle and a short note. If the display itself showed a time, the app uses it instead of the moment the photo was taken, as long as it is not in the future and not more than two days old. A display's own irregular heartbeat mark, when one is shown, is carried onto the reading as a small icon and nothing more: it is shown, never interpreted or scored.

The model that reads the photograph is told, in absolute terms, to copy only what the display
shows: never to estimate a missing digit, never to sort the reading into a stage and never to add
advice. The same instruction sits on the included server as the display_read task
(backend/config/ai_tasks.php); test/proxy_tasks_sync_test.dart fails if the
two drift apart, so every route is asked the same thing.
8The log and context tags
Every reading, grouped by day with the newest day first, each row showing its time, its two numbers and its stage tag. A row of filter chips along the top narrows the list to one stage at a time - Normal is always there, and the rest follow whichever guideline is chosen in Settings, so switching from ACC/AHA to the ESC home thresholds changes the chips as well as the stage lines.

Opening a reading shows its numbers, each with a Correct a number action that reopens the same number pad the confirm step used, its photo (when it has one), its slot, arm, posture, the Took my tablets flag, its note and, when it was logged against one, the monitor. Deleting a reading also removes its photo, on the phone and, if it was ever kept there, on the server.

9Trends and averages
A twin line chart: the systolic trace above, the diastolic trace below, each point a morning (hollow) or an evening (filled) reading, joined in time order. A dashed target rail runs across both, the lower edge of the guideline's own "elevated" band, with a small flag at its right end naming the two numbers it marks. Any reading on or past that rail keeps a stage-colored outline on its point, so the chart answers "in target or not" at a glance before a single number is read.

The segmented control along the top switches the window between 7 / 30 / 90 days; a second switch splits the single trace into two colors, one for morning and one for evening, so a pattern that only shows up at one time of day is not hidden inside an average of both. Underneath, three plain figures - no ring, no bar - give the morning average, the evening average and the share of readings under the target line for the chosen window.
The averages are not a running mean kept somewhere: every time the window changes, the engine reads every reading inside it and works the three numbers out again, so changing the guideline or the window never leaves a stale figure on screen. Share with your doctor at the bottom opens the clinic sheet for the current seven day series, or for the last seven days when no series has been started.
10The seven day protocol and the clinic sheet
A seven day home series is the standard way a clinician asks for home readings ahead of a visit: two readings each morning and two each evening, for 7 days, 4 places a day and 28 in all. Start a series today on the Cuff tab opens the week; a strip of thin cells, one per place, fills in as readings are logged and leaves a hairline gap between days. A third morning reading, or one outside both slots, still goes in the log but takes no place on the strip - one extra reading never blocks the week from finishing.

The week counts as finished at 24 of its 28 places, not all of them - the European home method this follows treats one missed evening as normal rather than as a failed week. By the same method the first day is usually left out of the averages, because a first day at home tends to run high; a switch in Settings turns that back on.
Compose the clinic sheet builds one page: a header naming the period and how many readings it holds, four lines (morning average, evening average, overall, and the share under target) in the chosen guideline's own words, and underneath a table of every day's up-to-four readings. Nothing on the page is written by a model - every word comes from the app's own template and every number from the log.

Share as image turns the page into a 1080 pixel wide picture through the system share sheet; Share as CSV does the same with a plain text file, one line per reading, quoted where a note needs it. Neither share counts against anything and neither needs a network connection: the sheet is built from readings already on the phone.
11Monitors and cuff fit
The Cuff tab's upper half is the person's own monitors: each one a card with its brand and model, upper-arm or wrist, the arm circumference range printed on its cuff, and a Fits my arm check against the arm circumference entered below. Add a monitor photographs the label on the cuff or the monitor body and reads it the same way a display is read - brand, model, kind and the printed range, nothing estimated - or the details can be typed in by hand.

Typing an arm circumference in centimeters answers which cuff size fits, from the common upper-arm ranges:
| Size | Arm circumference |
|---|---|
| Small | 17–22 cm |
| Medium | 22–32 cm |
| Large | 32–42 cm |
| Extra Large | 42–50 cm |
On a shared edge the smaller size wins - a cuff at the top of its own range still closes, one at the bottom of a larger range may not - and the same arm number is checked against whatever range a monitor's own label reads or was typed in, so a mismatch between a person's arm and a specific cuff shows up on that monitor's own card.
Underneath, four checks a clinician would ask about before taking a reading - sitting quietly, both feet flat, the arm at heart height, no coffee, smoking or alcohol in the last half hour - sit above Start timer, a 5-minute countdown with a thin progress line along its top edge and nothing else moving. There is no ring, no chime: when it reaches zero the line is simply gone.

12Settings, the guideline and your data
Settings opens from the gear icon on the Read tab. From the top:
- Demo mode: six drawn sample displays and three weeks of sample readings, nothing written to disk. Turning it off starts an empty log of your own.
- Reading the display: Who reads the photo opens the AI routes screen (next chapter); Guideline chooses ACC/AHA 2017 or the ESC 2024 home thresholds, which decide every stage tag and the target line; Unit switches the display between mmHg and kPa (the log itself is always kept in mmHg).
- Appearance, language, lock and usage statistics: the feature packs' switches.
- Keep photos on the server: off until switched on (chapter "Where readings and photos are kept").
- Leave out day one: whether a finished seven day series drops its first day from the averages.
- Your data: export a backup, restore one, copy every reading as CSV, delete everything.

About, reached from Settings, explains in plain words what the app reads, what it works out on the phone and what it does not do - the same three-part answer this manual gives at length.
13AI routes and keys
Four routes can answer "what do these digits say": Google Gemini, OpenAI and Anthropic Claude
with a key of the person's own, called directly, or the included key proxy, which holds the keys on
your server instead. Demo mode is a fifth route that answers on the phone from six fixed drawings,
without a key or a connection. AiService
(lib/app/data/services/ai_service.dart:12) picks the active one; no screen
holds an adapter of its own.

A build pointed at the included server starts on it, with Use my own key as the alternative; a build with no server configured starts on Gemini, whose free tier is enough to try the app with a key of one's own. Choosing a direct route opens a key field and a model field (empty means the route's current default, and a link to that provider's model list); the key never leaves the phone's secure storage except to the provider it belongs to.
Error handling: every failure comes back as a sentence a person can act on - no key, a key the provider refused, a model name that no longer exists, an exhausted allowance, an unreachable server, a photo too large - and every one of them leaves Type the numbers in open, because a reading does not have to come from a model at all.
Two jobs are asked, never more: display_read (the three numbers, a unit, an irregular
mark and the display's own time, each with a confidence) and cuff_label_read (the brand,
model, kind and arm range printed on a label). Each job's instruction lives once, in its own file in
lib/app/data/providers/, and is checked against the included server's own copy of the
same text by a test, so the four routes can never be asked different things.
14Morning and evening reminders
Two reminders a day, at times set in the Cuff tab (07:30 and 20:30 as shipped, each changeable with the phone's own time picker). A slot that already has both of its readings for the day is skipped for that day only - logging an evening reading at 19:50 does not bring a reminder at 20:30 the same evening - and the plan is worked out again every time a time, the on/off switch, demo mode or the log itself changes.
Turning reminders on is the one moment the notification permission is asked for; refusing it leaves the switch showing why it did nothing. Reminders are the phone's own local notifications: no server and no Firebase project is involved, and none are scheduled while demo mode is on.
15Stages and guidelines
Two published guidelines, each a table in
lib/app/data/engines/stage_tables.dart - lib/app/data/engines/stage_tables.dart:30 - of bands tested most severe first, so a reading that is high on
either number, not only both, lands in the right one:
| Stage | ACC/AHA 2017 | ESC 2024 home |
|---|---|---|
| Normal | below 120 and below 80 | below 120 and below 70 |
| Elevated | 120–129 and below 80 | 120–134 or 70–84 |
| Stage 1 | 130–139 or 80–89 | 135/85 and above (hypertension) |
| Stage 2 | 140 and above, or 90 and above | not used |
| Crisis | above 180 and/or above 120 | above 180 and/or above 120 |
StageEngine (lib/app/data/engines/stage_engine.dart:5) does
nothing but look a reading up in the chosen table - no advice, no score, and the words shown for
each stage are the guideline's own. The same table decides the target rail on the Trends chart: the
lower edge of whichever band sits just above "elevated" (130/80 for ACC/AHA, 135/85 for the ESC
home thresholds). A reading above the crisis band is shown with the guideline's own sentence and
a prompt to contact a clinician, and nothing further is calculated for it.
Nothing here calls out to a model: test/engines_test.dart pins every boundary value on
both tables (the line between elevated and stage 1, between stage 1 and stage 2, and the crisis
threshold), so a reading of exactly 130/80 or 181/121 always lands in the stage this table says it
should.
16Where readings and photos are kept
Readings and monitors are two stores in the phone's encrypted storage: the Keychain on iOS, EncryptedSharedPreferences on Android. Each is written as one versioned JSON envelope, so a later release can migrate it on first launch. Photos of a display or a cuff label are files in the app's documents folder, and a record names a photo by file name only, never by a device path.
Where photos go. A photo leaves the phone to be read, to whichever route is chosen in Settings. A copy stays on the included server only once Keep photos on the server is switched on: from then on each new photo goes up a few seconds after it is taken, under this phone's own device key, and a photo deleted on the phone is deleted there too. Turning the switch off deletes every copy already on the server.
Delete everything in Settings removes both stores and every photo on the phone, and has the server forget this install - its device key, its daily count and any kept photos - in the same action; the next reading after that registers as a new device.
17Demo mode and the sample data
Demo mode is on in a fresh install and in the Live Preview. The log is filled from
lib/app/data/mock/sample_data.dart - 42 readings from three weeks, one finished seven
day series and two monitors - and nothing is written to disk; the clock is pinned to a Wednesday
morning with the day's first reading not yet taken, so the sample reads the same on every run.
Reading in demo mode answers from the same file: each of the six drawn sample displays has the reply a live route would give, including one display read with low confidence on its lower number, for the confirm step to show. Any other photo comes back unreadable, for the person to type in by hand. Turning demo mode off in Settings makes the stores live; turning it back on sets a real log aside and brings it back once demo mode goes off again.
The six sample displays are drawings, not photographs, and show no brand, model or logo of any
real monitor. Replace the files under assets/images/demo_displays/, and the sample file
itself, with your own.
18Exporting and restoring your log
Export a backup writes one JSON file with every reading and monitor and hands it to the
share sheet, so it can go to Files, iCloud Drive, Google Drive, mail or another phone. Each store's
part is exactly what that store writes to the phone, so a round trip is byte for byte
(test/backup_service_test.dart exports, wipes, imports and compares).
Restoring a backup
Settings → Restore a backup asks where it is:
- A file on this phone opens the system file picker (Files on iOS, the document
picker on Android, both of which also reach cloud drives such as iCloud Drive or Google Drive when
set up). It offers
.jsonand.txtfiles and needs no permission on either platform. This is the usual way: save the exported file on the new phone, then pick it here. - The clipboard is the fallback for a file that only opens in another app: open it there, Select All, Copy, come back and choose this.
Either way the app first checks the text and shows how many readings it holds and when it was exported; nothing changes until Restore is pressed. A restore replaces every reading and monitor on the phone and turns demo mode off first, so the restored log is kept. A file that is not a backup, or one from another app, is refused with a sentence saying why.
Photos after a restore on a new phone. Photos are not inside the backup file: a reading names its photo and the file itself stays on the old phone. After a restore on a new phone, a missing photo shows as a plain tile wherever it would appear; nothing crashes and no reading is lost, and every number, stage and date that came from it is still there. Copies kept on the included server, for people who switched that on, stay under the old phone's device key until it is deleted on the Devices page, or until the old phone switches the option off or uses Delete everything.
Copy every reading as CSV puts one line per reading on the clipboard, with its stage under the chosen guideline, for a spreadsheet.
19Renaming the app and replacing its icon
<angle-brackets> in this manual stand for your own values.
The name. The brand is written in one file,
lib/app/core/values/app_identity.dart:9: name (shown in the
app), slug (the storage key prefix) and wordmark (the splash and onboarding
header). The name under the icon is set in two more places: android:label in
android/app/src/main/AndroidManifest.xml, and CFBundleDisplayName and
CFBundleName in ios/Runner/Info.plist.
The bundle id. Android: namespace and applicationId in
android/app/build.gradle.kts (now com.diastora.diastora_ai_app), and the
folder path of MainActivity.kt. iOS: open ios/Runner.xcworkspace, select the
Runner target, Signing & Capabilities, and change Bundle Identifier
(now com.diastora.diastoraAiApp).
The app icon.
- Make one square PNG, 1024 × 1024 px, with no transparency and no rounded corners (the stores round it themselves).
- For Android's adaptive icon, make a second 1024 × 1024 PNG with a transparent background and the mark kept inside the middle 72%, so the circular mask cannot cut it.
- Save them as
assets/icon/app_icon.pngandassets/icon/app_icon_foreground.png, and setadaptive_icon_backgroundinpubspec.yamlto your color. - Run
dart run flutter_launcher_icons: it rewrites everymipmap-*folder andios/Runner/Assets.xcassets/AppIcon.appiconset. - Delete the app from the device and install it again; launchers cache the old icon.
The splash and the onboarding header draw the same mark in code; replace its painter with your own shape.
20Fonts and colors
Three files decide the look:
lib/app/core/theme/app_colors.dart: every color, light and dark side by side. The brand (clinic indigo) has three grades - the fill for buttons and the selected tab, a bright grade for the dark theme, and a deep grade for brand-colored words on paper - and the four stage colors sit in a band of their own, so a stage tag can never be mistaken for a button. The rust accent carries exactly one meaning: a number that still needs a tap.lib/app/core/theme/app_text_theme.dart: the three families. Red Hat Display for headings and the large readings (its digits are tabular, so one number lines up under the next); Atkinson Hyperlegible, drawn for low vision, for everything else people read; Azeret Mono only on data - times, the clinic sheet's table, the CSV preview. Fonts are bundled files inassets/fonts/, never downloaded at run time; to swap one, drop the files in, update thefonts:block ofpubspec.yamland the constant here, and updateassets/fonts/LICENSES.txt.lib/app/core/widgets/app_card.dartand the painters in the same folder (display_well.dart,stage_tag.dart,twin_trace.dart,cuff_band.dart,tally_bar.dart,chart_paper.dart): the inset reading well, the stage tag's arrow point and the rest of the app's drawn shapes.
The admin panel takes the same indigo from
backend/app/Providers/Filament/AdminPanelProvider.php, and the landing page from the
:root color variables at the top of landing/index.html.

21Customizing
Changing the guideline tables, or adding your own. Both tables live in one
file, lib/app/data/engines/stage_tables.dart; nothing else in the app reads a
threshold. Add a value to Guideline, a StageTable for it (a list of bands,
most severe first, and the target pair the Trends chart draws), a line to
StageTable.of and a name to StageStyle.guidelineName; the Settings picker
and every stage tag follow from there.
Adding a context tag. The five circumstances a reading carries - slot, arm,
posture, the tablets toggle and the note - are ReadingContext
(lib/app/data/models/reading.dart:52). To add one: a field on
ReadingContext, its line in toJson / fromJson, a control on
the result screen, and a result.<name> key in the three language files. The log,
the clinic sheet's CSV and the reading detail screen read the context as a whole and pick it up
without further changes.
Changing the protocol's length, or the reminder times. The seven day series is
ProtocolTracker (lib/app/data/engines/protocol_tracker.dart:49);
its days constructor parameter and completeAt are the two numbers to
change. Reminder times are set per install in Settings (morningAt /
eveningAt in SettingsService); to change the shipped defaults, edit their
starting values in the same file.
When a model name is retired. Providers retire model names every so often; the
app then shows that the model is no longer offered, with an Open settings button. Type a
current name into that route's Model field (the screen links to each provider's model list). The
defaults are defaultModel in packages/qh_ai/lib/src/gemini_provider.dart,
openai_provider.dart and claude_provider.dart; on the server a current
model is set on the admin panel's AI proxy page.
Changing what the model is asked. Edit the instruction in the job's own file
(lib/app/data/providers/display_read_job.dart or cuff_label_read_job.dart)
and the matching entry in backend/config/ai_tasks.php; flutter test fails
until the two agree.
22What is left for you to wire up, and where the numbers live
The app runs end to end as shipped: readings, the log, trends, the clinic sheet and the reminders all work on the phone, and reading a display goes through the included server once it has a model key. A few things are deliberately left for you to connect when you publish.
Model keys on the server
The server holds the model keys; the phones never see them. Put one in
backend/.env (backend/config/companion.php:7) or paste it on the admin
panel's AI proxy page, which also picks the provider (OpenAI as shipped) and the model. Until a key
is set the server cannot read a photo, and readings are typed in by hand:
# before
AI_OPENAI_KEY=
# after
AI_OPENAI_KEY=your-openai-key
Gemini and Anthropic use AI_GEMINI_KEY and AI_ANTHROPIC_KEY.
Analytics and crash reports from Firebase
The analytics and crash-report packs stay on their no-op versions until
lib/firebase_config.dart says Firebase is set up
(lib/firebase_config.dart:18):
// before
const bool firebaseConfigured = false;
// after running `flutterfire configure`
const bool firebaseConfigured = true;
The reminders do not need Firebase: they are scheduled on the phone.
Your server address and your signing key
A release build needs the address of your server, passed at build time
(lib/main.dart:38), and an Android upload key in
android/key.properties
(android/app/build.gradle.kts:15); the steps are in
Submitting to Google Play and the App Store.
flutter build appbundle --dart-define=API_BASE_URL=https://your-server.example.com
Where the numbers live
| Constant | Where | Value |
|---|---|---|
| Accepted systolic, diastolic and pulse | lib/app/data/providers/display_read_job.dart:79 | 50–300, 30–200, 25–250 |
| Readings per slot in the seven day series | lib/app/data/engines/protocol_tracker.dart:54 | 2 |
| Readings that complete the series | lib/app/data/engines/protocol_tracker.dart:56 | 24 of 28 |
| Default reminder times | lib/app/data/services/settings_service.dart:100 | 07:30 and 20:30 |
| Longest edge of a stored photo | lib/app/data/services/photo_store.dart:33 | 1400 px |
| Photos sent per request | backend/config/companion.php:38 | 1 |
| Largest photo the server accepts | backend/config/companion.php:34 | 1.2 MB |
| API requests per network per minute | backend/app/Providers/AppServiceProvider.php:39 | 120 |
| Photo reads per phone per day | backend/app/Models/AiSetting.php:36, changeable on the admin panel | 50 |
23Rearranging the bottom tabs
The four bottom tabs are wired in three places:
lib/app/modules/main/main_controller.dart: theMainTabindexes (lib/app/modules/main/main_controller.dart:16).lib/app/modules/main/main_view.dart: theIndexedStackchildren, the_tabIdslist (the keys tests tap) and thenavItem(...)rows of the bottom bar.lib/app/modules/main/main_binding.dart: oneGet.lazyPutper tab controller.
To add a tab, add one entry in each, a tab.<name> key to the three language
files in lib/l10n/, and a glyph in
lib/app/core/widgets/tab_glyphs.dart. To remove one, take it out of all three and
renumber MainTab so the indexes stay 0, 1, 2, 3. Watch two things: an index left
pointing past the end shows an empty page, and test/app_smoke_test.dart taps the tabs
by key.
24Submitting to Google Play and the App Store
The chapter "Demo builds and release builds" covers signing the Android build with your own upload key and the two build commands; this one is the two stores' own screens.
iOS, for the App Store.
- Open
ios/Runner.xcworkspacein Xcode, select the Runner target, open the Signing & Capabilities tab, tick Automatically manage signing and choose your Team (it is None as shipped). - Check the privacy texts on the same target's
Info.plist; the app declares four:NSCameraUsageDescription(photographing a display or a cuff label),NSPhotoLibraryUsageDescription(choosing a photo from the library),NSPhotoLibraryAddUsageDescription(saving a shared clinic sheet image) andNSFaceIDUsageDescription(the lock). flutter build ipa --dart-define=API_BASE_URL=https://<your-server>, then uploadbuild/ios/ipa/*.ipawith Transporter or Xcode's Organizer, and finish the listing in App Store Connect. App Store Connect takes an.ipa; it never takes an.aab.
Android, for Google Play. Once the upload key and key.properties
are in place (the signing chapter), Play Console → your app → Production (or a testing track) →
Create new release → upload
build/app/outputs/bundle/release/app-release.aab. Google Play takes the App Bundle;
an .ipa has no meaning there.
Both stores ask for a privacy policy URL and a data safety form before they will publish; the next chapter has the sentences this item needs for those forms.
25Moving to a newer release without losing your changes
When a newer release of Diastora comes out:
- Replace
lib/app/data/engines/,lib/app/data/providers/,packages/and the server'sapp/,database/migrations/androutes/. - Keep yours:
app_colors.dart,app_text_theme.dart,app_identity.dart,feature_config.dart,lib/l10n/if you changed wording,assets/, and on the server.env,config/panel.phpandconfig/ai_tasks.phpif you changed a prompt. - Database:
php artisan migrateonly adds tables and columns; check the new files indatabase/migrations/for anydroporrenamebefore you run it on a live install, and take a database export first. - Customizations survive if they stay in the files above. Compare the two releases with a diff tool before copying, and copy folder by folder rather than over the whole project.
Phones keep their data across an update: each store is versioned and migrated on first launch.
If a migration fails halfway
MySQL and MariaDB commit every table change as it runs, so a migration that stops in the middle cannot roll itself back: some of its changes are in, the rest are not, and Laravel has not recorded it as run. Back up before every update so this is never more than an inconvenience:
mysqldump --single-transaction -u USER -p DATABASE > before-update.sql
- Put the site in maintenance mode so nothing writes meanwhile:
php artisan down. - Find where it stopped.
php artisan migrate:statuslists every migration as Ran or Pending; the first Pending one is the one that failed. The error itself is at the end ofstorage/logs/laravel.log. - Open that migration file and compare it with the database: a table it creates that already exists, or a column it adds that is already there, is what it got through before it stopped.
- Either remove those half-made pieces by hand and run
php artisan migrate --forceagain, or restore the backup (mysql -u USER -p DATABASE < before-update.sql), fix the cause (most often a full disk, a timeout or a missing database permission) and run the update again. php artisan upwhenmigrate:statusshows nothing pending.
Never run migrate:fresh or migrate:reset on a live server: both drop every table.
26What costs money, and whose bill it is on
Third-party services this app can talk to, and who pays:
- AI providers (Google Gemini, OpenAI, Anthropic): every display or label read is a billed request on the key that makes it, the person's own or the one on your server. Gemini has a free tier through AI Studio.
- Your server for the key proxy: any PHP 8.4 host or a Docker machine.
- Firebase (push, analytics): free tiers, then billed by Google.
- Apple Developer Program and Google Play Console: needed to publish.
Each of them bills you directly; none is included in the purchase price.
27Troubleshooting
Each row starts with what you will actually see, then why and what to check next. Questions that are not errors are in the chapter Questions buyers ask first.
| What you see | Why | What to check next |
|---|---|---|
| Add a key in Settings | The chosen route has no key (demo mode is off, or this is a release build) | Settings → Who reads the photo: paste a key, or choose the included server; a demo build can also switch demo mode back on |
| Did not accept this key | The key was cut short when pasted, revoked, or belongs to another provider | Paste it again; check it is active in the provider's console |
| Allowance used up | The provider account has no credit or hit its rate limit | The provider's billing page. A new OpenAI or Anthropic key needs a payment method before it reads anything |
| The model is no longer offered | The provider retired that model name | Type a current one in that route's Model field (chapter "Customizing") |
| The server could not be reached | Wrong address, the site is down, or plain http on a phone | Check the connection, open https://your-server.com/api/version in the phone's browser |
| This phone can no longer use the server | The phone was blocked on the Devices page | Admin panel → Devices: unblock it |
| Today's photo readings are used up | The phone, or the whole server, reached a daily limit | Admin panel → AI proxy for the limits, Usage for who used them |
| That photo is too large to send | The photo is over the server's per-request size | Raise AI_MAX_IMAGE_BYTES in .env, or take the photo a little closer to the display |
| A reading looks like the wrong stage | The guideline, not the number, changed | Check Settings → Guideline: the ESC home thresholds and ACC/AHA 2017 sort some readings differently |
| No reminders arrive | Notifications are blocked for the app, the switch in the Cuff tab is off, or demo mode is on (it never schedules any) | The phone's notification settings for the app, then the Cuff tab's reminder switch |
Server: a blank page at the domain; storage/logs/laravel.log says Permission denied | storage/ and bootstrap/cache/ are not writable | Set both to 775 in the file manager, or chmod -R 775 storage bootstrap/cache |
| Server: a blank page, the log is empty | The domain points at backend, not backend/public | The document root in your host's domain settings |
Server: 500; the log says No application encryption key has been specified. | APP_KEY is empty | php artisan key:generate, on a first install only |
28What the included server does
backend/ is a Laravel application with a Filament admin panel whose job is to read
a display for phones that have no AI key of their own. It keeps the OpenAI, Anthropic and Gemini
keys on your server; a phone registers a random device key once and gets a token back, so there are
no accounts to make for reading. It runs only the two jobs in config/ai_tasks.php, with
the instruction fixed on the server: a phone can send a job's name and a photograph, but it cannot
send a system prompt, pick a provider or pick a model - the keys stay yours whatever gets into an
app's memory.
It also sets a daily photo allowance per phone, keeps the photo copies of people who switch on Keep photos on the server (stored per device, with thumbnails in the panel) and publishes app-update notices. There are no user accounts on it, only the admin who opens the panel. Without it the app still reads a display with a key of its own, and runs in demo mode with no key at all.




Connecting the app, two ways:
- At build time:
flutter run --dart-define=API_BASE_URL=https://<your-server>(or the same flag onflutter build). The server route is then chosen and demo mode starts off. - Without the command line: edit the default value of
apiBaseUrlinlib/app/core/values/feature_config.dart:19to'https://<your-server>'before you build.
HTTP or HTTPS. Use https with a valid certificate (Let's Encrypt is free) for
anything a real phone talks to: the device token travels in an Authorization header.
Android refuses plain http by default (cleartext traffic), and so does iOS (App Transport
Security); this project keeps both defaults. For a local test against
http://10.0.2.2:8000 only, allow cleartext in a debug
network_security_config.xml on Android and add an NSAppTransportSecurity
exception in ios/Runner/Info.plist; never ship either.
29Getting the server online
Requirements: PHP 8.4 or later (Laravel 13 needs it; many hosting plans still
default to 8.2, so check before you buy), the extensions Laravel lists (including
fileinfo), MySQL 8 or MariaDB 10.6, and Composer; or any machine with Docker.
A. Docker, from backend/:
# first edit .env.docker: APP_URL, and the AI keys (or set them later in the panel)
docker compose up -d --build # the server, MySQL and the scheduler
The first start copies .env.docker into a volume as the live .env,
writes the app key, creates the tables and loads the sample devices; later starts keep all of it.
Editing .env.docker after that changes nothing: backend/docs/DEPLOY.md
shows how to edit the live .env in the volume. Do not run key:generate
yourself: a new key cannot read the provider keys already saved in the panel.
B. A server with a terminal: ./install.sh checks the PHP version,
installs the packages, writes .env and the app key, creates the tables, loads the
sample devices and makes storage/ writable. Then point your web server's document root
at backend/public.
C. Shared hosting with no terminal (cPanel, Plesk): run the one-time setup from your own computer against the host's database, then upload the folder. The seven steps are in Shared hosting with no terminal, in the chapter on running the server in production.
Everyday tasks without a terminal:
| Task | How |
|---|---|
| Back up the database | phpMyAdmin → the database → Export → Go; restore with Import. |
| Change a provider key or the daily limit | Admin panel → AI proxy. |
| Block a phone | Admin panel → Devices → Block on that row. |
| See what was read | Admin panel → Usage, filtered by device or job. |
| Delete kept photos | Admin panel → Pictures; or the person turns the switch off. |
| Run the scheduler | One cron line in the panel: * * * * * php <path-to-backend>/artisan schedule:run. |
Before going live, sign in once as the seeded admin (the panel asks for a new password before
anything else opens), keep APP_DEBUG=false, and remove the sample devices with
php artisan demo:clear. The full walkthrough, with the same steps, is in
backend/docs/DEPLOY.md.
30Setting up the admin panel, step by step
The admin panel is part of the Laravel application in backend/. These are the
steps for a server where you run the commands yourself; install.sh does steps 2 to 6
in one go, and the Docker route at the end needs none of them.
1. What the server needs
- PHP 8.4.1 or newer with the
pdo_mysql(orpdo_sqlite),mbstring,openssl,fileinfo,zipandintlextensions - Composer
- A database: MySQL 8 / MariaDB 10.6 or newer for a live server, or SQLite for a quick look
2. Create the environment file
cd backend
cp .env.example .env
Set APP_URL to the address the panel will be served from, and
APP_TIMEZONE to your own timezone.
3. Configure the database
MySQL or MariaDB. Create an empty database and a user that owns it,
then put them in .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=diastora
DB_USERNAME=diastora
DB_PASSWORD=choose-a-strong-password
SQLite. Leave DB_CONNECTION=sqlite as shipped and create the
file it points at:
touch database/database.sqlite
4. Install the dependencies and generate the app key
Install with the development packages included: the demo data in step 6 is generated
with them. Once the demo data is cleared you can reinstall with --no-dev.
composer install --optimize-autoloader
php artisan key:generate
Generate the key on the first install only. The server encrypts the secrets it stores with it, so a new key on a live server makes them unreadable; install.sh skips this step when .env already has a key.
5. Create the tables
php artisan migrate --force
Run it again after every update you install; it only adds what is new and never drops your data.
6. Load the demo data, once
php artisan demo:seed
This creates the admin account below and the sample records on a fresh install,
and does nothing on every later run. When you are ready to go live, Settings →
Clear demo data in the panel (or php artisan demo:clear) removes every
seeded record and leaves yours; running the installer again afterwards does not bring
them back. The admin account is kept so you can still sign in; it asks for a new password
at the first sign-in.
7. Serve it and sign in
Point your web server's document root at backend/public (docs/DEPLOY.md
in the back end covers web servers and shared hosting), or try it locally:
php artisan serve
Open /admin and sign in:
| Password | |
|---|---|
admin@diastora.test | password |
The panel then asks for a new password and opens nothing else until it has one, so the published password never survives the first sign-in. Or create your own admin account under Users and delete this one.
8. Scheduled jobs
Notifications you schedule for later are sent by Laravel's scheduler. Add one cron line on the server:
* * * * * cd /path/to/backend && php artisan schedule:run >> /dev/null 2>&1
Or: Docker
With Docker installed, steps 1 to 8 are one command. It starts MySQL, creates the tables, loads the demo data on the very first start only and runs the scheduler:
cd backend
docker compose up -d --build
The panel is then at http://localhost:8000/admin, with the same login.
docker compose down keeps your data; docker compose down -v deletes
it and the next start loads the demo data again.
Port 8000 speaks plain HTTP and is bound to 127.0.0.1: only this computer
(and the Android emulator, as 10.0.2.2) reaches it. Before phones can, put it
behind a web server that serves HTTPS with a certificate (Nginx, Caddy or your host's
proxy) and forwards to http://127.0.0.1:8000, and set APP_URL to the
https:// address.
31API reference
Every endpoint the app uses, in one table. There is one kind of token: a device
token from POST /api/ai/device, for reading and photos. There are no user
accounts.
Authentication headers: send Authorization: Bearer <token> and
Accept: application/json on every call; Accept-Language picks the
language of error messages.
| Method | Path | Auth | Body | Returns |
|---|---|---|---|---|
POST | /api/ai/device | none | device_key, platform, app_version | token, device |
GET | /api/ai/status | device token | none | providers available, today's requests, the daily limit |
POST | /api/ai/chat | device token | task, input, images[] (mime, data) | text, provider, model, usage |
DELETE | /api/ai/device | device token | none | 204; the device and its token are removed |
GET | /api/media | device token | none | kept photos: name, sha256, size; totals |
PUT | /api/media/{name} | device token | the image bytes | 201 or 200 |
GET | /api/media/{name} | device token | none | the image |
DELETE | /api/media/{name} | device token | none | 204 |
GET | /api/version | none | none | latest and minimum app versions, message, store links |
Register this phone
POST /api/ai/device
{"device_key": "k3v9q2m8x1c7r5t0b4n6y8w2e1u3i9o7", "platform": "ios", "app_version": "1.0.0"}
201 {"token": "12|8fQe...", "device": {"id": 7, "platform": "ios"}}
Read a display
POST /api/ai/chat
Authorization: Bearer 12|8fQe...
{"task": "display_read", "input": "unit_hint: mmHg",
"images": [{"mime": "image/jpeg", "data": "<base64>"}]}
200 {"provider": "gemini", "model": "gemini-2.5-flash",
"text": "{\"systolic\": 128, \"diastolic\": 82, \"pulse\": 68, \"unit\": \"mmHg\", ...}",
"usage": {"prompt_tokens": 1180, "completion_tokens": 96}}
Today's allowance
GET /api/ai/status
Authorization: Bearer 12|8fQe...
200 {"enabled": true, "providers": {"gemini": {"available": true}, ...},
"requests_today": 2, "daily_request_limit": 50}
A task the server does not run, a second photo on either job, or free text over the limit is answered with 422; a phone over its daily limit with 429.
Error responses
Every error is JSON with a message; a 422 adds errors, one list
per field. These are the bodies the included server sends:
401
No token, or a revoked one: GET /api/ai/status without Authorization.
HTTP/1.1 401 Unauthorized
{"message": "Unauthenticated."}
422
A field is missing or wrong: POST /api/ai/device with an empty body.
HTTP/1.1 422 Unprocessable Content
{"message": "The device key field is required.",
"errors": {"device_key": ["The device key field is required."]}}
429
Too many requests: POST /api/ai/device allows 10 a minute from one network. Retry-After says how many seconds to wait.
HTTP/1.1 429 Too Many Requests
Retry-After: 58
{"message": "Too Many Attempts."}
Open-source licenses
The server is built on these packages, at the versions composer.lock pins. Each
license allows use and redistribution inside a commercial product, with no fee per seat or per
site for you or your customers. Their full texts are in vendor/<package>/LICENSE
after composer install.
| Package | Version | License |
|---|---|---|
filament/filament | v5.7.8 | MIT |
kreait/firebase-php | 8.4.2 | MIT |
laravel/framework | v13.30.1 | MIT |
laravel/sanctum | v4.3.2 | MIT |
laravel/tinker | v3.0.2 | MIT |
32The environment file, key by key
Every key in backend/.env.example, its default, and what it decides. Shared-host owners can check a configuration against this table.
| Key | Default | In the file | What it decides |
|---|---|---|---|
APP_NAME | Diastora | set | Name shown by the panel. |
APP_ENV | local | set | production on a live server, local on your machine. |
APP_KEY | empty | set | Encryption key; php artisan key:generate fills it. Never change it on a live install. |
APP_DEBUG | false | set | Detailed error pages; false on a live server. |
TRUSTED_PROXIES | empty | set | Set when the server sits behind a proxy or load balancer, so per-network limits see real addresses. Comma-separated, no spaces, for example 10.0.0.5,10.0.1.0/24; Cloudflare and * are under Behind a proxy or load balancer in the production chapter. |
APP_URL | http://localhost | set | The server's public address, with https. |
APP_TIMEZONE | UTC | set | Time zone for daily limits and logs. |
APP_LOCALE | en | set | Default language of server messages. |
APP_FALLBACK_LOCALE | en | set | Language used when a translation is missing. |
APP_FAKER_LOCALE | en_US | set | Locale of generated sample data. |
APP_MAINTENANCE_DRIVER | file | set | How maintenance mode is stored. |
APP_MAINTENANCE_STORE | database | commented out | Cache store for maintenance mode, when the driver is cache. |
PHP_CLI_SERVER_WORKERS | 4 | commented out | Workers for php artisan serve on your machine. |
BCRYPT_ROUNDS | 12 | set | Cost of password hashing. |
LOG_CHANNEL | stack | set | Where logs go. |
LOG_STACK | single | set | Channels in the log stack. |
LOG_DEPRECATIONS_CHANNEL | null | set | Where deprecation notices go. |
LOG_LEVEL | debug | set | Lowest level logged. |
DB_CONNECTION | sqlite | set | mysql on a live server; sqlite for a quick local try. |
DB_HOST | 127.0.0.1 | commented out | Database host. |
DB_PORT | 3306 | commented out | Database port. |
DB_DATABASE | laravel | commented out | Database name. |
DB_USERNAME | root | commented out | Database user. |
DB_PASSWORD | empty | commented out | Database password. |
SESSION_DRIVER | database | set | Where panel sessions are kept. |
SESSION_LIFETIME | 120 | set | Minutes before a panel session expires. |
SESSION_ENCRYPT | false | set | Encrypt the panel's session data. |
SESSION_PATH | / | set | Cookie path. |
SESSION_DOMAIN | null | set | Cookie domain. |
BROADCAST_CONNECTION | log | set | Broadcast driver; unused by this app. |
FILESYSTEM_DISK | local | set | Disk for kept photos (local by default). |
QUEUE_CONNECTION | database | set | Queue for scheduled work; database works everywhere. |
CACHE_STORE | database | set | Cache for limits and locks. |
CACHE_PREFIX | empty | commented out | Prefix for cache keys. |
MEMCACHED_HOST | 127.0.0.1 | set | Memcached host, if used. |
REDIS_CLIENT | phpredis | set | Redis client, if used. |
REDIS_HOST | 127.0.0.1 | set | Redis host. |
REDIS_PASSWORD | null | set | Redis password. |
REDIS_PORT | 6379 | set | Redis port. |
MAIL_MAILER | log | set | How email is sent; log writes it to the log file instead of sending, so a fresh install never errors for lack of SMTP. |
MAIL_SCHEME | null | set | smtp or smtps. |
MAIL_HOST | 127.0.0.1 | set | SMTP host of your email provider. |
MAIL_PORT | 2525 | set | SMTP port. |
MAIL_USERNAME | null | set | SMTP user. |
MAIL_PASSWORD | null | set | SMTP password. |
MAIL_FROM_ADDRESS | "hello@example.com" | set | Sender address of the mail this server sends. |
MAIL_FROM_NAME | "${APP_NAME}" | set | Sender name. |
AWS_ACCESS_KEY_ID | empty | set | S3 key, if photos are kept on S3. |
AWS_SECRET_ACCESS_KEY | empty | set | S3 secret. |
AWS_DEFAULT_REGION | us-east-1 | set | S3 region. |
AWS_BUCKET | empty | set | S3 bucket. |
AWS_USE_PATH_STYLE_ENDPOINT | false | set | Path-style S3 addresses, for S3-compatible stores. |
APP_LATEST_VERSION | 1.0.0 | set | Newest app version; older apps are offered an update. |
APP_MINIMUM_VERSION | 1.0.0 | set | Oldest version allowed; older apps must update. |
APP_UPDATE_MESSAGE | empty | set | Text of the update prompt. |
APP_STORE_URL_ANDROID | empty | set | Where the Android prompt sends people. |
APP_STORE_URL_IOS | empty | set | Where the iOS prompt sends people. |
MEDIA_FILE_MAX_BYTES | 2097152 | set | Largest single kept photo. |
MEDIA_MAX_TOTAL_BYTES | 52428800 | set | Most bytes of photos kept per device. |
MEDIA_MAX_SERVER_BYTES | 5368709120 | set | Most bytes of photos on the whole server. |
FIREBASE_CREDENTIALS | storage/app/firebase-service-account.json | set | Path to the service account JSON used to send push. |
AI_OPENAI_KEY | empty | set | OpenAI key; a key saved in the panel wins. |
AI_ANTHROPIC_KEY | empty | set | Anthropic key. |
AI_GEMINI_KEY | empty | set | Gemini key. |
AI_TIMEOUT_SECONDS | 90 | commented out | Seconds before a provider call gives up. |
AI_MAX_IMAGES | 1 | commented out | Most photos per request (1: a display or a label is always one photo). |
AI_MAX_IMAGE_BYTES | 1258291 | commented out | Largest photo per request. |
33Feature packs
Every pack lives in packages/ inside the app folder and has its own README with the full setup. In short:
| Pack | What it does | What you set up | Its README |
|---|---|---|---|
qh_ai | Four routes to a language model, one interface, no vendor SDK | Nothing for the three key routes and demo | packages/qh_ai/README.md |
qh_analytics | Analytics behind one interface | Nothing | packages/qh_analytics/README.md |
qh_analytics_firebase | AnalyticsGateway on Firebase Analytics + Crashlytics | A Firebase project (flutterfire configure), Analytics and Crashlytics enabled in the console, firebaseConfigured = true in lib/firebase_config.dart. | packages/qh_analytics_firebase/README.md |
qh_biometric | Face ID / Touch ID / fingerprint lock behind one interface | iOS: NSFaceIDUsageDescription in Info.plist (shipped; change the sentence) | packages/qh_biometric/README.md |
qh_image | One image widget for URLs that may be empty, slow, dead , or bundled | Nothing | packages/qh_image/README.md |
qh_l10n | Multi-language for a GetX app, without code generation | Nothing | packages/qh_l10n/README.md |
qh_push | Push notifications behind one interface | Nothing here | packages/qh_push/README.md |
qh_push_firebase | PushGateway on Firebase Cloud Messaging | A Firebase project; iOS: an APNs key in the console and the Push Notifications capability (Xcode → Signing & Capabilities → + Capability; it adds aps-environment to Runner.entitlements, which ships empty; UIBackgroundModes is shipped); Android: POST_NOTIFICATIONS (shipped). | packages/qh_push_firebase/README.md |
qh_share | The system share sheet, reduced to what an app needs | Nothing. | packages/qh_share/README.md |
qh_upgrade | Version-upgrade prompts driven by your own backend | --dart-define=API_BASE_URL=… and, on the included Laravel back end, four .env lines (latest, minimum, message, store URLs). | packages/qh_upgrade/README.md |
The feature packs live in packages/, each a small local package with one interface
and a working default, switched on in lib/app/core/values/feature_config.dart and
chosen in lib/app/data/services/feature_packs.dart.
- qh_l10n: English, Spanish and Arabic with right-to-left; add a language step by step in the chapter Adding a language.
- qh_biometric: Face ID, Touch ID or fingerprint on launch; Settings → Lock on launch.
- qh_share: the system share sheet for the clinic sheet, backups and CSV.
- qh_upgrade: optional and required update prompts from the server's
APP_*_VERSIONlines. - qh_analytics (+ Firebase): screen views, only after consent in Settings. Needs a Firebase project.
- qh_push (+ Firebase): remote push, and the local morning and evening reminders, which need no Firebase project at all.
- qh_image: bundled and remote pictures with placeholders and fallbacks.
Plus qh_ai, the four AI routes behind one adapter. Each pack's own
README.md lists its console steps.
Costs: switching on Firebase will involve a Google account, which will incur its own separate costs once a build is live.
34Store listing and health policies
Two sentences the store listing and any patient-facing copy for this item should carry exactly as written, because they are the line between "reads a display" and a medical-device claim:
Diastora is not a medical device and does not diagnose, treat, cure, or prevent any medical condition.
It reads the numbers shown on the display of a blood pressure monitor you already own; it does not take a reading itself.
A third sentence belongs wherever the item explains what the camera permission is for - on Google Play's Data safety form, in a privacy policy, or in the app's own permission rationale. It is the one place in anything written about this app where that sentence's final word is allowed at all, and only in this negative form:
The camera is used only to photograph the display of a blood pressure monitor; the app does not use the camera or any other sensor to take a measurement.
Google Play's Data safety form asks, for a health app, whether it collects health data. Diastora's own answer: the systolic, diastolic and pulse numbers a person types or confirms are health information and should be declared as such (collected, and shared with the AI provider chosen in Settings, or with your own server when the included key proxy is used); they are not shared with any analytics or advertising service, and the form's "used for app functionality" purpose applies. Photographs of a display or a cuff label should be declared the same way, with the same destination, and as deleted on request (Delete everything in Settings, which also reaches the included server).
Neither store should be told this app connects to Health Connect or HealthKit: it does not, and declaring an integration the app has none of is its own kind of rejection risk.
Device compatibility. The app has no minimum camera resolution or sensor requirement beyond what its target Android API level and iOS deployment target already assume; any phone that can run a current Flutter release can run Diastora.
35Questions buyers ask first
Do I need a server?
No. The app reads a display with a key of the user's own (OpenAI, Anthropic or Gemini, pasted in Settings), and with no key at all it runs in demo mode on six drawn sample displays. The included key proxy is for when you would rather your users never handle a key: it keeps your keys on your server, with a daily limit per phone and a usage log.
What happens offline?
The log, the stages, both averages, the seven day series and the clinic sheet all live on the phone and need no connection. Reading a new display does: offline the app says No connection. The log, trends and the clinic sheet work offline; reading a photo needs a connection.
One business or many?
There is no account and no sign-in anywhere in the app. Each phone is one person's own log; one key proxy can serve every phone that installs your app, each registering once and counted and limited on its own, and the admin panel lists them. Nothing is kept under a person's name, only under a phone's own device key.
How do I switch the demo off?
Demo mode ships on (lib/app/data/services/settings_service.dart:58). Users switch it off in Settings and then need a reading route. A release build never runs on the sample data at all (chapter Demo builds and release builds).
What does reading a display cost?
With a user's own key, their provider bills them. With the key proxy, your provider account is billed for every photo your users have read (the example in the API reference used 1,180 tokens in and 96 out; the usage log shows your real figures). The daily limit per phone on the AI proxy page caps what you can be billed.
A user moved to a new phone. Do the photos come back?
The readings do, from the backup file (Settings, Restore a backup, then pick the file). The photos are not in that file, and the app on the new phone does not download the old phone's server copies, so each missing photo shows as an empty tile until it is attached again. Photos after a restore on a new phone has what the app shows.
Why does the app read a display instead of connecting to the monitor itself?
Bluetooth and Health Connect or HealthKit integrations tie the app to specific monitor models and, on Android, pull it under Google Play's stricter health-data review. Reading a photograph works with any monitor that has a display, needs no pairing, and keeps the app's only sensor use to the one sentence in the Store listing and health policies chapter.
Locked out after Face ID or the fingerprint stopped working?
The lock only stands in the way while the phone can still check a face or a fingerprint. If the phone no longer offers one (Face ID switched off for the app, the last fingerprint removed, no passcode set), the app opens without asking. If the phone has locked biometrics after too many failed tries, unlock the phone itself once with its passcode, then tap Unlock again. The lock never deletes anything: if all else fails, re-enabling a fingerprint or Face ID in the phone's settings gets the person back in, and they can then turn Lock on launch off in the app's settings. Demo mode never locks.
What if I lose my Android keystore?
The keystore signs every Android release, and Google Play only accepts an update signed by the same key. Two habits make losing it survivable:
- Enroll in Play App Signing when you create the app (Play Console offers it on the first upload). Google then keeps the key that signs what users install; yours is only an upload key, and a lost upload key can be replaced through Play Console's App integrity page, with a request to Google support.
- Keep the
.jksfile and itskey.propertiespasswords in two places outside the project folder (a password manager and an offline copy). Never commit them.
Without Play App Signing a lost key cannot be recovered: the only way forward is a new app listing with a new package name.
Before you ship: a checklist
Publishing with the placeholder text still in the Terms or the Privacy Policy is very likely to get the app rejected by both the App Store and Google Play: both require a privacy policy that names who runs the app and how to reach them. Fill every blank and publish the two pages at a web address before you submit.
- Fill in every blank in the legal texts:
diastora_ai_app/assets/legal/terms.md: 5 blanks in [square brackets]diastora_ai_app/assets/legal/privacy.md: 7 blanks in [square brackets]
- Switch the demo off (above) and add one real record of your own once.
- Sign in once as the seeded admin, if your item runs the included server: the panel asks for a new password before anything else.
- Replace the app name, the bundle id and the icon (chapter on renaming).
- Build a release on a real phone and go through every tab once.
- Read the chapter on the services you pay for, and set up only the ones you use.
36Running the server in production
Shared hosting with no terminal: set it up from your own computer
The database tables are made by one command, and a host without a terminal cannot run it. Run it from your own computer instead, against the host's database, then upload the result. You need PHP 8.4.1 and Composer on your computer (once), and the host's file manager and database page.
- Create the database. In cPanel open MySQL Databases: create a database and a user, and add the user to the database with All privileges. Write down the three names; shared hosts put your account name in front of each one.
- Let your computer in. Open Remote MySQL (cPanel) or Remote database access
(Plesk) and add your computer's public IP address (search "what is my IP" to see it). Note the
host name the page shows for remote connections; it is often your domain, not
localhost. Some hosts do not offer remote access at all: ask their support to run step 5 for you, or use a host with a terminal. - Prepare the folder on your computer. In the
backendfolder copy.env.exampleto.envand setAPP_URL=https://<your-domain>,APP_ENV=production,APP_DEBUG=falseand the database lines with the remote host from step 2:DB_CONNECTION=mysql DB_HOST=<the remote host from step 2> DB_PORT=3306 DB_DATABASE=<account>_<database> DB_USERNAME=<account>_<user> DB_PASSWORD=<its password> - Install the packages and make the key, on your computer:
The last line copies the admin panel's scripts intocomposer install --optimize-autoloader php artisan key:generate php artisan vendor:publish --tag=livewire:assets --forcepublic/; a server with a terminal gets them from Composer on its own. - Make the tables and the demo data in the host's database, still from your computer:
If this stops with Access denied or Connection refused, step 2 is not done for the address your computer has now.php artisan migrate --force php artisan demo:seed - Point the database at the host itself. In
.envchangeDB_HOSTtolocalhost(what PHP on the host uses), then upload the wholebackendfolder,vendor/and.envincluded, next topublic_html, not inside it. - Finish in the panel. Set the domain's document root to
backend/public, choose PHP 8.4.1, makestorage/,bootstrap/cache/writable (775) in the file manager, openhttps://<your-domain>/adminand sign in. Remove your IP address from Remote MySQL again.
For each update, repeat steps 4 to 6 with the new files: migrate --force only adds what is
new. Back up the database first (phpMyAdmin → Export).
Behind a proxy or load balancer: TRUSTED_PROXIES
When nginx, Cloudflare or a load balancer sits in front of PHP, every request reaches the server
from the proxy's address. Until that address is trusted, the server sees one visitor, so all your
users share one rate limit. TRUSTED_PROXIES names the proxies whose
X-Forwarded-For header the server believes. Write IP addresses or CIDR ranges separated
by commas, then run php artisan config:clear.
| Your setup | Value in backend/.env |
|---|---|
| PHP faces the internet directly | leave it empty |
| nginx or Apache on the same machine | TRUSTED_PROXIES=127.0.0.1 |
| A load balancer on a private network (cloud VPC, Docker network) | TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 |
| One proxy at a known address | TRUSTED_PROXIES=203.0.113.10 (the proxy's own address) |
| Cloudflare | Cloudflare's published ranges, listed at cloudflare.com/ips, joined with commas: TRUSTED_PROXIES=173.245.48.0/20,103.21.244.0/22,… |
| A firewall lets nothing but the proxy reach PHP | TRUSTED_PROXIES=* |
Never use * on a server the internet can reach directly: anyone could then send a
made-up X-Forwarded-For header and get a fresh rate limit with every request.
Rate limits
Every limit the server applies to the API. A request over a limit gets 429 Too Many Requests
with a Retry-After header in seconds; the apps show a short message and the request can be
tried again after that.
| Routes | Limit | Counted | Defined in |
|---|---|---|---|
Every route under /api | 120 a minute | Per phone once it has a device token; per network before that | 'api' |
POST /api/ai/device | 10 a minute | Per network (an IPv6 /64 counts as one) | 'auth' |
The named limits are in app/Providers/AppServiceProvider.php (RateLimiter::for);
a limit written on a route (->middleware('throttle:10,1'): 10 per 1 minute) is in
routes/. Change the number there and run php artisan config:clear. Behind a proxy,
set TRUSTED_PROXIES (above) or every user is counted as one network.
How far it scales, and SQLite or MySQL
The server ships with DB_CONNECTION=sqlite. How many people it carries
depends on your host far more than on the code: the number of PHP workers, the CPU, the disk and
the database server. That is why this manual prints no user count; measure your own server
instead (below).
| SQLite | MySQL / MariaDB | |
|---|---|---|
| How it writes | One file; one write at a time, the others wait their turn | Many writes at once, row by row |
| Good for | Trying the item, a demo, one person or a small team | Anything live with real users |
| Backups | Copy the file while nothing writes | mysqldump, or the host's backup tool |
| More than one server | No: the file lives on one disk | Yes |
Move to MySQL before you go live, or as soon as one of these is true:
- more than a handful of people use the app at the same time;
database is lockedappears instorage/logs/laravel.log;- you want a second server behind a load balancer, or your host does not keep local files.
To move: create the MySQL database, set the DB_* lines in .env as in
Configure the database, then php artisan config:clear and
php artisan migrate --force. There is no one-step copy of the rows from SQLite to MySQL,
so switch before real data goes in.
The rate-limit counters live in the cache, kept in the database as shipped
(CACHE_STORE=database). That is fine on MySQL; with
several servers, point the cache at Redis so they share one count.
To see what your own server carries, send it a burst from another machine and watch the
response times and the error count, for example with hey (a free load tool, github.com/rakyll/hey):
hey -n 2000 -c 50 https://<your-domain>/api/version
# raise -c until responses slow down or errors appear
What the server keeps about a person
For a privacy policy, a GDPR request or a store's data form: every table in which a row points at one device, the columns it has, and how long it stays. Nothing here is sent to the author of this item or to anyone else; it lives in your database only.
| Table | Columns | How long it is kept |
|---|---|---|
users | name, role, email, email_verified_at, password, remember_token, must_change_password | The admin accounts of the panel. Deleted on the panel's Users page. |
password_reset_tokens | email, token, created_at | Laravel's own reset table for the admin panel; a row stops working after 60 minutes (config/auth.php). |
sessions | user_id, ip_address, user_agent, payload, last_activity | Admin panel browser sessions. One expires after SESSION_LIFETIME minutes without use, and Laravel clears expired rows on its own. |
media_files | owner_type, owner_id, name, sha256, size_bytes, mime, path | The pictures a phone uploaded. Deleted, files included, together with their owner. |
push_sends | kind, target, title, body, route, status, send_at, sent_at, delivered, gone, refused, error, sent_by | The panel's history of push messages: who they went to and what they said. Nothing removes it on its own; delete old rows in phpMyAdmin if your policy needs it. |
devices | device_key, platform, app_version, label, blocked, last_seen_at | One row per phone. Deleted by the delete button in the app's Settings, or by you on the Devices page. |
ai_usage_logs | device_id, device_key_hash, provider, model, prompt_tokens, completion_tokens, latency_ms, status, error | Counts and timings per request, never the prompt, the photo or the answer. Kept for the totals until you delete rows on the usage page (select, then delete); deleting a device clears its link and keeps the numbers with a hash of its key. |
ai_device_registrations | key_hash, ip, blocked | The network address each new device registered from and a hash of its key. Kept so the per-network daily limit and a block survive deleting the device; nothing removes it on its own, so clear old rows in phpMyAdmin when you no longer need them. |
personal_access_tokens | tokenable_type, tokenable_id, name, token, abilities, last_used_at, expires_at | One per registered phone. Deleted with its device (the delete button in the app's Settings, or the Devices page); they do not expire on their own (expiration in config/sanctum.php is how to make them). |
Deleting one person's data
- In the admin panel open Devices, find the phone (the page lists each one's platform, app version and when it was last seen) and delete it. Its token, its pictures and its link in the usage log go with it.
- Or have the person use the delete button in the app's Settings, which does the same.
Two copies the server cannot reach: what is stored on the person's phone (it goes when they delete the app or use the delete button in it), and your own database backups, which keep a row until the backup itself is deleted.
37Demo builds and release builds
Every build is one of two kinds. Which one is decided when you build, not by a setting a user can change:
| Build | Command | What it is |
|---|---|---|
| Demo build | | What you try the app on, and what the Live Preview runs: the sample data and the Demo mode switch in Settings. |
| Release build | | The app you publish, signed with your upload key (below). No sample data, no Demo mode switch. |
DEMO=on is the only switch back to the demo; leave it out of anything you upload to a store.
A release build needs the server address. The app reaches its online features through the included server,
so a release build without API_BASE_URL stops at launch, with this line in the
device log: This release build has no server address. Pass the address of your server as above,
on every release build.
Android release builds are signed with your own upload key. The project never
signs a release with the debug key: without android/key.properties a release build stops
with No android/key.properties. Make the key once, keep it safe, and point the build at it:
keytool -genkey -v -keystore ~/upload-keystore.jks -storetype JKS \
-keyalg RSA -keysize 2048 -validity 10000 -alias upload
Then create android/key.properties (it is ignored by git, like the keystore itself):
storePassword=<the store password you chose>
keyPassword=<the key password you chose>
keyAlias=upload
storeFile=<the full path of upload-keystore.jks>
Google Play re-signs what you upload with the app-signing key it keeps for you (Play App Signing); your upload key only proves the upload is yours.
38Adding a language
The apps ship in 3 languages (ar, en, es). Adding one takes
four steps in the app and one optional step on the server; French (fr) is the example.
- Copy a table. Copy
lib/l10n/es.darttolib/l10n/fr.dart. In the copy, rename the constant (const spanish→const french), setlocale: Locale('fr')andnativeName: 'Français', and translate every value. Keep the keys and the@p1placeholders exactly as they are; underdate.*put the month and weekday names in their order. - Register it. In
lib/l10n/app_languages.dartadd the import and the name:
That list is the only registration: the language picker in Settings, the date words, right-to-left layout and theimport 'fr.dart'; const appLanguages = <AppLanguage>[ english, spanish, arabic, french, ];Accept-Languageheader all follow it. The first entry stays the fallback. - Check it. Run
flutter test test/l10n_test.dart. It fails on a key the new table lacks or has extra, and on a value left in English, and names each one. - Try it.
flutter run --dart-define=LOCALE=frpins the new language for one run; or pick it under Settings. On iOS nothing else is needed: a build step writes the list into the app (ios/scripts/sync_localizations.sh), which is what lets iOS open the app in the phone's language. - The server's messages (optional). The API answers in the language the app sends in
Accept-Language, if it has it. Copybackend/lang/es.jsontobackend/lang/fr.jsonand translate the values; the server picks the new file up on its own (config/mobile.phpreads the folder). For Laravel's validation messages, take the French files from the Laravel-Lang project (lang/fr/*.phpthere) intobackend/lang/fr/, keeping their license header; or copybackend/lang/es/and translate every value.
Removing a language is the reverse: take its name and import out of the list; the file can go too.
39Tests and continuous integration
Every suite the item ships, run on your own computer:
cd diastora_ai_app && flutter analyze && flutter test && cd ..
cd backend && composer test
The same as a GitHub Actions workflow: put your copy of the item in a GitHub repository, save this
as .github/workflows/tests.yml at its root, and every push and pull request runs the
app and server tests. The same file is in backend/docs/github-actions-tests.yml. The server job uses SQLite, so it needs no database service.
# Copy to .github/workflows/tests.yml at the root of your repository.
name: tests
on:
push:
pull_request:
jobs:
diastora-ai-app:
runs-on: ubuntu-latest
defaults:
run:
working-directory: diastora_ai_app
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.47.2'
channel: stable
cache: true
- run: flutter pub get
- run: flutter analyze
- run: flutter test
backend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: mbstring, intl, pdo_sqlite, fileinfo, zip
tools: composer
- run: composer install --no-interaction --prefer-dist
- run: cp .env.example .env && php artisan key:generate
- run: composer test
Other CI services take the same commands: install Flutter stable and run
flutter pub get, flutter analyze and flutter test in each app
folder, then PHP with Composer and composer test in backend/.
40The landing page
landing/ is a one-page website for the app: one HTML file with its styles
inside, a fonts/ folder and an img/ folder. There is no build step and
no server code, so it opens straight from the disk and goes online on any static host.

What is on it
Each block is a <section> in landing/index.html, in this order:
| Block | Its heading as shipped |
|---|---|
class="hero" | Photograph the monitor. Keep a blood pressure log your doctor can read. |
class="features" | Made for the week before the appointment. |
class="gallery" | Read, log, trends, clinic sheet. |
class="band" | What reads the display. |
class="faq" | Questions from the kitchen table. |
class="closing" | Keep the log before the appointment. |
Changing the words
- The browser tab and search result:
<title>and<meta name="description">at the top (now: Diastora - Photograph the monitor. Keep a blood pressure log your doctor can read.). - Every heading and paragraph is plain text inside its section; edit it in any text editor.
- The contact address
hello@diastora.app: search formailto:and replace each one. - The 3 store buttons point at
#: put your App Store and Google Play links in theirhrefonce the app is live. - The footer's Privacy and Terms links point at
#too: link them to the pages you publish (the texts in the app'sassets/legal/are a starting point).
Changing the colors and pictures
The colors are CSS variables in the :root block near the top of the file; the
rest of the page is mixed from them, and a second :root under
prefers-color-scheme: dark holds the dark version:
| Variable | Shipped value |
|---|---|
--primary | #5250E0 |
--accent | #C2410C |
--surface | #F4F4FB |
--ink | #13141F |
The screenshots are the files in landing/img/ (8 of them, 07-read.png
and on). Replace a file with your own of the same name, or change the src that points at it.
Putting it online
- Upload the whole
landing/folder, keepingfonts/andimg/besideindex.html. Any static host serves it as it is: Netlify, Cloudflare Pages, GitHub Pages, or thepublic_htmlfolder of ordinary shared hosting. - Point your domain at it in the host's settings and turn on HTTPS there.
- Open the address on a phone and on a computer; check the store buttons and the contact links.
# try it on your own computer first
cd landing
python3 -m http.server 8080
# then open http://localhost:8080
The page loads nothing from other servers: no web fonts from a CDN, no scripts, no tracking.
41Version history
What changed in each version, newest first. The same list is in CHANGELOG.md in the app folder; when you install an update, it tells you what to look at without comparing every file.
1.0.0
- First release.
- Display reading through the included Laravel key proxy (OpenAI, Anthropic or Google Gemini), or with a key of your own.
- Read-and-confirm: a model only copies the numbers on the display; every unsure digit waits for a tap before it can be saved.
- Stages, morning and evening averages and the in-target share worked out on the phone, from a chosen guideline (ACC/AHA 2017 or ESC 2024 home).
- A seven-day home series tracker and a one-page clinic sheet, shared as an image or as CSV.
- Monitor and cuff records, a cuff-size check from an arm circumference, a before-a-reading checklist and a five-minute rest timer.
- Morning and evening reminders, skipped once a slot already has its two readings for the day.
- Backup to a JSON file, and restore from a file on the phone or from the clipboard.
- Optional copies of display and cuff-label photos on the included server, per install.
- English, Spanish and Arabic, light and dark themes.
42AI disclosure
AI-assisted tools were used to help write and review the source code and the documentation of this item. The author reviewed, tested and finalized every part before release. The photographs are licensed Pexels stock images, each listed with its photographer in assets/images/clinic/LICENSES.txt; the illustrations, including the six sample display graphics, are SVG drawings written as code for this item; no image-generation model was used.
In addition, Diastora's display reading is AI-powered: a photo of a monitor's display or a cuff label is sent to a vision model, which copies only the digits and symbols printed on it. The model never estimates a missing number, never sorts a reading into a stage and never gives advice; every stage, average and target line is calculated afterward by a small Dart engine on the phone, from the numbers the person confirmed. A low-confidence digit must be checked or corrected before a reading can be saved. Without a key or the included proxy, the Read tab runs Demo mode on bundled sample displays.