|
| 1 | +# Agent Instructions |
| 2 | + |
| 3 | +> **Copy this file to `docs/Agents.md` in any new project.** |
| 4 | +> Customize sections marked with `<!-- CUSTOMIZE -->`. |
| 5 | +> Delete this notice and all `<!-- CUSTOMIZE -->` comments after setup. |
| 6 | +
|
| 7 | +This document provides instructions for AI agents working on this codebase. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Project Overview |
| 12 | + |
| 13 | +<!-- CUSTOMIZE: Replace with your project details --> |
| 14 | + |
| 15 | +**Project:** `PROJECT_NAME` |
| 16 | +**Description:** Brief description of what this project does |
| 17 | + |
| 18 | +**Stack:** |
| 19 | +- Frontend: <!-- e.g., Next.js 14+, TypeScript, Tailwind CSS, shadcn/ui --> |
| 20 | +- Backend: <!-- e.g., Next.js Route Handlers --> |
| 21 | +- Auth: <!-- e.g., Supabase Auth --> |
| 22 | +- Database: <!-- e.g., Supabase Postgres --> |
| 23 | +- Hosting: <!-- e.g., Vercel --> |
| 24 | + |
| 25 | +See `docs/PRD.md` for full product requirements. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Development Environment |
| 30 | + |
| 31 | +### Prerequisites |
| 32 | + |
| 33 | +<!-- CUSTOMIZE: List your prerequisites --> |
| 34 | + |
| 35 | +- Node.js 18+ |
| 36 | +- Docker (if using local database) |
| 37 | +- <!-- Other tools --> |
| 38 | + |
| 39 | +### Starting the Dev Environment |
| 40 | + |
| 41 | +**IMPORTANT:** Do not start the dev server automatically. The user typically runs it in a separate terminal. |
| 42 | + |
| 43 | +Before running server commands, check if already running: |
| 44 | + |
| 45 | +```bash |
| 46 | +# Check if dev server is running |
| 47 | +lsof -i :3000 |
| 48 | + |
| 49 | +# Check if local database is running (if applicable) |
| 50 | +<!-- CUSTOMIZE: e.g., npx supabase status --> |
| 51 | +``` |
| 52 | + |
| 53 | +### Environment Variables |
| 54 | + |
| 55 | +```bash |
| 56 | +cp .env.example .env.local |
| 57 | +``` |
| 58 | + |
| 59 | +<!-- CUSTOMIZE: List required variables --> |
| 60 | + |
| 61 | +Required: |
| 62 | +```bash |
| 63 | +# Database |
| 64 | +DATABASE_URL= |
| 65 | + |
| 66 | +# Auth |
| 67 | +# ... |
| 68 | + |
| 69 | +# API Keys |
| 70 | +# ... |
| 71 | +``` |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Database Access |
| 76 | + |
| 77 | +<!-- CUSTOMIZE: Adapt for your database setup --> |
| 78 | + |
| 79 | +### Local Development |
| 80 | + |
| 81 | +<!-- Example for Supabase: --> |
| 82 | +```bash |
| 83 | +# Get database URL |
| 84 | +npx supabase status |
| 85 | + |
| 86 | +# Run SQL |
| 87 | +psql "postgresql://postgres:postgres@127.0.0.1:XXXXX/postgres" -c "YOUR SQL" |
| 88 | +``` |
| 89 | + |
| 90 | +### Remote Environments |
| 91 | + |
| 92 | +| Environment | Reference | Notes | |
| 93 | +|-------------|-----------|-------| |
| 94 | +| Development | `<!-- DEV_REF -->` | Default for CLI | |
| 95 | +| Production | `<!-- PROD_REF -->` | Use with caution | |
| 96 | + |
| 97 | +### Switching Environments |
| 98 | + |
| 99 | +```bash |
| 100 | +# Check current environment |
| 101 | +npm run db:which |
| 102 | + |
| 103 | +# Switch to production (careful!) |
| 104 | +npm run db:link:prod |
| 105 | + |
| 106 | +# Switch back to development |
| 107 | +npm run db:link:dev |
| 108 | +``` |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## Database Migrations |
| 113 | + |
| 114 | +### Golden Rules |
| 115 | + |
| 116 | +1. **Never modify existing migration files** that have been applied |
| 117 | +2. **Never reset the database** unless absolutely necessary |
| 118 | +3. **Always create new migration files** for schema changes |
| 119 | +4. **Test locally first** before pushing to remote |
| 120 | + |
| 121 | +### Creating Migrations |
| 122 | + |
| 123 | +<!-- CUSTOMIZE: Adapt for your migration tool --> |
| 124 | + |
| 125 | +```bash |
| 126 | +# Create new migration |
| 127 | +npx supabase migration new <name> |
| 128 | + |
| 129 | +# Apply migrations |
| 130 | +npx supabase migration up |
| 131 | + |
| 132 | +# Check status |
| 133 | +npx supabase migration list |
| 134 | +``` |
| 135 | + |
| 136 | +### Best Practices |
| 137 | + |
| 138 | +```sql |
| 139 | +-- Use built-in UUID generation |
| 140 | +id UUID PRIMARY KEY DEFAULT gen_random_uuid() |
| 141 | + |
| 142 | +-- Include IF NOT EXISTS for safety |
| 143 | +CREATE TABLE IF NOT EXISTS users (...); |
| 144 | + |
| 145 | +-- Enable RLS in same migration as table |
| 146 | +ALTER TABLE public.users ENABLE ROW LEVEL SECURITY; |
| 147 | +``` |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Coding Conventions |
| 152 | + |
| 153 | +### TypeScript |
| 154 | + |
| 155 | +- No `any` types—use proper typing or `unknown` |
| 156 | +- Use interfaces for object shapes |
| 157 | +- Export types from dedicated `types.ts` files |
| 158 | + |
| 159 | +### File Structure |
| 160 | + |
| 161 | +<!-- CUSTOMIZE: Define your project structure --> |
| 162 | + |
| 163 | +``` |
| 164 | +src/ |
| 165 | +├── app/ # Pages/routes |
| 166 | +├── components/ |
| 167 | +│ ├── ui/ # Reusable UI components |
| 168 | +│ └── [feature]/ # Feature-specific |
| 169 | +├── lib/ # Utilities and clients |
| 170 | +└── types/ # TypeScript definitions |
| 171 | +``` |
| 172 | + |
| 173 | +### Imports |
| 174 | + |
| 175 | +```typescript |
| 176 | +// External imports first |
| 177 | +import { useState } from 'react'; |
| 178 | + |
| 179 | +// Internal imports (absolute paths) |
| 180 | +import { Button } from '@/components/ui/button'; |
| 181 | +import type { User } from '@/types'; |
| 182 | +``` |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## AI Agent Workflow |
| 187 | + |
| 188 | +### Execution Order |
| 189 | + |
| 190 | +``` |
| 191 | +1. PRD → 2. Database → 3. Backend → 4. UI → 5. Test → 6. Document |
| 192 | +``` |
| 193 | + |
| 194 | +**Database migrations MUST be applied before any other implementation.** |
| 195 | + |
| 196 | +### Before Starting Any Task |
| 197 | + |
| 198 | +1. Read `docs/PRD.md` for context |
| 199 | +2. Check for any implementation tracker |
| 200 | +3. Verify dev environment is ready |
| 201 | +4. Check for pending migrations |
| 202 | + |
| 203 | +### Task Format |
| 204 | + |
| 205 | +```markdown |
| 206 | +### Task Name |
| 207 | +**Goal:** What needs to be done |
| 208 | +**Deliverables:** |
| 209 | +- [ ] Item 1 |
| 210 | +- [ ] Item 2 |
| 211 | +**Files:** `path/to/files` |
| 212 | +**Success Criteria:** How to verify |
| 213 | +**Dependencies:** What must be done first |
| 214 | +``` |
| 215 | + |
| 216 | +--- |
| 217 | + |
| 218 | +## Commits |
| 219 | + |
| 220 | +### Format |
| 221 | + |
| 222 | +Use conventional commits: |
| 223 | + |
| 224 | +```bash |
| 225 | +feat(scope): add new feature |
| 226 | +fix(scope): fix bug |
| 227 | +docs(scope): update documentation |
| 228 | +chore(scope): maintenance task |
| 229 | +``` |
| 230 | + |
| 231 | +### Before Committing |
| 232 | + |
| 233 | +1. Only commit files for the current task |
| 234 | +2. Verify staged files: `git status --short` |
| 235 | +3. Run checks: `npm run type-check && npm run lint` |
| 236 | + |
| 237 | +### Co-Author Attribution |
| 238 | + |
| 239 | +``` |
| 240 | +feat: implement feature |
| 241 | +
|
| 242 | +Co-Authored-By: Claude <noreply@anthropic.com> |
| 243 | +``` |
| 244 | + |
| 245 | +--- |
| 246 | + |
| 247 | +## Quality Checklist |
| 248 | + |
| 249 | +Before marking any task complete: |
| 250 | + |
| 251 | +- [ ] TypeScript compiles (`npm run type-check`) |
| 252 | +- [ ] Linting passes (`npm run lint`) |
| 253 | +- [ ] Migrations apply cleanly |
| 254 | +- [ ] Error states handled |
| 255 | +- [ ] Loading states implemented |
| 256 | +- [ ] No console.log in production code |
| 257 | +- [ ] No hardcoded secrets |
| 258 | + |
| 259 | +--- |
| 260 | + |
| 261 | +## Workflow Capture |
| 262 | + |
| 263 | +**IMPORTANT:** This project tracks the development process to improve future workflows. |
| 264 | + |
| 265 | +### When to Log |
| 266 | + |
| 267 | +Add entries to `docs/WorkflowJournal.md` when you observe: |
| 268 | + |
| 269 | +| Tag | When to Use | |
| 270 | +|-----|-------------| |
| 271 | +| `[MANUAL]` | Something done by hand that could be scripted | |
| 272 | +| `[REPETITIVE]` | Something done in other projects too | |
| 273 | +| `[FRICTION]` | Snag, workaround, or unexpected complexity | |
| 274 | +| `[INSIGHT]` | Something worth remembering | |
| 275 | +| `[DECISION]` | Choice between alternatives | |
| 276 | + |
| 277 | +### Entry Format |
| 278 | + |
| 279 | +```markdown |
| 280 | +### YYYY-MM-DD HH:MM - [TAG] Short title |
| 281 | +**Context:** What were you trying to do? |
| 282 | +**Action:** What did you actually do? |
| 283 | +**Time spent:** Estimate |
| 284 | +**Automation opportunity:** None | Low | Medium | High |
| 285 | +**Notes:** Any additional context |
| 286 | +``` |
| 287 | + |
| 288 | +### Proactive Capture |
| 289 | + |
| 290 | +After completing a task, consider: |
| 291 | +1. Was any part manual when it could be automated? |
| 292 | +2. Have I done this in another project? |
| 293 | +3. Did I learn something useful? |
| 294 | + |
| 295 | +If yes, add a journal entry. |
| 296 | + |
| 297 | +--- |
| 298 | + |
| 299 | +## Related Documents |
| 300 | + |
| 301 | +| Document | Purpose | |
| 302 | +|----------|---------| |
| 303 | +| `docs/PRD.md` | Product requirements | |
| 304 | +| `docs/Workflow.md` | Development process playbook | |
| 305 | +| `docs/WorkflowJournal.md` | Real-time action capture | |
| 306 | + |
| 307 | +--- |
| 308 | + |
| 309 | +## Quick Reference |
| 310 | + |
| 311 | +<!-- CUSTOMIZE: Add your common commands --> |
| 312 | + |
| 313 | +| Command | Purpose | |
| 314 | +|---------|---------| |
| 315 | +| `npm run dev` | Start dev server | |
| 316 | +| `npm run build` | Production build | |
| 317 | +| `npm run type-check` | TypeScript check | |
| 318 | +| `npm run lint` | Linting | |
| 319 | + |
| 320 | +--- |
| 321 | + |
| 322 | +*Template version: 1.0* |
0 commit comments