Skip to content

TML-2185 port retail store v2 e commerce app to prisma next mongodb#327

Draft
wmadden wants to merge 29 commits intotml-2231-m2-full-index-vocabulary-validators-collection-optionsfrom
tml-2185-port-retail-store-v2-e-commerce-app-to-prisma-next-mongodb
Draft

TML-2185 port retail store v2 e commerce app to prisma next mongodb#327
wmadden wants to merge 29 commits intotml-2231-m2-full-index-vocabulary-validators-collection-optionsfrom
tml-2185-port-retail-store-v2-e-commerce-app-to-prisma-next-mongodb

Conversation

@wmadden
Copy link
Copy Markdown
Contributor

@wmadden wmadden commented Apr 10, 2026

No description provided.

wmadden added 29 commits April 10, 2026 09:00
Add _prisma_migrations collection support for MongoDB:
- readMarker, initMarker, updateMarker (CAS), writeLedgerEntry
- MongoControlDriverInstance extending ControlDriverInstance with db access
- Wire readMarker() on MongoControlFamilyInstance
- Integration tests using mongodb-memory-server
Reset branch to tml-2220-m1-family-migration-spi-vertical-slice
which provides the full Mongo framework stack (embedded value
objects, ORM CRUD, pipeline builder, migrations). Carry forward
the project spec and retail-store plan (revised for the new
capabilities) and predictive-maintenance plan.
Add workspace package with Next.js, PN Mongo deps, and config
files mirroring mongo-demo. No contract or source files yet.
Define 8 value object types (Price, Image, Address, CartItem,
OrderLineItem, StatusEntry, InvoiceLineItem, EventMetadata) and
7 models (Product, User, Cart, Order, Location, Invoice, Event)
with nested value objects and reference relations.

Extend scalar type descriptors with Float -> mongo/double@1 since
the default Mongo PSL interpreter does not include Float.
db.ts exposes orm, runtime, pipeline, raw, and contract.
seed.ts populates all 7 collections with realistic e-commerce data.
scripts/seed.ts provides a standalone entry point with .env support.
Implement typed data access functions for all 7 collections:
products, users, carts, orders, locations, invoices, events.

Add objectIdEq helper to handle BSON ObjectId filtering via
MongoParamRef, since MongoFieldFilter.eq resolveValue corrupts
raw ObjectId instances by treating them as plain objects.

Integration tests cover: CRUD lifecycle, embedded value objects
(Price, Image, Address, CartItem, OrderLineItem, StatusEntry,
InvoiceLineItem, EventMetadata), upsert, clear cart, relation
loading via $lookup (cart->user, order->user, invoice->order),
and seed data population across all 7 collections.
Implement addToCart ($push), removeFromCart ($pull), and
updateOrderStatus ($push to statusHistory) using raw MongoDB
commands through mongoRaw. These bypass the ORM to use native
array operators not yet supported in the typed ORM surface.

Tests verify push/pull on cart items and status history append.
aggregateEventsByType uses $match -> $group -> $sort to count
event types per user. getRandomProducts uses $sample to return
a random subset from the products collection.

Tests verify group counts and sample cardinality.
RESTful API routes backed by the data access layer:
- GET/POST/DELETE /api/cart (add/remove items, clear)
- GET /api/products, GET /api/products/[id], GET /api/products/random
- GET/POST /api/orders, GET/DELETE/PATCH /api/orders/[id]
- GET /api/locations

db-singleton provides lazy-initialized shared db client.
Server-rendered pages using the data access layer directly:
- Product catalog grid (/) with brand, category, and pricing
- Product detail (/products/[id]) with full metadata
- Cart view (/cart) with line items and total
- Order history (/orders) with status badges
- Order detail (/orders/[id]) with items and status timeline

Uses inline styles for simplicity (no Tailwind dependency).
Add findSimilarProducts via $vectorSearch (requires Atlas).
Fix instanceof checks on string params for typecheck.
Document demonstrated features and known framework gaps in README.
Document .env configuration, seed workflow, DEMO_USER_ID
requirement for cart/orders pages, and optional Atlas vector
search setup.
seed() now returns the demo user ID. The seed script writes it
into .env automatically, removing the manual mongosh step from
the setup workflow.
- F01: fix objectIdEq param type from string|unknown to string|ObjectId
- F02: replace as-string casts in seed.ts with String() calls
- F03: guard cart/orders API routes against empty DEMO_USER_ID
- F04: document why raw commands skip MongoParamRef wrapping
- F06: document why findSimilarProducts uses raw aggregate
- F07: document migration gap in README
- F08: explain standalone biome config in biome.jsonc
- F09: type pipeline return values (Product[], EventTypeCount[])
- F10: extract executeRaw/collectResults helpers
Install tailwindcss, @tailwindcss/postcss, class-variance-authority,
clsx, tailwind-merge, lucide-react, and Radix UI primitives. Create
postcss.config.mjs, Tailwind v4 globals.css with @theme, cn() utility,
and 8 UI components (Button, Card, Input, Badge, Select, RadioGroup,
Separator, DropdownMenu).
Next.js middleware redirects unauthenticated visitors to /login.
Sign Up creates a user doc via ORM and sets a userId cookie.
getAuthUser() server helper reads the cookie and fetches the user.
…write

