Architecture
Garmint is a Next.js 15 application with a layered architecture designed for AI-first workflows.High-Level Overview
Directory Structure
Data Flow
Generation Flow
Production Order Flow
Database Schema
Core Tables
| Table | Purpose |
|---|---|
profiles | User accounts (synced from Supabase Auth) |
projects | Workspaces with billing & settings |
project_members | User-project associations |
subscriptions | Stripe subscription state |
token_grants | Credit additions (subscription, purchases) |
usage_ledgers | Token consumption records |
Chat & Generation
| Table | Purpose |
|---|---|
prompt_threads | Chat conversation containers |
prompt_messages | Individual messages in threads |
render_jobs | AI generation job records |
render_assets | Generated images (mockups, graphics) |
Production
| Table | Purpose |
|---|---|
production_orders | Production order headers |
production_line_items | Size/quantity breakdown |
fulfillment_events | Status change history |
Views
| View | Purpose |
|---|---|
project_token_balances | Computed token balances per project |
Authentication
/api/auth/callback completes PKCE exchange and sets session cookies.
Token System
Image Generation
Two-step process for production-ready output:State Management
Client-side state via React Context (providers.tsx):
localStorage with garmint:* keys.
Realtime Updates
Production orders use Supabase Realtime:Security Model
- RLS (Row Level Security): All tables use project-scoped policies
- Service Role: Only for server-side admin operations
- Anon Key: Safe for browser, limited to user’s own data
- Stripe Webhooks: Verified via signature
- Admin Routes:
/ops/*gated byisOpsEmail()check