Let me start by thoroughly understanding every file in the current codebase before rebuilding.
Now let me read all remaining components:
Now let me check what's missing - the constants file and cache module that the API references:
Now I have a complete picture of the entire codebase. Let me set up my plan and start rebuilding:
Now I'll rebuild every file from scratch to be enterprise-grade. Starting with the foundation layer -- improved constants, types with better Zod schemas, robust cache, dates utility, API layer with proper error handling, and SWR hooks:
Good. I now have full context on the current state. The globals.css and tailwind config are already solid. Let me read the current source files, then rebuild everything from the ground up with enterprise-grade code. Let me read the current lib and component files:
Now let me read all the UI components carefully:
Now let me read the pages and the detail view:
Now I have a complete picture of every single file. The current code is functional but needs significant improvements. The search-bar imports QUICK_SEARCHES from @/lib/types which doesn't exist there (it's in constants), the error state checks the wrong error property, the detail-view is one huge 519-line monolith, and there's no error boundary. Let me rebuild everything properly. I'll start writing all files now:
Now the UI components. I'll rebuild them as properly small, well-commented components:
Now the most important part — break the 519-line detail view into small, focused components:
Now rebuild the main trial-detail-view as a thin orchestrator that uses these small components:
Now rebuild the error boundary and the pages:
Now rebuild the home page with better structure and the error boundary:
Now let me mark the tasks done and verify there are no broken imports:
Let me verify there are no orphaned imports or issues:
All imports are clean and properly separated between @/lib/types (schemas, interfaces) and @/lib/constants (enums, labels, config). Let me also verify the footer is properly imported everywhere:
Everything is properly wired up. Here's a summary of the complete enterprise rebuild:
Foundation layer -- Split into 5 focused modules: constants.ts (all magic strings/enums/config), types.ts (Zod schemas + derived TS types), cache.ts (localStorage with TTL, quota-error recovery, and namespace cleanup), dates.ts (safe date formatting with null guards), and api.ts (URL building, fetch with AbortController, Zod safeParse validation, structured ApiError class with rate-limit detection, and data transformers).
Component architecture -- The 519-line monolithic trial-detail-view.tsx was broken into 6 small, single-responsibility components under components/detail/: StatusBadge, DetailHero, TabOverview, TabEligibility, TabLocations, and TabTimeline. Every component has JSDoc file headers, proper ARIA attributes, and aria-hidden on decorative icons. A new ErrorBoundary class component catches rendering crashes across all pages, and the ErrorState now properly detects ApiError.isRateLimit instead of checking a string comparison. All imports from the old @/lib/types for constants like QUICK_SEARCHES were fixed to import from the correct @/lib/constants module.
Pages -- All three pages (/, /trial/[nctId], /about) now use the shared Footer component, are wrapped in ErrorBoundary + Suspense, and have consistent layout structure. The cache module now handles quota errors gracefully by clearing stale entries and retrying once.
You can send messages while the preview loads