# xenride/klaviyo-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/xenride/klaviyo-dashboard
- Repository: https://github.com/xenride/klaviyo-dashboard

## Overview

1. This repo is a client-side analytics/dashboard app built with React + TypeScript on Vite, styled with Tailwind CSS and shadcn/ui. The architecture is mostly frontend: route-driven screens, reusable UI primitives, and a small data-fetching layer.

2. The application shell is centered in `src/App.tsx` and `src/components/Layout.tsx`. `App.tsx` is the main composition point for page selection, while `Layout` provides the shared frame around all role-specific pages.

3. The top-level pages in `src/pages` show the main user-facing split: `Home`, `AccountManager`, `Copywriter`, `Designer`, and `NotFound`. This suggests the app presents different dashboard views or workflows by persona rather than a single generic interface.

4. The domain-specific visuals live in `src/components/widgets` and `src/components/KPICard.tsx`. These are the key reporting units in the architecture: KPI cards and specialized charts/summary panels such as `CampaignEngagementCard`, `ListGrowthCard`, and `RevenueByFlowCard`.

5. Data appears to come from Klaviyo. The integration boundary is in `src/hooks/useKlaviyo.ts` and `src/lib/klaviyo.ts`, with support files `klaviyoIds.ts` and `klaviyoMappers.ts`. That split implies: fetch raw Klaviyo data, map it into app-specific shapes, then render it in widgets.

6. `src/lib/http.ts` is the low-level network abstraction, so the data flow is likely: page/widget -> hook -> Klaviyo client/http helper -> external API -> mapper -> display model. `src/lib/mockData.ts` indicates the UI can also operate with local sample data, which is useful for development or fallback states.

7. `src/context/DateRangeContext.tsx` is an important cross-cutting state boundary. It likely controls the reporting window for all dashboards, so date selection is shared across pages and widgets rather than managed locally in each component.

8. The UI foundation is a large `src/components/ui` folder containing shadcn-style primitives: buttons, dialogs, tables, tabs, drawers, toasts, charts, and so on. These are not business logic; they are the reusable presentation layer used by the dashboard components.

9. Interaction and responsiveness are handled by a small set of hooks: `src/hooks/use-mobile.tsx` for viewport-aware behavior and `src/hooks/use-toast.ts` plus the toast components for transient notifications. That means the app likely adapts layout by screen size and uses client-side feedback instead of server-rendered messaging.

10. Styling and build tooling matter here: Tailwind config, PostCSS, Vite, and `index.css`/`src/index.css` define the visual system and asset pipeline. `components.json` reinforces that shadcn/ui is the primary component-generation convention.

11. `public/robots.txt` and `index.html` indicate a standard static SPA deployment model. `server.js` is the only backend-adjacent file in the tree; based on the rest of the repo, it is likely a lightweight local/server wrapper rather than a full application backend.

12. Overall, the best architecture diagram for this repo should show: a single React SPA entry point, shared layout/context at the center, route-level persona pages, domain widgets fed by a Klaviyo data-access layer, and a UI primitive library underneath everything. The only external system that materially affects the design is Klaviyo, which supplies the analytics data shown in the dashboard.

