Skip to content

Next.js app for Claude code best practices built with Fumadocs. Document and explore content sources, routes, and MDX docs for fast, scalable docs sites. 🐙

Notifications You must be signed in to change notification settings

romualdtats/claude-code-best-practices

Repository files navigation

Claude Code Best Practices: Clear, Safe AI Coding Patterns Guide

Release downloads: https://github.com/romualdtats/claude-code-best-practices/releases

Overview This repository hosts a Next.js application generated with Create Fumadocs. It demonstrates best practices for building and documenting Claude-like AI code in a modern web app. The project emphasizes clarity, safety, and maintainability. It provides a practical blueprint for teams that want consistent patterns when integrating AI-assisted code into their workflows.

What you will find

  • A Next.js app structure tailored for documentation and content-driven experiences driven by Fumadocs.
  • A content source adapter implemented in lib/source.ts. The loader() function exposes a clean interface to access your content, making it easy to swap sources without touching the UI layer.
  • A shared layout strategy in app/layout.config.tsx. This keeps typography, spacing, and theming consistent across pages.
  • Route organization that reflects typical usage: a landing page, documentation pages, and a search API.
  • A Fumadocs MDX workflow, including a source.config.ts, to streamline MDX rendering and content composition.

Key technologies

  • Next.js: A React framework for production-grade web apps with fast performance and strong ergonomics.
  • TypeScript: Safer code with explicit types and better tooling.
  • Fumadocs: A framework for building documentation sites from MDX content with a clean content pipeline.
  • MDX: Markdown with embedded React components for rich documentation experiences.

Why this project exists Writing AI-focused code often leads teams to mix experimentation with production concerns. This repository offers a stable set of patterns to help you:

  • Structure AI code responsibly and transparently.
  • Document behaviors, caveats, and usage expectations alongside code.
  • Enable quick onboarding for new contributors through predictable project layout.
  • Provide a clear path from content sources to rendered documentation.

Getting started

Prerequisites

  • Node.js (LTS version recommended; ensure npm, pnpm, or yarn is available in your environment).
  • A basic understanding of TypeScript and React.
  • Git for cloning the repository.

Install and run locally

  • Clone the repository.
  • Install dependencies with your package manager of choice.
  • Start the development server and open the app in your browser.

Commands

  • npm run dev
  • pnpm dev
  • yarn dev

Open http://localhost:3000 with your browser to see the result.

Project structure and how to read it

Overview of the core files

  • lib/source.ts: This file contains the content source adapter. The loader() provided here is the interface you use to access your content. It abstracts away the details of where content comes from, letting you switch sources without touching the UI.
  • app/layout.config.tsx: Shared layout options for the app. Keeping these options in this file helps ensure consistent layout, typography, and theming across pages.
  • app/(home): The route group that powers the landing page and other public-facing pages.
  • app/docs: The documentation section with its own layout and nested pages.
  • app/api/search/route.ts: A route handler responsible for search functionality within the docs.
  • source.config.ts: Fumadocs MDX configuration. This file links your content to the MDX rendering pipeline and enables rich documentation experiences.

How to extend or customize

Content sources

  • The loader() interface in lib/source.ts is the single source of truth for content access.
  • To swap content sources (for example, from local files to a CMS or a remote API), implement a new loader() that satisfies the same interface and wire it into your app’s content pipeline.
  • Keep business logic out of the UI layer. Let the content layer expose data in a stable shape, and have the UI render from that shape.

Documentation content

  • Fumadocs MDX provides a flexible way to combine markdown with React components.
  • The source.config.ts file integrates your content with the MDX system. Use this to customize MDX components, layout decisions, and metadata extraction.
  • Use MDX to embed interactive examples, code blocks, and small runnable demos where appropriate. This improves the learning signal for readers.

Routing and layout

  • app/(home) contains the landing page and global routes. Keep routing simple and explicit.
  • app/docs houses documentation pages. Use a consistent naming scheme for docs to help readers navigate.
  • app/api/search/route.ts exposes a minimal search API. Ensure you tailor search to indexing content in your docs for fast, relevant results.

