|
| 1 | +# AGENTS.md — AI Coding Agent Instructions |
| 2 | + |
| 3 | +> This file provides project context and instructions for AI coding agents (Cursor, Claude, Copilot, Windsurf, Cline) working within this codebase. |
| 4 | +
|
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**Vibe Stack** is a production-ready Next.js 15 + Supabase boilerplate designed for AI-assisted development. It includes 22 `.mdc` architecture rule files that constrain AI models to generate secure, modern, production-grade code. |
| 8 | + |
| 9 | +### Tech Stack |
| 10 | +- **Framework:** Next.js 15 (App Router, Server Components, Server Actions) |
| 11 | +- **Runtime:** React 19 |
| 12 | +- **Database & Auth:** Supabase (PostgreSQL, Auth with SSR, Row Level Security) |
| 13 | +- **Payments:** Stripe (Checkout Sessions, Webhooks, Customer Portal) |
| 14 | +- **Email:** Resend (transactional email with HTML templates) |
| 15 | +- **Validation:** Zod (runtime validation at every boundary) |
| 16 | +- **Styling:** Tailwind CSS + shadcn/ui |
| 17 | +- **Language:** TypeScript (strict mode, no `any`) |
| 18 | + |
| 19 | +### Architecture Principles |
| 20 | +1. **Server Components by default** — Only use `'use client'` when hooks or event handlers are required |
| 21 | +2. **`getUser()` over `getSession()`** — Server-side auth MUST use `getUser()` for JWT verification |
| 22 | +3. **`@supabase/ssr` only** — Never import from the deprecated `@supabase/auth-helpers-nextjs` |
| 23 | +4. **Zod at every boundary** — All user input validated before processing |
| 24 | +5. **RLS on every table** — Row Level Security is mandatory, never optional |
| 25 | + |
| 26 | +## Directory Structure |
| 27 | + |
| 28 | +``` |
| 29 | +src/ |
| 30 | +├── app/ # Next.js App Router pages and layouts |
| 31 | +│ ├── (auth)/ # Auth route group (login, signup) |
| 32 | +│ │ ├── actions.ts # Auth server actions with Zod validation |
| 33 | +│ │ ├── login/page.tsx # Login page (Server Component) |
| 34 | +│ │ └── signup/page.tsx # Signup page (Server Component) |
| 35 | +│ ├── auth/confirm/ # PKCE email verification callback |
| 36 | +│ ├── dashboard/ # Protected pages (requires auth) |
| 37 | +│ ├── api/webhooks/ # External webhook handlers (Stripe) |
| 38 | +│ ├── layout.tsx # Root layout (fonts, metadata, dark mode) |
| 39 | +│ ├── page.tsx # Landing page |
| 40 | +│ ├── loading.tsx # Global loading state |
| 41 | +│ ├── error.tsx # Global error boundary |
| 42 | +│ └── not-found.tsx # Custom 404 |
| 43 | +├── lib/ # Business logic & integrations |
| 44 | +│ ├── supabase/ # Server + Client factories + middleware helper |
| 45 | +│ ├── stripe/ # Checkout session + customer portal helpers |
| 46 | +│ ├── email/ # Resend email templates (welcome, password reset) |
| 47 | +│ ├── env.ts # Type-safe environment variable access |
| 48 | +│ └── utils.ts # cn() helper and general utilities |
| 49 | +├── types/ # Shared TypeScript types |
| 50 | +│ └── index.ts # ActionResponse<T>, UserProfile, PaginatedResponse |
| 51 | +└── middleware.ts # Session refresh entry point |
| 52 | +
|
| 53 | +.cursor/ |
| 54 | +├── rules/ # 22 .mdc architecture rules (auto-loaded by Cursor) |
| 55 | +└── mcp.json # 4 MCP server configurations |
| 56 | +
|
| 57 | +docs/ |
| 58 | +├── VIBE-CODING.md # The 3-stage agentic loop framework |
| 59 | +├── ARCHITECTURE.md # 8 Architecture Decision Records |
| 60 | +└── MCP-SETUP.md # MCP server setup guide |
| 61 | +
|
| 62 | +n8n-workflows/ # 3 importable n8n automation templates |
| 63 | +``` |
| 64 | + |
| 65 | +## Key Patterns |
| 66 | + |
| 67 | +### Server Actions |
| 68 | +All mutations use Server Actions with this pattern: |
| 69 | +```typescript |
| 70 | +'use server' |
| 71 | +import { z } from 'zod' |
| 72 | +import { createClient } from '@/lib/supabase/server' |
| 73 | + |
| 74 | +const schema = z.object({ /* fields */ }) |
| 75 | + |
| 76 | +export async function myAction(formData: FormData): Promise<ActionResponse<T>> { |
| 77 | + const parsed = schema.safeParse(Object.fromEntries(formData)) |
| 78 | + if (!parsed.success) return { error: 'Validation failed' } |
| 79 | + |
| 80 | + const supabase = await createClient() |
| 81 | + const { data: { user } } = await supabase.auth.getUser() |
| 82 | + if (!user) return { error: 'Not authenticated' } |
| 83 | + |
| 84 | + // ... business logic |
| 85 | + return { data: result } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Auth Check Pattern |
| 90 | +```typescript |
| 91 | +// ALWAYS use this pattern in Server Components and Server Actions |
| 92 | +const supabase = await createClient() |
| 93 | +const { data: { user }, error } = await supabase.auth.getUser() |
| 94 | +if (error || !user) redirect('/login') |
| 95 | +``` |
| 96 | + |
| 97 | +### Environment Variables |
| 98 | +- `NEXT_PUBLIC_*` — Safe to expose to client (Supabase URL, app URL) |
| 99 | +- Everything else — Server-only (Stripe secret, Supabase service role, Resend key) |
| 100 | +- Access via `src/lib/env.ts` for type safety |
| 101 | + |
| 102 | +## Rules System |
| 103 | + |
| 104 | +The `.cursor/rules/` directory contains 22 `.mdc` files that auto-activate based on file globs. These rules override AI training data defaults to prevent: |
| 105 | +- Insecure auth patterns (`getSession()` → `getUser()`) |
| 106 | +- Deprecated package imports |
| 107 | +- Next.js 15 breaking changes (async params) |
| 108 | +- Missing RLS policies |
| 109 | +- Client-side Stripe usage |
| 110 | +- Hydration mismatches |
| 111 | +- N+1 query patterns |
| 112 | + |
| 113 | +When adding new features, the AI should read and follow all applicable rules automatically. |
| 114 | + |
| 115 | +## MCP Integrations |
| 116 | + |
| 117 | +4 MCP servers are pre-configured in `.cursor/mcp.json`: |
| 118 | +- **GitHub MCP** — Read repos, PRs, issues, commits |
| 119 | +- **Supabase MCP** — Inspect database schema and RLS policies (read-only) |
| 120 | +- **Filesystem MCP** — Navigate project structure |
| 121 | +- **Browser MCP** — Take screenshots and test the running app |
| 122 | + |
| 123 | +## Contributing |
| 124 | + |
| 125 | +When adding new features: |
| 126 | +1. Follow the 3-stage agentic loop: Plan → Implement (in batches) → Verify |
| 127 | +2. Check applicable `.mdc` rules before writing code |
| 128 | +3. Use Server Components by default |
| 129 | +4. Validate all input with Zod |
| 130 | +5. Add RLS policies for any new tables |
| 131 | +6. Use conventional commits (`feat:`, `fix:`, `docs:`) |
0 commit comments