Running and testing¶
This page shows how to run Dinatos on your computer and how to test your
changes. Before you start, finish Environment setup.
The project has a Python API (backend/) and a Flutter app (frontend/).
Fastest path: just dev¶
cp .env.example .env
# edit .env: set POSTGRES_PASSWORD (no default),
# and DINATOS_ADMIN_EMAIL / DINATOS_ADMIN_PASSWORD so you have an account to log in with
just dev
just dev starts Postgres in Docker and runs the migrations. Then it runs the
backend (http://127.0.0.1:8000) and the frontend. Open
http://127.0.0.1:8081. Log in with the admin credentials that you set.
To stop the backend and the frontend, press Ctrl+C. Postgres keeps running.
To stop the containers and keep the data, run
just docker down.To remove the containers, run
just dev-clean.
Warning
just dev-clean deletes the Postgres data volume. Before you use
it on data you want to keep, read
Upgrades and backups.
Running pieces separately¶
Backend only¶
Use one of these two methods.
Method 1: use a Postgres that you run yourself.
docker run -d --name dinatos-pg -e POSTGRES_USER=dinatos -e POSTGRES_PASSWORD=dinatos \
-e POSTGRES_DB=dinatos -p 5432:5432 postgres:16-alpine
just backend migrate
just backend run # http://127.0.0.1:8000, interactive API docs at /docs
just backend run reads backend/.env and DINATOS_DATABASE_URL. The
default is postgresql+asyncpg://dinatos:dinatos@localhost:5432/dinatos.
Method 2: use Docker for the backend, the web app and Postgres together.
just docker up # http://127.0.0.1:8000; migrations run on start
just docker logs
just docker down # keeps the data volume
This method also builds the Flutter web app. It is slow if you change only the backend. For backend-only changes, use Method 1. For more information, see Deploying with Docker Compose.
Frontend only¶
cd frontend
just install
just run # flutter run -d web-server --web-port 8081, with hot reload
Open http://127.0.0.1:8081. The Server URL field on the login screen
tells the app which backend to use. The default is http://127.0.0.1:8000. To
hot-reload only the frontend, set the field to the backend of a just dev
run. For more information, see Getting started.
Creating an account for testing¶
On first start, the backend creates an admin account from
DINATOS_ADMIN_EMAIL and DINATOS_ADMIN_PASSWORD. If you do not set these
variables, the first account that you register on a new instance becomes the
admin account.
To register an account and call the API, run these commands:
curl -X POST http://127.0.0.1:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "you@example.com", "password": "at-least-8-characters"}'
token=$(curl -X POST http://127.0.0.1:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "you@example.com", "password": "at-least-8-characters"}' \
| jq -r .access_token)
curl http://127.0.0.1:8000/exercises -H "Authorization: Bearer $token"
Every endpoint except /health and /auth/* needs the bearer token. For more
information, see Authentication.
Importing from the command line¶
The importers are plain endpoints, so you can call them without the app. This
helps on a new instance, in a script, or when you debug an import. You need the
$token from the previous section.
Hevy takes the two CSV exports as a multipart upload:
curl -F file=@workout_data.csv http://127.0.0.1:8000/imports/hevy/workouts \
-H "Authorization: Bearer $token"
curl -F file=@measurement_data.csv http://127.0.0.1:8000/imports/hevy/measurements \
-H "Authorization: Bearer $token"
Intervals.icu has two steps. The API key goes in the request body, so it does not appear in a URL or an access log:
# 1. List activities (writes nothing)
curl -X POST http://127.0.0.1:8000/imports/intervals/preview \
-H "Authorization: Bearer $token" -H "Content-Type: application/json" \
-d '{"api_key": "'"$INTERVALS_KEY"'", "athlete_id": "0", "oldest": "2026-01-01"}'
# 2. Import the chosen ones
curl -X POST http://127.0.0.1:8000/imports/intervals/activities \
-H "Authorization: Bearer $token" -H "Content-Type: application/json" \
-d '{"api_key": "'"$INTERVALS_KEY"'", "oldest": "2026-01-01", "activity_ids": ["i123", "i124"]}'
newest defaults to today. If you send the same file or activity again, the
server returns 409. To import it anyway, add ?force=true to the URL. For the
other status codes (422, 400, 502) and the reasons for them, see
Hevy import and
Intervals.icu import.
Testing¶
Command |
What it tests |
Needs |
|---|---|---|
|
Lint, backend and MCP server tests, docs build (the |
Python, |
|
Backend tests only |
Python, |
|
Format, |
Flutter SDK |
|
Database migrations |
Docker |
|
The real web build in a browser |
Docker, Flutter SDK |
just check does not run the frontend suites or the Docker-based suites,
because they are heavy. CI runs each of them as a separate job. See
CI and checks.
Backend tests¶
The tests run on in-memory SQLite. They do not need Postgres.
The shared
clientfixture (backend/tests/conftest.py) registers a throwaway user. It returns anAsyncClientthat is already logged in. To test behavior without a login, use theanonymous_clientfixture.Each test file name must be unique in
backend/tests/. The directory has no__init__.pyfiles. If two files have the nametest_auth.py, collection fails with “import file mismatch”. For this reason, the files areapi/test_auth.pyandservices/test_auth_service.py.A new database table must be in
BACKED_UP_TABLESinbackend/src/dinatos_backend/services/backup.py. You can put it inEXCLUDED_TABLESinstead, with a reason. If the table is in neither,just testfails. Also add user-owned fields to theExported*models inschemas/backup.pyand toservices/user_export.py. See Backup and data export.Coverage needs
concurrency = ["greenlet"]in[tool.coverage.run](backend/pyproject.toml). The async engine of SQLAlchemy switches contexts throughgreenlet. Without this setting, coverage stops counting the lines of a function after its firstawait db.... If coverage drops sharply after you change database code, check this setting first.
Migration tests¶
A migration is a versioned script (Alembic) that changes the database schema.
just backend test-migrations runs
pytest-alembic against a throwaway
Postgres. testcontainers starts this Postgres. The suite checks four things:
The repository has a single head revision.
A clean upgrade from an empty database to head works.
The models match what the migrations produce.
test_up_down_consistencyupgrades and downgrades every migration, one at a time.
The last check is the most important. It found a downgrade() that left a
Postgres ENUM type behind. This broke the next upgrade(). SQLite cannot
show this problem, so the suite needs real Postgres. The suite is outside
backend/tests/. just check does not run it. CI runs it as the migrations
job.
To create a migration after you change a model, start a Postgres. Then run these commands:
just backend revision "add widget table"
just backend check-migrations # fails if models and migrations diverge
The Alembic configuration is in backend/pyproject.toml, in [tool.alembic].
The file backend/alembic.ini exists only for the logging sections. Do not
add an [alembic] section to it. If a key is in both files, the value from
the .ini file wins without a warning.
End-to-end tests¶
just e2e test builds the web app and starts a throwaway Postgres. It also
starts a backend that serves the build. Then it drives the app in Chromium
with Playwright. To iterate on the tests only, set these variables:
Variable |
Effect |
|---|---|
|
Skips the Flutter build |
|
Skips Docker |
|
Uses this browser when Playwright cannot download its own browser (“Executable doesn’t exist”) |
Flutter web paints to a <canvas>. For this reason, Playwright finds
elements through the accessibility tree of Flutter. Keep these rules in mind
when you write browser tests:
Start Chromium with
channel="chromium". The default headless shell has no WebGL support, which Flutter needs. With the shell, the page stays blank and shows no error. If a TLS-intercepting proxy is in your network, add--ignore-certificate-errorson your computer. Do not commit it.Use
get_by_role(...)locators. Do not use pixel coordinates. The roles are:textboxfor text fields,checkboxfor checkboxes,buttonfor buttons and FABs,menuitemfor menu items, andtabfor bottom-bar tabs. ACardis agroupwith the name of its label. An icon-only button needs atooltip:to get a name.Type with
press_sequentially(). Do not usefill(). Flutter copies its own controller state back to the<input>. This can replace a filled value with an empty value before Flutter sees it. If the field can already hold text, select all and delete first.The
NavigationRailof the wide layout is not in the accessibility tree. The e2e tests press it by coordinates. The bottom bar is in the tree.A click through the accessibility tree reaches the app as a semantic tap, not as pointer events. A
ListeneroronPointerUpnever sees it.Playwright does not click an element that another element covers. A modal tour scrim is an example. To test that the scrim blocks a click, expect a click with a short timeout to time out. Do not use
force=True.The build uses
--no-web-resources-cdn. Without it, Flutter gets CanvasKit from the CDN of Google. If the browser has no internet access, the page never renders.A password-manager extension fills fields with synthetic
inputandchangeevents. By default, Flutter web ignores these events. A new form that must work with an extension needs the wrapperWebAutofillSemantics(fields: ...). The wrapper matches fields by their label.e2e/test_autofill.pyreproduces the behavior of an extension.
Things only a real browser or device shows¶
flutter test and flutter analyze cannot find these problems. When you
change one of these areas, load the built app:
CORS.
flutter testmakes no cross-origin request. A missing CORS policy shows only as a failed preflight request in a browser. To check a web change, runflutter build web --release. Servebuild/web/. Open it against a running backend.Android release permission.
flutter createaddsINTERNETonly to the debug and profile manifests. A release APK without this permission infrontend/android/app/src/main/AndroidManifest.xmlinstalls. Then every request fails with “server not reachable”. To check the permission on a built APK without an emulator, runjust android check-apk.Keyring on Linux desktop. If the keyring is missing, or the user did not unlock it,
flutter_secure_storagethrows on every call.TokenStorageandServerUrlStorage(frontend/lib/core/) catch this error on purpose. Keep the catches.
Pitfalls when you edit build files¶
Dockerfile. The last
uv sync --locked --no-devneeds--no-editable. Without it, the virtual environment of the runtime image points to a path of the build stage that does not exist. Thenimport dinatos_backendfails when the container starts, althoughdocker buildsucceeds. Always run the built image against Postgres. If a TLS-intercepting proxy is in your network, you can pass its CA bundle to the build (PIP_CERT,SSL_CERT_FILE). Do not commit this.Seed data for global tables (for example
exercises). Use a fresh database for each run. A second “Bench Press” breaks the unique constraint. For this reason,screenshots/generate.pyuses a disposable Postgres.flutter create --platforms=...in this project. The command replaces the migration list infrontend/.metadataand removes the other platforms. After the command, compare.metadataandanalysis_options.yamlwith the old files. Restore the lost entries.Authentication. Sessions are server-side rows (
AuthSession) with opaque random tokens. They are not JWTs. For this reason, a logout revokes the session. Do not add JWT signing again before you read Authentication. Use only Argon2 for passwords. Never use a fast hash such as SHA-256 for a password. SHA-256 is correct for session tokens and for CSV content hashes, because these values have high entropy.
Next: CI and checks, then Releases and packaging.