Skip to content

Commit d61fc55

Browse files
committed
Review docs
1 parent dbb80e2 commit d61fc55

29 files changed

Lines changed: 778 additions & 0 deletions

docs/reviews/INDEX.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# StormCom Code Review Index
2+
3+
Date: 2025-11-10
4+
Branch: copilot/sub-pr-50
5+
6+
This index links to categorized review summaries generated for the Next.js 16 multi-tenant e‑commerce application. Each document contains per-file notes using a consistent rubric (architecture, Next.js 16 compliance, multi-tenancy, security, performance, accessibility, testing, size limits).
7+
8+
- Architecture Overview: ./architecture-overview.md
9+
- Database Schema: ./database/prisma-schema.md
10+
- App Router: ./app.md
11+
- Components
12+
- Analytics: ./components/analytics.md
13+
- Attributes: ./components/attributes.md
14+
- Audit Logs: ./components/audit-logs.md
15+
- Auth: ./components/auth.md
16+
- Brands: ./components/brands.md
17+
- Bulk Import: ./components/bulk-import.md
18+
- Categories: ./components/categories.md
19+
- Checkout: ./components/checkout.md
20+
- GDPR: ./components/gdpr.md
21+
- Integrations: ./components/integrations.md
22+
- Layout: ./components/layout.md
23+
- Orders: ./components/orders.md
24+
- Products: ./components/products.md
25+
- Storefront: ./components/storefront.md
26+
- Stores: ./components/stores.md
27+
- Theme: ./components/theme.md
28+
- UI: ./components/ui.md
29+
- Root (theme-provider): ./components/root.md
30+
- Libraries (lib): ./lib.md
31+
- Services: ./services.md
32+
- Hooks: ./hooks.md
33+
- Contexts: ./contexts.md
34+
- Providers: ./providers.md
35+
- Emails: ./emails.md
36+
- Types: ./types.md
37+
38+
Review Rubric (applies to every file):
39+
- Next.js 16 compliance (async params/searchParams; cookies/headers/draftMode as async; Proxy usage)
40+
- Server vs Client boundaries (no client-only APIs in server components; 'use client' where needed)
41+
- Multi-tenancy (storeId filtering, soft delete awareness)
42+
- Validation & security (Zod, auth checks, CSRF, rate limiting, secrets handling)
43+
- Performance (select fields, Suspense/loading, caching, bundle size, N+1 avoidance)
44+
- Accessibility (WCAG AA, ARIA, focus rings, contrast, keyboard support)
45+
- Testing (unit/integration coverage hints, E2E critical paths)
46+
- Size limits (file < 300 lines, function < 50 lines)

