Skip to content
Plotcnbeta
DocsChartsBlocksPlaygroundThemesExamples
Get started
Guide
  • Introduction
  • System Design
  • Engine Strategy
  • Installation
  • Project Setup
  • shadcn/ui Setup
  • Plotcn Registry
Fundamentals
  • Usage
  • Theming
  • Accessibility
  • Motion & Animation
  • Performance
  • TypeScript & I18n
Google Charts
  • Google Charts
  • Google GeoChart
SETUP BLUEPRINTSTEP 02 OF GETTING STARTED
Architecture Readiness

Project Setup

Prepare your codebase for Plotcn. Configure aliases, project structure, theme tokens, and shared chart infrastructure before installing visualization components.

PREREQUISITES:React 18 / 19TypeScript Strictshadcn/ui InitializedTailwind CSS v4 / v3components.json
Active Context:
Next.jspnpmTSTypeScript
Change framework
Architecture Overview

Codebase Architecture Blueprint

How your application directory tree, configuration files, and Plotcn visualization folders connect together.

WORKSPACE ROOT
WORKSPACE
Application Root
Houses your configuration, route tree, and visualization infrastructure.
Root Directory · TypeScript Project
REGISTRY CONFIG
CONFIG
components.json
Maps path aliases, styles, and CLI output destinations for chart installations.
shadcn CLI Manifest · JSON
PAGES & ROUTES
ROUTES
app/ or src/
Server-rendered pages, routes, and dashboard layouts that consume charts.
RSC Pages · Layouts · Route Tree
COMPONENT TREE
ActiveCOMPONENTS
components/ (ui + charts)
components/ui for shadcn primitives and components/charts for Plotcn visualizations.
Source Owned Components · TSX
UTILITIES
UTILS
lib/utils.ts
Contains cn helper and engine-independent chart calculations and formatters.
Utility Functions · TypeScript
THEME TOKENS
CSS
globals.css / app.css
Houses --chart-1 through --chart-5, axis, surface, and grid CSS variables.
CSS Variables · Dark / Light Theme Tokens

Before you begin

Project setup is the technical blueprint that connects your initial installation to building charts. It ensures your codebase has the directory structure, path aliases, theme variables, and architecture boundaries needed before adding visualization components.

Project setup assumes shadcn/ui is already initialized. If you have not created your project or run the shadcn init command yet, refer to Installation or shadcn/ui Setup.

Plotcn does not require you to reorganize your entire project. It is designed to integrate seamlessly into standard React and Next.js applications, matching your existing conventions for components, utilities, and styling tokens.

Project structure

Plotcn organizes chart code around engine isolation. Primitives for Recharts, D3, and Google Charts reside in dedicated directories, while cross-engine infrastructure stays strictly engine-independent.

my-app/
Plotcn paths highlighted
app/layout.tsx
Root layout (Server Component)
app/page.tsx
Dashboard or page route
app/globals.css
Tailwind & --chart-* tokens
components/charts/
Plotcn visualizations
components/charts/shared/
Engine-independent primitives
components/charts/recharts/
Recharts implementations
components/charts/d3/
D3 custom geometry
components/charts/google/
Google Charts wrappers
components/ui/
shadcn/ui primitives
lib/utils.ts
cn class merger
lib/charts/
Shared math & token adapters
components.json
shadcn CLI configuration
tsconfig.json
TypeScript paths mapping

Highlighted directories

  • components/charts/: The destination directory for all Plotcn visualization components. Components installed from the registry are copied directly here as editable source code.
  • components/ui/: Base shadcn/ui primitives (Button, Tooltip, Card, Dialog) utilized by chart headers, interactive legends, and filter controls.
  • lib/charts/: Engine-neutral math utilities, coordinate transforms, and theme option adapters (such as Google Charts palette generators).
  • globals.css: Defines CSS variables (--chart-1 through --chart-5, gridlines, axes) that power both light and dark visualization modes.
  • components.json: The shadcn configuration file instructing the CLI where to place imported components and how to resolve aliases.

