# ReadyGO - Unified Microfrontend Platform (Food Delivery + Cab Booking)

ReadyGO is an enterprise-grade, production-ready Microfrontend platform unifying two large, high-traffic consumer applications:
1. **ReadyEats (Food Delivery Platform)** — Built with Next.js 14 (App Router) + React 18 + Redux/Zustand + Tailwind CSS
2. **ReadyCab (Cab Booking Platform)** — Built with React 18 + Vite 5 + React Router v6 + TanStack Query + Tailwind CSS
3. **ReadyShell (Host Application)** — Built with Next.js 14 (App Router) + React 18 + Tailwind CSS + Unified Authentication
4. **Common Backend** — Powered by the existing shared NestJS backend API running on `https://readygo.api.clonifynow.com`.

---

## 🏛 Architecture Diagram

```
                    https://app.example.com / localhost:3000
                                       │
                         ┌─────────────┴─────────────┐
                         ▼                           ▼
                 Landing Page (/)           Login / Register (/login)
                         │
                  Service Hub (/services)
                  /                     \
                 /                       \
       🍔 Food Delivery (/food/*)     🚕 Cab Booking (/cab/*)
             [ReadyEats MFE]               [ReadyCab MFE]
                 \                       /
                  \                     /
                   ▼                   ▼
                 SHARED BACKEND (Port 3006)
```

---

## 📁 Repository Structure

```
.
├── shell/                       # Next.js Shell Host Application
│   ├── app/                     # Landing (/), Services (/services), Login (/login), Profile (/profile)
│   ├── components/              # Universal Header, Footer, Error Boundaries, Service Cards
│   ├── lib/                     # Unified Auth & Backend API Client
│   └── next.config.js           # Multi-Zone Reverse Proxy & Rewrites
│
├── zomatoclonecustomernextjs/   # Food Delivery Platform (Next.js 14 App Router)
│   ├── app/                     # Preserved Food Delivery Routes (/food/*)
│   └── next.config.js           # basePath: '/food'
│
├── cabappwebsitereactjs/        # Cab Booking Platform (React 18 + Vite 5 + React Router)
│   ├── src/                     # Preserved Cab Booking Routes (/cab/*)
│   └── vite.config.ts           # base: '/cab/'
│
├── packages/                    # Shared Contracts & Libraries
│   ├── shared-types/            # Auth, User, and Cross-MFE Event definitions
│   ├── shared-auth/             # Unified multi-cookie synchronization helpers
│   └── shared-utils/            # Event bus and health-check diagnostics
│
├── nginx.conf                   # Production Nginx reverse proxy configuration
├── ecosystem.config.js          # Production PM2 cluster & service manager
├── ARCHITECTURE.md              # In-depth architectural specification
├── DEPLOYMENT.md                # Production deployment, scaling & rollback guide
└── package.json                 # Root orchestration scripts
```

---

## 🚀 Quick Start (Development)

### 1. Prerequisites
- **Node.js**: v18+ (tested on Node 20 / 24)
- **Shared Backend**: Ensure backend API is running on `https://readygo.api.clonifynow.com`

### 2. Starting Applications

You can run all three applications concurrently or run each service independently:

#### Run All Services Concurrently:
```bash
npm run dev
```

#### Run Individual Services:
```bash
# Terminal 1: Main Platform Shell (Port 3000)
npm run dev:shell

# Terminal 2: Food Delivery Platform (Port 3001)
npm run dev:food

# Terminal 3: Cab Booking Platform (Port 3002)
npm run dev:cab
```

---

## 🔗 Route Map & Verification

| URL Route | Handled By | Features |
|---|---|---|
| `http://localhost:3000/` | **ReadyShell** | Platform Landing Page with dual service launcher |
| `http://localhost:3000/login` | **ReadyShell** | Unified Phone + OTP login, synced across both MFEs |
| `http://localhost:3000/services` | **ReadyShell** | Visual service selection hub |
| `http://localhost:3000/profile` | **ReadyShell** | Unified customer profile with order/ride quick links |
| `http://localhost:3000/food` | **Food MFE** | Food delivery home page & restaurant listings |
| `http://localhost:3000/food/grocery` | **Food MFE** | Grocery Mart shopping |
| `http://localhost:3000/food/myorders` | **Food MFE** | Food orders & live delivery status |
| `http://localhost:3000/cab` | **Cab MFE** | Cab booking hero & ride search |
| `http://localhost:3000/cab/booking` | **Cab MFE** | Pickup & drop destination selector with route fares |
| `http://localhost:3000/cab/trips` | **Cab MFE** | Ride history & invoice receipts |

---

## 🔐 Authentication & Session Synchronization

Both microfrontends consume the single unified session created by the Shell:
- When a user logs in on the Shell, the authentication token is written to both `COOKIES_USER_ACCESS_TOKEN` (for Food Next.js) and `cookies_user_access_token` (for Cab React/Axios) with `path: "/"`.
- When navigating into `/food/*` or `/cab/*`, both applications automatically attach the bearer token to all API requests made to the shared NestJS backend (`https://readygo.api.clonifynow.com`).
- Logging out from the Shell or any microfrontend automatically invalidates the cookies and notifies peer services via `BroadcastChannel` events.

---

## 🛡 Fault Tolerance & Error Handling

- If a microfrontend is unavailable or encounters a network error, the Shell's `MfeErrorBoundary` renders a graceful recovery UI with a **"Retry Connection"** action and direct navigation back to the healthy services.
- The failure of one service never crashes the main shell or the companion microfrontend.

---

## 🏗 Production Build & Validation

```bash
# 1. Build Shell
cd shell && npm run build && cd ..

# 2. Build Food MFE
cd zomatoclonecustomernextjs && npm run build && cd ..

# 3. Build Cab MFE
cd cabappwebsitereactjs && npm run build && cd ..
```

Refer to [DEPLOYMENT.md](file:///home/hf-mon-10/Desktop/projects/mrege%20customer/DEPLOYMENT.md) for Nginx reverse proxy configuration and PM2 ecosystem management.
