# Neuro — Web Angular frontend for **Neuro**, a perishables control-tower application. It sits on top of a retail chain's existing point-of-sale and inventory systems, capturing batch expiry once at receiving, driving first-expired-first-out dispatch, and surfacing at-risk stock to an outlet manager as a one-tap approve/adjust/reject decision — never acting on its own.
Beginners' Guide ## Development Environment Setup ### 1. Prepare Workspace ```bash git clone cd neuro-web npm install ``` ### 2. Requirements - Node.js **20.19+** (or 22.12+ / 24+). Anything older fails the Angular CLI's own version check before it does anything else. - No other language toolchain, database, or account is required to run the frontend on its own — it talks to a mock API by default (see below). ## How to Run The app is built mock-first, so you are never blocked by a real backend being available. ```bash # Terminal 1 — start the mock API (Mockoon, loaded from mock/neuro.mock.json) npm run mock # Terminal 2 — serve the app against that mock API npm run start:mock ``` Mockoon defaults to port `3001`, avoiding common local service conflicts. To choose another unused port, set `MOCKOON_PORT` to the same value in both terminals: ```bash MOCKOON_PORT=3100 npm run mock MOCKOON_PORT=3100 npm run start:mock ``` Open the URL Angular prints (typically `http://localhost:4200`). Sign in with one of the 5 seeded demo accounts and the shared mock-only password (see `mock/neuro.mock.json`'s `auth/login` route — the mock API, not the login screen, decides what's valid here; this password is unrelated to the real deployment's own demo password in the "Demo credentials" section below): | Email | Password | | --- | --- | | `dc_staff@neuro.local` | `mockpass123` | | `dc_manager@neuro.local` | `mockpass123` | | `outlet_staff@neuro.local` | `mockpass123` | | `outlet_manager@neuro.local` | `mockpass123` | | `head_office@neuro.local` | `mockpass123` | Anything else (unknown email or wrong password) gets the real backend's own 401 shape back. To point at the real backend instead of the mock: ```bash npm start # serves against the URL in src/environments/environment.ts # (default: https://neuro-nohg.onrender.com/api/v1, the live hosted backend # — see "Production Credentials" below for accounts to sign in with) ```
Deployment (Maintainers Only) ## 1. Production build ```bash npm run build # static output: dist/neuro-web/browser/ ``` This is a fully static bundle — no Node runtime, no server-side rendering. It can be handed to any static file host or CDN as-is. ## 2. Where it actually runs There is no paid hosting in this project's plan, and this repo is private — GitHub Pages isn't available for a private repo on a free plan, so there are two independent paths: - **Primary — Docker on a DietPi SBC, reached over Tailscale** (`Dockerfile`, `nginx:alpine` serving the static build) — no cloud dependency, no port forwarding. `.github/workflows/docker-publish.yml` publishes a multi-arch image to `ghcr.io/abumusasakib/neuro-web:latest` on every push to `main` that passes CI, and `docker-compose.yml` brings it up with one `docker compose up -d` (or, as an opt-in, alongside Mockoon or a real backend running on the same box — see `docs/deployment.md`). A second box with the same image is the actual disaster-recovery plan, not a cloud failover. - **Secondary — Cloudflare Workers with static assets**, live at — a free public URL for a judge/reviewer who doesn't want to install Tailscale. `.github/workflows/ci.yml`'s `deploy-cloudflare` job redeploys it automatically on every push to `main` that passes CI. See **`docs/deployment.md`** for the full walkthrough of both (Docker install on DietPi, disk-space caution, Tailscale mesh-only vs. Funnel, backend deployment options, Cloudflare specifics) and `CLAUDE.md`'s "Deployment" section for the reasoning and what this repo needs to keep true (stay static, don't assume runtime internet access) for either plan to keep working. ## 3. On-device deployment to an Orange Pi Same prebuilt `linux/arm64` image the DietPi path uses — Orange Pi boards run that architecture too, so there's nothing to build on-device. ```bash # On the Orange Pi (SSH in first): # 1. Install Docker (works on Armbian/Debian/Ubuntu-based Orange Pi images) curl -fsSL https://get.docker.com | sh sudo usermod -aG docker $USER # log out and back in (or `newgrp docker`) for the group change to apply # 2. Authenticate — one classic PAT covers both GHCR (the image is # private) and cloning the repo below (also private; its # docker-compose.yml can't be curl'd anonymously). Create it at # https://github.com/settings/tokens → scopes: read:packages + repo # (repo is broader than strictly needed for a read-only clone of one # repo — it can touch any repo your account can access — so treat # this token as sensitive; a narrower pair of separate tokens, # read:packages for GHCR and a fine-grained Contents:Read-only one # scoped to just this repo, is the more conservative alternative if # you'd rather not create one broader token) docker login ghcr.io -u # paste the PAT when prompted for a password — it's not echoed # 3. Clone the repo for its compose file, reusing that same PAT, and # bring the app up git clone https://github.com/abumusasakib/neuro-web.git ~/neuro-web # enter your GitHub username when prompted, then paste the same PAT # as the password — same not-echoed prompt step 2 used cd ~/neuro-web docker compose pull docker compose up -d # → http://:8080 ``` That's the default service: talks to the real, already-live backend directly (no extra containers needed). ### Also running the backend on-device, connected to this frontend Instead of calling the hosted Render backend, run `github.com/RahMaisha/Neuro`'s own backend (+ its own Postgres) on the same Orange Pi, with the frontend's nginx proxying `/api/` straight to it — no code or config changes, `docker-compose.yml`'s `local-backend` profile already wires this up: ```bash # Same GHCR login from step 2 above already covers the backend's image # too (ghcr.io/rahmaisha/neuro-backend) — one login covers both, as long # as your GitHub account has read access to that private package # (Maisha can grant this under RahMaisha/Neuro → Settings → Collaborators). cd ~/neuro-web # .env.example is already here from step 3's git clone — no need to # fetch it separately (and the same raw.githubusercontent.com curl # that broke for docker-compose.yml would break here too, same reason) cp .env.example .env # edit .env: at minimum set JWT_SECRET / WEBHOOK_SECRET / SYSTEM_TOKEN to # real values before exposing this box beyond a private LAN/Tailscale — # left blank, it falls back to a well-known dev default. docker compose --profile local-backend up -d # → frontend (talking to the on-device backend) at # http://:8082 # backend-db + backend + this frontend container all come up together. # The default neuro-web service (port 8080, step 3's real-backend one) # keeps running alongside it unless you stop it (docker compose stop neuro-web). ``` Gets `manifest unknown` or `No such image` here? See `docs/deployment.md` §6 — this profile needs the `:mock` tag already published, and that's a manual, not automatic, step. ### Exposing this beyond your LAN (Tailscale) No port forwarding, no public IP, no DDNS. Served under a path (`/neuro-web`) on the device's own tailnet hostname rather than the bare root — so another service sharing this same box later (its own container, its own port) can sit at its own path on the same hostname instead of needing its own port number remembered separately. Pick the port that matches whichever service you brought up above (`8080` for the default, real-backend service; `8082` if you're running the on-device backend too). ```bash # Install and join your tailnet curl -fsSL https://tailscale.com/install.sh | sh tailscale up ``` Tailnet-only access (reachable from any device already on your tailnet, nothing public) goes through `tailscale serve`'s own embedded HTTPS reverse proxy — `--set-path` is what mounts it under `/neuro-web` instead of the root; the proxy only accepts an `http://127.0.0.1` target, not a bare port or `localhost`: ```bash tailscale serve --bg --https=443 --set-path=/neuro-web 127.0.0.1: # → https://..ts.net/neuro-web # from any device already on your tailnet ``` For public HTTPS access instead (e.g. a judge/reviewer without Tailscale installed), use Funnel the same way: ```bash # One-time, in the Tailscale admin console: enable MagicDNS and HTTPS # Certificates, and confirm your ACL allows the `funnel` node attribute # for this device. Then, on the Orange Pi: tailscale cert ..ts.net tailscale funnel --bg --https=443 --set-path=/neuro-web 127.0.0.1: # verify: tailscale funnel status # → https://..ts.net/neuro-web # from any network # If Funnel ever drops (this only clears this one path's mount, not # any other service's — use `tailscale funnel reset` instead if you # want to clear every mount on this device): tailscale funnel --https=443 --set-path=/neuro-web off tailscale funnel --bg --https=443 --set-path=/neuro-web 127.0.0.1: ``` **Not live-verified** — Tailscale's own CLI reference (`tailscale.com/kb/1311/serve`, `tailscale.com/kb/1242/serve`) documents `--set-path`, `--bg`, `--https`, and an `http://127.0.0.1` target individually, but no worked example anywhere combines all of them in one command the way this repo's own build does; nothing here has actually been run against a real tailnet yet. If the exact syntax needs adjusting once you run it, `tailscale serve --help` / `tailscale funnel --help` on the box itself is the authoritative source for your installed client version — please report back what needed to change so this gets corrected. See `docs/deployment.md` §2–4 for updating to a newer image, disk-space upkeep, and running a mock backend instead.
Demo credentials Same backend, same demo accounts as `neuro-scanner` (`https://neuro-nohg.onrender.com`, `github.com/RahMaisha/Neuro`'s own `app/modules/demo/seed.py`) — one per role, all sharing the same starting password. Works against every deployment path above (and local dev via `npm start`, which points at the same live backend by default) since they all call the same backend. **This app role-gates two things**, both reflecting the real backend's own per-endpoint `Roles:` rules (`core/auth/roles.ts`, confirmed directly against `https://neuro-nohg.onrender.com/openapi.json`, not the SRS's own coarser 3-role table — see that file's doc comment): the **Delivery** tile/route (`/dc-receiving`, DC Receiving — `DC_STAFF`-only on the real backend, no other role at all) and Product Listing's **Add New Product**/**Edit** (`POST`/`PATCH /products` — `DC_MANAGER`/`HEAD_OFFICE` only; browsing has no restriction). An unauthorized role simply doesn't see that tile/button at all, rather than reaching it and hitting a 403 — not a security boundary, the backend's own enforcement remains the real one (see `core/auth/roles.ts` and `openspec/changes/add-frontend-rbac/`). | Role | Email | Features available in this app | | --- | --- | --- | | DC Staff | `dc_staff@neuro.local` | **Delivery** (DC Receiving) — the only role that can open `/dc-receiving` at all: log truck arrival, add receipt lines (packaged or loose), sample expiry dates, confirm the receipt. **Product Listing**: browsing only (no Add/Edit). | | DC Manager | `dc_manager@neuro.local` | **Product Listing**: full access, Add New Product and Edit, on top of browsing. No Delivery tile — DC Receiving is `DC_STAFF`-only even for this role. | | Outlet Staff | `outlet_staff@neuro.local` | **Product Listing**: browsing only. No Delivery tile. | | Outlet Manager | `outlet_manager@neuro.local` | Same as Outlet Staff in this app today — Outlet Today (the Decision Queue, where this role's real backend actions like approve/adjust/reject actually live) is still a skeleton placeholder, not built yet. | | Head Office | `head_office@neuro.local` | **Product Listing**: full access, Add New Product and Edit. No Delivery tile. | Every role, regardless of the above: **Change Password** (the topbar's Settings icon, `/change-password`) — not role-gated, and not forced at login either (the real backend doesn't enforce `must_change_password` on any other endpoint, so this app doesn't invent stricter enforcement than the backend has). **Password (all accounts):** `Sh@des` This is this deployment's actual `DEFAULT_PASSWORD` override (the backend's own code default is a different, well-known value — `RahMaisha/Neuro`'s `docs/DEPLOY_FREE.md` explicitly warns not to leave that one in place on a public URL, since anyone could log in as head office and wipe the demo data). **Rotate this before sharing this repo or the live URL any more widely than the current team/judges** — `DEFAULT_PASSWORD` is a Render environment variable on the `neuro-api` service (Render dashboard → service → Environment), separate from anything in this repo.
CI Notes (Maintainers Only) `.github/workflows/ci.yml`'s `verify` job runs on every push/PR to `main`: ```bash npx ng build --configuration production npx ng test --no-watch --no-progress --browsers=ChromeHeadless ``` Deploying is manual only, triggered from the Actions tab (or `gh workflow run `) rather than automatically on every push — a 2026-10-10 change, since auto-deploying/publishing on every single push spent real build minutes whether or not anyone was about to ship: - `ci.yml`'s `deploy-cloudflare` job runs only when the whole workflow is dispatched manually (`workflow_dispatch`, no inputs) — a dispatch run also re-runs `verify` alongside it, so a manual deploy still gets the same build/test guarantee the old automatic path had. - `.github/workflows/docker-publish.yml` is a fully independent, manual-only workflow (`workflow_dispatch` with a `build_configuration` input) — it no longer triggers off CI's completion at all. Commit messages are Conventional Commits (`type(scope): subject` — see `CLAUDE.md`) — nothing enforces this in CI yet beyond convention.
Technical Notes
Design System ## Design System `docs/design-system/` contains the actual design tokens (colors, type, spacing, radii), guideline specimens (`guidelines/*.card.html` — open any of these directly in a browser), and prototyping-reference components, extracted directly from the team's Figma file rather than invented. It's also registered as a Claude Code skill (`neuro-design-system`) for anyone using an AI assistant against this repo. `src/styles.scss` imports `docs/design-system/styles.css` directly, so every CSS custom property documented there (`--blue-ink`, `--radius-base`, etc.) is live in the running app, not a copy someone has to keep in sync by hand. Read `docs/design-system/readme.md`'s "Notes & gaps" section before designing anything status-driven (severity colors, at-risk indicators) — it honestly documents what the source design doesn't have yet rather than inventing values to fill the gap.
API Mocking ## Recipe - Install [Mockoon](https://mockoon.com/tutorials/getting-started/) if you want the desktop app/GUI, or just use the CLI already wired into `npm run mock` (no separate install needed — it runs via `npx`). - The mock environment lives at `mock/neuro.mock.json`, generated from `tools/build-mock.py` (`python3 tools/build-mock.py`) — edit the route/data definitions there and regenerate, rather than hand-editing the JSON directly; the large Handlebars template strings stay far more readable as Python. Re-test every touched route against a real `mockoon-cli` instance on a throwaway port before trusting a change (an escaping mistake can produce JSON that's syntactically valid but whose "body" text Handlebars itself then rejects at request time — `python3 -m json.tool` alone won't catch that). Opening the file in the Mockoon desktop app works too for a quick visual look, just regenerate from the script afterward rather than keeping manual edits. - `npm run mock` starts it on `MOCKOON_PORT` (default `3001`). `npm run start:mock` proxies the Angular app's relative `/api/v1` requests to that same port, so the browser never needs a hard-coded Mockoon origin. ## Why Mockoon (and not a hosted mocking service) - One route can return a different response depending on the request (a known code vs. an unknown one, for example) — so the same mock endpoint covers both the happy path and the error path, instead of needing a different URL per scenario. - Switching from mock mode to a real backend is a build-configuration flag (`--configuration mock`), never a code change. - The mock definitions are a single JSON file, committed and shared across the team — everyone's mock behaves identically. ## Disadvantage A build shipped in mock mode only works on whatever machine is also running the mock server — it's a development/demo aid, not something to ship.
Unit Tests ## Running them ```bash npm test # interactive, watches for changes npm run test:coverage # single run + a coverage summary + coverage/neuro-web/index.html # the way CI runs it (.github/workflows/ci.yml) ``` Tests are co-located `*.spec.ts` files next to the source they test (Angular CLI's own default, already the pattern `app.spec.ts` sets) — no separate `test/` tree mirroring `src/app/`. ## Coverage `npm run test:coverage` prints an Istanbul coverage summary and writes an HTML report to `coverage/neuro-web/index.html` (gitignored — regenerate locally rather than committing it). CI uploads that same report as a build artifact and echoes the summary into the job's step summary. CI also enforces a coverage **floor** — `script/ci/check-coverage.sh` parses that same printed summary and fails the job if any metric drops below it: | Metric | Floor | Actual (2026-10-04) | | --- | --- | --- | | Statements | 80% | 84.21% | | Branches | 55% | 62.55% | | Functions | 70% | 75.84% | | Lines | 85% | 88.31% | These are **regression floors a few points below the real numbers**, not targets to chase — they exist so a change can't quietly delete test coverage, not to block work until some arbitrary percentage is hit. Raise them as real coverage grows (e.g. once component testing — see below — closes more of the gap); don't lower them to turn a red build green without raising a flag for the team first. The check parses the printed summary rather than configuring Karma's own `coverageReporter.check` threshold directly — a custom `karma.conf.js` was tried and dropped (see the "ci(test): add coverage reporting" commit): Angular's esbuild-based `@angular/build:karma` builder doesn't reliably merge a custom `karmaConfig` file with its own generated config, so this stays a plain shell check against the builder's own default output instead. ## What gets a TestBed and what doesn't Three shapes so far, matching `Angular_Frontend_Clean_Architecture_for_Neuro_ERP.md`'s Testing Strategy: - **Pure domain functions** (`currency.ts`, `relative-time.ts`, `product-type.ts`, the DTO↔entity mappers) — plain Jasmine `describe`/`it`, no `TestBed` at all. "Unit-test pure domain functions without Angular TestBed," per that doc. - **Use cases** (`application/use-cases/*.use-case.ts`) — a minimal provider-only `TestBed` (the use case plus a `jasmine.createSpyObj` standing in for its abstract repository), no component or template involved. "Unit- test use cases with mocked repository interfaces." - **HTTP-calling services** (`ScanService`, `ActivityLogService`) — `provideHttpClientTesting()` / `HttpTestingController` against a real-shaped `HttpClient`, not a hand-rolled fake, per that doc's explicit recommendation for this layer. ## Current coverage, honestly (2026-10-04, 131 specs) ~83% statement / ~75% function / ~86% line coverage overall. Branch coverage (~62%) looks like it dropped from an earlier pass, but it didn't regress — the denominator grew a lot once component templates (`@if`/ `@for`/ternaries) started being measured at all, and only some of each component's branches are exercised yet, not all of them. - **Covered well:** pure domain functions and DTO↔entity mappers across both features; every HTTP-touching class (`AuthService`, `ScanService`, `ActivityLogService`, both `*.repository-impl.ts` classes); `authGuard`/ `authInterceptor`; all five use-cases across both features; and five components with real logic in them — `DcReceivingPageComponent` (the `lineToBatches` batch-building logic, end to end through the DOM), `ProductListingPageComponent` (the add/edit wizard end to end, plus the `canSave` defensive-guard branch), `PackagedSamplePanelComponent`, `LooseCratePanelComponent`, and `ReceiptLineRowComponent`. Two real bugs surfaced and got fixed while writing these: `type="number"` + `ngModel` silently handing a `string`-typed field a JS `number` at runtime, in both `packaged-sample-panel` and `loose-crate-panel`. - **Not covered yet:** `LocalSidebarComponent`/`ActivityPanelComponent` (exercised indirectly through the page specs above, but no dedicated spec of their own yet), `ReceivingOverviewComponent`/ `PrintLabelsModalComponent`, `ProductOverviewComponent`/ `ProductListTableComponent`/the two product-listing form components (exercised indirectly the same way), and `App` beyond its two existing smoke tests. - **Correctly untested:** Home/Outlet Today/Dispatch & Transit/Batch Detail/Impact Dashboard — all are intentional skeleton placeholders per CLAUDE.md, nothing there yet to test. The component-testing convention this pass established — `TestBed` + `fixture.componentRef.setInput()` for signal inputs, driving the template through real DOM events (`By.css` + dispatched `input`/`click`) rather than calling `protected` methods directly, spying on injected use-cases/services rather than standing up their full HTTP chain a second time — is documented at the top of `packaged-sample-panel.component.spec.ts`; later component specs should read that first rather than inventing a second convention. ## Gotcha: zoneless + TestBed Any spec that creates a `TestBed` needs `provideZonelessChangeDetection()` in its own `providers` array. This app has no `zone.js` (see "Zoneless Change Detection" below) — `provideZonelessChangeDetection()` is wired once in `app.config.ts` for the running app, but `TestBed.configureTestingModule(...)` builds its own injector from scratch and doesn't inherit it. Omit it and Angular throws `NG0908` ("this configuration requires Zone.js") the moment anything tries to read a signal — see `app.spec.ts`'s note.
Zoneless Change Detection ## Why no `zone.js` This app uses `provideZonelessChangeDetection()` and ships with the `zone.js` polyfill and dependency removed entirely — a direct response to wanting the app to feel lighter, both in bundle size and in how much "magic" change detection does behind the scenes. Every reactive value uses `signal` / `computed` explicitly instead. If a future dependency requires `zone.js` (rare, but some older libraries assume it), that's worth a deliberate decision before reintroducing it, not a silent side effect of adding a package.
Codebase Graph (graphify) ## Mapping the codebase `graphify` (installed globally, skill registered for Claude Code) builds a local knowledge graph of this repo from its actual source — tree-sitter AST parsing, no LLM calls for the extraction step itself. Invoke `/graphify .` from the repo root once there's enough real feature code to be worth mapping. Output (`graphify-out/`, `GRAPH_REPORT.md`) is gitignored — it's a regenerable artifact, not something to commit.
## Caution - `package-lock.json` is tracked. This is an application, not a library — pinning the exact dependency tree means every install (and every CI run) resolves identically instead of drifting silently. - `.claude/` is gitignored. The design system is real, tracked content at `docs/design-system/` — `.claude/skills/neuro-design-system` is just a local symlink to it for AI-assistant convenience, recreated per machine, not shipped via git. - Node 20.19 is the floor, not a suggestion — the Angular CLI itself refuses to run below it.