Skip to main content

Architecture Overview

CommonPlace follows a modern JAMstack architecture with React on the frontend and Supabase providing backend services.

System Diagram

┌─────────────────────────────────────────────────────────────────┐
│ Client (Browser) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ React Application │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────┐ │ │
│ │ │Components│ │ Hooks │ │ Context │ │ Pages │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └─────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Supabase Client │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘

│ HTTPS

┌─────────────────────────────────────────────────────────────────┐
│ Supabase Cloud │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────────────┐ │
│ │ Auth │ │ API │ │ Storage │ │ PostgreSQL │ │
│ │(GoTrue) │ │(PostgREST)│ │ │ │ Database │ │
│ └──────────┘ └──────────┘ └──────────┘ │ ┌───────────┐ │ │
│ │ │ RLS │ │ │
│ │ │ Policies │ │ │
│ │ └───────────┘ │ │
│ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘

Key Components

Frontend (React + Vite)

ComponentPurpose
ComponentsReusable UI elements
HooksData fetching and state logic
ContextGlobal state (theme, auth, messaging)
PagesRoute-level components

Backend (Supabase)

ServicePurpose
AuthUser authentication via GoTrue
DatabasePostgreSQL with Row Level Security
StorageFile uploads (images, media)
RealtimeLive subscriptions for messaging

Data Flow

  1. User Action → Component captures interaction
  2. Hook Call → Custom hook makes Supabase request
  3. RLS Check → Database validates permissions
  4. Response → Data returned to component
  5. Render → UI updates with new data

Authentication Flow

User Login


┌──────────────┐
│ Auth.signIn │
└──────────────┘


┌──────────────┐ ┌──────────────┐
│ Supabase │────▶│ Session │
│ Auth │ │ Created │
└──────────────┘ └──────────────┘


┌──────────────┐
│ App State │
│ Updated │
└──────────────┘


┌──────────────┐
│ Protected │
│ Routes │
│ Accessible │
└──────────────┘

Security Model

All data access is controlled by Row Level Security (RLS) policies in PostgreSQL:

  • Users can only see their own data (posts, settings)
  • Friends can see shared content (feed posts)
  • Blocked users are completely invisible (404, not "blocked")
  • Admin functions require is_admin flag

See Database Security for policy details.

File Structure

friends-network/
├── src/
│ ├── components/ # React components
│ ├── hooks/ # Custom React hooks
│ ├── context/ # React context providers
│ ├── pages/ # Page-level components
│ ├── lib/ # Utilities and configuration
│ └── index.css # Global styles
├── supabase/
│ └── migrations/ # Database migrations
├── docs/ # This documentation
└── public/ # Static assets

See File Structure for detailed breakdown.