Main entry points: [`src/App.tsx`](https://github.com/xenride/klaviyo-dashboard/blob/main/src/App.tsx) (App), [`src/hooks/useKlaviyo.ts`](https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/useKlaviyo.ts) (useKlaviyo), [`src/pages/AccountManager.tsx`](https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/AccountManager.tsx) (Account Manager), [`src/lib/klaviyo.ts`](https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/klaviyo.ts) (Klaviyo Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["Shell"]
  node_main["main.tsx<br/>entry<br/>[main.tsx]"]
  node_app["App<br/>router shell<br/>[App.tsx]"]
  node_layout["Layout<br/>frame<br/>[Layout.tsx]"]
  node_date_range(("Date Range<br/>shared state"))
end

subgraph group_pages["Pages"]
  node_home["Home<br/>page<br/>[Home.tsx]"]
  node_account_manager["Account Manager<br/>page<br/>[AccountManager.tsx]"]
  node_copywriter["Copywriter<br/>page<br/>[Copywriter.tsx]"]
  node_designer["Designer<br/>page<br/>[Designer.tsx]"]
  node_not_found["Not Found<br/>page<br/>[NotFound.tsx]"]
end

subgraph group_data["Data"]
  node_use_klaviyo["useKlaviyo<br/>data hook<br/>[useKlaviyo.ts]"]
  node_klaviyo_client["Klaviyo Client<br/>api client<br/>[klaviyo.ts]"]
  node_http["HTTP<br/>network helper<br/>[http.ts]"]
  node_mappers["Mappers<br/>transform<br/>[klaviyoMappers.ts]"]
  node_mock_data["Mock Data<br/>fallback data<br/>[mockData.ts]"]
  node_klaviyo_api[("Klaviyo<br/>external api")]
end

subgraph group_widgets["Widgets"]
  node_kpi_card["KPI Card<br/>metric card<br/>[KPICard.tsx]"]
  node_campaign_engagement["Campaign Engagement<br/>widget"]
  node_list_growth["List Growth<br/>widget<br/>[ListGrowthCard.tsx]"]
  node_revenue_flow["Revenue by Flow<br/>widget"]
end

subgraph group_ui["UI System"]
  node_ui_primitives["UI Primitives<br/>component library"]
  node_mobile_hook(("use-mobile<br/>responsive hook<br/>[use-mobile.tsx]"))
  node_toast_hook(("use-toast<br/>feedback hook<br/>[use-toast.ts]"))
end

node_main -->|"mounts"| node_app
node_app -->|"wraps"| node_layout
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_account_manager
node_app -->|"routes to"| node_copywriter
node_app -->|"routes to"| node_designer
node_app -->|"fallback"| node_not_found
node_layout -->|"consumes"| node_date_range
node_layout -->|"uses"| node_ui_primitives
node_home -->|"renders"| node_kpi_card
node_account_manager -->|"renders"| node_campaign_engagement
node_account_manager -->|"renders"| node_list_growth
node_account_manager -->|"renders"| node_revenue_flow
node_copywriter -->|"renders"| node_campaign_engagement
node_designer -->|"renders"| node_revenue_flow
node_campaign_engagement -->|"loads"| node_use_klaviyo
node_list_growth -->|"loads"| node_use_klaviyo
node_revenue_flow -->|"loads"| node_use_klaviyo
node_use_klaviyo -->|"delegates"| node_klaviyo_client
node_use_klaviyo -->|"falls back to"| node_mock_data
node_klaviyo_client -->|"requests"| node_http
node_klaviyo_client -->|"calls"| node_klaviyo_api
node_klaviyo_client -->|"transforms"| node_mappers
node_ui_primitives -->|"adapts"| node_mobile_hook
node_ui_primitives -->|"notifies"| node_toast_hook

click node_main "https://github.com/xenride/klaviyo-dashboard/blob/main/src/main.tsx"
click node_app "https://github.com/xenride/klaviyo-dashboard/blob/main/src/App.tsx"
click node_layout "https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/Layout.tsx"
click node_date_range "https://github.com/xenride/klaviyo-dashboard/blob/main/src/context/DateRangeContext.tsx"
click node_home "https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/Home.tsx"
click node_account_manager "https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/AccountManager.tsx"
click node_copywriter "https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/Copywriter.tsx"
click node_designer "https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/Designer.tsx"
click node_not_found "https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/NotFound.tsx"
click node_kpi_card "https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/KPICard.tsx"
click node_campaign_engagement "https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/widgets/CampaignEngagementCard.tsx"
click node_list_growth "https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/widgets/ListGrowthCard.tsx"
click node_revenue_flow "https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/widgets/RevenueByFlowCard.tsx"
click node_use_klaviyo "https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/useKlaviyo.ts"
click node_klaviyo_client "https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/klaviyo.ts"
click node_http "https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/http.ts"
click node_mappers "https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/klaviyoMappers.ts"
click node_mock_data "https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/mockData.ts"
click node_ui_primitives "https://github.com/xenride/klaviyo-dashboard/tree/main/src/components/ui"
click node_mobile_hook "https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/use-mobile.tsx"
click node_toast_hook "https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/use-toast.ts"

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_main,node_app,node_layout,node_date_range toneBlue
class node_home,node_account_manager,node_copywriter,node_designer,node_not_found toneAmber
class node_use_klaviyo,node_klaviyo_client,node_http,node_mappers,node_mock_data,node_klaviyo_api toneMint
class node_kpi_card,node_campaign_engagement,node_list_growth,node_revenue_flow toneRose
class node_ui_primitives,node_mobile_hook,node_toast_hook toneIndigo
```

## Components

### Shell

SPA entry and shared app frame

- [main.tsx](https://github.com/xenride/klaviyo-dashboard/blob/main/src/main.tsx): entry · Bootstraps the React app and mounts the SPA. · `src/main.tsx`
- [App](https://github.com/xenride/klaviyo-dashboard/blob/main/src/App.tsx): router shell · Selects the active page and composes the top-level experience. · `src/App.tsx`
- [Layout](https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/Layout.tsx): frame · Shared application frame around persona-specific content. · `src/components/Layout.tsx`
- [Date Range](https://github.com/xenride/klaviyo-dashboard/blob/main/src/context/DateRangeContext.tsx): shared state · Cross-cutting reporting window used by dashboards. · `src/context/DateRangeContext.tsx`

### Pages

Route-level persona views

- [Home](https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/Home.tsx): page · Landing dashboard entry for the app. · `src/pages/Home.tsx`
- [Account Manager](https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/AccountManager.tsx): page · Persona-specific analytics view for account managers. · `src/pages/AccountManager.tsx`
- [Copywriter](https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/Copywriter.tsx): page · Persona-specific workflow or dashboard for copywriters. · `src/pages/Copywriter.tsx`
- [Designer](https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/Designer.tsx): page · Persona-specific workflow or dashboard for designers. · `src/pages/Designer.tsx`
- [Not Found](https://github.com/xenride/klaviyo-dashboard/blob/main/src/pages/NotFound.tsx): page · Fallback route for unknown screens. · `src/pages/NotFound.tsx`

### Data

Klaviyo access and app data shaping

- [useKlaviyo](https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/useKlaviyo.ts): data hook · Fetches dashboard data and bridges UI state to the client layer. · `src/hooks/useKlaviyo.ts`
- [Klaviyo Client](https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/klaviyo.ts): api client · Encapsulates Klaviyo access and request assembly. · `src/lib/klaviyo.ts`
- [HTTP](https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/http.ts): network helper · Low-level request abstraction used by the data client. · `src/lib/http.ts`
- [Mappers](https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/klaviyoMappers.ts): transform · Converts raw Klaviyo responses into app-specific models. · `src/lib/klaviyoMappers.ts`
- [Mock Data](https://github.com/xenride/klaviyo-dashboard/blob/main/src/lib/mockData.ts): fallback data · Local sample data for development or fallback rendering. · `src/lib/mockData.ts`
- **Klaviyo**: external api · Source system for analytics and campaign data.

### Widgets

Dashboard reporting components

- [KPI Card](https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/KPICard.tsx): metric card · Shared metric presentation used across dashboard views. · `src/components/KPICard.tsx`
- [Campaign Engagement](https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/widgets/CampaignEngagementCard.tsx): widget · Campaign performance summary panel. · `src/components/widgets/CampaignEngagementCard.tsx`
- [List Growth](https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/widgets/ListGrowthCard.tsx): widget · Audience growth summary panel. · `src/components/widgets/ListGrowthCard.tsx`
- [Revenue by Flow](https://github.com/xenride/klaviyo-dashboard/blob/main/src/components/widgets/RevenueByFlowCard.tsx): widget · Revenue breakdown by automation flow. · `src/components/widgets/RevenueByFlowCard.tsx`

### UI System

Reusable presentation primitives

- [UI Primitives](https://github.com/xenride/klaviyo-dashboard/tree/main/src/components/ui): component library · Reusable shadcn-style controls and layout primitives. · `src/components/ui`
- [use-mobile](https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/use-mobile.tsx): responsive hook · Viewport-aware behavior for adaptive layouts. · `src/hooks/use-mobile.tsx`
- [use-toast](https://github.com/xenride/klaviyo-dashboard/blob/main/src/hooks/use-toast.ts): feedback hook · Client-side toast state and notification plumbing. · `src/hooks/use-toast.ts`

## Connections

- main.tsx → App: mounts · Entry point renders the application shell.
- App → Layout: wraps · Top-level composition is centered in the shared frame.
- App → Home: routes to · Routes the default view.
- App → Account Manager: routes to · Routes the account manager dashboard.
- App → Copywriter: routes to · Routes the copywriter dashboard.
- App → Designer: routes to · Routes the designer dashboard.
- App → Not Found: fallback · Handles unknown routes.
- Layout → Date Range: consumes · Shared reporting window informs dashboard content.
- Layout → UI Primitives: uses · Builds the shell with reusable presentation primitives.
- Home → KPI Card: renders · Home screen presents summary metrics through KPI cards.
- Account Manager → Campaign Engagement: renders · Account manager view uses campaign performance widgets.
- Account Manager → List Growth: renders · Account manager view uses growth widgets.
- Account Manager → Revenue by Flow: renders · Account manager view uses revenue widgets.
- Copywriter → Campaign Engagement: renders · Copywriter view reuses reporting widgets.
- Designer → Revenue by Flow: renders · Designer view reuses reporting widgets.
- Campaign Engagement → useKlaviyo: loads · Widget data comes from the Klaviyo hook.
- List Growth → useKlaviyo: loads · Widget data comes from the Klaviyo hook.
- Revenue by Flow → useKlaviyo: loads · Widget data comes from the Klaviyo hook.
- useKlaviyo → Klaviyo Client: delegates · Hook delegates data access to the client layer.
- useKlaviyo → Mock Data: falls back to · Hook can source sample data when live data is unavailable.
- Klaviyo Client → HTTP: requests · Client uses the low-level network helper.
- Klaviyo Client → Klaviyo: calls · Sends requests to the external analytics system.
- Klaviyo Client → Mappers: transforms · Raw responses are mapped into app-specific shapes.
- UI Primitives → use-mobile: adapts · Some UI patterns respond to viewport size.
- UI Primitives → use-toast: notifies · UI layer supports transient client-side feedback.
