# PRODUCT_ARCHITECTURE.md — HATEM AUTO RENTAL (v1 design scope)

Status: **v1.0 for owner review, 2026-11-30.** Design-phase document: no code, database or deployment changes come from it.
Brand: `BRAND_GUIDELINES.md` (authoritative). UI tokens: `DESIGN_SYSTEM.md`. Workflow rules: `DATABASE_AND_WORKFLOW_PROPOSAL.md` v1.1 (§1 statuses and transitions, §2 guest requests).

Labels: ✅ owner-confirmed · 🟡 proposed by the design team · ⛔ unknown / pending owner (never invented in designs; shown as a placeholder).

---

## 1. Final product understanding (Phase 2)

### 1.1 What HATEM is ✅
A small, individually owned car rental business in **Tripoli, Lebanon**, with **10–30 vehicles**. Most visitors are on **phones**. The site is **Arabic (RTL) and English (LTR)**. Customers reach HATEM through the **website plus WhatsApp**.

### 1.2 The one rule that shapes everything ✅
The website takes **Rental Requests, not bookings.** There is no instant confirmation and no online payment.
- A request **promises nothing** until staff approve it.
- **Approved = "Confirmed"** = vehicle, dates and agreed price settled with the customer (usually on WhatsApp). Confirmed is the **only** status that blocks a vehicle on the calendar.
- No page, message or email may say "confirmed", "booked" or "reserved" before that moment.

