How xenride/klaviyo-dashboard works
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: App.tsx App · useKlaviyo.ts useKlaviyo · AccountManager.tsx Account Manager · klaviyo.ts Klaviyo Client
Components 22
Shell
SPA entry and shared app frame
- main.tsx · Bootstraps the React app and mounts the SPA.
src/main.tsx - App · Selects the active page and composes the top-level experience.
src/App.tsx - Layout · Shared application frame around persona-specific content.
src/components/Layout.tsx - Date Range · Cross-cutting reporting window used by dashboards.
src/context/DateRangeContext.tsx
Pages
Route-level persona views
- Home · Landing dashboard entry for the app.
src/pages/Home.tsx - Account Manager · Persona-specific analytics view for account managers.
src/pages/AccountManager.tsx - Copywriter · Persona-specific workflow or dashboard for copywriters.
src/pages/Copywriter.tsx - Designer · Persona-specific workflow or dashboard for designers.
src/pages/Designer.tsx - Not Found · Fallback route for unknown screens.
src/pages/NotFound.tsx
Data
Klaviyo access and app data shaping
- useKlaviyo · Fetches dashboard data and bridges UI state to the client layer.
src/hooks/useKlaviyo.ts - Klaviyo Client · Encapsulates Klaviyo access and request assembly.
src/lib/klaviyo.ts - HTTP · Low-level request abstraction used by the data client.
src/lib/http.ts - Mappers · Converts raw Klaviyo responses into app-specific models.
src/lib/klaviyoMappers.ts - Mock Data · Local sample data for development or fallback rendering.
src/lib/mockData.ts - Klaviyo · Source system for analytics and campaign data.
Widgets
Dashboard reporting components
- KPI Card · Shared metric presentation used across dashboard views.
src/components/KPICard.tsx - Campaign Engagement · Campaign performance summary panel.
src/components/widgets/CampaignEngagementCard.tsx - List Growth · Audience growth summary panel.
src/components/widgets/ListGrowthCard.tsx - Revenue by Flow · Revenue breakdown by automation flow.
src/components/widgets/RevenueByFlowCard.tsx
UI System
Reusable presentation primitives
- UI Primitives · Reusable shadcn-style controls and layout primitives.
src/components/ui - use-mobile · Viewport-aware behavior for adaptive layouts.
src/hooks/use-mobile.tsx - use-toast · Client-side toast state and notification plumbing.
src/hooks/use-toast.ts
Connections 25
- 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.