feat: add collaborative shopping lists with items and invitations
Some checks failed
CI / Verify (push) Has been cancelled

API: lists, items and invitations modules (list, create, get, update,
set-primary, items create/list, invitation create/accept/list-pending),
BetterAuth session helper, list membership, mailer and Prisma schema plus
migrations.

Web: lists overview, list detail (items) and list management (settings)
views, item and invitation forms/hooks, sign-up and invitation accept pages.

Shared: shopping list DTOs.

Tooling: ignore the generated TanStack Router cache (apps/web/.tanstack).
This commit is contained in:
Jose Selesan
2026-10-16 10:12:11 -03:00
parent 964a3c7217
commit 6aa86a3b68
81 changed files with 3476 additions and 269 deletions

View File

@@ -0,0 +1,157 @@
-- CreateEnum
CREATE TYPE "list_role" AS ENUM ('owner', 'collaborator');
-- CreateEnum
CREATE TYPE "invitation_status" AS ENUM ('pending', 'accepted', 'revoked', 'expired');
-- CreateTable
CREATE TABLE "users" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"email_verified" BOOLEAN NOT NULL DEFAULT false,
"image" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "sessions" (
"id" TEXT NOT NULL,
"expires_at" TIMESTAMP(3) NOT NULL,
"token" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
"ip_address" TEXT,
"user_agent" TEXT,
"user_id" TEXT NOT NULL,
CONSTRAINT "sessions_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "accounts" (
"id" TEXT NOT NULL,
"account_id" TEXT NOT NULL,
"provider_id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"access_token" TEXT,
"refresh_token" TEXT,
"id_token" TEXT,
"access_token_expires_at" TIMESTAMP(3),
"refresh_token_expires_at" TIMESTAMP(3),
"scope" TEXT,
"password" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "verifications" (
"id" TEXT NOT NULL,
"identifier" TEXT NOT NULL,
"value" TEXT NOT NULL,
"expires_at" TIMESTAMP(3) NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "verifications_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "shopping_lists" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"owner_id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "shopping_lists_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "shopping_list_members" (
"id" TEXT NOT NULL,
"list_id" TEXT NOT NULL,
"user_id" TEXT NOT NULL,
"role" "list_role" NOT NULL DEFAULT 'collaborator',
"is_primary" BOOLEAN NOT NULL DEFAULT false,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "shopping_list_members_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "shopping_list_invitations" (
"id" TEXT NOT NULL,
"list_id" TEXT NOT NULL,
"email" TEXT NOT NULL,
"token" TEXT NOT NULL,
"status" "invitation_status" NOT NULL DEFAULT 'pending',
"invited_by_id" TEXT NOT NULL,
"expires_at" TIMESTAMP(3) NOT NULL,
"accepted_at" TIMESTAMP(3),
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "shopping_list_invitations_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
-- CreateIndex
CREATE INDEX "sessions_user_id_idx" ON "sessions"("user_id");
-- CreateIndex
CREATE UNIQUE INDEX "sessions_token_key" ON "sessions"("token");
-- CreateIndex
CREATE INDEX "accounts_user_id_idx" ON "accounts"("user_id");
-- CreateIndex
CREATE INDEX "verifications_identifier_idx" ON "verifications"("identifier");
-- CreateIndex
CREATE INDEX "shopping_lists_owner_id_idx" ON "shopping_lists"("owner_id");
-- CreateIndex
CREATE INDEX "shopping_list_members_user_id_is_primary_idx" ON "shopping_list_members"("user_id", "is_primary");
-- CreateIndex
CREATE UNIQUE INDEX "shopping_list_members_list_id_user_id_key" ON "shopping_list_members"("list_id", "user_id");
-- CreateIndex
CREATE INDEX "shopping_list_invitations_list_id_status_idx" ON "shopping_list_invitations"("list_id", "status");
-- CreateIndex
CREATE INDEX "shopping_list_invitations_email_status_idx" ON "shopping_list_invitations"("email", "status");
-- CreateIndex
CREATE UNIQUE INDEX "shopping_list_invitations_token_key" ON "shopping_list_invitations"("token");
-- AddForeignKey
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "shopping_lists" ADD CONSTRAINT "shopping_lists_owner_id_fkey" FOREIGN KEY ("owner_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "shopping_list_members" ADD CONSTRAINT "shopping_list_members_list_id_fkey" FOREIGN KEY ("list_id") REFERENCES "shopping_lists"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "shopping_list_members" ADD CONSTRAINT "shopping_list_members_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "shopping_list_invitations" ADD CONSTRAINT "shopping_list_invitations_list_id_fkey" FOREIGN KEY ("list_id") REFERENCES "shopping_lists"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "shopping_list_invitations" ADD CONSTRAINT "shopping_list_invitations_invited_by_id_fkey" FOREIGN KEY ("invited_by_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,20 @@
-- CreateTable
CREATE TABLE "list_items" (
"id" TEXT NOT NULL,
"shopping_list_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"completed" BOOLEAN NOT NULL DEFAULT false,
"quantity" TEXT,
"notes" TEXT,
"order" INTEGER NOT NULL DEFAULT 0,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "list_items_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "list_items_shopping_list_id_order_idx" ON "list_items"("shopping_list_id", "order");
-- AddForeignKey
ALTER TABLE "list_items" ADD CONSTRAINT "list_items_shopping_list_id_fkey" FOREIGN KEY ("shopping_list_id") REFERENCES "shopping_lists"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View File

@@ -1,5 +1,12 @@
// Prisma schema. Docs: https://pris.ly/d/prisma-schema
//
// Naming convention (see AGENTS.md): tables are plural snake_case
// (`shopping_lists`, `users`), columns are snake_case (`created_at`,
// `owner_id`) and enum types are snake_case (`list_role`), declared through
// `@@map` / `@map`. The Prisma *model* and *field* names stay PascalCase /
// camelCase because BetterAuth and the generated client address models by
// those names.
//
// After editing this file run `bun run db:migrate` (creates + applies a migration)
// and commit the generated migration under `prisma/migrations`.
@@ -14,67 +21,164 @@ generator client {
// --- BetterAuth core models -------------------------------------------------
// Shape generated by `bunx @better-auth/cli generate`. Keep in sync with the
// fields the auth config expects.
// fields the auth config expects, and keep the snake_case mapping below if you
// regenerate it.
model User {
id String @id
name String
email String
emailVerified Boolean @default(false)
emailVerified Boolean @default(false) @map("email_verified")
image String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
sessions Session[]
accounts Account[]
ownedLists ShoppingList[] @relation("ListOwner")
memberships ShoppingListMember[]
invitations ShoppingListInvitation[] @relation("InvitedBy")
@@unique([email])
@@map("user")
@@map("users")
}
model Session {
id String @id
expiresAt DateTime
expiresAt DateTime @map("expires_at")
token String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ipAddress String?
userAgent String?
userId String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")
userId String @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([token])
@@index([userId])
@@map("session")
@@map("sessions")
}
model Account {
id String @id
accountId String
providerId String
userId String
accountId String @map("account_id")
providerId String @map("provider_id")
userId String @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
accessToken String? @map("access_token")
refreshToken String? @map("refresh_token")
idToken String? @map("id_token")
accessTokenExpiresAt DateTime? @map("access_token_expires_at")
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
scope String?
password String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([userId])
@@map("account")
@@map("accounts")
}
model Verification {
id String @id
identifier String
value String
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([identifier])
@@map("verification")
@@map("verifications")
}
// --- Domain models ----------------------------------------------------------
/// A collaborative shopping list. Membership (and therefore access) lives in
/// `ShoppingListMember`, not in this table.
model ShoppingList {
id String @id @default(uuid())
name String
ownerId String @map("owner_id")
owner User @relation("ListOwner", fields: [ownerId], references: [id], onDelete: Cascade)
members ShoppingListMember[]
invitations ShoppingListInvitation[]
items ListItem[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([ownerId])
@@map("shopping_lists")
}
model ListItem {
id String @id @default(cuid())
shoppingListId String @map("shopping_list_id")
name String
completed Boolean @default(false)
quantity String? @map("quantity")
notes String? @map("notes")
order Int @default(0) @map("order")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
shoppingList ShoppingList @relation(fields: [shoppingListId], references: [id], onDelete: Cascade)
@@index([shoppingListId, order])
@@map("list_items")
}
enum ListRole {
owner
collaborator
@@map("list_role")
}
/// Join table between a user and a list. `isPrimary` is per user: each person
/// picks their own main list among the ones they belong to.
model ShoppingListMember {
id String @id @default(uuid())
listId String @map("list_id")
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
userId String @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
role ListRole @default(collaborator)
isPrimary Boolean @default(false) @map("is_primary")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([listId, userId])
@@index([userId, isPrimary])
@@map("shopping_list_members")
}
enum InvitationStatus {
pending
accepted
revoked
expired
@@map("invitation_status")
}
/// Pending or historical invitation of an email address to a list. When the
/// email already belongs to a user the membership is created immediately and
/// this record is stored as `accepted` for history.
model ShoppingListInvitation {
id String @id @default(uuid())
listId String @map("list_id")
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
email String
token String
status InvitationStatus @default(pending)
invitedById String @map("invited_by_id")
invitedBy User @relation("InvitedBy", fields: [invitedById], references: [id], onDelete: Cascade)
expiresAt DateTime @map("expires_at")
acceptedAt DateTime? @map("accepted_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([token])
@@index([listId, status])
@@index([email, status])
@@map("shopping_list_invitations")
}