houseofmaji

House of Maji Flow

Build “House of Maji Machines” — a fulfillment-tracking system for a water-

machine sales company. Use Supabase for all data persistence and Supabase

Auth for login — no mock/in-memory data anywhere.

======================================================================

ROLES & AUTH

======================================================================

Four roles: sales_rep, chief_engineer, engineer, admin.

admin is a distinct role from chief_engineer — NOT the same person or

permission set. Admin oversees the whole system; Chief Engineer runs the

day-to-day assembly/delivery pipeline.

Sign-up form: full name, email, password, role (dropdown: Sales Rep /

Engineer / Chief Engineer / Admin).

======================================================================

DATABASE SCHEMA

======================================================================

Row Level Security on every table: everyone signed in can read; writes

restricted per role (see PERMISSIONS below). Only admin can write to

profiles.role after initial sign-up (role management from the Admin

panel).

Compute commissions server-side via a Postgres function/trigger — never

client-side, so amounts can’t be tampered with from the browser:

======================================================================

FULFILLMENT FLOW

======================================================================

Stages, forward-only: received -> waiting_for_frame -> assembling ->

delivery -> installed. Each transition closes the current open

stage_events row (sets exited_at = now()) and opens the next one (stage,

actor_id, entered_at = now()).

  1. Sales Rep: handover form — client name, location, water analysis

    notes, machine type, agreed price (KES), agreed delivery date.

    Submitting creates the fulfillment at stage ‘received’, actor = the

    logged-in sales rep.

  2. Chief Engineer dashboard: all fulfillments grouped by stage

    (kanban-style).

    • On a ‘received’ item: “Order Frame” button -> stage

      ‘waiting_for_frame’, actor = the chief engineer.

    • On a ‘waiting_for_frame’ item: assign an Assembly Engineer

      (required, dropdown of engineer-role profiles) and optionally a

      separate Installation Engineer (optional dropdown — blank means the

      same engineer installs) -> stage ‘assembling’, actor = assembly

      engineer.

    • RLS-enforced: only chief_engineer can perform these two actions.

  3. Engineer view: list of fulfillments assigned to the logged-in

    engineer (as assembly or installation engineer).

    • On an ‘assembling’ item assigned to them: “Mark Assembly Complete”

      -> stage ‘delivery’, actor = installation engineer (or themselves

      if none assigned).

    • On a ‘delivery’ item assigned to them: “Mark Installed” -> stage

      ‘installed’, actor = same installer.

    • RLS-enforced: only the specific assigned engineer for that

      fulfillment (or a chief_engineer overriding) can perform these.

  4. Fulfillment detail page (any signed-in role): horizontal progress bar

    across the 5 stages. Each stage node shows the stage name, who was/is

    tasked there (full_name), and duration at that stage (live-ticking

    for the current stage, static for past stages, computed from

    entered_at/exited_at). Below it: client/machine details and a

    commissions panel (role, person, amount in KES, paid/unpaid badge).

  5. Commissions page (chief_engineer and admin, RLS-enforced): table of

    all commission rows, filterable by person and paid/unpaid, running

    total per person, paid/unpaid toggle button.

======================================================================

ADMIN PANEL (admin role only, RLS-enforced — chief_engineer cannot access)

======================================================================

Separate page/route from the Chief Engineer dashboard.

======================================================================

DESIGN

======================================================================

Clean, polished dashboard aesthetic — this should feel like one cohesive

product across every page, not five separately-styled screens:

This project was built with Lovable.

Live app: https://houseofmaji.lovable.app

Build with Lovable

Continue developing this project in the Lovable editor.

Development

Prefer working locally? You need Node.js and npm — install with nvm.

git clone <this-repository-url>
cd <repository-name>
npm i
npm run dev