> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pcm.game/llms.txt
> Use this file to discover all available pages before exploring further.

# Sprint 15: The Global Market & Gacha System

> Deploying the zero-trust transactional market ledger, Cloud Memorystore (Redis) sliding-window rate limiting, and 3D glassmorphic Gacha card-flip UI.

# Sprint 15: The Global Market & Gacha System

With the Ingress Policy Enforcement and Content Ingestion loops secured, Sprint 15 introduces the primary economic driver of the PCMTG ecosystem: **The Global Market & Gacha System**. The objective is to deploy a secure, atomic transaction ledger and high-throughput sliding-window rate limiter, and couple them with a premium, glassmorphic trading and synthesis user interface on the frontend.

## 🛠 Context & Required Rules for AI Agents

1. **Atomic Economy (Zero-Trust):** All market interactions must run inside `prisma.$transaction` blocks with pessimistic raw SQL `FOR UPDATE` row locks to prevent double-spending on serverless Cloud Run pools.
2. **Horizontal Scale-Safe Rate Limiter:** In-memory rate limiting is forbidden across scaled container instances. All `/market/*` routes must be governed by Google Cloud Memorystore (Redis) sliding windows.
3. **Ideological Defection ("Based Pill" mechanic):** Player alignment is fetched directly from the declared database record to allow faction defection without resetting the player's Euclidean ELO footprint.

***

## 🗺 Sprint 15 Roadmap

### \[x] Phase 1: Database & Schema Alignment

* **Objective:** Establish direct declared ideological quadrant storage.
* **Tasks:**
  * Add explicitly stored `quadrant` string property to `PlayerAccount` in `schema.prisma`.
  * Push the database schema updates to Neon Postgres and regenerate the Prisma Client.

### \[x] Phase 2: Cloud Memorystore sliding-window rate-limiting

* **Objective:** Prevent Sybil attacks and automated bulk synthesis script abuse.
* **Tasks:**
  * Centralize connection management pool for Google Cloud Memorystore via `ioredis`.
  * Build `marketRateLimiter` middleware running multi-exec pipelines on atomic Redis sorted sets to limit players to **5 requests per 10 seconds**.

### \[x] Phase 3: Zero-Trust Market Ledger Routers

* **Objective:** Deploy transaction-safe, Row-Locked item and pack synthesis endpoints.
* **Tasks:**
  * Build `/market/spot` to fetch active policy and passive modifier items.
  * Build `/market/buy-item` protecting against duplicate modifier purchases and atomic row locks.
  * Build `/market/buy-pack` enforcing the cross-quadrant pricing dynamic (20 units of native currency for native packs, 50 units for opposing quadrant packs) with backend-side cryptographically secure random pulls.

### \[x] Phase 4: High-Fidelity Glassmorphic Frontend

* **Objective:** Design a premium, highly reactive player dashboard.
* **Tasks:**
  * Build the React-based frontend page at `/market` supporting dual tab sections (`Spot Market` and `Meme Bazaar`).
  * Wire immediate, silent balance updates with the global `<WalletOverlay />` upon completed ledger purchases.
  * Construct full-screen, 3D CSS perspective card flips, tearing packs, and rarity glow colors (from silver to Golden celestial animations).

### \[x] Phase 5: Automated Verification Suite

* **Objective:** Programmatically prove performance, security bounds, and game theory compliance.
* **Tasks:**
  * Create the backend E2E integration runner [test-market.js](file:///home/andrew/pcmtg-core/backend/test-market.js).
  * Assert rate-limit throttling, double-spend resistance, duplicate item blocks, and asymmetrical cross-quadrant cost ratios.