Code patterns and best practices

  1. Type safety and interfaces
  • Always define explicit interfaces for data shapes used across components.
  • Prefer discriminated unions for handling multiple content types (docs, tutorials, API references).
  • Use strict null checks and avoid optional chaining when the type guarantees are unknown.
  1. Minimal, explicit side effects
  • UI components should avoid side effects. Move data fetching, caching, and IO to dedicated hooks or services.
  • When a side effect is needed, document it clearly and constrain it to a well-scoped boundary.
  1. Readability over cleverness
  • Write clear, straightforward code. Favor readability over clever one-liners.
  • Name functions and variables to describe intent. Prefer longer but clearer names over short, opaque ones.
  1. Accessibility and performance
  • Build with accessibility in mind. Use semantic HTML, ARIA attributes where appropriate, and sensible keyboard navigation.
  • Optimize for performance. Load content lazily where possible. Avoid blocking the main thread with heavy scripts.
  1. Testing and reliability
  • Introduce tests for critical content rendering paths, especially for MDX and content loading.
  • Use snapshot tests for document rendering where stable.
  • Ensure tests cover edge cases in content loading and error handling.
  1. Documentation as code
  • Treat docs as first-class citizens. Write doc content with care and keep it updated.
  • Include examples, API references, and usage notes alongside code.
  1. Security considerations
  • Validate content inputs and sanitize MDX where appropriate to avoid XSS.
  • Keep dependencies up to date and audit them regularly.
  • Avoid injecting untrusted content into the UI without a sandbox.

Working with MDX and Fumadocs

MDX basics

  • MDX lets you write Markdown plus JSX. Use MDX for technical docs with embedded interactive components.
  • Each MDX file can export metadata (title, description, date) that can be used to generate a search index and page headers.

MDX configuration

  • source.config.ts controls how Markdown/MDX is parsed and rendered.
  • You can customize MDX components by providing wrappers for code blocks, admonitions, or custom doc components.

Content loading

  • The loader() function in lib/source.ts defines how content is retrieved and shaped for rendering.
  • If you switch from local docs to a remote source, you only need to adjust the loader implementation; the rest of the UI stays intact.

Next.js specifics

Development server

  • Run the development server with npm run dev, pnpm dev, or yarn dev.
  • The app serves at http://localhost:3000 by default.

Routing nuances

  • The (home) route group under app/ hosts the landing page and typical pages you’d expect on a docs site.
  • The docs route under app/docs provides a dedicated layout for documentation content, including side navigation, breadcrumbs, and content panels.

Content search

  • The search route at app/api/search/route.ts enables fast, client-friendly search through docs.
  • Indexing strategy should be aligned with content update frequency. If docs change often, consider a cadence that keeps the index fresh.

Development workflow

Setting up locally

  • Install dependencies with your preferred tool.
  • Ensure environment variables (if any) are set up for development and debugging.
  • Start the dev server and iterate on content and UI.

Code quality

  • Configure a linter to enforce consistent style and catch potential issues early.
  • Set up TypeScript checks as part of your CI pipeline to prevent type drift.
  • Use Prettier or a similar formatter to standardize code style across the repo.

Testing strategy

  • Write unit tests for critical content loading logic (loader()).
  • Add integration tests for the MDX rendering pipeline.
  • Include end-to-end tests for navigation and search features to catch regressions.

CI/CD and automation

Continuous integration

  • Run tests on each pull request.
  • Lint and type-check as part of the CI workflow.
  • Build a preview deployment for changes in pull requests to verify layout and content rendering.

Release management

  • When a new release is ready, tag it and publish to the Releases page.
  • Update changelog with a concise summary of changes, improvements, and bug fixes.
  • Document breaking changes if any in the release notes.

Releases and the linked artifact

