|
| 1 | +# AGENTS.md - Frontend + AI Engineering Template |
| 2 | + |
| 3 | +This file provides context for AI assistants working with the `frontend-ai-template` repository. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This repository is a **production-ready Next.js 15 template** designed for building frontend applications with integrated AI capabilities. It provides a standardized structure and foundational components for projects involving AI interactions (chat, tool calling via MCP). |
| 8 | + |
| 9 | +- **Repository:** `cheshirecode/frontend-ai-template` |
| 10 | +- **Framework:** Next.js 15 (App Router) |
| 11 | +- **AI Integration:** Multi-provider (Google Gemini, OpenAI) via a service abstraction and Model Context Protocol (MCP) for tool orchestration. |
| 12 | +- **State Management:** Jotai |
| 13 | +- **Styling:** Tailwind CSS |
| 14 | +- **Testing:** Vitest (unit), Playwright (E2E) |
| 15 | + |
| 16 | +See `README.md` for detailed quick start and feature guides. |
| 17 | +See `docs/` directory for deeper architectural information. |
| 18 | + |
| 19 | +## Project Structure (High-Level) |
| 20 | + |
| 21 | +- `app/`: Next.js application structure. |
| 22 | + - `api/ai/route.ts`: Main AI chat endpoint. |
| 23 | + - `api/mcp/route.ts`: Model Context Protocol server endpoint for tools. |
| 24 | + - `api/mcp/tools/`: Directory for MCP tool definitions (e.g., `example-tool.ts`). |
| 25 | + - `components/`: UI components (organized by feature: `chat/`, `layout/`, `common/`). |
| 26 | + - `hooks/`: React hooks (organized by scope: `chat/`, `composed/`, `core/`). |
| 27 | + - `lib/`: Core libraries (e.g., `ai-service.ts`, `logger.ts`, `error-handler.ts`). |
| 28 | + - `store/`: Jotai state atoms (`index.ts`). |
| 29 | +- `types/`: TypeScript definitions. |
| 30 | +- `e2e/`: Playwright E2E tests. |
| 31 | +- `docs/`: Project documentation. |
| 32 | +- `scripts/`: Utility scripts (e.g., `init.sh`). |
| 33 | + |
| 34 | +## Outstanding Tasks / Areas for Improvement |
| 35 | + |
| 36 | +Based on `IMPROVEMENTS.local.md`, here are prioritized areas for potential work: |
| 37 | + |
| 38 | +### Priority 1: Security Hardening |
| 39 | +- Add message length/content validation in `useChat.ts`. |
| 40 | +- Add client-side rate limiting. |
| 41 | +- Configure CORS origin properly in `vercel.json`. |
| 42 | +- Add security headers in `next.config.ts`. |
| 43 | +- Add API key format validation in `ai-service.ts`. |
| 44 | + |
| 45 | +### Priority 2: Testing Coverage |
| 46 | +- Expand unit tests for `ai-service.ts`, `error-handler.ts`, `logger.ts`, `store/index.ts`, hooks, and components. |
| 47 | +- Add unit tests for API routes (`app/api/ai/route.ts`, `app/api/mcp/route.ts`). |
| 48 | +- Improve E2E tests for chat flow, error recovery, mode switching. |
| 49 | +- Aim for 70%+ test coverage. |
| 50 | + |
| 51 | +### Priority 3: Performance Optimization |
| 52 | +- Implement virtualization for the message list (`ChatMessageList.tsx`). |
| 53 | +- Add `React.memo` where appropriate. |
| 54 | +- Add `AbortController` for fetch requests in `useChat.ts`. |
| 55 | + |
| 56 | +### Priority 4: Error Handling UX |
| 57 | +- Add retry mechanisms for failed messages. |
| 58 | +- Standardize error logging using the `logger` utility. |
| 59 | +- Sanitize error messages returned to the client in API routes. |
| 60 | + |
| 61 | +### Priority 5: Code Quality |
| 62 | +- Remove unused imports (e.g., `React` in `ChatInterface.tsx`). |
| 63 | +- Extract magic strings to constants. |
| 64 | +- Address incomplete implementations (e.g., unused path alias for `/contexts`). |
| 65 | + |
| 66 | +### Future Enhancements |
| 67 | +- Dark mode toggle. |
| 68 | +- Message streaming display. |
| 69 | +- Copy message functionality. |
| 70 | +- Message editing support. |
| 71 | +- Conversation export. |
| 72 | +- Add Storybook. |
| 73 | +- Improve accessibility (ARIA labels, keyboard nav). |
| 74 | + |
| 75 | +## Key Files for Reference |
| 76 | + |
| 77 | +When working on specific aspects, these files are often relevant: |
| 78 | +- `app/hooks/chat/useChat.ts` (Chat logic, needs rate limiting, abort controller, logging) |
| 79 | +- `app/api/ai/route.ts` (API logic, needs error sanitization, validation) |
| 80 | +- `app/lib/ai-service.ts` (Service logic, needs API key validation) |
| 81 | +- `vercel.json` (Security headers, CORS) |
| 82 | +- `next.config.ts` (Security headers) |
| 83 | +- `app/components/chat/ChatMessageList.tsx` (Performance, needs virtualization) |
0 commit comments