Use this guide when you add, move, or test shared UI under src/components.
Shared components use a folder-per-component structure.
src/components/
└── Header/
├── index.tsx
└── __tests__/
├── Header.test.tsx
└── __snapshots__/
└── Header.test.tsx.snap
This gives each component one home for its source, tests, and optional snapshots while keeping imports stable through the folder entry file.
- Name the folder after the component, for example
HeaderorIssueList. - Keep the main component implementation in
index.tsx. - Export the component directly from that
index.tsxfile.
This allows route and component code to keep using imports like
@/components/Header without a separate barrel file.
Use src/components when the UI is:
- reused across multiple pages
- a distinct section that benefits from its own tests
- interactive enough that keeping it inline in a route would make the page hard to read
Keep code in src/app/.../page.tsx when the markup is small and only used by
that route.
- Create a folder such as
src/components/FaqSection/. - Add
index.tsxwith the component implementation. - Add
__tests__/FaqSection.test.tsxwhen the component has meaningful behavior or rendering worth protecting. - Add a snapshot only if the component output is stable and the snapshot will stay readable.
Each component should have its own test file inside that component folder.
Examples:
src/components/ContributorsGrid/__tests__/ContributorsGrid.test.tsxsrc/components/Menu/__tests__/Menu.test.tsxsrc/components/RichText/__tests__/RichText.test.tsx
Prefer direct assertions for behavior, accessibility, and important content.
Use snapshots selectively for stable presentational components such as:
HeaderFooterHeroSectionDividerSimpleContentPage
Do not default to snapshotting highly interactive or data-driven components when explicit assertions are clearer.
Use the folder path, not the inner file path:
import Header from "@/components/Header";
import RichText from "@/components/RichText";Avoid imports like @/components/Header/Header unless there is a specific local
reason to reach into the folder.