# rootdeveloperds/viewport_detective architecture

> Architecture diagram of the GitHub repository rootdeveloperds/viewport_detective, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rootdeveloperds/viewport_detective
- Repository: https://github.com/rootdeveloperds/viewport_detective

## Overview

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: [`src/app/page.tsx`](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/page.tsx) (Main Page), [`src/hooks/use-viewport.ts`](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-viewport.ts) (Viewport Hook), [`src/components/ui`](https://github.com/rootdeveloperds/viewport_detective/tree/main/src/components/ui) (UI Primitives), [`src/components/viewport-info.tsx`](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/viewport-info.tsx) (Viewport Info)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App Shell"]
  node_src_app_layout["Layout<br/>app entry<br/>[layout.tsx]"]
  node_src_app_page["Main Page<br/>app page<br/>[page.tsx]"]
end

subgraph group_sensing["Viewport Sensing"]
  node_use_viewport(("Viewport Hook<br/>state hook<br/>[use-viewport.ts]"))
  node_use_mobile(("Mobile Hook<br/>helper hook<br/>[use-mobile.tsx]"))
end

subgraph group_presentation["Inspector UI"]
  node_viewport_info["Viewport Info<br/>readout<br/>[viewport-info.tsx]"]
  node_pixel_grid["Pixel Grid<br/>overlay<br/>[pixel-grid.tsx]"]
  node_click_grid["Click Grid<br/>overlay<br/>[click-grid.tsx]"]
end

subgraph group_theme["Theme"]
  node_theme_provider["Theme Provider<br/>context provider<br/>[theme-provider.tsx]"]
  node_theme_toggle["Theme Toggle<br/>control<br/>[theme-toggle.tsx]"]
end

subgraph group_feedback["Feedback"]
  node_use_toast(("Toast Hook<br/>feedback hook<br/>[use-toast.ts]"))
  node_toaster["Toaster<br/>toast host<br/>[toaster.tsx]"]
end

subgraph group_ui["UI Primitives"]
  node_ui_primitives[("UI Primitives<br/>component kit")]
end

subgraph group_style["Styling"]
  node_src_app_globals_css["Global CSS<br/>styles<br/>[globals.css]"]
  node_utils(("Utils<br/>shared helper<br/>[utils.ts]"))
  node_tailwind_config["Tailwind Config<br/>design system<br/>[tailwind.config.ts]"]
  node_components_json["Components Config<br/>ui config<br/>[components.json]"]
end

node_src_app_layout -->|"wraps"| node_theme_provider
node_src_app_layout -->|"imports"| node_src_app_globals_css
node_src_app_page -->|"reads"| node_use_viewport
node_src_app_page -->|"renders"| node_viewport_info
node_src_app_page -->|"renders"| node_pixel_grid
node_src_app_page -->|"renders"| node_click_grid
node_src_app_page -->|"contains"| node_theme_toggle
node_src_app_page -->|"mounts"| node_toaster
node_use_mobile -.->|"builds on"| node_use_viewport
node_viewport_info -->|"consumes"| node_use_viewport
node_pixel_grid -->|"consumes"| node_use_viewport
node_click_grid -->|"consumes"| node_use_viewport
node_theme_toggle -->|"updates"| node_theme_provider
node_use_toast -->|"feeds"| node_toaster
node_viewport_info -->|"notifies"| node_use_toast
node_ui_primitives -.->|"uses"| node_utils
node_ui_primitives -.->|"styled by"| node_tailwind_config
node_ui_primitives -.->|"configured by"| node_components_json
node_theme_provider -.->|"depends on"| node_src_app_globals_css
node_src_app_page -.->|"assembles with"| node_ui_primitives

click node_src_app_layout "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/layout.tsx"
click node_src_app_page "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/page.tsx"
click node_src_app_globals_css "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/globals.css"
click node_use_viewport "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-viewport.ts"
click node_use_mobile "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-mobile.tsx"
click node_viewport_info "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/viewport-info.tsx"
click node_pixel_grid "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/pixel-grid.tsx"
click node_click_grid "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/click-grid.tsx"
click node_theme_provider "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/theme-provider.tsx"
click node_theme_toggle "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/theme-toggle.tsx"
click node_use_toast "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-toast.ts"
click node_toaster "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/ui/toaster.tsx"
click node_ui_primitives "https://github.com/rootdeveloperds/viewport_detective/tree/main/src/components/ui"
click node_utils "https://github.com/rootdeveloperds/viewport_detective/blob/main/src/lib/utils.ts"
click node_tailwind_config "https://github.com/rootdeveloperds/viewport_detective/blob/main/tailwind.config.ts"
click node_components_json "https://github.com/rootdeveloperds/viewport_detective/blob/main/components.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_src_app_layout,node_src_app_page,node_src_app_globals_css,node_utils,node_tailwind_config,node_components_json toneBlue
class node_use_viewport,node_use_mobile toneAmber
class node_viewport_info,node_pixel_grid,node_click_grid toneMint
class node_theme_provider,node_theme_toggle toneRose
class node_use_toast,node_toaster toneIndigo
class node_ui_primitives toneTeal
```

## Components

### App Shell

Next.js App Router entrypoints and global composition.

- [Layout](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/layout.tsx): app entry · Root shell that wires global structure and providers. · `src/app/layout.tsx`
- [Main Page](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/page.tsx): app page · Primary screen composing the viewport detective experience. · `src/app/page.tsx`

### Viewport Sensing

Browser-derived state and responsive classification.

- [Viewport Hook](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-viewport.ts): state hook · Reads window metrics, breakpoints, orientation, and safe-area data. · `src/hooks/use-viewport.ts`
- [Mobile Hook](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-mobile.tsx): helper hook · Small branching helper for mobile-aware behavior. · `src/hooks/use-mobile.tsx`

### Inspector UI

Main viewport readout and visual overlays.

- [Viewport Info](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/viewport-info.tsx): readout · Main live display of viewport metrics and classifications. · `src/components/viewport-info.tsx`
- [Pixel Grid](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/pixel-grid.tsx): overlay · Visual grid for pixel-level layout inspection. · `src/components/pixel-grid.tsx`
- [Click Grid](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/click-grid.tsx): overlay · Interaction-oriented grid overlay for inspecting layout behavior. · `src/components/click-grid.tsx`

### Theme

App-wide appearance state and controls.

- [Theme Provider](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/theme-provider.tsx): context provider · Supplies light/dark theme state to the app. · `src/components/theme-provider.tsx`
- [Theme Toggle](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/theme-toggle.tsx): control · User control for switching themes. · `src/components/theme-toggle.tsx`

### Feedback

Clipboard and toast feedback loop.

- [Toast Hook](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/hooks/use-toast.ts): feedback hook · Global toast state and notification trigger API. · `src/hooks/use-toast.ts`
- [Toaster](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/components/ui/toaster.tsx): toast host · Renders queued toast notifications for the app. · `src/components/ui/toaster.tsx`

### UI Primitives

Shared component library used across the app.

- [UI Primitives](https://github.com/rootdeveloperds/viewport_detective/tree/main/src/components/ui): component kit · Shared shadcn-style building blocks for dialogs, forms, tables, and controls. · `src/components/ui`

### Styling

Design system and global styling layers.

- [Global CSS](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/app/globals.css): styles · Base styles and theme variables for the entire app. · `src/app/globals.css`
- [Utils](https://github.com/rootdeveloperds/viewport_detective/blob/main/src/lib/utils.ts): shared helper · Common helper utilities such as class name composition. · `src/lib/utils.ts`
- [Tailwind Config](https://github.com/rootdeveloperds/viewport_detective/blob/main/tailwind.config.ts): design system · Tailwind theme and utility configuration. · `tailwind.config.ts`
- [Components Config](https://github.com/rootdeveloperds/viewport_detective/blob/main/components.json): ui config · Generated component-library configuration and conventions. · `components.json`

## Connections

- 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.
