Architecture ποΈ
Stackwright is a typed DSL that compiles YAML into production-ready Next.js applications.
Visual rendering + constrained grammar + AI iteration = non-technical people building enterprise apps that are safe by construction.
The Big Picture
Stackwright transforms your intent into a working app through a predictable pipeline:
Data Flow
Here's what happens when you build a Stackwright site:
YAML β JSON Transformation
The prebuild step compiles your YAML into static JSON. Here's what that looks like:
YAML β JSON
Package Architecture
Stackwright is a pnpm monorepo with 10 packages. Here's how they relate:
File Structure
Where everything lives in the monorepo:
Package Details
Here's what each package does:
@stackwright/core
**The engine.** YAMLβReact compilation, component registry, content rendering, hooks, utilities. Exports: `renderContent()`, `stackwrightRegistry`, `registerComponent()`.
@stackwright/types
**The grammar.** Zod schemas for all content types, TypeScript types, JSON schemas for IDE support. The source of truth for what's valid YAML.
@stackwright/nextjs
**The adapter.** Next.js-specific components: `StackwrightImage`, `StackwrightLink`, `createStackwrightNextConfig()`. Handles App Router and Pages Router.
@stackwright/themes
**The skin.** CSS custom properties theming, `ThemeProvider`, `ColorModeScript` for dark mode. Your stackwright.yml colors become CSS variables.
@stackwright/build-scripts
**The compiler.** Prebuild pipeline: YAMLβJSON compilation, image copying, search index generation. Runs before `next build` via predev/prebuild hooks.
@stackwright/cli
**The CLI.** `npx launch-stackwright`, `stackwright validate`, `stackwright preview`. Developer interface for scaffolding and testing.
@stackwright/mcp
**The AI bridge.** MCP server exposing content authoring tools, visual rendering preview, git workflow to AI agents. Enables the Otter Raft.
@stackwright/icons
**The icons.** Lucide icon registry. `registerDefaultIcons()` makes all Lucide icons available by name in YAML. Add custom icons the same way.
@stackwright/ui-shadcn
**The components.** Radix UI primitives styled with Tailwind CSS: Accordion, Tabs, Dialog, etc. More flexible than core components for complex UI.
Component Registry
The component registry maps YAML `type` values to React components:
Safe by Construction
Stackwright's constrained grammar creates a fundamentally different security posture:
Bounded Expressiveness
The Zod schema defines exactly what behaviors are possible. No escape hatch to arbitrary code execution. You audit the framework once β every app is safe.
Build-Time Validation
Every content change is validated against the schema before it reaches the browser. Bad YAML fails the build, not the user.
Auditable Surface Area
Security review reduces to reviewing the component library β a fixed, bounded codebase. Not thousands of YAML files.
Safe AI Generation
When an AI agent generates YAML, it literally cannot express unsafe behavior. The schema is the security policy.
Common Extension Points
Stackwright apps are standard Next.js apps. Extend freely:
Custom Components
Add React components anywhere in the page:
```tsx
// pages/index.tsx
<PageLayout {...props}>
<MyCustomWidget />
</PageLayout>
Custom Content Types
Register new YAML types:
```tsx
registerComponent(
'my-type',
MyComponent
);
Custom Providers
Add React context providers:
```tsx
<MyProvider>
<PageLayout {...props} />
</MyProvider>
Custom Prebuild
Extend the prebuild pipeline:
```ts
// stackwright.yml
prebuild:
hooks:
afterCompile: myTransform