Spaces:
Sleeping
Sleeping
File size: 3,845 Bytes
b6e19c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | # 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 |