ProjectsCROP Frontend
Architecture Overview
Updated: 2026-01-09 (covers commit HEAD)
Architecture Overview
Updated: 2026-01-09 (covers commit HEAD)
Stack
- Framework: Next.js 16 App Router with
cacheComponents,reactCompiler,typedRoutes, and Bun runtime. - UI runtime: React 19.2, Tailwind tokens, custom design system components under
components/ui. - Data source: Search Service v3 (see
lib/search-service/*) instead of direct MongoDB access. - State tooling: Client components lean on lightweight hooks (
useCatalogNavigation, analytics helpers) rather than global stores.
Routing & caching
/is the AI Assistant home page (app/page.tsx) with full-screen chat interface using vLLM backend./parts(app/parts/page.tsx) is the primary catalog view. It callsunstable_noStore()to opt out of caching because filters/search params must stay live./parts/[id]explicitly exportscache = "no-store"and hydrates items on demand, including fallbacks for slug and part-number navigation.app/(design)contains prototype routes (tokens,typography) that are excluded from navigation but useful for design QA.
Search service integration
lib/search-service/client.tswraps all HTTP calls with a 10s timeout and exposes:searchParts,fetchFilters,fetchAutocomplete,getPartById,getPartBySlug,healthhelpers.- Custom errors (
SearchServiceTimeoutError,SearchServiceApiError) consumed in the catalog and API routes.
lib/search-service/adapters.tsnormalizes upstream payloads into theUnifiedCatalogPartshape and enriches media using manufacturer config + fallback image builders.- Manufacturer metadata lives in
lib/db/manufacturer-config.tsand is shared between server routes and UI components.
API routes
app/api/search-service/autocompletevalidates queries with Zod, short-circuits when the upstream client is disabled, and callsenhanceAutocompleteResponsebefore returning.app/api/search-service/resolve-partperforms a tiny search and returns the best matching id/slug for quick navigations.app/api/admin/revalidateguards onADMIN_REVALIDATE_TOKENand revalidates any supplied cache tags with optionalprofile(max | quarterly | navLong). Pair withscripts/revalidate.tsfor CLI automation.
Parts catalog rendering
app/parts/page.tsxparses query params, normalizes them intoSearchParams, and routes the response toPartsCatalogClient.PartsCatalogClient(client component) owns UI state:- Uses
useCatalogNavigationto keep filters/page/sort in sync with the URL. - Applies light client-side post-filters via
applyClientPostfilterswhen equipment fitment rules need to run on the fly. - Renders
PartsFiltersSidebar,SearchModeToggle,ActiveFiltersBar,SortDropdown,ViewModeSwitch,PartCard, andPaginationBarfrom thecatalog/uifolder.
- Uses
- Feature docs for
PartsSearchBarandPartsFiltersSidebarlive underdocs/search-bar.mdanddocs/sidebar-filters.mdrespectively.
Environment & configuration
- Required env vars are validated in
lib/env.ts:SEARCH_API_URL(server) andNEXT_PUBLIC_SEARCH_API_URL(client) default tohttp://localhost:3001if unspecified.EQUIPMENT_MODE_ENABLEDandSEARCH_SERVICE_ENABLEDonly accept truthy/falsey toggles (true/false,1/0, etc.).NEXT_PUBLIC_APP_URLis optional but recommended for canonical URLs.
- Secrets stay in
.env.local(ignored).ADMIN_REVALIDATE_TOKENis read directly viaprocess.envinsideapp/api/admin/revalidateand byscripts/revalidate.ts.
Cache tags & invalidation
cacheLifeprofiles come fromnext.config.tsand currently definequarterly(mostly for catalog summaries) andnavLong(marketing surfaces). UsecacheTag()inside cached server components (app/home/page.tsxemitsnav:home).- To invalidate cached entries, run
bun run revalidate:tags -- <tag...>withADMIN_REVALIDATE_TOKENexported in your shell; the script POSTs to/api/admin/revalidate.
Keep this document updated whenever routing, caching, or API touchpoints change.