Path aliases

Registry-installed source files require predictable import paths to find helper functions, theme tokens, and UI primitives without fragile relative imports like ../../../lib/utils.

Stabilizing your path aliases early is essential: changing aliases after installing components requires manually updating import statements across your chart files.

tsconfig.jsonJSON
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    }
  }
}

Import conventions

When components are imported into your pages or dashboards, use the root alias:

app/dashboard/page.tsx
// Recommended: Clean root-relative importsimport { LineChartBasic } from "@/components/charts/recharts/line-chart-basic"import { ChartContainer } from "@/components/charts/shared/chart-container"

components.json

The components.json file is the registry manifest used by the shadcn CLI to determine styles, Tailwind CSS paths, import aliases, and target directories for new components.

components.jsonRSC Enabled
Registry Preset
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "base-nova",
  "rsc": true,
  "tsx": true,
  "tailwind": {
    "config": "",
    "css": "app/globals.css",
    "baseColor": "neutral",
    "cssVariables": true,
    "prefix": ""
  },
  "iconLibrary": "hugeicons",
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib",
    "hooks": "@/hooks"
  }
}
If shadcn/ui is already configured in your project, keep your existing components.json file and simply verify that your aliases point to valid directories. Do not overwrite a working configuration.

Key configuration fields

  • rsc: Set to true in Next.js App Router and full-stack SSR environments. Set to false in client-only Vite or SPA setups.
  • tailwind.css: Points to your primary CSS entrypoint containing the @theme inline definitions and CSS variables (app/globals.css or src/index.css).
  • aliases.components: Maps @/components so registry components install into your component hierarchy without manual path entry.
  • aliases.utils: Resolves @/lib/utils where the cn() class merge utility is located.

Chart directories

Plotcn enforces strict separation between visualization engines. Each engine has unique rendering models, runtime lifecycles, and dependency requirements.

shared/
Engine-Neutral

Engine-independent infrastructure. Only universal concerns belong here: responsive wrappers, loading states, accessibility summaries, and theme adapters.

RULE:Must NEVER import recharts, d3-*, or google.visualization.
recharts/
Recharts Only

Components and wrappers built specifically for Recharts SVG primitives (ResponsiveContainer, Line, Bar, Area, CartesianGrid).

RULE:No D3 or Google-specific code permitted.
d3/
Modular D3

Custom layouts, scales, force simulations, and mathematical geometry generators. Uses modular micro-imports (d3-shape, d3-scale).

RULE:Avoid monolithic `import * as d3 from 'd3'`.
google/
External Runtime

Google Charts wrappers, GeoCharts, and external runtime loader scripts. Isolated because Google Charts loads an external CDN runtime script.

RULE:Must NEVER execute or read window.google during SSR.

Engine isolation principles

Shared means engine-independent. If a utility references recharts, d3-*, or google.visualization, it does not belong in components/charts/shared/.

Cross-engine dependencies are strictly prohibited:

TypeScript
// ❌ WRONG: Cross-engine coupling// In components/charts/google/geo-chart.tsx:import { Tooltip } from "@/components/charts/recharts/tooltip"// ✅ CORRECT: Engine-independent shared layer// In components/charts/google/geo-chart.tsx:import { ChartContainer } from "@/components/charts/shared/chart-container"import { getGoogleChartTheme } from "@/lib/google-charts/theme"

Shared chart infrastructure

Plotcn shares common product concerns across all chart engines without forcing them into a rigid, monolithic wrapper.

Decoupled Systems

Cross-Engine Shared Architecture

Plotcn separates universal product concerns from engine-specific rendering code, avoiding monolithic prop wrappers.

