An interactive e-commerce example application demonstrating Prisma Next's MongoDB capabilities with a Next.js frontend.
# 1. Build framework packages (from repo root)
pnpm build
# 2. Emit contract
pnpm emit
# 3. Run tests (uses mongodb-memory-server)
pnpm testTo run the full app (UI + API) against a real MongoDB cluster:
1. Create .env in examples/retail-store/:
DB_URL=mongodb+srv://user:pass@your-cluster.mongodb.net
MONGODB_DB=retail-store2. Seed the database:
pnpm db:seedThis populates all 7 collections with 24 products across 5 brands, 4 store locations, and sample users/orders/events.
3. Start the dev server:
pnpm devOpen http://localhost:3000. You'll be redirected to the login page — click "Sign Up" to create a user and start browsing.
- Sign Up → creates a user doc via ORM, sets
userIdcookie - Browse → paginated product catalog (8 per page), search bar
- Add to Cart → click on a product, "Add to Cart" button
- Cart → view items, remove individual items, clear cart
- Checkout → choose home delivery or store pickup, place order
- Orders → view order history, advance status (placed → shipped → delivered)
- Log Out → clears cookie, redirects to sign-up
To test findSimilarProducts, create a vector search index named product_embedding_index on the products collection's embedding field in Atlas, and populate the embedding arrays with actual vectors (the seed data sets embedding: null by default).
Products ─── Price, Image (embedded value objects)
Users ─── Address? (optional embedded)
Carts ──→ User (reference relation), CartItem[] (embedded array)
Orders ──→ User (reference relation), OrderLineItem[], StatusEntry[]
Locations ─── flat fields
Invoices ──→ Order (reference relation), InvoiceLineItem[]
Events ─── polymorphic (@@discriminator on type)
├── ViewProductEvent (productId, subCategory, brand)
├── SearchEvent (query)
└── AddToCartEvent (productId, brand)
prisma/contract.prisma PSL schema with types and models
src/contract.json Generated contract (machine-readable)
src/contract.d.ts Generated types (compile-time safety)
src/db.ts Database factory (orm, runtime, pipeline, raw)
src/seed.ts Seed data for all 7 collections
src/data/ Data access layer (typed functions per collection)
src/lib/auth.ts Server-side auth helper (cookie-based)
src/lib/utils.ts cn() utility for Tailwind class merging
src/components/ Navbar, CartProvider, AddToCartButton, UI primitives
test/ Integration tests against mongodb-memory-server
app/ Next.js App Router (pages + API routes)
middleware.ts Auth middleware (redirects to /login)
- ObjectId in filters:
MongoFieldFilter.eqwith ObjectId values requires wrapping inMongoParamRef(seesrc/data/object-id-filter.ts) - Schema migrations: Migration artifacts are committed under
migrations/; runpnpm migration:applyto apply. The planner handles indexes and collection validators but not all schema-level operations. - Typed
$push/$pull: ORM doesn't expose array update operators; usemongoRawwith untyped commands - Pipeline output types: The pipeline builder doesn't propagate output types through aggregation stages; results are cast to expected shapes at the call site
- Atlas Search: Requires extension pack not yet available
- Change Streams: Not yet supported in the framework