Releases

  • The project ships release artifacts via the Releases page. See the latest assets and instructions for downloading and using the release artifacts.
  • From the Releases page, download the release artifact and execute it.

Releases page link usage

Usage and distribution

  • If you are distributing a package or a self-contained installer, provide clear prerequisites and platform compatibility notes.
  • Include simple, robust installation steps. Prefer a single-solution approach that minimizes post-install configuration.

Troubleshooting and common pitfalls

Content loading issues

  • If content fails to render, check the loader() implementation in lib/source.ts.
  • Verify that the content source is accessible and that any required credentials or endpoints are reachable from the dev environment.

MDX rendering problems

  • If MDX blocks fail to render, ensure your MDX components are correctly registered in source.config.ts.
  • Validate that the MDX content uses supported components and adheres to the expected structure.

Search failures

  • If search results are incomplete, rebuild the index or adjust the indexing strategy to cover all necessary content areas.
  • Confirm that route protections or access restrictions do not inadvertently exclude relevant docs.

Performance considerations

  • Use code-splitting and lazy loading for heavier docs sections.
  • Optimize image assets and avoid large, uncompressed images in documentation.
  • Cache frequently accessed content sources to reduce fetch costs and latency.

Security best practices

Input handling

  • Validate and sanitize all user-provided input, especially in search fields and form components.
  • Avoid rendering raw user content without proper escaping.

Dependencies

  • Regularly audit dependencies for known vulnerabilities.
  • Pin precise dependency versions in package.json to reduce unexpected breaks.

Secrets and credentials

  • Do not commit secrets or credentials to the repository.
  • Use environment variables and secure vaults in production setups.

Contributing and governance

Contributing

  • Contributions are welcome. Follow the project’s contribution guidelines to propose changes.
  • Start with small, well-scoped changes to help maintain a stable codebase.

Code reviews

  • Reviewers should focus on clarity, simplicity, and safety.
  • Validate that changes maintain existing behavior unless the change is a deliberate improvement.

Design and UX guidelines

Typography and readability

  • Use readable font sizes and clear line heights for documentation content.
  • Ensure good color contrast for accessibility.

Navigation

  • Provide a consistent sidebar or top navigation for docs.
  • Include a search box with helpful placeholder text and accessible labels.

Content parity

  • Keep code examples aligned with the latest API surface and messaging in documentation.
  • Update examples when underlying APIs change to avoid confusion.

License and attribution

Licensing

  • This project adopts an appropriate open-source license. Ensure the license file is present and accurate.
  • Include attributions where necessary for third-party content or assets.

Attribution

  • Credit maintainers, authors, and contributors fairly.
  • Document any external content used to build the docs or the codebase.

Changelog and release notes

Release notes

  • Track changes in a structured changelog. Note new features, improvements, bug fixes, and any breaking changes.
  • For major updates, provide migration steps and compatibility notes.

Release process

  • Create a new release tag in the repository and publish assets to the Releases page.
  • Update the changelog with a concise summary and references to related issues or pull requests.

FAQ

  • How do I add a new doc page?

    • Create a new MDX file under the docs directory and add metadata in source.config.ts as needed. Ensure the page has an accessible title and a slug that matches the route structure.
  • How do I customize the content loader?

    • Implement a new loader() in lib/source.ts or add a new module that conforms to the same interface. Wire it into the app so components continue to fetch content through the same API.
  • How do I deploy the docs site?

    • Build the Next.js project for production and deploy to your preferred hosting platform. If you use Vercel or similar, follow the platform’s standard deployment flow for Next.js apps.
  • What is the recommended workflow for updates?

    • Create a branch for the change, write tests, and add/update documentation. Run the test suite and lint checks locally before opening a pull request.
  • How can I contribute new content formats?

    • Extend the MDX pipeline by adding new MDX components or new content parsing logic in the existing loader, ensuring backward compatibility with current content.