universal infrastructurePlotcn Shared Layer (components/charts/shared/)
100% Engine-Neutral
SHELL
ChartContainer
Responsive aspect ratio and dimensions.
Responsive Shell
TOKENS
Theme Tokens
CSS variable extraction and color roles.
CSS Variables
STATES
ChartState
Loading skeletons, empty data, and error views.
Lifecycle States
A11Y
Accessibility
ARIA data table and screen-reader summaries.
ARIA & AT Fallback
specialized engine implementations
RECHARTS ENGINE
Declarative SVG
@/components/charts/recharts/*
Declarative React SVG. Cartesian charts, lines, bars, areas, and interactive hover tooltips.
React JSX Primitives
D3.JS ENGINE
Custom Math
@/components/charts/d3/*
Mathematical coordinate precision. Force networks, hierarchies, radar geometry, and custom scales.
Geometry Generators
GOOGLE CHARTS ENGINE
CDN Runtime
@/components/charts/google/*
External runtime adapter. GeoChart choropleths and mature core charts with dynamic theme translation.
Google Singleton Loader
Do not normalize every chart engine into one giant prop API. Shared infrastructure handles cross-engine concerns (responsive shells, loading states, accessibility, theme tokens), leaving engine-specific rendering declarative and idiomatic.

Shared vs engine-specific concerns

Concern Shared Layer Engine-Specific Layer
ConcernShared LayerEngine-Specific Layer
Responsive shell & aspect ratioYes (ChartContainer)No
Loading, empty & error statesYes (ChartState)No
Theme color tokensYes (CSS variables)Adapter only
Accessibility summary & tableYes (ChartAccessibility)No
Recharts primitives & SVGNoRecharts (Line, Bar, XAxis)
D3 geometry, curves & force mathNoD3 (d3-shape, d3-scale)
Google Charts script & runtimeNoGoogle (google-chart-loader.ts)

Theme tokens

Plotcn charts adapt directly to your design system using CSS variables rather than hardcoded hex colors. This ensures charts automatically match your light and dark themes.

Tailwind CSS v4 variables

Add chart tokens to your @theme inline block in app/globals.css:

app/globals.css
@import "tailwindcss";@import "tw-animate-css";@theme inline {  --color-background: var(--background);  --color-foreground: var(--foreground);  --color-border: var(--border);  --color-muted: var(--muted);  --color-muted-foreground: var(--muted-foreground);  /* Plotcn categorical chart color tokens */  --color-chart-1: var(--chart-1);  --color-chart-2: var(--chart-2);  --color-chart-3: var(--chart-3);  --color-chart-4: var(--chart-4);  --color-chart-5: var(--chart-5);}

Semantic palette values

Plotcn uses a restrained Zinc / Titanium palette for crisp contrast in both light and dark modes:

app/globals.css
:root {  --background: oklch(1 0 0);  --foreground: oklch(0.145 0 0);  --border: oklch(0.922 0 0);  --muted: oklch(0.97 0 0);  --muted-foreground: oklch(0.556 0 0);  /* Light mode chart palette (Zinc / Titanium scale) */  --chart-1: oklch(0.87 0 0);  --chart-2: oklch(0.556 0 0);  --chart-3: oklch(0.439 0 0);  --chart-4: oklch(0.371 0 0);  --chart-5: oklch(0.269 0 0);}.dark {  --background: oklch(0.145 0 0);  --foreground: oklch(0.985 0 0);  --border: oklch(1 0 0 / 10%);  --muted: oklch(0.269 0 0);  --muted-foreground: oklch(0.708 0 0);  /* Dark mode chart palette */  --chart-1: oklch(0.87 0 0);  --chart-2: oklch(0.556 0 0);  --chart-3: oklch(0.439 0 0);  --chart-4: oklch(0.371 0 0);  --chart-5: oklch(0.269 0 0);}

Google Charts theme adapter

Unlike React SVG charts that read CSS variables directly, Google Charts renders inside an isolated iframe/canvas managed by an external script. Plotcn provides theme adapter functions in lib/google-charts/theme.ts that resolve your CSS variables into Google options at runtime.

Server and client boundaries

In Next.js App Router and modern SSR frameworks, maintaining strict server and client boundaries is essential for performance and bundle size.

App Router & SSR Architecture

Server & Client Execution Boundary Strategy

