Mattrax
Open device management infrastructure for Apple, Windows, Android, and Linux fleets.
mattrax.app
·
Discord
·
Twitter
Mattrax is a TypeScript monorepo for building and operating our device management products. It includes all product surfaces including Enterprise, Platform and Whitelabel.
Requirements:
- Node.js
>=22.12.0 - pnpm
>=12.21.0 - MySQL 8 (local development uses
mysql://mattrax:mattrax@localhost:3306/mattraxe)
Install dependencies, apply migrations and start the dashboard + API Worker:
pnpm install
cp .dev.vars.example apps/cloud/.dev.vars
cp .dev.vars.example apps/web/.dev.vars
pnpm cloud db:migrate
pnpm web devORIGIN in .dev.vars must match the URL you open in the browser
(http://localhost:9050 by default), because it is the WebAuthn relying party.
To run the dev server over HTTPS instead, run pnpm dev:cert and
DEV_HTTPS=1 pnpm web dev, then set ORIGIN=https://localhost:9050.
| Command | Description |
|---|---|
pnpm test |
Run the Vitest suites. |
pnpm test:e2e |
Run the Playwright browser tests over CDP. |
pnpm typecheck |
Typecheck the workspace. |
pnpm format |
Run formatting and linting through Vite Plus. |
pnpm doc |
Start the documentation site locally. |
pnpm doc:build |
Build the documentation site. |
pnpm web dev |
Run only the web app (and its API Worker). |
pnpm cloud dev |
Run only the API app. |
pnpm catalog:split |
Rebuild the split Windows policy catalogue. |
pnpm catalog:check |
Verify the committed catalogue split is current. |
The Windows policy catalogue is served incrementally from
apps/web/public/catalog/windows/; the source file stays at
data/catalog/windows.json. See docs/reference/policy-catalogue.md
for the file layout and regeneration steps.
The browser suite drives a real Chrome via CDP by default. Set
E2E_BASE_URL to test an already-running deployment, or E2E_CHANNEL=bundled
to use Playwright's bundled Chromium (as CI does). For the default local URL,
Playwright applies pending database migrations before tests, including when it
reuses an already-running dev server; an E2E_BASE_URL target must already be
migrated. Migrations use only MATTRAX_DEV_DATABASE_URL or the local default;
inherited DATABASE_URL/DATABASE_* values are ignored. A non-local dev database
requires E2E_ALLOW_REMOTE_DATABASE=1. The suite creates its own users and
tenants, so it is safe to point at a disposable database.
The suite runs with a single Playwright worker because its tests share the dev
mailbox and rate-limit buckets through one server. CI shards it across four
runners instead — each gets its own database and dev server — with
pnpm test:e2e --shard=1/4; use the same flag to reproduce a single shard
locally.
The repository is split into protocol, management and product layers so each piece can be tested in isolation:
| Layer | Packages / apps |
|---|---|
| Protocol | dm-apple, dm-windows, dm-android, scep, soap, plist |
| Management contract | management-backend, management-backend-http |
| Management services | mdm-core, mdm-apple, mdm-windows |
| Product contracts | enterprise-domain (entity modules + HTTP) |
| Product services | enterprise-api, enterprise-backend, enterprise-billing, enterprise-identity, entra-id, apple-business-manager |
| Data | enterprise-core (Drizzle/MySQL, R2, secrets) |
| Hosted services | cloud-services |
| Surfaces | apps/web (dashboard, landing, docs) |
Mattrax's Cloud deployment consists of two Cloudflare Workers: a web Worker that serves the
dashboard and documentation at e.mattrax.app, and an API Worker that is only reachable
through the web Worker's service binding.
The same dashboard and API run as one Node container, published as
ghcr.io/mattrax/mattrax. It needs MySQL and an HTTPS reverse proxy, and
nothing else:
export ORIGIN=https://mdm.example.com
export AUTH_SECRET="$(openssl rand -base64 32)"
docker compose -f apps/docker/docker-compose.yml pull
docker compose -f apps/docker/docker-compose.yml up -dBuild from a checkout instead with
docker compose -f apps/docker/docker-compose.yml -f apps/docker/docker-compose.build.yml up -d --build.
See docs/operations/self-hosting.md for version
pinning, TLS, storage, backups and upgrade notes.
Configuration lives in each app's cloudflare.config.ts and deployments use the
cf CLI. Authenticate once with:
cf auth loginThen deploy:
# Deploy the web Worker (builds and copies the docs into the assets bundle)
pnpm web deploy:prod
# Deploy the API Worker
pnpm cloud deploy:prodTo deploy both hosted surfaces:
ORIGIN=https://e.mattrax.app pnpm deploy:prod:allORIGIN is baked into the API Worker as its canonical origin (passkey RP id,
cookies, links); leave it unset during local development and CI previews set
their own. GitHub Actions does this automatically.
GitHub Actions deploys production from main and creates a Worker Preview for
each pull request (posted as a sticky comment, deleted when the PR closes).
The required secrets, Cloudflare resources and preview limitations are in
docs/operations/deployment.md.
Database migrations are managed with Drizzle Kit:
# Generate a migration after changing the schema
pnpm cloud db:generate
# Apply pending migrations (MySQL connection fields)
DATABASE_HOST=localhost DATABASE_PORT=3306 DATABASE_USER=mattrax \
DATABASE_PASSWORD=mattrax DATABASE_NAME=mattraxe pnpm cloud db:migrateBoth Worker bundles are checked before every production deploy:
pnpm bundle:checkIt prints the gzipped size of mattrax-api and mattrax and exits non-zero above
2.5 MiB, leaving headroom under Cloudflare's script limit. deploy:prod runs the
same check automatically.
Client routes are split into per-route chunks (fileRoutes codeSplitting) and
heavy optional code loads after hydration (PostHog). For a module-level analysis,
run a report build and inspect it with @rolldown/perf-kit:
MATTRAX_PERF_REPORT=1 pnpm web build
cd apps/web && npx perf-kit graph \
--report node_modules/.rolldown/report/.cloudflare/output/v0/workers/default/assetsThe Worker uses the same workflow through apps/cloud/perf-kit.vite.config.ts
(generated by npx perf-kit worker-config --app apps/cloud).
Mattrax is built on:
- Cloudflare Workers + R2, Email Sending, Hyperdrive
- Effect
- Drizzle ORM
- Stripe
- Vite Plus
- cf CLI
- SolidJS
- TailwindCSS