Spaces:
Sleeping
Sleeping
| # Architecture β Stack, Structure & Data Models | |
| ## Purpose | |
| Read this file when building or modifying any structural part | |
| of the project. Update this file when architecture changes. | |
| Do not guess the stack β confirm here first. | |
| --- | |
| ## Tech Stack | |
| Frontend: [e.g. Next.js 14, React, TypeScript] | |
| Styling: [e.g. Tailwind CSS, shadcn/ui] | |
| Backend: [e.g. Next.js API Routes / Edge Functions] | |
| Database: Supabase (PostgreSQL) | |
| Auth: Supabase Auth | |
| Storage: Supabase Storage | |
| Deployment: [e.g. Vercel / Railway] | |
| Testing: Jest, ts-jest, React Testing Library | |
| Package Mgr: [e.g. npm / pnpm] | |
| --- | |
| ## Folder Structure | |
| project-root/ | |
| βββ src/ | |
| β βββ app/ β Next.js app router pages | |
| β β βββ (auth)/ β auth route group | |
| β β βββ (dashboard)/ β protected route group | |
| β β βββ api/ β API routes | |
| β βββ components/ β reusable UI components | |
| β β βββ ui/ β base components (shadcn) | |
| β β βββ [feature]/ β feature specific components | |
| β βββ lib/ β shared utilities and clients | |
| β β βββ supabase.ts β supabase client | |
| β β βββ supabase-server.tsβ server side supabase client | |
| β β βββ utils.ts β shared utility functions | |
| β βββ hooks/ β custom React hooks | |
| β βββ types/ β TypeScript type definitions | |
| β βββ constants/ β app wide constants | |
| βββ supabase/ | |
| β βββ migrations/ β all DB migration files | |
| βββ tests/ β all test files | |
| βββ docs/ β project documentation | |
| βββ scripts/ β shell scripts | |
| βββ logs/ β runtime and test logs | |
| --- | |
| ## Database Schema | |
| ### Tables | |
| [Update this section as tables are created] | |
| users | |
| id UUID PRIMARY KEY DEFAULT gen_random_uuid() | |
| email TEXT NOT NULL UNIQUE | |
| created_at TIMESTAMPTZ DEFAULT NOW() | |
| updated_at TIMESTAMPTZ DEFAULT NOW() | |
| ### Relationships | |
| [Document foreign keys and relationships here] | |
| users.id β referenced by [table].[column] | |
| ### RLS Summary | |
| [Document which tables have RLS enabled and policy types] | |
| Table RLS Policies | |
| users YES owner CRUD | |
| --- | |
| ## Auth Flow | |
| User lands on /login | |
| Supabase Auth handles email/OAuth | |
| On success β session stored in cookie | |
| Protected routes check session via middleware | |
| API routes validate session server side | |
| On signout β session cleared, redirect to /login | |
| --- | |
| ## API Routes | |
| [Document API routes as they are created] | |
| POST /api/auth/login β handle login | |
| POST /api/auth/logout β handle logout | |
| GET /api/user β get current user | |
| --- | |
| ## Environment Variables | |
| NEXT_PUBLIC_SUPABASE_URL β supabase project URL | |
| NEXT_PUBLIC_SUPABASE_ANON_KEY β supabase anon key | |
| SUPABASE_SERVICE_ROLE_KEY β server only, never expose | |
| --- | |
| ## Key Architectural Decisions | |
| [Document WHY decisions were made as project grows] | |
| [YYYY-MM-DD] β Used app router over pages router for better | |
| server component support | |
| [YYYY-MM-DD] β Used Supabase RLS over API-level auth checks | |
| for defence in depth | |
| --- | |
| ## Constraints | |
| [Document hard technical constraints] | |
| No direct DB access from client side components | |
| Service role key only used in server side code | |
| All DB changes must go through migration files | |
| RLS must be enabled on every table | |
| --- | |
| ## Rules for This File | |
| - Update when a new table is added | |
| - Update when a new API route is created | |
| - Update when a key architectural decision is made | |
| - Keep schema section in sync with actual migrations | |
| - Do not document implementation details β only structure |