Plotcn isolates client execution boundaries strictly to interactive visualization shells, keeping pages and utilities server-safe.

SERVER (RSC)Server-Safe Domain (Default)
NO 'USE CLIENT'
  • Doc pages, dashboard layouts, and route handlers
  • Data transformation, normalization & math utilities
  • TypeScript chart interfaces, contracts & Zod schemas
  • Static CSS theme token and variable declarations
CLIENT (ISOLATED)Client-Only Domain (Interactive)
'USE CLIENT'
  • Interactive chart render shells and SVG viewport
  • ResizeObserver & responsive dimension measurement
  • Google Charts runtime loader (window.google client script)
  • Hover tooltips, pointer focus, legends, and animations

Best practices for Next.js

  1. Keep pages server-first: Never place "use client" at app/layout.tsx, docs layouts, or entire page routes. Fetch data and construct layout on the server.
  2. Isolate interactive charts: Add "use client" only at the leaf component boundary where DOM measurements (ResizeObserver), SVG animations, or user hover events take place.
  3. D3 math utilities: D3 calculation functions (scales, shapes, pie layouts) are pure functions and can run on both server and client without "use client".
  4. Google Charts runtime: Google Charts requires the browser window object. Keep the loader and chart wrapper behind a strict client component boundary to prevent SSR hydration errors.

Registry output

When you install a component using the shadcn CLI, Plotcn copies the component source code directly into your repository.

Distribution Flow

How Components Enter Your Codebase

The end-to-end path from the remote Plotcn catalog directly into your local Git repository.

  1. 01
    Plotcn Registry

    Uncompiled, typed source code hosted in the open registry catalog.

    Remote Catalog
  2. 02
    shadcn CLI

    Reads your components.json aliases and determines local destination paths.

    Path Resolution
  3. 03
    Files Injected

    Components are written directly into your components/charts directory.

    components/charts/*
  4. 04
    Engine Dependencies

    Only the required library (recharts or d3) is added to package.json.

    Scoped Packages
  5. 05
    100% Owned Code

    No opaque wrapper. Customize CSS, SVGs, and interactions without limits.

    Complete Ownership

Source ownership

  • No opaque packages: Installed components are regular TypeScript and React files in your project. You have complete freedom to tweak SVG markup, add custom animations, or adjust styling.
  • Dependency isolation: Installing a Recharts component installs recharts only. Installing a D3 component installs modular micro-packages like d3-shape. No single chart forces you to install an all-in-one bundle.

Example file placement after installing a line chart and a Google GeoChart:

Local File Tree Structure

Example placement inside your project after installation

Source In Your Repo
components/charts/recharts/line-chart-basic.tsxrecharts

Local editable component source for standard business line chart.

components/charts/google/google-geochart.tsxgoogle

Local editable choropleth component for regional heatmaps.

components/charts/google/google-chart-container.tsxruntime wrapper

Singleton loader and client-side lifecycle container.

components/charts/shared/chart-container.tsxshared / a11y

Engine-independent responsive wrapper, theme tokens, and accessible summary.

Verify setup

Before installing components, confirm your project configuration using this readiness checklist and run verification commands:

Readiness Checklist

Verify every architectural requirement before installing your first visualization.

8 of 8 Ready
Verification Commands (pnpm)Direct CLI check
1. Typecheck aliases & imports:pnpm dlx tsc --noEmit
2. Lint configuration:pnpm lint
3. Verify production build:pnpm build

Next steps

With your codebase structured and verified, explore component installation and theming:

  • shadcn/ui Setup: Learn how components.json and registry namespaces work.
  • Plotcn Registry: Explore the full catalog of source-available visualization components.
  • Installation Guide: Revisit package manager commands and framework setup.
PreviousInstallationNextshadcn/ui Setup

On this page

  • Before you begin
  • Project structure
  • Path aliases
  • components.json
  • Chart directories
  • Shared chart infrastructure
  • Theme tokens
  • Server and client boundaries
  • Registry output
  • Verify setup
  • Next steps