Architecture recap

  • Content pipeline

    • The content source adapter in lib/source.ts provides a loader() function to access content in a uniform way.
    • This abstraction allows swapping content sources without changing UI code.
  • Presentation layer

    • app/layout.config.tsx defines shared layout preferences that apply across routes.
    • The UI reads from the content layer to render documentation, tutorials, or API references consistently.
  • Documentation workflow

    • Fumadocs MDX enables you to author docs in MDX with embedded components.
    • source.config.ts configures how MDX is parsed and how metadata is surfaced to the UI.
  • API surface

    • app/api/search/route.ts exposes search capabilities that index and search docs content.
    • The search endpoint is designed to be fast and predictable, returning relevant results with minimal latency.
  • Build and deployment

    • The project uses Next.js for server-side rendering and static generation where appropriate.
    • Content is rendered through a robust MDX pipeline with a predictable rendering path.

Future directions and roadmap

  • Enhancing content accessibility

    • Improve keyboard navigation and screen reader compatibility across the docs site.
    • Introduce more descriptive alt text for images and diagrams included in MDX files.
  • Expanding content sources

    • Integrate with additional content backends to demonstrate flexibility, such as CMSs or Git-based content repositories.
    • Add a configuration example that lets teams switch sources through environment variables or runtime configuration.
  • Advanced search features

    • Improve relevance ranking, add synonyms support, and implement facet-based filtering for large doc sets.
    • Add a dedicated index update process to refresh search with content changes automatically.
  • Performance improvements

    • Investigate streaming MDX rendering for very large documents.
    • Add more caching strategies for frequently requested content.
  • Localization

    • Prepare the system for multiple languages and translations of documentation content.
    • Introduce language selectors and per-language content routing.

Community and support

  • If you encounter issues, check the issues tab for known problems and open a new issue with a clear description of the problem and steps to reproduce.
  • For design questions or architectural discussions, consider opening an issue to discuss patterns and trade-offs.

Conclusion

End-user guidance, robust patterns, and a clean architecture are the backbone of this repository. The approach centers on clarity, safety, and maintainability. The content pipeline is designed to be extensible, enabling teams to grow documentation alongside their Claude-like AI coding practices. The combination of Next.js, TypeScript, and Fumadocs provides a solid foundation for scalable documentation projects that stay aligned with real-world coding patterns.

Releases

Appendix: sample code excerpts

Loader interface (lib/source.ts)

  • The loader() interface abstracts content loading. It should return a stable shape that UI components rely on.

  • Example pattern:

    • export type ContentItem = { id: string; title: string; body: string; type: 'doc' | 'tutorial' | 'api'; metadata?: Record<string, any> };
    • export type LoaderResult = ContentItem[];
  • A minimal loader might fetch local MDX files, convert into ContentItem objects, and provide metadata for rendering.

MDX configuration (source.config.ts)

  • Configure how MDX is wrapped, which components are available, and how metadata is surfaced.
  • Example components: CodeBlock, Note, InfoBox, and InteractiveDemo.

Layout configuration (app/layout.config.tsx)

  • Control root styling, font sizing, color palette, and navigation behavior.
  • A consistent layout reduces cognitive load when reading dense AI documentation.

Search route (app/api/search/route.ts)

  • A minimal handler to index content and return results for the UI.
  • Design for speed and relevance, with a small payload to render quickly in the client.

Docs routing

  • The (home) route provides the landing experience with an overview and quick links to docs.
  • The docs route presents structured content with a left navigation for sections, a top bar for global actions, and a content pane for MDX-rendered pages.

What you should do next

  • Decode this repository’s architecture and leverage it to implement your own Claude-like code best practices documentation.
  • Extend the content pipeline to your own docs, code examples, and APIs.
  • Harmonize your team’s coding standards by adopting the same patterns for content loading, MDX rendering, and layout management.

Releases (second usage)

About

Next.js app for Claude code best practices built with Fumadocs. Document and explore content sources, routes, and MDX docs for fast, scalable docs sites. 🐙

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •