Skip to content

Commit 7950211

Browse files
Add hierarchical AGENTS.md documentation for AI coding agents
Creates token-efficient documentation system to guide AI agents: - Root AGENTS.md: Universal conventions, JIT index, and architecture overview - client/AGENTS.md: Frontend patterns (React, TanStack Query, Shadcn UI, Firebase) - server/AGENTS.md: Backend patterns (Express, Drizzle ORM, auth middleware) - shared/AGENTS.md: Database schema and type management (Drizzle + Zod) Key features: - Nearest-wins hierarchy (agents read closest AGENTS.md to working file) - JIT indexing with ripgrep commands (no content dumps) - Real file examples for DO/DON'T patterns - Pre-PR checklists with copy-paste commands - 1600+ lines of actionable guidance across all layers Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 25db94c commit 7950211

4 files changed

Lines changed: 1611 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# CodePatchwork - AGENTS.md
2+
3+
## Project Snapshot
4+
5+
**Type**: Full-stack TypeScript web application (single project, not a monorepo)
6+
**Stack**: React 18 + Vite (frontend) | Express + PostgreSQL (backend) | Firebase Auth
7+
**Architecture**: Client/server with shared types via `shared/` directory
8+
**Note**: Sub-directories have their own detailed AGENTS.md files — always check the closest one to your working file.
9+
10+
---
11+
12+
## Root Setup Commands
13+
14+
```bash
15+
# Install dependencies
16+
npm install
17+
18+
# Start development (both client + server)
19+
npm run dev
20+
21+
# Build for production (client + server)
22+
npm run build
23+
24+
# Typecheck
25+
npm run check
26+
27+
# Database: Push schema changes
28+
npm run db:push
29+
```
30+
31+
---
32+
33+
## Universal Conventions
34+
35+
### Code Style
36+
- **TypeScript strict mode** enabled
37+
- **ESM modules** (`"type": "module"`)
38+
- **Path aliases**: `@/` (client/src), `@shared/` (shared types), `@assets/` (assets)
39+
- **Functional React components** with hooks (no class components)
40+
- **TailwindCSS** for all styling (no inline styles)
41+
42+
### Commit & Branch
43+
- **No strict format enforced**, but prefer descriptive messages
44+
- Branch from `main`, PRs welcome
45+
- See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines
46+
47+
---
48+
49+
## Security & Secrets
50+
51+
- **NEVER commit** Firebase credentials, API keys, or tokens
52+
- **Environment variables**: Use `.env` file (not committed)
53+
- `DATABASE_URL` - PostgreSQL connection string
54+
- `VITE_FIREBASE_*` - Firebase client config (safe for client)
55+
- Keep Firebase Admin SDK JSON in `.gitignore`
56+
- **No PII in logs** - Winston logs to `~/logs/codepatchwork.log`
57+
58+
---
59+
60+
## JIT Index (what to open, not what to paste)
61+
62+
### Directory Structure
63+
64+
```
65+
client/ → Frontend React app [see client/AGENTS.md](client/AGENTS.md)
66+
src/
67+
components/ → UI components (Shadcn + custom)
68+
pages/ → Route pages
69+
hooks/ → Custom React hooks
70+
contexts/ → Global state providers
71+
lib/ → Utilities, Firebase config, query client
72+
73+
server/ → Backend Express API [see server/AGENTS.md](server/AGENTS.md)
74+
routes.ts → All API endpoints (1100+ lines)
75+
storage.ts → Database operations (Drizzle)
76+
db.ts → PostgreSQL pool
77+
logger.ts → Winston logger
78+
79+
shared/ → Shared types & schemas [see shared/AGENTS.md](shared/AGENTS.md)
80+
schema.ts → Drizzle tables + Zod validation
81+
82+
scripts/ → Database and migration utilities
83+
public/ → Static assets
84+
```
85+
86+
### Quick Find Commands
87+
88+
```bash
89+
# Find a React component
90+
rg -n "export (default function|function)" client/src/components
91+
92+
# Find a page
93+
rg -n "export default" client/src/pages
94+
95+
# Find a hook
96+
rg -n "export (const use|function use)" client/src/hooks
97+
98+
# Find API endpoints
99+
rg -n "app\.(get|post|put|patch|delete)" server/routes.ts
100+
101+
# Find database operations
102+
rg -n "export (async function|const)" server/storage.ts
103+
104+
# Find Drizzle schemas
105+
rg -n "export const.*=.*pgTable" shared/schema.ts
106+
107+
# Find all TypeScript errors
108+
npm run check
109+
```
110+
111+
---
112+
113+
## Definition of Done
114+
115+
Before creating a PR, ensure:
116+
117+
1. ✅ Code typechecks: `npm run check`
118+
2. ✅ Client builds: `npm run build` succeeds
119+
3. ✅ No hardcoded credentials (run `scripts/check-no-hardcode.sh`)
120+
4. ✅ Firebase env vars use `VITE_` prefix for client-side
121+
5. ✅ Database migrations tested if `shared/schema.ts` changed
122+
123+
**Note**: Tests exist in `__tests__` directories but no test runner is configured in package.json yet.
124+
125+
---
126+
127+
## Architecture Overview
128+
129+
```
130+
┌─────────────────┐
131+
│ Client (Vite) │ React + TailwindCSS
132+
│ Port: Vite Dev │ TanStack Query for data fetching
133+
└────────┬────────┘
134+
│ HTTP (fetch via apiRequest)
135+
136+
┌────────▼────────┐
137+
│ Server (Express)│ TypeScript + esbuild
138+
│ Auth Middleware│ Firebase Admin SDK
139+
└────────┬────────┘
140+
141+
┌────────▼────────┐
142+
│ Storage Layer │ Drizzle ORM
143+
│ (storage.ts) │ Interface abstraction
144+
└────────┬────────┘
145+
146+
┌────────▼────────┐
147+
│ PostgreSQL │ Tables: users, snippets, collections, comments
148+
└─────────────────┘
149+
```
150+
151+
---
152+
153+
## Technologies at a Glance
154+
155+
| Layer | Technologies |
156+
|-------|-------------|
157+
| **Frontend** | React 18, TypeScript, Vite, TailwindCSS, Shadcn UI, Prism.js, Wouter, TanStack Query |
158+
| **Backend** | Express, TypeScript, esbuild, Firebase Admin, Winston, express-session |
159+
| **Database** | PostgreSQL, Drizzle ORM, Drizzle Kit |
160+
| **Auth** | Firebase Authentication (Google OAuth + Email/Password) |
161+
| **Validation** | Zod (schemas in `shared/schema.ts`) |
162+
163+
---
164+
165+
## Common Pitfalls
166+
167+
1. **Database column naming**: DB uses lowercase (e.g., `userid`), TS uses camelCase (e.g., `userId`). Drizzle handles mapping.
168+
2. **Environment variables**: Client-side vars must use `VITE_` prefix or they won't be exposed.
169+
3. **Path imports**: Always use `@/` and `@shared/` aliases, never relative paths across major boundaries.
170+
4. **Auth tokens**: API expects `Authorization: Bearer <token>` header. Use `apiRequest()` from `queryClient.ts` for automatic token handling.
171+
172+
---
173+
174+
## Next Steps
175+
176+
For detailed guidance:
177+
- Working on **frontend code**? → [client/AGENTS.md](client/AGENTS.md)
178+
- Working on **backend API**? → [server/AGENTS.md](server/AGENTS.md)
179+
- Modifying **database schema**? → [shared/AGENTS.md](shared/AGENTS.md)

0 commit comments

Comments
 (0)