Skip to content

Installation

Dmitri Chudinov edited this page Aug 28, 2026 · 1 revision

Installation

Getting a development stack running on your own machine. Standing one up on a real host is Deployment.


Prerequisites

  • Python 3.13+
  • Node 24+
  • Docker

Docker is required to run the backend tests, not only to run the app: the suite runs against real PostgreSQL and fails rather than skipping when none is reachable (ADR-0021). docker compose up -d postgres is enough.

The short version

run_web.bat

Brings up database, API, workers and the storefront on :5173. run_console.bat adds the farm console on :5174, reusing anything already running. run_design.bat serves the static design kit on :4180. Each script checks what is already up, so running two of them does not start a second API or collide on a port.


First run, step by step

1. Infrastructure.

docker compose up -d

Postgres runs on 5433 and Redis on 6380 — deliberately off the default ports so a locally installed Postgres does not shadow the project's.

2. Backend virtualenv.

cd backend && python -m venv .venv && .venv/Scripts/python -m pip install -e ".[dev]" -c constraints.txt

-c constraints.txt matters. pyproject.toml declares floors (>=); the constraints file says which versions the image, CI and your machine all actually install. Without it, three people can pass the same gates against three different dependency sets. Regenerating it is a deliberate act — the file's own header says how.

3. Migrations.

cd backend && .venv/Scripts/python -m alembic upgrade head

4. Frontend.

cd frontend && npm install

5. An owner account. Made with the same tool a real farm uses — it prompts for the password rather than taking it as an argument, and outside production it does not object to the documentation domain:

cd backend && ./.venv/Scripts/python.exe tools/provision_owner.py --email boss@printorian.example

The operator account is then made through the console, by the owner, like every other staff account.

6. Seed data, if you want a populated catalogue, materials and journal: backend/scripts/seed_*.py, each idempotent.


Seeded accounts

The development database carries two accounts. Their passwords are published, and that is safe only because a farm can no longer be served with them: the API refuses to start in production while any account sits in a domain reserved for documentation (contexts/identity/reserved.py). Restoring a developer dump into a real farm is now a container that will not come up, rather than a published owner password.

Account Password Role
boss@printorian.example owner-pass-12345 owner — every screen
floor@printorian.example shop-floor-pass-1 operator — production screens only

Two roles rather than one on purpose: most authorization bugs only show up when somebody who should not see a screen opens it, and that needs an account that cannot.

Known drift. The stored hash for floor@ does not match the password above, and that account is engineer in the database rather than operator. A role is an authorization decision, so it was left alone rather than silently changed. Recorded in HANDOFF.md §5.


Running it by hand

Two terminals. The API:

cd backend && .venv/Scripts/python -m uvicorn printorian.api.app:create_app --factory --reload

The workers:

cd backend && .venv/Scripts/python -m printorian.workers

Separate on purpose. A sweep holding a database session should not compete with request handling for the same event loop, and a deployment running several API workers behind a proxy would otherwise run one copy of every clock per worker — each recomputing the same credits and publishing the same events.

The frontends:

cd frontend && npm run dev --workspace @printorian/web
cd frontend && npm run dev --workspace @printorian/console

PRINTORIAN_API_URL points the dev proxy at a different backend (default http://localhost:8000); PRINTORIAN_CONSOLE_PORT moves the console's dev server.


Tests

cd backend && .venv/Scripts/python -m pytest -q
cd frontend && npx vitest run
Path Purpose
tests/unit/ Context logic — money, permissions, identity, rollups
tests/api/ HTTP behaviour, especially the authorization boundary
tests/contract/ The contract every printer driver must satisfy
tests/virtualfarm/ End-to-end farm runs against mock printers
tests/test_migrations.py Real Alembic against real PostgreSQL

The virtual farm is deterministic: it advances a FixedClock rather than sleeping, so a farm-day of printing runs in milliseconds and never flakes.

tests/contract/test_bambu_hardware.py needs a real printer and a git-ignored printers.local.toml. Without that file every one of its cases skips, so CI is untouched and nobody needs a printer to work on the rest of the system.


Regenerating the API client

The TypeScript client is generated from the backend's OpenAPI schema and is never hand-edited (ADR-0005). After changing any route or DTO:

cd backend && .venv/Scripts/python tools/export_openapi.py --out openapi.json
cd frontend && npm run generate:api

In CI the client is generated from the schema the backend job exported and never committed. That is what makes a breaking backend change fail the build at the commit that caused it, rather than in somebody's editor a week later.


Before opening a pull request

Run the six gates locally. Each encodes a specific way this kind of system rots, so a failure is a design signal rather than a formality — see Development and Governance.

cd backend && .venv/Scripts/python -m ruff check . && .venv/Scripts/python -m ruff format --check .
cd backend && .venv/Scripts/python -m mypy
cd backend && .venv/Scripts/lint-imports
cd backend && .venv/Scripts/python tools/check_context_isolation.py
cd backend && .venv/Scripts/python tools/check_file_length.py

Never pipe a gate into tail. cmd | tail returns tail's exit code. npm ci | tail once reported success while the install had failed, and every check after it ran against a stale node_modules. Use cmd > /tmp/out.log 2>&1; echo "exit=$?".


A Windows note

If Git's bundled ssh cannot find your key, a Cyrillic home directory is the likely cause. Keep keys on an ASCII path and point core.sshCommand at it.

Clone this wiki locally