docs/reviews/app.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: App Router Review
3+
sourcePath: src/app
4+
category: app
5+
riskLevel: medium
6+
---
7+
8+
# App Router Review
9+
10+
Overview:
11+
- Next.js 16 App Router with route groups `(auth)`, `(dashboard)`, and storefront under `shop/`.
12+
- Global files: `layout.tsx`, `page.tsx`, `error.tsx`, `loading.tsx`, `not-found.tsx`, `globals.css` present.
13+
- API routes: Extensive coverage under `src/app/api/*` (products, categories, brands, checkout, analytics, auth/MFA, inventory, webhooks, integrations, GDPR, notifications, stores, subscriptions, docs, csrf, dev helpers).
14+
15+
Global Layout (src/app/layout.tsx):
16+
- Uses Inter font, includes Vercel Analytics and Speed Insights.
17+
- Wraps app with `SessionProvider` (client) and `ThemeProvider` (client) inside body—OK for server layout composing client providers.
18+
- Recommendation: Verify providers are minimal in client surface and avoid heavy client dependencies at root; ensure no client-only code leaks into other server components.
19+
20+
Route Groups:
21+
- (auth): login, register, forgot-password, reset-password, mfa/enroll, mfa/challenge.
22+
- Expectations: Client forms with server actions or API calls, Zod validation, no SSR-disabled dynamic in server components.
23+
- (dashboard): dashboard, products (list, [id], loading/error states), orders (list, [id]), categories, brands, attributes, inventory, marketing, analytics, integrations, settings (theme, privacy), stores (list, [id], new), subscription (plans, billing).
24+
- Expectations: Server Components for data display; interactive tables/forms via client components. All tenant queries filtered by session.storeId; respect soft delete; use loading.tsx skeletons.
25+
- Storefront (shop): home, products (list, [slug]), categories ([slug]), cart, checkout, orders, profile, search, wishlists.
26+
- Expectations: Predominantly Server Components with client components for cart/checkout interactions; caching strategy for catalog pages (consider cache tags and cacheLife profiles).
27+
28+
API Routes (high-level checks to apply per file):
29+
- Must use Next.js 16 patterns: `const { id } = await params;` and async `cookies()/headers()` if used.
30+
- Validate inputs with Zod and return standard { data | error } response shape.
31+
- Enforce auth (NextAuth session) and tenant isolation (storeId) where applicable.
32+
- Apply rate limiting to sensitive endpoints; add audit logs for admin mutations.
33+
34+
File inventory captured (partial listing; see route-list.md for full):
35+
- Global: page.tsx, layout.tsx, error.tsx, loading.tsx, not-found.tsx, globals.css
36+
- Storefront pages: shop/page.tsx, shop/products/page.tsx, shop/products/[slug]/page.tsx, shop/categories/[slug]/page.tsx, shop/cart/page.tsx, shop/checkout/page.tsx, shop/orders/[id]/confirmation/page.tsx, shop/orders/page.tsx, shop/profile/page.tsx, shop/search/page.tsx, shop/wishlists/page.tsx
37+
- (auth): (auth)/login/page.tsx, register/page.tsx, forgot-password/page.tsx, reset-password/page.tsx, mfa/enroll/page.tsx, mfa/challenge/page.tsx
38+
- (dashboard): layout.tsx, dashboard/page.tsx, products/page.tsx, products/[id]/page.tsx, products/loading.tsx, products/error.tsx, orders/page.tsx, orders/[id]/page.tsx, orders/loading.tsx, orders/error.tsx, categories/page.tsx, brands/page.tsx, attributes/page.tsx, attributes/loading.tsx, inventory/page.tsx, inventory/loading.tsx, analytics/page.tsx, analytics/sales/page.tsx, analytics/customers/page.tsx, marketing/campaigns/page.tsx, marketing/coupons/page.tsx, settings/page.tsx, settings/theme/page.tsx, settings/privacy/page.tsx, settings/privacy/privacy-settings-client.tsx, stores/page.tsx, stores/new/page.tsx, stores/[id]/page.tsx, audit-logs/page.tsx, integrations/page.tsx, subscription/plans/page.tsx, subscription/billing/page.tsx
39+
- API routes: see below sections by domain.
40+
41+
Recommendations (global):
42+
- Ensure all pages import only what they need; heavy charts and editors should be client-only and dynamically imported inside client components, not server parents.
43+
- Confirm Next.js 16 async param usage across dynamic routes ([slug]/[id]).
44+
- Provide loading.tsx where lists or detail pages fetch data; prefer Suspense in composite pages.
45+
- For storefront, consider cache strategies with cache tags for products, categories, brands; invalidate on admin mutations.
46+
47+
Appendix: API endpoints list (from inventory)
48+
- products: /api/products, /api/products/[id], /api/products/export, /api/products/import, /api/products/[id]/stock, /api/products/[id]/stock/check, /api/products/[id]/stock/decrease
49+
- categories: /api/categories, /api/categories/[id], /api/categories/[id]/move, /api/categories/reorder
50+
- brands: /api/brands, /api/brands/[id], /api/brands/[id]/products
51+
- attributes: /api/attributes, /api/attributes/[id], /api/attributes/[id]/products
52+
- orders: /api/orders, /api/orders/[id], /api/orders/[id]/status, /api/orders/[id]/invoice
53+
- checkout: /api/checkout/validate, /api/checkout/payment-intent, /api/checkout/complete, /api/checkout/shipping
54+
- auth: /api/auth/login, /api/auth/logout, /api/auth/register, /api/auth/forgot-password, /api/auth/reset-password, /api/auth/[...nextauth], /api/auth/mfa/*, /api/auth/custom-session, /api/auth/test
55+
- analytics: /api/analytics/dashboard, /api/analytics/sales, /api/analytics/customers, /api/analytics/products, /api/analytics/revenue
56+
- inventory: /api/inventory, /api/inventory/adjust
57+
- notifications: /api/notifications, /api/notifications/[id]/read
58+
- stores: /api/stores, /api/stores/[id], /api/stores/[id]/admins, /api/stores/[id]/theme
59+
- subscriptions: /api/subscriptions, /api/subscriptions/[storeId], /api/subscriptions/[storeId]/cancel, /api/themes
60+
- webhooks: /api/webhooks/stripe, /api/webhooks/stripe/subscription
61+
- integrations: /api/integrations/* (shopify/mailchimp connect/export/disconnect)
62+
- emails: /api/emails/send
63+
- docs: /api/docs
64+
- csrf: /api/csrf-token
65+
- dev: /api/dev/* (session-info, create-session, echo-cookies)
66+
- GDPR: /api/gdpr/export, /api/gdpr/delete, /api/gdpr/consent
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Architecture Overview
2+
3+
This document summarizes the project structure and counts per category, based on repository scan at 2025-11-10.
4+
5+
Top-level categories under `src/` with file counts (approximate):
6+
- app/: 136 files
7+
- components/: 83 files
8+
- lib/: 34 files
9+
- services/: 30 files
10+
- hooks/: 6 files
11+
- contexts/: 1 file
12+
- providers/: 1 file
13+
- emails/: 4 files
14+
- types/: 5 files
15+
16+
Key conventions observed:
17+
- Next.js 16 App Router present with route groups (auth, dashboard, storefront) and extensive API routes under `src/app/api/*`.
18+
- Server Components by default; Client Components explicitly marked with `'use client'` in select hooks, providers, and UI components.
19+
- Multi-tenant boundaries enforced in Prisma schema (extensive storeId indexes) and mirrored in services.
20+
- Tailwind and Radix UI used; global styles at `src/app/globals.css`.
21+
22+
Recommendations:
23+
- Keep files under 300 lines and functions under 50 lines; refactor large components into smaller composables.
24+
- Ensure App Router pages and route handlers use Next.js 16 async patterns (await params, await searchParams; cookies/headers/draftMode now async).
25+
- Maintain 70%+ Server Components; minimize client bundle by isolating client-only interactivity.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Components – Analytics
3+
category: components/analytics
4+
files:
5+
- analytics-dashboard.tsx
6+
- analytics-date-picker.tsx
7+
- revenue-chart.tsx
8+
- sales-revenue-chart.tsx
9+
- sales-report.tsx
10+
- sales-metrics-cards.tsx
11+
- metrics-cards.tsx
12+
- top-products.tsx
13+
- top-products-table.tsx
14+
- top-products-chart.tsx
15+
- customer-metrics.tsx
16+
- customer-metrics-chart.tsx
17+
riskLevel: medium
18+
---
19+
20+
# Analytics Components Review
21+
22+
General Observations:
23+
- All files expected to be Client Components if they use charts, hooks, or interactivity; verify `'use client'` directive present where hooks (state, effects) are used.
24+
- Performance: Heavy chart components should leverage dynamic import with suspense boundaries inside client shells, not at server level.
25+
- Data Fetching: Prefer server-side data aggregation passed as props to minimize client data mass; use lean datasets.
26+
- Accessibility: Charts require textual summaries (ARIA live regions or descriptive text) for screen readers.
27+
- Multi-tenancy: Ensure analytics queries filter by storeId and respect soft deletion; avoid leaking cross-tenant aggregates.
28+
29+
Per-File Notes (Heuristic):
30+
- analytics-dashboard.tsx: Likely orchestrates multiple metric cards—should split layout vs data fetching; server component parent + client metric cards is preferred.
31+
- analytics-date-picker.tsx: Ensure keyboard navigation, focus management, and proper aria-labels for date inputs.
32+
- revenue-chart.tsx / sales-revenue-chart.tsx / top-products-chart.tsx / customer-metrics-chart.tsx: Confirm canvas/svg elements have fallback textual descriptions. Avoid large bundle of charting libs; tree-shake.
33+
- sales-report.tsx: If generating tabular PDF/CSV export, do so server-side; avoid heavy client loops.
34+
- sales-metrics-cards.tsx / metrics-cards.tsx / customer-metrics.tsx: Keep each card small (<50 lines), use semantic elements (<section>, <h2>). Provide skeleton loading states.
35+
- top-products-table.tsx / top-products.tsx: Paginate tables; limit columns; ensure responsive design.
36+
37+
Recommendations:
38+
1. Add explicit `<figure>` + `<figcaption>` for each chart for accessibility.
39+
2. Provide loading/error boundaries (Suspense + error boundary) wrapping chart components.
40+
3. Export pure data transformation utilities into `lib/analytics-utils.ts` to reduce duplication and improve testability.
41+
4. Add unit tests for data bucketing and sorting logic (e.g., top products, revenue grouping).
42+
5. Consider cache tags (e.g., `analytics:revenue`) for server-fetched aggregations to reduce recalculation.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Components – Attributes
3+
category: components/attributes
4+
files:
5+
- attribute-form.tsx
6+
- attributes-filters.tsx
7+
- attributes-table.tsx
8+
riskLevel: low
9+
---
10+
11+
# Attribute Components Review
12+
13+
Notes:
14+
- Forms: attribute-form.tsx should use controlled inputs, Zod validation server-side; client form should handle optimistic UI updates.
15+
- Filters/table: Ensure table is paginated and accessible (table headers <th>, sortable columns with aria-sort).
16+
- Multi-tenancy: All modify/read operations must filter attributes by storeId indirectly through products/categories if applicable.
17+
- Performance: Debounce filter inputs; avoid fetching large attribute lists at once.
18+
- Accessibility: Provide labels for filters, keyboard navigation in table.
19+
20+
Recommendations:
21+
1. Add skeleton states for table loading.
22+
2. Add unit tests for value list normalization (e.g., parsing JSON arrays of attribute values).
23+
3. Ensure attribute-form enforces unique attribute names if required.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Components – Audit Logs
3+
category: components/audit-logs
4+
files:
5+
- audit-logs-table.tsx
6+
- audit-logs-filters.tsx
7+
riskLevel: low
8+
---
9+
10+
# Audit Logs Components Review
11+
12+
Notes:
13+
- Read-only views; must be server-fetched and paginated.
14+
- Ensure filters (date range, user, action) debounce requests and use accessible controls.
15+
- Security: Mask sensitive changes; avoid displaying secrets.
16+
- Performance: Use indexed fields (createdAt, userId, entityType) as per schema; select necessary columns only.
17+
18+
Recommendations:
19+
1. Add CSV export server-side with permission checks.
20+
2. Provide row-level details in a dialog with keyboard accessible triggers.

docs/reviews/components/auth.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Components – Auth
3+
category: components/auth
4+
files:
5+
- form-error.tsx
6+
- form-success.tsx
7+
- password-strength-indicator.tsx
8+
riskLevel: low
9+
---
10+
11+
# Auth Components Review
12+
13+
Notes:
14+
- Pure UI components; ensure no secrets exposed; provide clear aria-live regions for error/success messages.
15+
- Password-strength-indicator: Perform checks client-side only; do not transmit raw passwords beyond submission.
16+
- Internationalization: Ensure messages are translatable if i18n is planned.
17+
18+
Recommendations:
19+
1. Add unit tests for strength indicator heuristics.
20+
2. Sanitize error content before rendering.

docs/reviews/components/brands.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Components – Brands
3+
category: components/brands
4+
files:
5+
- brands-table.tsx
6+
- brands-filters.tsx
7+
- brands-bulk-actions.tsx
8+
riskLevel: low
9+
---
10+
11+
# Brand Components Review
12+
13+
Notes:
14+
- Table: Paginated; ensure accessible sorting and selection for bulk actions.
15+
- Filters: Debounce; provide clear labels and ARIA descriptions; maintain state in URL params for deep linking.
16+
- Bulk actions: Confirm authorization (STORE_ADMIN only) and optimistic updates with server validation.
17+
18+
Recommendations:
19+
1. Add integration tests for bulk publish/unpublish flows.
20+
2. Use Suspense boundaries around table data for streaming updates if applicable.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Components – Bulk Import
3+
category: components/bulk-import
4+
files:
5+
- bulk-import-upload.tsx
6+
- bulk-import-templates.tsx
7+
- bulk-import-history.tsx
8+
riskLevel: medium
9+
---
10+
11+
# Bulk Import Components Review
12+
13+
Notes:
14+
- Upload: Enforce file size/type restrictions; provide progress UI; use server-side streaming parse for scalability.
15+
- Templates: Offer downloadable sample CSV/JSON; keep versioning if schema evolves.
16+
- History: Paginate results; show status (success/partial/failed) with links to error reports.
17+
- Security: Sanitize filenames; prevent path traversal; scan content for malicious payloads.
18+
- Performance: Offload heavy parsing to worker/job queue; UI should poll or subscribe for status updates.
19+
20+
Recommendations:
21+
1. Implement optimistic UI for job submission.
22+
2. Provide accessible status indicators (aria-live for completion).
23+
3. Add tests covering error handling for malformed files.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Components – Categories
3+
category: components/categories
4+
files:
5+
- category-form.tsx
6+
- categories-tree.tsx
7+
riskLevel: low
8+
---
9+
10+
# Categories Components Review
11+
12+
Notes:
13+
- Tree: Use accessible tree patterns (aria-expanded, role=tree); keyboard navigation for expand/collapse.
14+
- Form: Validate slug uniqueness per store; show preview URL.
15+
- Performance: Virtualize long trees; lazy load children.
16+
17+
Recommendations:
18+
1. Include drag-and-drop reordering with keyboard fallback.
19+
2. Add unit tests for tree manipulation utilities.

0 commit comments

Comments
 (0)