Repository navigation
Development and testing
You need Node.js 22.22.2 or newer and npm. package.json declares it under engines, and .nvmrc pins Node 22, which is what CI uses; on Node 20 the jsdom tests crash.
git clone https://github.com/ch-bas/threejs-sims-house-builder.git
cd threejs-sims-house-builder
npm install
npm run dev| Command | What it does |
|---|---|
npm run dev |
Dev server at http://localhost:3000 (Next moves to 3001 if 3000 is taken). |
npm run build |
Production build. The app is a static export, so the output is plain files in out/. A postbuild step then preloads the editor and engine chunks from out/index.html, adds the Content-Security-Policy to every page, writes third-party-licenses.txt and writes the offline service worker, out/sw.js (see below). It needs no network: the Sora and Nunito fonts are committed under app/fonts/. |
npm start |
Serves the built out/ folder locally (serve, fetched by npx). next start doesn't work on a static export. |
npm run typecheck |
next typegen && tsc --noEmit: Next writes its route types first, then TypeScript checks the whole project. |
npm run lint |
ESLint 9 over app/, components/, lib/ and scripts/, configured in the flat eslint.config.mjs. |
npm run test |
The Vitest unit suite, once (configured in vitest.config.mts). |
npm run test:watch |
Vitest in watch mode. |
npm run check:bundle |
After a build: the gzip size of the first-load JavaScript, the largest chunk and the CSS against scripts/bundle-budget.json (see below). |
npm run test:smoke |
After a build: loads out/ in a headless browser and fails on errors (see below). Needs Playwright. |
Setting GITHUB_PAGES=true during the build adds the /threejs-sims-house-builder base path used on GitHub Pages.
The build also stamps the version from package.json into the bundle (NEXT_PUBLIC_APP_VERSION, set in next.config.mjs). The app uses it to note which version saved a house (lib/saved-by.ts) and which version this browser last opened (lib/app-version.ts).
Builds are reproducible: next.config.mjs names the build after the commit (GITHUB_SHA in CI, dev on your machine) instead of Next's random id, so two builds of one commit in CI give the same files, and the same CSP hashes. Only builds from the same checkout directory match byte for byte, because Next's entry modules hash their absolute path.
app/page.tsx starts the editor and the 3D engine with import(), so without help the browser only learns their file names once React has hydrated. scripts/add-preloads.mjs reads Next's loadable manifest and writes one low-priority <link rel="preload" as="script"> per chunk into out/index.html, so the downloads start with the page. It runs before the CSP step, reads the base path from the HTML Next wrote, and is safe to run twice.
GitHub Pages can't send headers, so the policy is a <meta http-equiv="Content-Security-Policy"> that scripts/add-csp.mjs writes into every HTML file in out/ after the build. Only the app's own scripts run: the few inline scripts Next writes are allowed by their hash, computed from that build, and nothing loads from other sites. The step fails the build if a page has an inline event handler (an on…= attribute), because the policy would silently block it; attach handlers in code instead. It's safe to run twice.
GitHub Pages serves every project site of an account from one origin, so 'self' would also allow a script from a sibling site. On a build with the Pages base path the script source is therefore narrowed to the app's own folder, https://<owner>.github.io/threejs-sims-house-builder/_next/. The origin is CSP_SITE_ORIGIN when set, otherwise the repository owner's github.io in Actions, otherwise the origin of homepage in package.json. The step fails if a page loads a script from outside that one _next/ folder. A local build without the base path keeps 'self'. Because the policy names the address, a Pages build only runs at its real address; the deploy checks that address before publishing (see Releasing).
scripts/build-sw.mjs runs last in postbuild and writes out/sw.js. It lists the page, the shell (manifest, icons, the 404 page) and every file under _next/static/ with a SHA-256 each, and prints how many files and bytes it precaches. The page registers it after the first frame, in production builds only (lib/service-worker.ts, hooks/use-service-worker.ts); npm run dev removes any worker an earlier npm start left on the same origin, so a dev server never runs from a stale precache. The CSP allows that one file as a worker (worker-src). See Data safety for what it caches and how it checks it.
To build with the worker switched off, set NEXT_PUBLIC_SERVICE_WORKER=off (or false, or 0): NEXT_PUBLIC_SERVICE_WORKER=off npm run build. That build ships a worker that deletes the app's offline caches, unregisters itself and reloads its pages. On the deployed site the repository variable SERVICE_WORKER does the same; see Releasing.
When checking a change in a browser against npm start, remember the worker: a hard reload, or Application → Service workers → Unregister in the developer tools, makes sure you're looking at the new build.
The minifier strips licence comments from the chunks, so scripts/third-party-notices.mjs writes out/third-party-licenses.txt instead, served at /third-party-licenses.txt. It lists the production dependencies from package-lock.json (and Tailwind, whose base CSS ships), the React builds and polyfill libraries Next bundles from its own copies (their texts are kept in scripts/licenses/), and the assets: both fonts and the people model. It reads the lockfile and node_modules, not the network, and fails if Next's bundled core-js version moves away from the one its text was taken for.
scripts/check-bundle.mjs gzips what the export ships and compares three numbers with scripts/bundle-budget.json: the first-load JavaScript (the scripts out/index.html loads, plus the editor and engine chunks the page imports as it starts), the largest single chunk and the CSS. It prints a table naming the largest files and, in CI, adds it to the job summary. Going over a budget fails; CI runs it with --report-only for now, which turns that into a warning. A deliberate increase updates the budget in the same pull request (npm run check:bundle -- --update writes today's sizes plus the headroom), so the cost shows up in review.
scripts/smoke-test.mjs serves out/ at the base path it was built with and loads it in headless Chromium with software WebGL, so no GPU is needed. It fails on any console or page error, failed request, HTTP error, CSP violation or unexpected reload, and checks that:
-
/starts the 3D engine within 60 s (and on a phone viewport too, withSMOKE_PHONE=1); at the desktop viewport, under forced colours, the selected option of a radio group must look different from the others; -
/404.htmland an unknown path show the "Nothing built here" page with its link back; - when the editor chunk answers 404, the page reloads exactly once and then shows the error screen;
- offline: after the desktop load, once the service worker is active, a reload with the network cut off opens the editor from the precache. The page must be this build's, and no request may reach the server.
Playwright isn't a project dependency: install playwright (with its Chromium) or playwright-core with an installed Chrome (SMOKE_BROWSER_CHANNEL=chrome) in your checkout first. SMOKE_SCREENSHOTS=<dir> saves a screenshot per check and SMOKE_VERBOSE=1 logs progress.
.github/workflows/ci.yml is the only workflow. Its test job runs on every pull request and every push to main:
npm ci-
npm audit --omit=dev --audit-level=high: no production dependency may have a known high or critical advisory npm run typecheck-
npm run lint -- --max-warnings=0: a warning fails CI npm run test-
npm run buildwithGITHUB_PAGES=true, so a pull request checks the very buildmaindeploys, andNEXT_PUBLIC_SERVICE_WORKERfrom the repository variableSERVICE_WORKER(unset: the offline worker is on) -
node scripts/add-csp.mjs, the Content-Security-Policy step -
npm run check:bundle -- --report-only: the bundle budget, reported in the job summary; over budget is a warning for now -
npm run test:smoke: the smoke test, with the runner's own Chrome, including the offline reload. It's report-only for now: a failure shows as an annotation but doesn't fail the job or block the deploy
The job runs on the pinned ubuntu-24.04 image rather than ubuntu-latest, so the build doesn't change under it. A separate weekly workflow, .github/workflows/audit.yml, audits every dependency, dev dependencies included; see Releasing.
Branch protection on main requires this check, so every change lands through a pull request. On main, the deploy and release jobs only run after it passes; see Releasing. Run the checks locally before pushing:
npm run typecheck && npm run lint -- --max-warnings=0 && npm run testAdd npm audit --omit=dev --audit-level=high when you've changed dependencies, and npm run build when you've touched anything the static export or the policy depends on (app/, inline scripts, next.config.mjs).
-
TypeScript 6, strict, with no
any, plusexactOptionalPropertyTypesandverbatimModuleSyntax. Pass an optional field through with a conditional spread (...(x.terrain ? { terrain: x.terrain } : {})) rather thanterrain: x.terrain. Whereundefinedgenuinely means "clear", say so in the input type rather than casting at the call site. In tests, leave a key out instead of setting it toundefined. -
Lint is type-aware: unhandled promises, non-exhaustive
switches over unions (adefault:counts) and value imports of types all fail CI. -
ESLint 9 runs on a flat config (
eslint.config.mjs): Next's core web vitals set plus the project's own. It stays on 9 until its plugins support ESLint 10; Dependabot holds the major back. The build scripts inscripts/are linted too. -
Imports are alphabetised (
import/order, no blank lines between groups).no-consoleallows onlyconsole.warnandconsole.error. -
Layers: pure logic in
lib/, Three.js inthree/, React glue inhooks/, UI inpanels/. See Architecture. - Don't add runtime dependencies without opening an issue first.
-
New modules get a line in docs/architecture.md in the same pull request;
lib/docs-drift.test.tsfails otherwise. That coverscomponents/room-organizer/,app/,scripts/and the root*.config.*files. See Architecture.
Tests are Vitest files next to the code they test (geometry.ts → geometry.test.ts). The default environment is Node, which suits the pure lib/ code most tests cover. React and DOM suites (mostly named *.react.test.ts(x)) opt into jsdom with a comment on their first line:
// @vitest-environment jsdomWhat's well covered: the reducer (including locks, no-ops and caps), geometry and collision, snapping, the schema and repairs, persistence and restore points, the share codec, the plan exporters (the DXF test includes a structural validator), the 2D renderer's maths, and the stores.
Speed checks measure CPU time, not the clock. A test that bounds how long something takes uses measureCpu or measureCpuAsync from lib/__testfixtures__/cpu-time.ts (user plus system time from process.cpuUsage()), which barely grows on a busy machine, so the test checks the work done rather than the load. A long, CPU-bound simulation (the walker runs, the reducer's long random run, the multi-storey DXF export) takes an explicit 30 s timeout; everything else keeps Vitest's 5 s default, so a real hang still fails fast.
What unit tests can't tell you: whether the layout looks right, whether a drag feels right, or whether the scene renders. For that, run the app.
For any UI or scene change:
- Try it in 3D and on the 2D plan, and check undo and redo.
- Check a phone-sized window (the browser's device toolbar is fine) if the HUD is involved.
- For a scene change, try each Quality choice (View options), and a phone with touch emulation on: phones skip reveals and relief maps and use smaller textures, decided once when the page loads, so reload after switching the emulation.
- Watch the
?debugcounters (add?debugto the URL) before and after: geometries and textures should come back to the same numbers after a rebuild, and the frame count should stand still when nothing moves. See Rendering.
Playwright isn't a project dependency; install it in your checkout when you need it (npm install --no-save playwright, then npx playwright install chromium). A useful pattern is to seed a house into local storage before the page loads, then drive the UI:
import { chromium } from 'playwright';
const layout = { /* a RoomLayout: name, width, height, floors[], roof, … */ };
const browser = await chromium.launch({
// A real GPU instead of software rendering (macOS shown).
args: ['--use-angle=metal', '--enable-gpu', '--ignore-gpu-blocklist'],
});
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
// Seed once per session, so a reload keeps whatever the app saved since.
await page.addInitScript((json) => {
if (sessionStorage.getItem('seeded')) return;
sessionStorage.setItem('seeded', '1');
localStorage.setItem('standalone-room-organizer-layout', json);
localStorage.setItem('standalone-room-organizer-welcome-dismissed', '1'); // no start chooser
}, JSON.stringify(layout));
await page.goto('http://localhost:3000/');
await page.waitForSelector('canvas:not(.hidden)'); // engine ready
await page.keyboard.press('2'); // 2D plan
await page.screenshot({ path: 'plan.png' });
await browser.close();Tips:
- After an edit, wait at least 1.5 s (the autosave debounce) before reading
localStorage. - Questions are in-app dialogs, not native ones: answer them with
page.getByRole('alertdialog')and its buttons. - Mobile layouts: use a Playwright device such as
devices['iPhone 13']andtap()rather thanclick(). - You can simulate a lost GPU with the
WEBGL_lose_contextextension, and a stale deploy by routing a/_next/static/chunks/request to a 404. - The welcome flag alone leaves a new browser in Home builder. To check the game, leave the flag out and answer the start chooser's Play the game, which starts the quick job, or switch in the House menu. A build made with
NEXT_PUBLIC_CAREER_FIXTURES=1exposeswindow.__pcCareerFixtures(startQuickJob,playMoveIn,skipMoveIn,finishMoveIn) to drive the career with a fixture commission and result; any other build drops it.
Headless browsers have limits: they can't take pointer lock (the walkthrough stops at "Click again to look around"), modifier-click multi-select is unreliable to script, and software rendering says nothing about real shadow quality or frame rates. Check those by hand in a real browser.
The PR template asks for a description, screenshots for visual changes, how to test, and a short checklist (typecheck, Chrome and Safari, no new console warnings, placement/drag/undo/save still work, mobile checked for UI changes). Write one closing keyword per issue on its own line (Closes #12 and Closes #34); a comma-separated list closes only the first.
Also see the repository's CONTRIBUTING.md and Releasing.
Open the app · Source on GitHub · Report an issue · MIT licence
Using the app
- Getting started
- Architect career
- Building the house
- Rooms and zones
- Roof and dormers
- Site and neighbours
- Tracing a floor plan
- Furnishing
- Catalogue
- Budget
- Templates, themes and sets
- Floors and stairs
- Lighting, weather and time of day
- Wi-Fi and security planning
- Views and tools
- The 2D plan
- Walkthrough
- Phones and tablets
- Achievements and statistics
- Saving, sharing and history
- Export and print
- Accessibility
- Keyboard shortcuts
- FAQ and troubleshooting
Contributing
Links