How rootdeveloperds/viewport_detective works
1. Overall shape
- This is a single-purpose Next.js App Router app with a very small surface area.
- There is no backend, database, or API layer in the repo. The app is entirely driven by browser state and client-side React components.
2. Application entry and composition
- src/app/layout.tsx is the root shell: it likely wires global styling and providers.
- src/app/page.tsx is the main screen and probably composes the entire viewport inspector experience.
- src/app/globals.css provides the global theme and base styles that the UI depends on.
3. Viewport sensing subsystem
- src/hooks/use-viewport.ts is the core data source. It likely listens to window resize/orientation changes and derives:
- viewport width and height
- device pixel ratio
- orientation
- breakpoint bucket
- safe-area inset values
- src/hooks/use-mobile.tsx is a smaller helper for mobile-aware branching.
4. Primary UI data consumers
- src/components/viewport-info.tsx appears to be the main readout component for the live viewport metrics.
- src/components/pixel-grid.tsx and src/components/click-grid.tsx suggest a visual overlay or diagnostic grid used to inspect pixel-level or interaction-related layout behavior.
- These components are likely pure presentational consumers of the viewport hook state.
5. Theme subsystem
- src/components/theme-provider.tsx provides app-wide theme context.
- src/components/theme-toggle.tsx is the user control for switching themes.
- The README confirms light/dark mode support, so theme state is a first-class cross-cutting concern rather than a local component detail.
6. Notification and clipboard feedback
- src/hooks/use-toast.ts plus src/components/ui/toaster.tsx indicate a global toast pipeline.
- The README’s “copy to clipboard” feature implies a flow where viewport data is copied from the UI, then toast feedback confirms success/failure.
- This is one of the few interactive state loops besides resize sensing.
7. UI component library boundary
- src/components/ui/* is a large set of reusable primitives: dialog, dropdown, tabs, toast, tooltip, form controls, etc.
- These look like shadcn/ui-style wrappers over lower-level headless primitives, used to keep the app visually consistent.
- Architecturally, these are shared infrastructure rather than domain logic.
8. Styling and design system
- tailwind.config.ts, postcss.config.mjs, and components.json show a Tailwind-based design system with generated component conventions.
- src/lib/utils.ts likely contains shared helpers for class name composition and other small utilities used throughout the UI.
9. Runtime and interaction model
- The app is browser-driven: viewport changes come from the DOM/window environment, and the UI reacts immediately.
- Because it depends on browser APIs like resize events, clipboard, and theme preference, most interactive components are effectively client-side components.
10. Data flow for the main feature
- Browser viewport changes -> useViewport hook recalculates metrics -> viewport-info and related visual components render updates -> optional copy action writes a summary to clipboard -> toast confirms the action.
- That’s the central architecture loop of the product.
11. Responsiveness and breakpoints
- Breakpoint logic is part of the product itself, not just styling.
- The README references standard breakpoints (xs/sm/md/lg/xl), so the hook likely owns the breakpoint classification and the UI renders it as part of the live inspector.
12. Deployment and external dependencies
- The stack is Next.js 14 + React 18 + TypeScript + Tailwind CSS, with iconography likely from Lucide React.
- The repo appears optimized for static/client deployment, with Vercel as the natural hosting target, but there are no material external service integrations in the architecture.
Main entry points: page.tsx Main Page · use-viewport.ts Viewport Hook · ui UI Primitives · viewport-info.tsx Viewport Info
Components 16
App Shell
Next.js App Router entrypoints and global composition.
Viewport Sensing
Browser-derived state and responsive classification.
- Viewport Hook · Reads window metrics, breakpoints, orientation, and safe-area data.
src/hooks/use-viewport.ts - Mobile Hook · Small branching helper for mobile-aware behavior.
src/hooks/use-mobile.tsx
Inspector UI
Main viewport readout and visual overlays.
- Viewport Info · Main live display of viewport metrics and classifications.
src/components/viewport-info.tsx - Pixel Grid · Visual grid for pixel-level layout inspection.
src/components/pixel-grid.tsx - Click Grid · Interaction-oriented grid overlay for inspecting layout behavior.
src/components/click-grid.tsx
Theme
App-wide appearance state and controls.
- Theme Provider · Supplies light/dark theme state to the app.
src/components/theme-provider.tsx - Theme Toggle · User control for switching themes.
src/components/theme-toggle.tsx
Feedback
Clipboard and toast feedback loop.
- Toast Hook · Global toast state and notification trigger API.
src/hooks/use-toast.ts - Toaster · Renders queued toast notifications for the app.
src/components/ui/toaster.tsx
UI Primitives
Shared component library used across the app.
- UI Primitives · Shared shadcn-style building blocks for dialogs, forms, tables, and controls.
src/components/ui
Styling
Design system and global styling layers.
- Global CSS · Base styles and theme variables for the entire app.
src/app/globals.css - Utils · Common helper utilities such as class name composition.
src/lib/utils.ts - Tailwind Config · Tailwind theme and utility configuration.
tailwind.config.ts - Components Config · Generated component-library configuration and conventions.
components.json
Connections 20
- Layout → Theme Provider: wraps · Layout applies app-wide theme context.
- Layout → Global CSS: imports · Root layout loads global styles.
- Main Page → Viewport Hook: reads · Main page consumes live viewport metrics.
- Main Page → Viewport Info: renders · Page composes the primary readout.
- Main Page → Pixel Grid: renders · Page includes pixel inspection overlay.
- Main Page → Click Grid: renders · Page includes interaction inspection overlay.
- Main Page → Theme Toggle: contains · Page exposes theme switching control.
- Main Page → Toaster: mounts · Page provides global toast host.
- Mobile Hook → Viewport Hook: builds on · Mobile helper is a smaller viewport-aware branch.
- Viewport Info → Viewport Hook: consumes · Readout is driven by viewport state.
- Pixel Grid → Viewport Hook: consumes · Overlay aligns to viewport measurements.
- Click Grid → Viewport Hook: consumes · Overlay responds to viewport state.
- Theme Toggle → Theme Provider: updates · Toggle changes global theme state.
- Toast Hook → Toaster: feeds · Toast hook pushes notifications to the host.
- Viewport Info → Toast Hook: notifies · Copy or action feedback is surfaced through toasts.
- UI Primitives → Utils: uses · Shared primitives rely on common helpers.
- UI Primitives → Tailwind Config: styled by · Primitives follow the Tailwind design system.
- UI Primitives → Components Config: configured by · Component conventions come from generated config.
- Theme Provider → Global CSS: depends on · Theme context is expressed through global CSS.
- Main Page → UI Primitives: assembles with · Main page uses shared UI building blocks.