### 1.3 Customers need to…
1. See which cars HATEM has, with honest information (photos, seats, transmission, fuel, what's included). Prices are shown **only once the owner provides them** (⛔ D-01, D-07).
2. Compare 2–3 cars side by side ✅.
3. Ask for a car for specific dates **quickly on a phone**, without creating an account ✅ (guest request).
4. Get a reference and continue on **WhatsApp** with a prepared message.
5. Check what's happening with their request, and withdraw it while it's still open.
6. Use the whole site in Arabic or English, with Western digits everywhere ✅.

### 1.4 Staff need to…
1. See new requests immediately, in priority order (oldest new first, pickup soonest).
2. Review a request, talk to the customer on WhatsApp in AR or EN using **quick replies** ✅, record the agreed price and how the customer agreed, then **approve** in one action.
3. Know **at a glance** which cars are free or blocked on which dates (calendar).
4. Create a request **on behalf of** a customer who called or walked in ✅.
5. Manage the fleet: add/edit vehicles, photos, publish/unpublish, mark inactive.
6. Look up a customer's history; block abusive phone numbers.
7. Owner only: business settings, staff access.

---

## 2. Scope

### 2.1 In v1 ✅
Public site · guest Rental Request · request status for the requester · staff review/approve/decline/cancel/complete · approved-request modification (atomic) · **vehicle comparison (2–3)** · **staff-created requests** · **WhatsApp quick replies AR/EN** · availability calendar · vehicles CRUD · customers · business settings · staff access.

### 2.2 Postponed (not designed for v1) ✅
Guest request lookup by reference + phone · Smart Match (car suggestions) · online payment · instant booking · SMS/OTP verification · reviews/ratings · loyalty · multi-branch.

### 2.3 Not added silently
Anything not listed in 2.1 is out of scope until the owner asks for it. Designs must not show features (e.g. "Pay now", star ratings, "Book instantly", live chat) that v1 doesn't have.

---

## 3. Sitemap (Phase 3)

Routes are prefixed by locale: `/ar/...` (default 🟡) and `/en/...`.

### 3.1 Public website
| # | Screen | Route | Purpose |
|---|---|---|---|
| P1 | Home | `/` | Brand, what HATEM offers, how a request works, featured cars, start a request |
| P2 | Fleet | `/fleet` | All published cars; filters (type, seats, transmission, fuel); add to compare |
| P3 | Vehicle Details | `/fleet/[slug]` | Photos, specs, what's included, "Request this car" |
| P4 | Vehicle Comparison | `/compare?ids=` | 2–3 cars side by side; differences highlighted |
| P5 | Rental Request | `/request?vehicle=` | Dates, pickup/return, contact, note; CAPTCHA (invisible) |
| P6 | Request Submitted | `/request/[ref]/submitted` | Reference, what happens next, "Continue on WhatsApp" |
| P7 | Contact / About | `/contact` | Who HATEM is, WhatsApp, phone, map, hours (⛔ D-05) |

### 3.2 Customer experience
| # | Screen | Route | Purpose |
|---|---|---|---|
| C1 | My Account | `/account` | Sign in / profile (name, phone, language). Guest sessions see a "save your requests" prompt 🟡 |
| C2 | My Requests | `/account/requests` (+ `/[ref]`) | List and detail of my requests with status timeline; withdraw while open |

Guest note ✅: a guest sees their requests **only in the same browser session**. If the session is lost they continue on WhatsApp with the reference (lookup is postponed).

### 3.3 Admin dashboard (`/admin`, staff only)
| # | Screen | Route | Who |
|---|---|---|---|
| A1 | Dashboard Overview | `/admin` | Staff, owner |
| A2 | Rental Requests | `/admin/requests` | Staff, owner |
| A3 | Request Details | `/admin/requests/[ref]` | Staff, owner |
| A4 | Create Staff Request | `/admin/requests/new` | Staff, owner |
| A5 | Vehicles | `/admin/vehicles` | Staff, owner |
| A6 | Add / Edit Vehicle | `/admin/vehicles/new`, `/[id]` | Staff, owner |
| A7 | Availability Calendar | `/admin/calendar` | Staff, owner |
| A8 | Customers | `/admin/customers` | Staff, owner |
| A9 | Customer Details | `/admin/customers/[id]` | Staff, owner |
| A10 | WhatsApp Quick Replies | `/admin/quick-replies` | Edit: owner 🟡; use: staff |
| A11 | Business Settings | `/admin/settings` | Owner |
| A12 | Staff / Admin Access | `/admin/staff` | Owner |

Total: **21 screens** (7 public + 2 customer + 12 admin).

### 3.4 Shared modules
Header (logo, nav, language switch, account) · Footer (dark, ivory mark) · Admin shell (dark Night sidebar with reversed mark; top bar; mobile bottom bar 🟡) · Compare tray (sticky, up to 3) · StatusBadge · Request timeline · WhatsApp handoff · Calendar · DataTable/Card list · Empty / Error / Loading states.

---

## 4. Screen states (every screen gets these)
| State | Rule |
|---|---|
| Loading | Skeletons matching the final layout; no spinners over blank pages |
| Empty | Plain explanation + one next action (e.g. "No requests yet") |
| Error | What happened in plain words + retry; never raw error codes |
| Success | Toast (`aria-live`) for staff actions; full page for request submitted |
| Not configured | When owner data is missing (prices, WhatsApp number, hours), show a neutral placeholder: "Price on request" / "Contact details coming soon". **Never invent a value.** |
| Permission | Staff hitting an owner-only page see "Only the owner can change this" |

---

## 5. Journeys (Phase 4)

### 5.1 Customer journey: find a car and send a request
1. **Home → Fleet.** Filters; each card shows photo, name, key specs, "Request" and "Compare".
2. **(Optional) Compare 2–3 cars.** Adding a 4th asks to replace one. Compare page highlights differences.
3. **Vehicle Details → "Request this car".**
4. **Rental Request form.** Required: pickup date+time, return date+time, pickup location (Tripoli branch ✅; others ⛔ D-14), full name, phone (E.164 with country picker, default LB +961), preferred language. Optional: message. Consent line about being contacted on WhatsApp/phone.
5. **Submit** → invisible CAPTCHA → DB function with idempotency key.
6. **Request Submitted:** reference (e.g. `HAR-2026-00042` format 🟡), status "Submitted", what happens next, **"Continue on WhatsApp"** (prepared AR/EN message including the reference).

| States | Detail |
|---|---|
| Success | P6 page; status "Submitted / تم الإرسال" — never "Confirmed" |
| Validation errors | Inline under each field + summary at top; focus moves to the first error |
| Submitting | Button loading + disabled (no double submit) |
| Failed | Network/server: keep all entered data, offer retry (same idempotency key) |
| Limits hit | "You've sent several requests today. Please continue on WhatsApp." (3 per session / 5 per phone per 24 h ✅) |
| Blocked phone | Same neutral message as limits (doesn't reveal the block) |
| WhatsApp not configured | P6 hides the WhatsApp button and shows "We'll contact you" |

Edge cases: return before pickup · pickup in the past · car unpublished between viewing and submitting · RTL phone input (number stays LTR) · CAPTCHA fails silently → visible retry message · same form resubmitted → same reference returned.

### 5.2 Customer journey: follow my request
My Requests list (status badge + dates + car) → detail with **timeline** (Submitted → In review → Awaiting your reply → Confirmed / Declined …). "Withdraw request" only while `submitted` / `in_review` / `awaiting_customer`; after Confirmed: "Contact HATEM to change or cancel" (policy ⛔ D-04).
Edge cases: lost guest session → empty list with WhatsApp help · request expired → explain + "Send a new request".

### 5.3 Staff journey: review → agree → confirm
1. **Dashboard:** counts of New, Awaiting customer, Pickups today, Returns today; list of newest requests.
2. **Requests list:** tabs by status; search by reference/name/phone; sort by pickup.
3. **Request Details:** customer snapshot, dates, requested car, history timeline, **availability check** for the requested dates, WhatsApp panel.
4. **Start review** (`submitted → in_review`).
5. **WhatsApp:** pick a quick reply in the customer's language, it fills the reference, name, car, dates; opens WhatsApp with the text. Staff can edit before sending.
6. **Send terms** → `awaiting_customer`.
7. **Approve (Confirm)** dialog. Required: assigned vehicle, **agreed price** (currency ⛔ D-07), **agreement note** ("Accepted on WhatsApp 30/11 10:12"). Shows conflict check result. Success → status Confirmed, block appears on calendar.
8. Other actions: Decline (reason) · Cancel (reason) · Mark completed · **Modify** (vehicle/dates, reason; atomic re-block for confirmed).

| States | Detail |
|---|---|
| Conflict on approve | "This car is already confirmed for 2–4 Dec (HAR-…)." Nothing changes; suggest another car or dates |
| Missing fields | Approve button disabled with the reason listed |
| Concurrent edit | "This request was updated by someone else. Reload." |
| Pickup in the past | Approve blocked; explain |
| Deactivated staff | Session ends; sign-in page |

### 5.4 Staff journey: create a request for a customer ✅ (gap noted)
A4 form = customer form + "source" (Phone / Walk-in / WhatsApp), optional link to an existing customer (search by phone), staff note. Created as `submitted` with "Created by staff" in history; normal review flow follows.
⚠️ **Gap:** the v1.1 database has no staff-create function yet (`submit_rental_request` is for customer/guest sessions). **D-20** below.

### 5.5 Vehicle management journey
Vehicles list (photo, name, plate (staff-only), status: Draft / Published / Inactive) → Add/Edit: name EN + AR, category, seats, doors, transmission, fuel, year, colour, plate, included features, photos (5-shot plan: front ¾, side, rear ¾, interior, detail), price fields **only if** D-01/D-19 decided, publish toggle.
States: missing required AR or EN name → can't publish · deactivating a car with future confirmed reservations → warning listing them (they stay; staff must modify) · photo upload fail → retry per photo · no photos → can save as Draft, can't publish 🟡.

### 5.6 Calendar journey
Month view (default desktop/tablet) and week/agenda (default mobile 🟡). Rows = vehicles, columns = days. **Bars = confirmed reservations only**, labelled with reference + customer short name; completed shown faded. Click → Request Details. Filter by vehicle/category. Today line. Legend with icon + word.
Edge cases: overlapping is impossible by design (DB constraint) — if the UI ever receives overlap, show an error banner · reservations crossing month edges · inactive cars greyed · RTL: days run right-to-left in Arabic, dates in Western digits.
Open requests are **not** shown as blocks; optional "show pending requests" toggle displays them as dashed outlines that clearly say "Not reserved" 🟡.

### 5.7 WhatsApp journey (customer + staff)
- **Customer handoff (P6):** "Continue on WhatsApp" opens `wa.me/<HATEM number ⛔>` with a prepared message: greeting, reference, car, dates, name. AR or EN per site language.
- **Staff quick replies (A10):** templates with variables `{name} {ref} {car} {pickup} {return} {price}`; each template has AR and EN text; categories: Received · Need info · Terms/price · Confirmed · Declined · Reminder 🟡. Preview with sample values clearly marked "Sample".
- States: number not configured → buttons hidden, admin banner "Add the WhatsApp number in Settings" · variable missing (e.g. no price yet) → template marked "needs price", insertion blocked · message too long warning.
⚠️ Template storage is undecided → **D-21**.

---

## 6. Responsive and bilingual rules (Phase 6)
- **Breakpoints:** mobile 375 · tablet 768 · desktop 1280.
- **Mobile:** single column; sticky bottom CTA on Vehicle Details and Request; filters in a drawer; compare = swipeable columns (max 2 visible); admin tables become cards; admin nav = bottom bar + "More".
- **Tablet:** 2-column fleet grid; admin sidebar collapses to icons.
- **Desktop:** 3-column fleet grid; admin sidebar 248 px.
- **Arabic RTL:** Tajawal, one size step larger, line height 1.75; composed for RTL (reading order, label lengths, icon directions); numbers/phones/references LTR via `<bdi>`; Western digits; English-only logo stays as is.

---

## 7. Decisions needed (new in this document)
| ID | Decision | Why it matters |
|---|---|---|
| **D-20** | Staff-created requests need a new staff-only DB function (e.g. `staff_create_rental_request`) with its own tests | A4 can be designed now; can't be built on v1.1 as is |
| **D-21** | Where WhatsApp quick-reply templates live: a DB table editable in admin 🟡 recommended, or fixed in code | Affects A10 (editable vs read-only) |
| **D-22** | Which specs appear in Compare (seats, doors, transmission, fuel, luggage, year, A/C…) | Needs real vehicle data |
| **D-23** | Default site language: Arabic 🟡 or English | Affects `/` redirect and first impression |
| **D-24** | Can staff edit quick replies, or owner only | A10 permissions |
| D-01, D-04, D-05, D-07, D-10, D-14, D-17, D-18 | Pricing, cancellation, hours, payment/currency, expiry, locations, agreement definition, approver | Placeholders in designs until decided |
