See what an AI action will set in motion before it happens.
Why · Features · Demo · Architecture · Quick Start · Team
Mercora is a demo e-commerce operations app for orders, products, customers, and inventory. Its refund flow connects the operator experience to Cascade, a consequence-intelligence engine.
Live sites:
- Mercora (frontend): https://demo-polish-web---mercora-web-gp5ciyqy6a-el.a.run.app/dashboard
- Cascade API (consequence engine backend): https://cascade-api-1097302968574.asia-south1.run.app
- Cascade engine (backend of the consequence simulation): https://github.com/KRYSTALM7/cascade
Operators using AI agents to cancel, refund, or edit orders often cannot see what an action will trigger downstream. Cascade is the engine; Mercora is the real-world surface. A refund starts as a button in a familiar operations app, showing the integration working inside a product rather than only inside Cascade's own UI.
Refunds are a useful first case: money moves, the action can be partly irreversible, and it can involve finance, CRM, and inventory agents. Cascade maps those consequences before a human decides. The simulation is read-only: it does not execute the refund or change Mercora order data. The direct refund endpoint returns 410 Gone so a refund cannot bypass the simulate-before-act flow. Refund execution itself is not implemented.
| Without Cascade | With Mercora + Cascade |
|---|---|
| An operator sees the requested refund. | The operator sees a consequence report before deciding. |
| Downstream agent actions are difficult to anticipate. | Blast radius, risk, and policy decision are visible together. |
| A refund can look like one isolated action. | The simulation shows it as a connected set of consequences. |
E-commerce Operations
- Dashboard, orders, products, customers, inventory, and analytics.
- Review order details, manage catalog and stock, and track customer value.
- Administrator-managed access; evaluators have a read-only role.
Cascade Integration
- Simulate refunds for the demo orders mapped to Cascade.
- Review blast radius, risk factors, and policy decisions in the order workflow.
- Run a built-in Cascade demo scenario. Simulations do not execute operations.
The operator starts a simulation from an order. Mercora's API sends a scoped request to Cascade and returns its consequence report to the UI.
sequenceDiagram
actor Operator
participant UI as Mercora UI
participant API as Mercora API
participant Cascade as Cascade API
Operator->>UI: Choose simulate refund
UI->>API: POST /api/cascade/simulate-refund
API->>Cascade: POST /api/actions/simulate
Cascade-->>API: Consequence report
API-->>UI: Blast radius, risk, decision
UI-->>Operator: Review before deciding
The simulation is read-only: it checks that the order is unchanged and does not call a refund execution API. The direct POST /api/orders/{order_id}/refund endpoint is disabled and returns 410 Gone. Only orders in the configured demo mapping can be simulated.
| Sign in and dashboard | Orders and refund flow |
|---|---|
| Component | Technology | Purpose |
|---|---|---|
| Frontend | Next.js 15, React 19, TypeScript, Tailwind CSS | Operator interface |
| Backend | FastAPI, Python 3.11+, SQLAlchemy | Commerce API and Cascade client |
| Database | PostgreSQL | Users and commerce records |
| Deployment | Google Cloud Run | API and web services; see the deployment guide |
| Consequence engine | Cascade REST API | Refund consequence simulation |
Key dependencies and versions
Frontend versions below are the project-declared versions from package.json; the backend versions are pinned in backend/requirements.txt.
| Area | Dependencies |
|---|---|
| Frontend | Next.js ^15.0.0, React / React DOM ^19.0.0, TypeScript ^5.3.0, Tailwind CSS ^3.4.0, Axios ^1.6.0, Recharts ^2.10.0, date-fns ^2.30.0, lucide-react ^0.460.0; dev: @types/node ^20.0.0, @types/react / @types/react-dom ^19.0.0, PostCSS ^8.4.0, Autoprefixer ^10.4.0, ESLint ^8.54.0, eslint-config-next ^15.0.0 |
| Backend | FastAPI 0.104.1, Uvicorn 0.24.0, SQLAlchemy 2.0.23, psycopg2-binary 2.9.9, Pydantic 2.5.0, pydantic-settings 2.1.0, python-dotenv 1.0.0, httpx 0.27.2, PyJWT 2.9.0 |
Prerequisites: Node.js 18+, Python 3.11+, and PostgreSQL 14+. Run Cascade separately if you want live consequence reports.
From the repository root:
python -m venv .venv
source .venv/bin/activate
pip install -r backend/requirements.txt
cd frontend && npm installPowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r backend\requirements.txt
Set-Location frontend
npm installCreate backend/.env and frontend/.env.local. Keep real credentials out of source control. The frontend API URL is embedded at build time for production builds.
Environment variables
Backend backend/.env (example-only values):
API_TITLE=Mercora API
API_VERSION=1.0.0
DATABASE_URL=postgresql://USER:PASSWORD@HOST/DB?sslmode=require
CORS_ORIGINS=http://localhost:3000
LOG_LEVEL=INFO
SECRET_KEY=replace-with-a-long-random-value
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_HOURS=24
ADMIN_EMAIL=admin@example.test
ADMIN_PASSWORD=replace-with-a-strong-secret
EVALUATOR_EMAIL=evaluator@example.test
EVALUATOR_PASSWORD=replace-with-a-demo-password
CASCADE_API_URL=http://localhost:8000
CASCADE_DEMO_USER=demo-operator
CASCADE_TIMEOUT_SECONDS=30Frontend frontend/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:8001ADMIN_EMAIL and ADMIN_PASSWORD are used only by the one-time bootstrap command. Never use example values in a shared environment. Optional frontend settings include NEXT_PUBLIC_EVALUATOR_EMAIL, NEXT_PUBLIC_EVALUATOR_PASSWORD, NEXT_PUBLIC_APP_NAME, and NEXT_PUBLIC_APP_VERSION; values prefixed with NEXT_PUBLIC_ are public in the browser bundle and must never contain secrets.
Start the backend from the repository root:
uvicorn backend.app:app --host 127.0.0.1 --port 8001 --reloadPowerShell equivalent:
python -m uvicorn backend.app:app --host 127.0.0.1 --port 8001 --reloadThen start the frontend in another terminal:
cd frontend
npm run devOpen http://localhost:3000. The API docs are served at /docs on the backend. Database tables are created at startup; an administrator account must be provisioned separately.
First-time administrator and access flow
Set ADMIN_EMAIL and a strong ADMIN_PASSWORD in backend/.env, then run once from the repository root:
python -m backend.scripts.bootstrap_adminPowerShell:
python -m backend.scripts.bootstrap_adminThe command is idempotent: it creates the admin if absent and leaves an existing admin password unchanged. Normal API startup does not create an administrator. In the deployed setup, the one-off bootstrap is run as described in the Cloud Run guide.
Staff can submit Request access. An administrator reviews requests through the admin-only API and approves them; the generated temporary password is returned only to that administrator for secure delivery. Password reset is unavailable; users must contact their administrator.
Sample data warning: backend/scripts/load_kaggle_data.py inserts synthetic products, customers, orders, and order items. It is not part of normal setup. Run it only against a disposable database, never a working Mercora dataset.
The repository includes a Cloud Run staging and release runbook: docs/DEPLOY_CLOUD_RUN.md. Review its environment and target details carefully before using it.
The legacy backend/test_cascade_integration.py script mutates fixture data and order statuses. Run it only against a dedicated disposable test database, never a working Mercora database. The sample-data loader is also for disposable databases only.
Safe checks and test commands
Non-mutating backend smoke check:
.venv\Scripts\python.exe test_backend.pyFrontend tests and validation:
cd frontend
npm test
npm run type-check
npm run lint
npm run buildThe backend unit tests use the project's unittest setup; for example:
python -m unittest backend.test_auth backend.test_config backend.test_evaluator_demoRepository map
backend/ FastAPI app, routers, models, services, scripts, and tests
routers/ Auth, commerce, analytics, and Cascade routes
services/ Order, product, customer, inventory, and analytics logic
scripts/ Admin bootstrap and data utilities
frontend/src/app/ Next.js pages and global styles
frontend/src/components/ Shared layout, UI, and Cascade result components
frontend/src/context/ Authentication state
frontend/src/lib/ API client and display helpers
docs/ Deployment guide, screenshots, and README assets
| Contributor | Focus | Profiles |
|---|---|---|
| Sujan Kumar | Product engineering, Cascade integration and implementation | |
| Ipjrb12 | Planning, system design, workflow design and architecture |
Mercora is released under the MIT License. Mercora's refund consequence simulation is powered by Cascade. PostgreSQL hosting is configured separately; see the Cloud Run deployment guide.
Built for Google AI Builder Cup 2026








