{
  "id": "build-a-nextjs-ai-tool-directory",
  "type": "prompts",
  "category": "prompts",
  "locale": "en",
  "url": "/prompts/build-a-nextjs-ai-tool-directory",
  "title": "Prompt to Build a Next.js AI Tool Directory",
  "description": "AI agent prompt to build a searchable Next.js AI tool directory with MDX data files, category filters, and static generation.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Next.js",
    "TypeScript",
    "Tailwind"
  ],
  "tags": [
    "nextjs",
    "typescript",
    "tailwind",
    "seo",
    "search"
  ],
  "difficulty": "medium",
  "updated": "2026-06-08",
  "markdown": "Give this prompt to your agent to build a statically generated, SEO-friendly directory\nof AI tools with category filtering, client-side search, and a detail page per tool —\nwithout it reaching for a database when flat MDX files are sufficient.\n\n## Main Prompt\n\n```txt title=\"Main Prompt\"\nYou are building a new Next.js 15 App Router project using TypeScript and Tailwind CSS v4.\n\nTask: build an AI tool directory site.\n\nData model — each tool is a `.mdx` file in `src/data/tools/` with this frontmatter:\n  name, slug, tagline, description, category, website, pricing ('free'|'freemium'|'paid'),\n  tags (string[]), logo (relative path to public/).\n\nRequirements:\n- `src/lib/tools.ts`: read all MDX files at build time using `fs` + `gray-matter`; export\n  `getAllTools()` returning `Tool[]` and `getToolBySlug(slug)` returning `Tool | undefined`.\n- `src/app/page.tsx`: static page showing a grid of `<ToolCard>` components.\n  - A `<CategoryFilter>` client component that filters by category using URL search params\n    (`?category=writing`). Use `useSearchParams` — no external state library.\n  - A `<SearchBar>` client component that does client-side substring match on name and tagline\n    using `useSearchParams` (`?q=cursor`).\n- `src/app/tools/[slug]/page.tsx`: static detail page with `generateStaticParams` and\n  `generateMetadata`. Include og:title, og:description, og:image (the tool logo).\n- `src/app/categories/[category]/page.tsx`: static list filtered by category.\n- Seed data: create 5 real AI coding tools as MDX files (Cursor, GitHub Copilot, Claude Code,\n  Codeium, Tabnine) with accurate free/paid info.\n- Do NOT use a database, Contentlayer, or next-mdx-remote. Use `gray-matter` + `fs` only.\n\nStop and list all planned files before writing code.\n```\n\n## Implementation Notes\n\n- `getAllTools()` must only run server-side; calling it in a Client Component will expose `fs`\n  to the browser and crash the build. Pass data as props to client components.\n- `generateStaticParams` for `[slug]` should call `getAllTools()` and map to `{ slug }` objects.\n- For category pages, derive the category list from the tools data rather than hard-coding it.\n\n## Expected File Changes\n\n```txt\nsrc/lib/tools.ts                              (new)\nsrc/app/page.tsx                              (new)\nsrc/app/tools/[slug]/page.tsx                 (new)\nsrc/app/categories/[category]/page.tsx        (new)\nsrc/components/ToolCard.tsx                   (new)\nsrc/components/CategoryFilter.tsx             (new — Client)\nsrc/components/SearchBar.tsx                  (new — Client)\nsrc/data/tools/cursor.mdx                     (new)\nsrc/data/tools/github-copilot.mdx            (new)\nsrc/data/tools/claude-code.mdx               (new)\nsrc/data/tools/codeium.mdx                   (new)\nsrc/data/tools/tabnine.mdx                   (new)\n```\n\n## Acceptance Criteria\n\n- `bun run build` exits 0 and generates a static page for each tool slug.\n- Clicking a category filter updates the URL and filters the grid without a full reload.\n- Each tool detail page has unique `og:title` and `og:description` in the HTML `<head>`.\n- Searching for \"cursor\" shows only the Cursor card.\n\n## Test Commands\n\n```bash\nbun run typecheck\nbun run build\nbun run start\ncurl -s http://localhost:3000/tools/cursor | grep 'og:title'\n# navigate to /?category=writing and confirm filter\n```\n\n## Common AI Mistakes\n\n- Calling `getAllTools()` inside a Client Component, breaking the build with a `fs` module error.\n- Forgetting `generateStaticParams` on the `[slug]` page, causing 404s in static export.\n- Using `next-mdx-remote` when the prompt explicitly bans it.\n- Hard-coding the category list instead of deriving it from tool data.\n\n## Fix Prompt\n\n```txt title=\"Fix Prompt\"\nThe build fails because `fs` is used in a client component, or static pages are not generated.\nFix in order:\n1. Move `getAllTools()` to a Server Component and pass the `tools` array as a prop to\n   `CategoryFilter` and `SearchBar`.\n2. Add `export async function generateStaticParams()` to `src/app/tools/[slug]/page.tsx`.\n3. Confirm `gray-matter` is installed: `bun add gray-matter`.\nShow only the corrected diff.\n```"
}