Products now span Apparel/Accessories/Footwear in Heritage, UrbanEdge,
Craftsman, TrailMark brands. Added 4 store locations. Seed script no
longer writes DEMO_USER_ID to .env since auth uses cookies.
Replace inline styles with Tailwind + shadcn Card components. Add
findProductsPaginated (ORM skip/take) and searchProducts ($regex via
MongoOrExpr) to data layer. Add Navbar server+client components with
auth display. Include integration tests for search and pagination.
API routes read userId from auth cookie instead of env var. Cart and
order pages redirect unauthenticated users. Add CartActions client
component for remove/clear, OrderStatusButtons for status progression.
…r badge

CartProvider wraps the app with cart count state, fetched from
GET /api/cart/count. AddToCartButton on product pages posts to the
cart API and triggers context refresh. Cart badge in navbar shows
item count. CartActions invalidate context after mutations.
Server component loads cart, user address, and store locations.
CheckoutForm client component lets user choose between home delivery
(with address input) and Buy Online Pick Up In Store (location select).
Places order via POST /api/orders, clears cart, redirects to order.
Document the full user flow (signup → browse → cart → checkout →
orders), expanded feature table, updated project structure listing.
Include middleware.ts in tsconfig include paths.
The useState initializer must be pure — side effects like fetch are
not allowed there. Use useEffect for initial count fetch and inline
the fetch in invalidateCart to avoid the exhaustive-deps lint.
addToCart uses raw updateOne/$push which silently matches zero docs
when no cart exists yet. Now check for an existing cart first and
fall back to upsertCart to create the document with the first item.
The adapter resolveValue and resolveDocument now apply codec.encode()
when a MongoParamRef carries a codecId. createMongoAdapter() registers
all standard codecs (ObjectId, String, Int32, etc.) by default so
existing call sites gain encoding without changes.
#toDocument and #toSetFields now look up each field type in the
contract and set codecId on the MongoParamRef. This enables the
adapter to encode values correctly (e.g. string -> ObjectId for
ObjectId-typed fields). Value object sub-fields are processed
recursively.
Cover the exact scenario that was broken (addToCart on non-existent cart)
and the full happy paths for cart (add, append, remove, clear) and order
(create from cart, status progression, user relation, deletion).
addToCart now uses findOneAndUpdate with upsert:true so adding to a
non-existent cart atomically creates it instead of silently doing nothing.
updateOrderStatus now returns the document (or null), letting callers
detect missing orders. The cart POST handler drops the check-then-branch
workaround in favor of the single atomic operation.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 5673a53d-3f73-4aa0-884f-e2a38af6b4fc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2185-port-retail-store-v2-e-commerce-app-to-prisma-next-mongodb

Comment @coderabbitai help to get the list of available commands and usage tips.

@wmadden wmadden changed the base branch from main to tml-2231-m2-full-index-vocabulary-validators-collection-options April 10, 2026 09:46
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

Open in StackBlitz

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-runtime@327

@prisma-next/family-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-mongo@327

@prisma-next/sql-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-runtime@327

@prisma-next/family-sql

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-sql@327

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-paradedb@327

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-pgvector@327

@prisma-next/postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/postgres@327

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-orm-client@327

@prisma-next/sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sqlite@327

@prisma-next/target-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-mongo@327

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-mongo@327

@prisma-next/driver-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-mongo@327

@prisma-next/contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract@327

@prisma-next/utils

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/utils@327

@prisma-next/config

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/config@327

@prisma-next/errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/errors@327

@prisma-next/framework-components

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/framework-components@327

@prisma-next/operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/operations@327

@prisma-next/contract-authoring

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract-authoring@327

@prisma-next/ids

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ids@327

@prisma-next/psl-parser

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-parser@327

@prisma-next/psl-printer

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-printer@327

@prisma-next/cli

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/cli@327

@prisma-next/emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/emitter@327

@prisma-next/migration-tools

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/migration-tools@327

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/vite-plugin-contract-emit@327

@prisma-next/runtime-executor

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/runtime-executor@327

@prisma-next/mongo-codec

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-codec@327

@prisma-next/mongo-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract@327

@prisma-next/mongo-value

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-value@327

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-psl@327

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-contract-ts@327

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-emitter@327

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-schema-ir@327

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-query-ast@327

@prisma-next/mongo-orm

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-orm@327

@prisma-next/mongo-pipeline-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-pipeline-builder@327

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-lowering@327

@prisma-next/mongo-wire

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-wire@327

@prisma-next/sql-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract@327

@prisma-next/sql-errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-errors@327

@prisma-next/sql-operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-operations@327

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-schema-ir@327

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-psl@327

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-ts@327

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-emitter@327

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-lane-query-builder@327

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-relational-core@327

@prisma-next/sql-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-builder@327

@prisma-next/target-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-postgres@327

@prisma-next/target-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-sqlite@327

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-postgres@327

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-sqlite@327

@prisma-next/driver-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-postgres@327

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-sqlite@327

commit: f6820e2

@wmadden wmadden force-pushed the tml-2231-m2-full-index-vocabulary-validators-collection-options branch from c6c3885 to b13db34 Compare April 10, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant