diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..a59c755 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,161 @@ +# AI Agent Instructions for Thoth + +This file contains the instructions for AI agents working on the Thoth codebase. + +## Project Overview + +Thoth is a Next.js 15 application using React 19, Mantine UI 8, and TypeScript. It's managed with pnpm. + +**Tech Stack:** + +- Next.js 15 with App Router +- React 19 +- Mantine UI 8 +- TypeScript +- pnpm + +**Architecture:** + +- Atomic Design Methodology for UI components +- App Router for routing +- API routes in `src/app/api/` +- Use TypeScript types over interfaces + +## Creating API Routes + +API routes follow this pattern: + +### 1. Type Definitions (`src/types/`) + +Create Zod schemas for request/response validation: + +```typescript +import { z } from 'zod'; + +export const getPagesTreeQuerySchema = z.object({ + parentId: z.string().min(1).optional(), +}); + +export const getPagesTreeResponseSchema = z.object({ + branches: z.array( + z.object({ + page: z.object({ + id: z.string(), + title: z.string(), + }), + }) + ), +}); + +export type GetPagesTreeQuery = z.infer; +export type GetPagesTreeResponse = z.infer; +``` + +### 2. Route Implementation (`src/app/api/{route}/route.ts`) + +Use the `apiRoute` wrapper with typed parameters: + +```typescript +export const GET = apiRoute( + { + expectedQuerySchema: getPagesTreeQueryVariablesSchema, + }, + async ({ query }, session) => { + const containerRepository = await getContainerRepository(); + const databaseQuery = addUserIdToQuery(containerRepository.createQuery(), session.user.id).sort( + 'lastUpdated', + 'desc' + ); + + if (query?.parentId) { + databaseQuery.eq('parentId', query.parentId); + } + + const containers = (await containerRepository.getByQuery(databaseQuery)).filter( + (container) => query?.parentId || !container.parentId + ); + + return { + branches: containers.map((container) => ({ + page: { + id: container.id, + name: container.name, + }, + })), + }; + } +); +``` + +### API Route Structure + +``` +src/app/api/ +├── pages/ +│ └── tree/ +│ └── route.ts # Handles /api/pages/tree +├── users/ +│ └── route.ts # Handles /api/users +└── auth/ + └── login/ + └── route.ts # Handles /api/auth/login +``` + +### Key Points for API Routes + +- Use Zod schemas for request/response validation +- Implement proper error handling with appropriate HTTP status codes +- Integrate with authentication system (better-auth) +- Use NextRequest/NextResponse objects +- Export functions named after HTTP methods (GET, POST, PUT, DELETE, etc.) + +## React/TSX Component Guidelines + +### Styling + +- Always use CSS modules (`.module.css` files) for component-specific styles +- Never use inline `