Skip to content

Project Structure

Sparkle is organized as a TypeScript monorepo with focused packages and clear separation of concerns.

sparkle/
β”œβ”€β”€ πŸ“¦ packages/ # Core Sparkle packages
β”‚ β”œβ”€β”€ 🎨 ui/ # React component library
β”‚ β”œβ”€β”€ 🌈 theme/ # Design tokens and providers
β”‚ β”œβ”€β”€ πŸ“ types/ # TypeScript definitions
β”‚ β”œβ”€β”€ πŸ”§ utils/ # Utility functions
β”‚ β”œβ”€β”€ πŸ§ͺ error-testing/ # Testing framework
β”‚ └── βš™οΈ config/ # Shared configurations
β”œβ”€β”€ πŸ“± apps/ # Example applications
β”‚ └── fro-jive/ # Expo mobile app
β”œβ”€β”€ πŸ“š docs/ # Documentation site (you're here!)
β”œβ”€β”€ πŸ”¨ scripts/ # Build and utility scripts
β”œβ”€β”€ πŸ—οΈ infrastructure files # Package configs, CI/CD, etc.

Understanding how packages relate to each other:

@sparkle/ui ← Main component library
β”œβ”€β”€ @sparkle/theme # ← Design tokens & theming
β”œβ”€β”€ @sparkle/types # ← TypeScript definitions
└── @sparkle/utils # ← Shared utilities
@sparkle/theme ← Design system foundation
└── @sparkle/types # ← Core type definitions
@sparkle/utils ← React hooks & utilities
└── @sparkle/types # ← Type safety everywhere
@sparkle/error-testing ← Development tools
└── @sparkle/types # ← Consistent type usage

This bottom-up architecture means:

  • βœ… No circular dependencies - Clean, predictable imports
  • βœ… Incremental adoption - Use just what you need
  • βœ… Independent versioning - Packages can evolve separately
  • βœ… Clear boundaries - Each package has distinct responsibilities

The main component library containing all React components:

packages/ui/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/ # Individual components
β”‚ β”‚ β”œβ”€β”€ Button/ # Button component + stories
β”‚ β”‚ β”œβ”€β”€ Form/ # Form components
β”‚ β”‚ └── ... # Other components
β”‚ β”œβ”€β”€ hooks/ # Component-specific hooks
β”‚ β”œβ”€β”€ utils/ # UI utilities
β”‚ └── index.ts # Public API exports
β”œβ”€β”€ dist/ # Built JavaScript + CSS
β”œβ”€β”€ styles.css # Component styles
└── package.json

Key Features:

  • 🎯 Accessible by default - WCAG 2.1 AA compliant
  • πŸ”§ Highly customizable - CSS custom properties + Tailwind
  • πŸ“š Storybook integration - Interactive component playground
  • πŸ§ͺ Comprehensive testing - Unit, integration, and visual regression

Design token management and theme providers:

packages/theme/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ tokens/ # Design token definitions
β”‚ β”‚ β”œβ”€β”€ base.ts # Core tokens (colors, spacing, etc.)
β”‚ β”‚ β”œβ”€β”€ light.ts # Light theme overrides
β”‚ β”‚ └── dark.ts # Dark theme overrides
β”‚ β”œβ”€β”€ providers/ # Theme context providers
β”‚ β”‚ β”œβ”€β”€ ThemeProvider.tsx # Web theme provider
β”‚ β”‚ └── NativeThemeProvider.tsx # React Native provider
β”‚ β”œβ”€β”€ utils/ # Token transformation utilities
β”‚ └── index.ts # Public exports
β”œβ”€β”€ styles.css # Generated CSS custom properties
└── package.json

Key Features:

  • πŸ”„ Cross-platform tokens - Web CSS + React Native StyleSheet
  • 🎨 Dynamic theming - Runtime theme switching
  • πŸ”§ Token transformation - Automatic format conversion
  • πŸ“± Mobile support - React Native compatible

Shared TypeScript definitions used across all packages:

packages/types/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/ # Component prop types
β”‚ β”œβ”€β”€ theme/ # Theme-related types
β”‚ β”œβ”€β”€ utils/ # Utility types
β”‚ └── index.ts # Re-exports
└── package.json

Utility functions and React hooks:

packages/utils/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ hooks/ # React hooks
β”‚ β”‚ β”œβ”€β”€ useDebounce.ts
β”‚ β”‚ β”œβ”€β”€ useClickOutside.ts
β”‚ β”‚ └── useAsync.ts
β”‚ β”œβ”€β”€ functions/ # Pure utility functions
β”‚ └── index.ts
└── package.json

Error testing framework for development:

packages/error-testing/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ builders/ # Test scenario builders
β”‚ β”œβ”€β”€ fixtures/ # Test data fixtures
β”‚ β”œβ”€β”€ utils/ # Testing utilities
β”‚ └── index.ts
└── package.json

Sparkle uses modern tooling for efficient development:

Orchestrates builds across packages with intelligent caching:

Terminal window
# Build all packages (with dependency order)
pnpm build
# Build only changed packages
pnpm build --filter=...[HEAD~1]
# Parallel development mode
pnpm dev

Manages dependencies with workspace linking:

Terminal window
# Install dependency in specific package
pnpm add --filter @sparkle/ui react
# Install dev dependency globally
pnpm add -Dw typescript
# Run command in all packages
pnpm -r build

Fast TypeScript compilation for packages:

tsdown.config.ts
export default defineConfig({
entry: ['./src/index.ts'],
outDir: 'dist',
dts: true, // Generate .d.ts files
clean: true, // Clean dist/ before build
})

Start all development servers:

Terminal window
# Terminal 1: Type checking in watch mode
pnpm build:types:watch
# Terminal 2: All development servers
pnpm dev

This starts:

  • πŸ“š Storybook at http://localhost:6006
  • πŸ“ Documentation at http://localhost:4321
  • πŸ“± Mobile app via Expo CLI
  • πŸ”§ Package builds in watch mode

Comprehensive testing at multiple levels:

Terminal window
# Unit tests with Vitest
pnpm test
# Visual regression tests with Playwright
pnpm test:visual
# Type checking
pnpm check:types
# Full quality check
pnpm check

Using Changesets for coordinated releases:

Terminal window
# Create changeset for your changes
pnpm changeset
# Version packages based on changesets
pnpm changeset version
# Publish to npm (CI only)
pnpm changeset publish

Key configuration files and their purposes:

FilePurpose
turbo.jsonTask orchestration and caching
pnpm-workspace.yamlWorkspace package definitions
tsconfig.jsonRoot TypeScript configuration
eslint.config.tsESLint rules for all packages
.changeset/config.jsonRelease configuration

Now that you understand the structure: