This file provides guidance to Verdent when working with code in this repository.
- Commonly Used Commands
- High-Level Architecture & Structure
- Key Rules & Constraints
- Development Hints
npm run install:all- Install all dependencies (root, server, client)npm run dev- Run both frontend (port 3000) and backend (port 3001) concurrentlynpm run dev:server- Run only backend server with hot reloadnpm run dev:client- Run only frontend with hot reloadnpm run build- Build both client and server for productionnpm start- Start production server (after build)
- Frontend (React + Vite): User interface with 3 main features
- Generator: AI hook generation from topics
- Analyzer: Hook scoring and feedback
- Patterns: Template library browser
- Backend (Express + TypeScript): REST API for AI operations and data persistence
- Routes: API endpoints for hooks, patterns, history
- Services: OpenAI integration for generation and analysis
- Database: SQLite for storing hooks, patterns, and history
- AI Layer: OpenAI GPT-4 for hook generation and analysis
-
Hook Generation Flow:
- User enters topic → Frontend sends POST to
/api/hooks/generate - Backend calls OpenAI with prompt → Returns 5 hooks
- Hooks saved to DB → Frontend displays results
- User enters topic → Frontend sends POST to
-
Hook Analysis Flow:
- User pastes hook → Frontend sends POST to
/api/hooks/analyze - Backend calls OpenAI for scoring → Parses score + feedback
- Result saved to DB → Frontend displays score and suggestions
- User pastes hook → Frontend sends POST to
-
Pattern Library Flow:
- Frontend requests GET
/api/hooks/patterns - Backend queries SQLite → Returns pre-seeded templates
- Frontend displays filterable pattern cards
- Frontend requests GET
- OpenAI API (GPT-4) - requires
OPENAI_API_KEYinserver/.env - No authentication system implemented (JWT setup exists but unused)
- Frontend:
client/src/main.tsx→App.tsx - Backend:
server/src/index.ts - API client:
client/src/api.ts(axios-based)
graph TD
A[React Frontend] -->|HTTP Requests| B[Express API]
B -->|Prompts| C[OpenAI GPT-4]
B -->|Read/Write| D[SQLite DB]
A -->|Proxy /api| B
D -->|Hooks Table| E[Generated Hooks]
D -->|Patterns Table| F[Hook Templates]
- Frontend runs on port 3000, backend on port 3001
- Vite proxy configured to forward
/api/*to backend - TypeScript strict mode enabled on both client and server
- SQLite database auto-initialized on server start with 10 pre-seeded patterns
- Node.js 18+ required
- OpenAI API key is mandatory - app will fail without it
server/.envmust be created fromserver/.env.example
- React components use functional style with hooks
- No prop-types (TypeScript interfaces instead)
- Tailwind utility classes for all styling
- Error handling with try/catch + user-friendly messages
- API responses follow
{ data }or{ error }pattern
- Patterns are seeded in
server/src/db.ts→initDatabase() - Add to the
patternsarray:[name, template, category, example] - Pattern table has 4 fields:
name,template,category,example - Frontend automatically displays new patterns (no changes needed)
- Generation prompt:
server/src/services/ai.ts→generateHooks() - Analysis prompt:
server/src/services/ai.ts→analyzeHook() - Both use
gpt-4model with different temperatures (0.9 for generation, 0.7 for analysis)
- Add route in
server/src/routes/hooks.ts - Use Zod for request validation (see existing
generateSchema,analyzeSchema) - Add corresponding method in
client/src/api.ts - Update TypeScript interfaces if needed
hookstable:id,topic,hook,score,created_atpatternstable:id,name,template,category,example- Database file:
server/data/hooks.db(auto-created)
- Each tab has its own component in
client/src/components/ - Components manage their own state with
useState - API calls use async/await with loading + error states
- All components follow same structure: header → form → results