Skip to content

Development environment setup

Steps required to run the server, the panel, and the mobile agent on a machine from scratch.

Tool Version Note
Dart SDK ^3.12.2 All packages; Docker image dart:3.12.2
Flutter ^3.44.4 Panel and agent; CI uses 3.44.4
Serverpod CLI 4.1.2 dart install serverpod_cli 4.1.2
Android SDK + adb For the agent; emulator or physical device
Docker not needed Development and tests use embedded PostgreSQL

PostgreSQL is not installed separately. Thanks to database.dataPath in config/development.yaml and config/test.yaml, Serverpod starts its own embedded PostgreSQL 16 under .serverpod/<mod>/pgdata. Redis is disabled in all modes.

The root pubspec.yaml is a pub workspace:

wonkru_mdm/
pubspec.yaml workspace (name: _)
wonkru_core_server/ Serverpod module: shared enums, DTOs, catalog
wonkru_core_client/ generated client of the module
wonkru_mdm_server/ server
wonkru_mdm_client/ generated client (not edited by hand)
wonkru_mdm_flutter/ admin panel
wonkru_mdm_mobil/ Android agent (not a workspace member, has its own lock)

Application source: wonkru_mdm. Documentation: docs.wonkrumdm.com.

Generate local development secrets from the application repository root:

Terminal window
flutter pub get
dart run wonkru_mdm_server/tool/create_dev_passwords.dart

The command creates a development: block with independent random values and refuses to overwrite an existing file. Configure other run modes separately; production deployment uses deploy/vps/init-env.sh to create its own secrets.

The file is not committed to git. Create it if it does not exist; one block is needed for each mode. Values must be random and long (e.g. openssl rand -base64 48).

development:
database: '<random>'
redis: '<random>'
serviceSecret: '<random>'
emailSecretHashPepper: '<random>'
jwtHmacSha512PrivateKey: '<random>'
jwtRefreshTokenHashPepper: '<random>'
passwordHashPepper: '<random>'
storageSigningKey: '<at least 32 characters, optional>'
test:
database: '<random>'
redis: '<random>'
emailSecretHashPepper: '<random>'
jwtHmacSha512PrivateKey: '<random>'
jwtRefreshTokenHashPepper: '<random>'
passwordHashPepper: '<random>'
# staging: and production: blocks with the same keys (except redis)

Each key can also be provided with the SERVERPOD_PASSWORD_<key> environment variable.

Terminal window
cd wonkru_mdm_server
serverpod start

serverpod start:

  1. Opens embedded PostgreSQL and applies pending migrations.
  2. Starts the server; on file changes it generates code and hot reloads.
  3. Opens the panel in Chrome at http://localhost:8099 via lib/driver.dart (server pubspec.yaml → serverpod.flutter_apps.wonkru_mdm). Ctrl+R reopens the panel.

On first launch the panel shows a “set up first admin” form. Enter an email and password to create the first admin, then sign in.

In development, account registration and password-reset verification codes are written to the server log.

Service Port Note
API (RPC + device stream) 8090 The panel and agent connect here
Insights 8081 Serverpod Insights
Web server 8082 Compiled panel, /storage, /downloads/local-ca
Panel (flutter run) 8099 Fixed; in allowedOrigins for the cookie
Embedded PostgreSQL 8090 Unix socket only (.serverpod/development/run), does not listen on TCP
Test DB 9090 Embedded

The API and the embedded DB show the same port number, but they do not conflict because the DB does not listen on TCP. If you start an external Postgres with docker-compose.yaml, it conflicts with the API on 8090; change the port if you are going to use compose.

Embedded PostgreSQL listens only on a unix socket:

Terminal window
psql -h "$PWD/.serverpod/development/run" -p 8090 -U postgres wonkru_mdm

(from the wonkru_mdm_server directory; password passwords.yaml → development.database.)

Terminal window
cd wonkru_mdm_flutter
flutter run -d chrome --web-port=8099

Login does not work on any port other than 8099.

2.5 Connecting the mobile agent to the local server

Section titled “2.5 Connecting the mobile agent to the local server”

The emulator reaches the host machine via 10.0.2.2. That is why webServer.publicHost: 10.0.2.2 in development.yaml is left this way (the APK/file/certificate download addresses in the policy are generated from this host).

Terminal window
cd wonkru_mdm_mobil
flutter run --debug --dart-define-from-file=config.json --dart-define=HOST=10.0.2.2
Terminal window
adb shell dpm set-device-owner com.wonkrumdm/.core.receivers.MdmDeviceAdminReceiver

Do not add a Google account to the emulator image.

The device must be on the same network as the computer and must reach the server via the LAN IP:

  1. In config/development.yaml, locally (without committing) change the apiServer.publicHost and webServer.publicHost values to the machine’s LAN IP.
  2. HOST in wonkru_mdm_mobil/config.json must be the same IP.
  3. Let the machine’s firewall open 8090 and 8082 to the LAN.
  4. Factory reset the device (without adding an account), install the APK, and assign Device Owner (Mobile agent).

localhost and 10.0.2.2 do not work on a physical device; the device enrolls but cannot download APKs and files.

The agent’s setup screen asks for the server address and the enrollment key. Instead of typing the key (WNKR-XXXX-XXXX-XXXX), scan the panel’s enrollment QR from the setup screen’s camera button, push it with tool/adb_enroll.sh, or set ENROLLMENT_KEY in config.json. The key is under Settings → Device Enrollment Key in the panel. Before enrollment, create a policy in the panel and make it the default; a device without a policy cannot complete setup.

HTTPS and self-signed certificate (optional)

Section titled “HTTPS and self-signed certificate (optional)”

You can use HTTP for development. To use HTTPS with your own CA, save the CA certificate in PEM format at wonkru_mdm_server/certs/local-ca.crt. The server makes it available at /downloads/local-ca. For Docker Compose and first-time Android enrollment, follow the TLS guide. HTTPS with your own TLS certificate

While serverpod start is running, code is generated automatically on model (*.spy.yaml) or endpoint changes. If the table schema changes, create a migration and apply it before using the new schema. For manual code generation or migration creation, run:

Terminal window
cd wonkru_mdm_server && serverpod generate
Terminal window
cd wonkru_mdm_server && serverpod create-migration

A destructive change needs --force. lib/src/generated/ and wonkru_mdm_client/ are not edited by hand.

After a change, in this order:

Terminal window
cd wonkru_mdm_server && dart analyze && dart format .
Terminal window
cd wonkru_mdm_server && dart test
Terminal window
cd wonkru_mdm_flutter && flutter analyze && flutter test
Terminal window
cd wonkru_mdm_mobil && flutter analyze && flutter test

Tests do not need Docker.

  • .vscode/tasks.json: the serverpod_start task. .vscode/launch.json: attach to the panel and the server, and a “full stack” compound that launches both together.
  • .github/workflows/: analyze.yml, format.yml, tests.yml. All three are triggered only manually (workflow_dispatch) and cover only the server. There is no CI for the panel and the agent.