Files
co-lite/solvway-admin-portal
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00
..

Back-Office Template — babyboo.my

Migration in progress. This module is being converted from a Vite SPA to a Next.js App Router project (see openspec/changes/add-admin-portal-auth). app/ currently holds only a placeholder shell; the real pages, components and services below still live under src/ — specifically src/legacy-pages/ (renamed from src/pages/ because Next.js reserves that name for its own Pages Router) — pending a later change that ports them into app/*/page.tsx with react-router calls rewired to next/navigation. Everything in this README describing routes, the mock-data architecture and theming still describes that src/ tree.

A reusable admin/back-office front end for MLM (multi-level marketing) clients. It ships against mock data behind an API-shaped service layer, so a client project can swap in a real backend without touching any page or component code.

Currently skinned for babyboo.my — baby & maternity retail, competing with Medela, Momcozy, Kinderkraft and Hamilton. The audience is sleep-deprived, time-poor, highly selective parents, so decisions are ranked clarity → speed → trust. The look is deliberately warm and soft-edged rather than clinical: cream page, warm neutrals, brand brown #6E3E17 with a gold #F2BC57 accent, and a 1rem radius so nothing has a sharp corner.

Stack

  • Next.js 16 (App Router, output: "standalone") — build tool and server
  • React 19 + TypeScript (strict mode)
  • Tailwind CSS 3 via PostCSS + tailwind.config.ts — matches solvway-customer-portal's wiring
  • Sass — token maps and mixins in src/styles/ (pending port into app/globals.css, which currently carries a plain-CSS transliteration of the same tokens)
  • shadcn/ui — owned component source, themed with CSS variables
  • Recharts via shadcn's chart wrapper — dashboard charts
  • TanStack Table — data tables
  • lucide-react — icons
  • react-router-dom v7 — still a dependency for the not-yet-ported src/legacy-pages/ tree; removed once that tree is rewired to next/navigation
  • Vitest + React Testing Library — tests

Getting Started

npm install
npm run dev          # next dev --port 3001
npm test             # run the full test suite (Vitest, run once)
npm run test:watch   # run tests in watch mode
npm run build        # next build (type-checks + production build)
npm start            # next start --port 3001, after a build

python3 scripts/check-contrast.py   # verify token contrast in both themes

Auth

Login is no longer mocked. /login posts to the same-origin /api/auth/login route handler, which proxies solvway-mobile-api (app/lib/server/mobileApi.ts) and sets an httpOnly session cookie server-side. Signing in requires:

  • MOBILE_API_BASE_URL and MOBILE_API_KEY set (see .env.example), pointing at a reachable solvway-mobile-api instance.
  • A real UserType.A account in that instance's services-system.

Without a configured Mobile API, /login still renders, but submitting the form reports "Mobile API is not configured" — there is no local/offline demo login anymore.

Visiting any other route while unauthenticated redirects back to /login; logging out clears the session and returns you there as well.

Screen Inventory

Route Page Notes
/login Login Email/password with a password-reveal toggle; inline error on invalid credentials
/ Dashboard Live KPI tiles (members, settled revenue/orders, rewards; Malaysia-time month), 12-month revenue and member-growth charts, revenue by channel, rank/status mix, rewards by type, top-earner leaderboard
/members Members Sortable, faceted, URL-synced member table with column visibility and CSV export
/members/:id Member Detail Identity header, performance strip, tabs for Sales · Commissions · Downline
/reports Reports Live Sales (settled orders) and Rewards tabs, Malaysia-time period presets + date range, paged, period totals, full-result-set CSV export
/network Network Genealogy as an indented tree or a top-down chart, with search that expands ancestors and highlights matches

Navigation is a collapsible sidebar with up to three levels: it collapses to an icon rail on desktop (persisted per browser) and becomes an overlay drawer below lg. Every leaf resolves to a real view — Members → By rank → Diamond applies ?rank=Diamond, the Reports children select ?tab= — so none of them are decorative.

src/components/app/nav-config.ts is the contract a backend menu endpoint would return: plain label / to / children / isDefault data, with the icon as the only client-side concern. nav-config.test.ts encodes the invariants such an endpoint must satisfy (leaf-xor-group, depth cap, real routes, unique targets, one default per group), so a backend implementation can be validated against the same rules the UI relies on.

Design Standard

docs/design/DASHBOARD-STANDARD.md is authoritative. It defines the tokens, layout grid, KPI and chart specs, required data states, accessibility floor (WCAG 2.1 AA) and the anti-patterns. Read it before adding a screen. Where it and a component disagree, the component is wrong.

Mock-Data Architecture

Everything under src/services/* is written to look and behave like a real API client: every function is async, returns plain data (no framework types leak out), and pagination, filtering and sorting happen the same way a backend would do them. The Dashboard and Reports are live (app/lib/services/adminDashboard.ts -> BFF -> mobile-api aggregate reads); src/services/api.ts holds shared helpers (pagination, sorting, an artificial network delay).

**Pages only call functions from the other src/services/* modules. This is the intended swap point: to connect a real backend, replace the bodies of these service functions with fetch calls that return the same shapes (see src/types/index.ts), and no page or component needs to change.

src/
  components/
    app/           # two-level sidebar + nav config
    ui/            # shadcn primitives + DataTable, states, chart skeletons
    dashboard/     # KPI tile, chart card (chart + its accessible table)
    genealogy/     # tree view and org chart
  styles/
    _variables.scss  # $palettes (light + dark), breakpoints, layout, z-index
    _mixins.scss     # respond-to, focus-ring, tap-target, brand gradient
    index.scss       # emits the token blocks from the maps + base layer
    tailwind.css     # Tailwind entry + @theme (kept as CSS on purpose)
  lib/
    theme.tsx      # light/dark provider, persists to localStorage
    utils.ts       # cn()
  services/
    api.ts         # shared mock helpers (pagination, sorting, delay)
    period.ts      # month labels
    auth.ts        # login/logout/session         — swap point
    members.ts     # list/detail/facets/stats     — swap point
    network.ts     # genealogy tree               — swap point

Theming

Colour lives in Sass maps in src/styles/_variables.scss, emitted as CSS custom properties by index.scss and exposed to Tailwind via @theme inline in tailwind.css. No component contains a colour literal.

The babyboo palette is brand brown #6E3E17 with a gold #F2BC57 accent on a cream page, plus warm neutrals and a warm-espresso dark mode (not slate).

One thing to know about the gold: #F2BC57 is 1.73:1 against white, so it can only ever be a filled surface carrying --accent-foreground text — never text, a thin indicator, or a chart series, all of which would be invisible in light mode. Anything in the accent family that must carry meaning uses --accent-strong (#9A6212, 5.08:1). That is why the accent is absent from the chart ramp.

Both themes live in the same map, so a token cannot be added to light and forgotten in dark.

To re-skin for a client:

  1. Edit $palettes in src/styles/_variables.scss — primary, accent, chart ramp, radius.
  2. Swap the font <link> (was index.html, now belongs in app/layout.tsx — see the Migration note above) and the --font-* tokens (now in app/globals.css, ported from src/styles/tailwind.css).
  3. Replace the wordmark in src/components/app/app-sidebar.tsx.
  4. Run python3 scripts/check-contrast.py.

Fonts

Headings are Google Sans, body and numerals are Inter — two families, no monospace. Numerals use Inter's own tabular figures (.tabular), so columns still align while avoiding the technical register of monospace digits, and it saves a font request.

Fonts were linked from index.html's <link> tags before the Next.js conversion; the placeholder app/layout.tsx does not yet re-add them (Task 6 restores the font <link>s or switches to next/font). If Google Sans must be self-hosted (offline builds, or a licensed variant), src/styles/index.scss has a commented @font-face block — drop the woff2 files into public/fonts/ and uncomment; the heading stack already requests the family first. DM Sans is the fallback if it fails to load.

Light is the default; dark is opt-in via the header toggle and persisted per browser. Note that --border (dividers, decorative) and --input (form-control boundaries, must clear 3:1) are deliberately different values — see the standard's §2.

scripts/check-contrast.py verifies all of the above (both themes, exits non-zero on regression). Run it after any palette edit.

Testing

143 tests across 29 files (npx vitest run), covering the ported Next.js app under app/. Server-only modules (app/lib/server/mobileApi.ts, the /api/auth/* route handlers) run under jsdom because vitest.config.ts aliases server-only to test/stub-empty.ts. Client components mock apiGet/apiPost (app/lib/clientApi.ts) rather than hitting a network, so UI tests don't depend on solvway-mobile-api being reachable.

Charts are asserted through the accessible data table that every chart is required to ship (standard §6) rather than by measuring SVG — so no chart library gets stubbed, and the assertions check real figures.

vitest.setup.ts (repo root) stubs matchMedia, ResizeObserver, and the Pointer Events APIs that Radix needs and jsdom lacks.

Known Issues

  • The production bundle is a single ~958 kB (288 kB gzip) chunk. That is down from 2.62 MB (797 kB gzip) under antd, but a client project with stricter budgets should still code-split with dynamic import().
  • sass-embedded is pinned to 1.77.8 via an overrides entry in package.json, and removing it will hang the build on macOS 13. Vite auto-installs sass-embedded as an optional peer; from roughly 1.83 its bundled Dart VM requires macOS 14+ and aborts with VM initialization failed. Because that happens during the compiler handshake, the build hangs rather than failing, which makes it look like an infinite loop. On macOS 14+ the pin is harmless and can be dropped.
  • In-browser visual verification across all breakpoints has not been automated. The contrast floor is checked by script; layout at 375/768/1024/1440px still needs a human or a browser-driver pass.