@tekton/core
Minimal design system pipeline - Theme → Blueprint → Screen generation
Overview
89,993 LOC → 1,526 LOC (98.3% reduction)
This package replaces 14 bloated packages with a single, focused implementation of the core pipeline.
NEW: Screen Generation Pipeline (SPEC-LAYOUT-002) ✅
Transform JSON screen definitions into production-ready React components with multiple CSS frameworks.
Features:
- 🎯 JSON Schema-based definitions - Type-safe with TypeScript and Zod validation
- 🔄 Token resolver pipeline - Automatic layout and component token resolution
- 🎨 Multiple CSS outputs - CSS-in-JS (styled-components, Emotion) and Tailwind support
- ⚛️ React component generation - TypeScript React functional components
- 🤖 MCP server integration - 3 tools for Claude Code/Desktop LLM usage
- ✅ 85%+ test coverage - TRUST 5 framework compliant
Quick Start:
import {
validateScreenDefinition,
resolveScreen,
generateReactComponent,
} from '@tekton/core/screen-generation';
const validation = validateScreenDefinition(screenDef);
const resolved = await resolveScreen(screenDef);
const result = generateReactComponent(resolved);
📚 Documentation:
NEW: Responsive Web Enhancement (SPEC-LAYOUT-003) ✅
Advanced responsive design system with xl/2xl breakpoints, Container Queries, and Orientation support.
Features:
- 📱 Extended Breakpoints - xl (1280px), 2xl (1536px) for large displays
- 📦 Container Queries - Component-level responsiveness independent of viewport
- 🔄 Orientation Support - Portrait/Landscape optimizations for tablets
- 🎯 27 Layout Tokens Updated - All shells, pages, and sections enhanced
- ✅ 100% Test Coverage - 1041/1041 tests passing
- 🌐 Browser Compatibility - Chrome 105+, Safari 16+, Firefox 110+ with fallback
Quick Start:
import {
generateResponsiveCSS,
generateContainerQueryCSS,
generateOrientationCSS,
} from '@tekton/core/layout-tokens';
const responsive = generateResponsiveCSS({
default: { gridColumns: 1 },
md: { gridColumns: 2 },
xl: { gridColumns: 4 },
'2xl': { gridColumns: 6 },
});
const container = generateContainerQueryCSS({
name: 'card-grid',
type: 'inline-size',
breakpoints: {
md: { minWidth: 480, css: { 'grid-template-columns': 'repeat(2, 1fr)' } },
lg: { minWidth: 640, css: { 'grid-template-columns': 'repeat(3, 1fr)' } },
},
});
const orientation = generateOrientationCSS({
portrait: { gridColumns: 1 },
landscape: { gridColumns: 2 },
});
📚 Documentation:
Installation
pnpm add @tekton/core
Quick Start
import { loadTheme, createBlueprint, render } from '@tekton/core';
const theme = loadTheme('calm-wellness');
const blueprint = createBlueprint({
name: 'Dashboard',
themeId: theme.id,
layout: 'dashboard',
components: [
{ type: 'Heading', props: { level: 1 }, children: ['Welcome'] },
{
type: 'Card',
children: [
{ type: 'Text', children: ['Your stats here'] },
{ type: 'Button', props: { variant: 'primary' }, children: ['View More'] },
],
},
],
});
const result = render(blueprint);
console.log(result.code);
Features
🎨 3-Layer Token System (NEW)
Professional design token architecture with atomic, semantic, and component layers:
import type { ThemeWithTokens } from '@tekton/core';
import { resolveToken, generateThemeCSS } from '@tekton/core';
const theme: ThemeWithTokens = {
id: 'my-theme',
name: 'My Theme',
tokens: {
atomic: {
color: {
blue: { '500': '#3b82f6', '600': '#2563eb' },
neutral: { '50': '#f9fafb', '900': '#111827' },
},
spacing: { '4': '16px', '8': '32px' },
radius: { md: '8px' },
},
semantic: {
background: {
page: 'atomic.color.neutral.50',
surface: '#ffffff',
},
foreground: {
primary: 'atomic.color.neutral.900',
accent: 'atomic.color.blue.500',
},
},
component: {
button: {
primary: {
background: 'semantic.foreground.accent',
foreground: '#ffffff',
hover: { background: 'atomic.color.blue.600' },
},
},
},
},
};
const color = resolveToken('component.button.primary.background', theme.tokens);
const css = generateThemeCSS(theme);
Key Features:
- ✅ 3-Layer Architecture: Atomic → Semantic → Component
- ✅ Automatic Resolution: Multi-level reference resolution with circular detection
- ✅ Fallback Chain: Component → Semantic → Atomic
- ✅ Type Safety: Full TypeScript support with Zod validation
- ✅ Dark Mode: Built-in dark mode token overrides
- ✅ CSS Variables: Auto-generate CSS custom properties
- ✅ Zero Dependencies: Only Zod for runtime validation
🎯 Token Resolution
import { resolveToken, resolveWithFallback } from '@tekton/core';
resolveToken('atomic.color.blue.500', tokens);
resolveToken('component.button.primary.background', tokens);
resolveWithFallback(
'component.button.custom.background',
'semantic.foreground.accent',
'atomic.color.blue.500',
tokens
);
🌓 Dark Mode Support
const theme: ThemeWithTokens = {
darkMode: {
tokens: {
semantic: {
background: {
page: 'atomic.color.neutral.900',
surface: 'atomic.color.neutral.800',
},
},
component: {
button: {
primary: {
background: 'atomic.color.blue.400',
},
},
},
},
},
};
const css = generateThemeCSS(theme);
✅ Runtime Validation
import { validateTheme } from '@tekton/core';
const result = validateTheme(myTheme);
if (!result.valid) {
console.error('Validation errors:', result.errors);
}
API Reference
Token Module
import type { AtomicTokens, SemanticTokens, ComponentTokens, ThemeWithTokens } from '@tekton/core';
import { resolveToken, resolveWithFallback } from '@tekton/core';
import { generateThemeCSS } from '@tekton/core';
import { validateTheme } from '@tekton/core';
resolveToken(ref, tokens)
Resolves a token reference to its final value with multi-level resolution.
Parameters:
ref: string - Token reference in dot notation (e.g., 'atomic.color.blue.500')
tokens: ThemeWithTokens['tokens'] - Theme token structure
Returns: string - Resolved token value
Throws:
Error - If token not found
Error - If circular reference detected
Examples:
resolveToken('atomic.color.blue.500', tokens);
resolveToken('semantic.background.page', tokens);
resolveToken('component.button.primary.background', tokens);
resolveToken('#3b82f6', tokens);
resolveWithFallback(componentRef, semanticRef, atomicRef, tokens)
Resolves token with graceful fallback: Component → Semantic → Atomic.
Parameters:
componentRef: string - Component-level token reference
semanticRef: string - Semantic-level token reference (fallback)
atomicRef: string - Atomic-level token reference (final fallback)
tokens: ThemeWithTokens['tokens'] - Theme token structure
Returns: string - Resolved value from first successful resolution
Throws: Error - If all fallback attempts fail
Example:
resolveWithFallback(
'component.button.custom.background',
'semantic.foreground.accent',
'atomic.color.blue.500',
tokens
);
generateThemeCSS(theme)
Generates complete CSS with CSS Variables from theme tokens.
Parameters:
theme: ThemeWithTokens - Theme with 3-layer token structure
Returns: string - Generated CSS with :root and .dark selectors
Example:
const css = generateThemeCSS(theme);
validateTheme(theme)
Validates theme with token structure using Zod schemas.
Parameters:
theme: unknown - Theme object to validate
Returns: ValidationResult
interface ValidationResult {
valid: boolean;
errors?: string[];
}
Example:
const result = validateTheme(myTheme);
if (result.valid) {
console.log('✅ Theme is valid');
} else {
console.error('❌ Validation failed:');
result.errors?.forEach(err => console.error(` - ${err}`));
}
Theme Module
const theme = loadTheme('calm-wellness');
const themes = listThemes();
const isBuiltin = isBuiltinTheme('calm-wellness');
const cssVars = generateCSSVariables(theme);
const css = oklchToCSS({ l: 0.7, c: 0.1, h: 170 });
Blueprint Module
const blueprint = createBlueprint({
name: 'Page Name',
description: 'Optional description',
themeId: 'calm-wellness',
layout: 'single-column',
components: [{ type: 'Button', children: ['Click'] }],
});
const validation = validateBlueprint(blueprint);
if (!validation.valid) {
console.error(validation.errors);
}
isValidComponent('Button');
isValidComponent('FakeComponent');
const slots = getLayoutSlots('dashboard');
Render Module
const result = render(blueprint);
if (result.success) {
console.log(result.code);
}
const resultWithTheme = renderWithTheme(blueprint);
const result = render(blueprint, {
typescript: true,
indent: 2,
semicolons: true,
});
const jsx = renderSingleComponent({ type: 'Button', children: ['Click'] });
const jsx = renderComponents([
{ type: 'Heading', children: ['Title'] },
{ type: 'Text', children: ['Content'] },
]);
CSS Variables Naming Convention
The token system generates CSS Variables with a consistent naming pattern:
Atomic Tokens
--color-{palette}-{shade}: {value}
--spacing-{size}: {value}
--radius-{size}: {value}
--typography-{name}-size: {value}
--typography-{name}-line-height: {value}
--typography-{name}-weight: {value}
--shadow-{name}: {value}
--transition-{name}: {value}
Examples:
--color-blue-500: #3b82f6;
--color-neutral-50: #f9fafb;
--spacing-4: 16px;
--radius-md: 8px;
--typography-body-size: 16px;
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
Semantic Tokens
--{category}-{name}: {value}
Examples:
--background-page: #f9fafb;
--foreground-primary: #111827;
--border-default: #e5e7eb;
--surface-primary: #ffffff;
Component Tokens
--{component}-{variant}-{property}: {value}
--{component}-{variant}-{state}-{property}: {value}
Examples:
--button-primary-background: #3b82f6;
--button-primary-foreground: #ffffff;
--button-primary-hover-background: #2563eb;
--button-primary-disabled-foreground: #9ca3af;
--input-background: #ffffff;
--input-border: #e5e7eb;
--input-focus-ring: #3b82f6;
--input-error-border: #ef4444;
Dark Mode Overrides
Dark mode uses the same variable names but scoped to .dark class:
.dark {
--background-page: #111827;
--foreground-primary: #f9fafb;
--button-primary-background: #60a5fa;
}
Usage in Components:
.button-primary {
background: var(--button-primary-background);
color: var(--button-primary-foreground);
border-radius: var(--radius-md);
padding: var(--spacing-4);
}
.button-primary:hover {
background: var(--button-primary-hover-background);
}
.button-primary:disabled {
background: var(--button-primary-disabled-background);
color: var(--button-primary-disabled-foreground);
}
Migration Guide
From Old Theme System
Before (0.1.0):
const theme = loadTheme('calm-wellness');
const cssVars = generateCSSVariables(theme);
After (0.2.0 with Token System):
import type { ThemeWithTokens } from '@tekton/core';
import { generateThemeCSS } from '@tekton/core';
const theme = loadTheme('calm-wellness');
const themeWithTokens: ThemeWithTokens = {
...theme,
tokens: {
atomic: {
},
semantic: {
},
component: {
},
},
};
const css = generateThemeCSS(themeWithTokens);
Key Changes
- New Token Structure: 3-layer architecture (atomic/semantic/component)
- Type Safety: Full TypeScript support with
ThemeWithTokens interface
- Runtime Validation: Zod schema validation with
validateTheme()
- CSS Generation: New
generateThemeCSS() replaces generateCSSVariables()
- Dark Mode: Built-in dark mode support via
darkMode property
Breaking Changes
None - the token system is an additive feature in 0.2.0.
Available Layouts
single-column | header?, main, footer? |
two-column | header?, left, right, footer? |
sidebar-left | header?, sidebar, main, footer? |
sidebar-right | header?, main, sidebar, footer? |
dashboard | header, sidebar, main, footer? |
landing | hero, features?, cta?, footer? |
Available Components
Button, Input, Card, Text, Heading, Image, Link, List, Form, Modal, Tabs, Table, Badge, Avatar, Dropdown, Checkbox, Radio, Switch, Slider, Progress
Built-in Themes
calm-wellness - Soft, meditative atmosphere
dynamic-fitness - Energetic, bold design
korean-fintech - Clean, trustworthy finance
media-streaming - Dark, immersive entertainment
premium-editorial - Elegant, typography-focused
saas-dashboard - Professional, data-rich
saas-modern - Clean, modern SaaS
tech-startup - Bold, innovative tech
warm-humanist - Friendly, approachable
Architecture
@tekton/core (1,526 LOC)
├── Core Pipeline (742 LOC)
│ ├── types.ts (94 LOC) - Core type definitions
│ ├── theme.ts (131 LOC) - Theme loading & CSS generation
│ ├── blueprint.ts (169 LOC) - Blueprint creation & validation
│ ├── render.ts (297 LOC) - Template-based JSX generation
│ └── index.ts (51 LOC) - Public API exports
│
└── Token System (784 LOC) [NEW in 0.2.0]
├── tokens.ts (189 LOC) - 3-layer token type definitions
├── token-resolver.ts (146 LOC) - Token resolution & fallback logic
├── token-validation.ts (176 LOC) - Zod schema validation
└── css-generator.ts (273 LOC) - CSS Variables generation
Design Decisions
3-Layer Token Architecture:
- Atomic Layer: Raw design values (colors, spacing) - foundation
- Semantic Layer: Meaning-based mappings (background.page, foreground.primary) - context
- Component Layer: Component-specific bindings (button.primary.background) - usage
Benefits:
- Clear separation of concerns
- Maintainable theming system
- Type-safe token references
- Automatic dark mode support
- Scalable to complex design systems
Template-based rendering (not AST-based):
- Zero dependencies (no Babel, Prettier)
- Faster execution
- Easier to understand and debug
- Sufficient for JSX generation use case
What was removed:
- Babel AST builders
- Prettier formatting
- Slot registries (Global/Local)
- Semantic scoring engine
- Safety protocols (4 validators)
- MCP server infrastructure
- 13 unnecessary packages
Testing
pnpm test
pnpm test:watch
pnpm test:coverage
Current: 132 tests, 96.37% coverage
Test Coverage by Module
| Token Types | 28 | 100% |
| Token Resolution | 35 | 98.5% |
| Token Validation | 32 | 97.2% |
| CSS Generation | 37 | 95.8% |
| Core Pipeline | - | 83% |
Performance
Token system is highly optimized for production use:
- Token Resolution: < 1ms per token (avg 0.3ms)
- Multi-level Resolution: < 1ms for deep references
- CSS Generation: ~5ms for complete theme
- Validation: < 10ms for full theme structure
Benchmarked on Node.js 20, Apple M1.
License
MIT