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