MetaDebate / docs /architecture.md
vajeeda's picture
base structure of the project formed
b6e19c7
|
Raw
History Blame Contribute Delete
3.85 kB
# 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