# Agent Instructions - Link Shortener Project ⚠️ **CRITICAL: Before generating ANY code, you MUST read the relevant documentation files in the `/docs` directory first.** ⚠️ This document provides comprehensive guidance for AI coding assistants working on this Next.js-based link shortener application. ## Project Overview This is a modern link shortener application built with: - **Framework**: Next.js 16 (App Router) - **Language**: TypeScript 5 - **Database**: PostgreSQL via Neon (serverless) - **ORM**: Drizzle ORM - **Authentication**: Clerk - **Styling**: Tailwind CSS v4 - **UI Components**: Custom components with shadcn/ui patterns ## Quick Reference 🔴 **MANDATORY REQUIREMENT**: Before writing ANY code related to the topics below, you MUST first read and understand the corresponding documentation file. This is NOT optional. 🔴 For detailed instructions on specific topics, refer to these documents in the `/docs` directory: - **Authentication**: [authentication.md](./docs/authentication.md) - Clerk integration, protected routes, and auth patterns - ⚠️ **READ THIS FIRST** before implementing any authentication-related code - **Components**: [components.md](./docs/components.md) - shadcn/ui component usage and UI guidelines - ⚠️ **READ THIS FIRST** before creating or modifying any UI components **CRITICAL**: Never skip reading the relevant documentation. The documentation contains essential patterns, conventions, and requirements that must be followed. Generating code without reading the docs will result in incorrect implementations. ## Core Principles ### 1. Type Safety First - Use TypeScript strictly - no `any` types without explicit justification - Define proper interfaces and types for all data structures - Leverage Drizzle's type inference for database operations ### 2. Server-First Architecture - Prefer Next.js Server Components and Server Actions - Use Client Components only when necessary (interactivity, browser APIs) - Keep business logic on the server ### 3. Database Best Practices - All database operations through Drizzle ORM - Use prepared statements for performance - Implement proper error handling and transactions ### 4. Modern React Patterns - Functional components with hooks - Proper separation of concerns - Composition over inheritance ### 5. Code Quality - Follow ESLint rules strictly - Maintain consistent formatting - Write self-documenting code with clear naming - Add comments only when necessary to explain "why", not "what" ## Development Workflow 1. **Before Making Changes** ⚠️ **CRITICAL STEP** - **FIRST**: Read the relevant documentation files in `/docs` directory - **SECOND**: Understand the existing code structure - **THIRD**: Review related components and utilities - **NEVER** skip the documentation step - it contains essential requirements 2. **While Coding** - Follow established patterns in the codebase - Use existing utilities and components when possible - Write type-safe code - Consider performance implications 3. **After Implementation** - Test functionality thoroughly - Update related documentation if needed - Ensure ESLint passes - Verify TypeScript compilation ## Key Conventions ### File Naming - React components: `PascalCase.tsx` - Utilities/helpers: `camelCase.ts` - Types/interfaces: `types.ts` or inline with component - Server actions: `actions.ts` - API routes: `route.ts` ### Import Order 1. External dependencies (React, Next.js, etc.) 2. Internal absolute imports (`@/`) 3. Relative imports 4. Type imports (separate or inline) ### Component Structure ```tsx // 1. Imports // 2. Types/Interfaces // 3. Component definition // 4. Helper functions (if small and local) // 5. Export ``` ## Common Patterns ### Server Components (Default) ```tsx export default async function MyPage() { const data = await fetchData(); return