MANDATORY checklist before writing ANY new code. Use this skill FIRST before implementing any feature, component, utility, type, or hook. Enforces DRY principle and existing pattern reuse.
ā ļø STOP! Before writing ANY code, complete this checklist.
This skill enforces the DRY principle and ensures you search for existing patterns before creating new ones. Skipping this checklist leads to code duplication and inconsistency.
Before creating ANYTHING new, search the codebase:
# Search by concept name
grep -r "slug validation" --include="*.ts" --include="*.tsx"
grep -r "price format" --include="*.ts" --include="*.tsx"
# Search by function name patterns
grep -r "isValid" --include="*.ts" utils/
grep -r "format" --include="*.ts" utils/
grep -r "build" --include="*.ts" utils/
grep -r "use[A-Z]" --include="*.ts" components/hooks/
# Search by literal values (regex, constants)
grep -r "YOUR_REGEX_PATTERN" --include="*.ts"
Report findings BEFORE proposing implementation:
isValidCategorySlugFormat in utils/category-mapping.ts - will reuse"useImageRetry in components/hooks/ - will extend"| What You're Creating | Where to Search First |
|---|---|
| Type/Interface | types/ directory, check types/README.md |
| Validation function | utils/ for isValid*, validate* |
| Helper/Utility | utils/, lib/ |
| Constant/Config | utils/constants.ts, config/ |
| Component | components/ui/ |
| Hook | components/hooks/ |
| API call | lib/api/ |
Check these specific files for existing patterns:
types/common.ts ā NavigationItem, SocialLinks, shared types
types/props.ts ā Reusable component props
types/api/*.ts ā DTOs (CitySummaryResponseDTO, etc.)
utils/constants.ts ā Shared constants (dates, distances, labels)
utils/api-helpers.ts ā buildEventsQuery, buildNewsQuery, getInternalApiUrl
config/filters.ts ā Filter configurations
After searching, propose a 2-4 step plan:
Plan:
1. Reuse `isValidSlug` from utils/validation.ts
2. Create new `PriceFilter` component in components/ui/filters/
3. Add type to types/filters.ts (extending existing FilterConfig)
4. Update tests in test/filter-system.test.ts
Wait for user confirmation before implementing.
// WRONG: Implementing inline, then searching
const isValidSlug = (slug: string) => /^[a-z0-9-]+$/.test(slug);
// "Oh wait, let me check if this exists..."
// CORRECT: Search first, then decide
// "Searching for 'isValid.*Slug' in utils/..."
// "Found isValidCategorySlugFormat in utils/category-mapping.ts - reusing"
// WRONG: Inline type in component
type ButtonProps = { variant: string; size: string };
// CORRECT: Define in types/props.ts
// types/props.ts
export interface ButtonProps {
variant: ButtonVariant;
size: ButtonSize;
}
// WRONG: Hardcoded values
const DEFAULT_DISTANCE = 50;
const DATE_OPTIONS = ["avui", "dema", "setmana"];
// CORRECT: Import from constants
import { DEFAULT_DISTANCE, DATE_OPTIONS } from "@utils/constants";
// WRONG: Over-abstraction
const formatEventTitle = (title: string) => title.trim();
// Only used in one place
// CORRECT: Inline simple logic, abstract only when reused
<h1>{event.title.trim()}</h1>;
index.ts) for Component Folders// WRONG: Barrel re-exports "use client" components from different routes
// components/ui/sponsor/index.ts
export { default as SponsorBannerSlot } from "./SponsorBannerSlot";
export { default as CheckoutButton } from "./CheckoutButton";
export { default as PricingSectionClient } from "./PricingSectionClient";
// Any route importing SponsorBannerSlot from the barrel
// also leaks CheckoutButton + PricingSectionClient into its manifest!
import { SponsorBannerSlot } from "@components/ui/sponsor";
// CORRECT: Always use direct file imports
import SponsorBannerSlot from "@components/ui/sponsor/SponsorBannerSlot";
Why: In Next.js RSC, every "use client" module re-exported from a barrel gets registered in the client-reference-manifest of every route that imports from that barrel. This caused 24 KB of bloat on /[place] (Feb 2026). optimizePackageImports only works for npm packages.
connection()// WRONG: new Date() drives tree structure in a cached server component
const status = computeTemporalStatus(event.startDate); // uses new Date()
return (
<>
{status.state !== "past" && <EventWeather />} // tree shape changes over time!
{status.state === "past" && <PastEventBanner />}
</>
);
// CORRECT: call connection() first to opt out of component caching
import { connection } from "next/server";
await connection(); // signals dynamic rendering
const status = computeTemporalStatus(event.startDate);
// Now the conditional tree is safe ā no stale cache replay
Why: With cacheComponents: true, React caches the RSC payload. If new Date() produces a different tree shape on replay (e.g., event went from "upcoming" to "past"), React throws "Couldn't find all resumable slots" and falls back to full client rendering ā killing SSR performance and SEO. This caused repeated errors in production (Apr 2026). Content-only date usage (formatting text) is fine without connection().
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Need to implement something new? ā
āāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Did you search for existing patterns? ā
ā (grep, semantic_search, file_search) ā
āāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāā¤
ā NO ā YES ā
ā ā ā ā ā
ā STOP! ā Continue ā
ā Search first ā ā
āāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Found existing pattern? ā
āāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāā¤
ā YES ā NO ā
ā ā ā ā ā
ā REUSE or ā Create new, but: ā
ā EXTEND it ā - Place in canonical ā
ā ā location ā
ā ā - Follow conventions ā
ā ā - Add tests ā
āāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāā
types/
āāā common.ts # Shared UI types (NavigationItem, SocialLinks)
āāā props.ts # Component props (ButtonProps, CardProps)
āāā event.ts # Event domain types
āāā filters.ts # Filter types (FilterConfig, FilterState)
āāā api/
ā āāā event.ts # EventDTO, EventResponseDTO
ā āāā news.ts # NewsDTO, NewsResponseDTO
ā āāā city.ts # CitySummaryResponseDTO
ā āāā ...
āāā README.md # Type organization guide
utils/
āāā constants.ts # Shared constants (CHECK FIRST!)
āāā api-helpers.ts # API query builders
āāā url-filters.ts # URL building
āāā url-parsing.ts # URL parsing
āāā date-helpers.ts # Date formatting
āāā category-mapping.ts # Category validation
āāā ...
components/
āāā ui/
ā āāā filters/ # Filter components
ā āāā events/ # Event cards, lists
ā āāā forms/ # Form components
ā āāā ...
āāā hooks/ # Custom hooks (useXxx)
āāā partials/ # Layout partials
/types directoryutils/constants.tsindex.ts) re-exporting "use client" components from different routesyarn typecheck && yarn lint && yarn test# Find existing types
grep -r "interface\|type " types/ --include="*.ts"
# Find existing hooks
ls components/hooks/
# Find existing utilities
ls utils/
# Find constants
grep -r "export const" utils/constants.ts
# Find validation functions
grep -r "isValid\|validate" utils/ --include="*.ts"
# Find formatters
grep -r "format\|Format" utils/ --include="*.ts"
Remember: 5 minutes of searching saves 30 minutes of refactoring.
Last Updated: January 15, 2026