# StyleSeed Engine Architecture
StyleSeed's goal is to make expert design judgment repeatable by coding agents. The current
engine converts recorded intent and visual evidence into a design method, separating **core
floors**, **task-specific grammar**, and **project-specific choices**. It supports experts rather
than replacing them with one universal aesthetic. A compiled contract is not proof of expert
approval or of the resulting design quality; see `PRODUCT-PRINCIPLES.md`.

## System flow
```mermaid
flowchart LR
A[Product brief
domain · surface · page] --> B{Grammar source}
R[User references
images · URLs · existing UI] --> C[Reference compiler]
C --> D[Project-local grammar
evidence · confidence · tokens · checks]
B --> E[Built-in output grammar]
D --> F[Context compiler
ss-resolve]
E --> F
P[Core judgment
non-negotiable] --> F
S[Surface adapter
canvas · renderer · export] --> F
X[Domain + page type] --> F
Z[Brand recipe
morphology · components] --> F
Q[Palette engine
posture · key color · OKLCH · role graph] --> F
Y[Optional style profile] --> F
L[STYLESEED.md
bounded selections] --> F
F --> K[Effective rule bundle
manifest + source hashes]
K --> G[Agent build method]
G --> H[Code gate
ss-score]
H -->|fix loop| G
H --> I[Pixel gate
ss-verify]
I -->|fix + re-render| G
I --> T[Temporal gate
record · frames · interrupt]
T -->|fix + re-record| G
T --> U[Human acceptance
named reviewer]
U --> J[Designed output
code · visual · temporal evidence]
U -->|explicit capture only| V[Local learning candidate
generalized · privacy-minimized]
V --> W[Separate human review]
W -->|explicit export only| X2[Local share package
no transport]
X2 -->|one-time grant| M[Local MCP bridge]
M -->|grant consumed| N[Connected client/model
exposure disclosed]
```
## Artifact registry boundary
For registry projects, `.styleseed/project.json` contains project-wide design DNA and
`.styleseed/artifacts/index.json` names independent artifact contracts. Each artifact owns its target,
implementation roots, validation contract, compiled bundle, manifest, and evidence run. A skill first
resolves one artifact ID, verifies its manifest and actual output bytes, and reads only that artifact's
bundle. The legacy `.styleseed/effective-rules.md` and `.styleseed/manifest.json` pair is a compatibility
path for projects without a registry; it is never a fallback inside a registry project.
The machine-readable `engine/skill-contracts.json` matrix records which skills consume a bundle, may
select a grammar, may mutate project configuration, and which computed evidence level they may claim.
`scripts/validate-skill-contracts.mjs` checks that matrix against the canonical skills before generation.
Project instruction files are not silently rewritten. `scripts/write-managed-instructions.mjs` is dry-run
by default and writes only with explicit `--write`; it preserves text outside the managed markers and
refuses symlinks, hardlinks, malformed markers, and multiple managed blocks.
## Layers and authority
| Layer | Responsibility | May change | May not change |
|---|---|---|---|
| Product constitution | Stable design judgment | maintained invariants | per-project aesthetics |
| Output grammar | Organize attention and action for an output class | bounded twelve-axis contract | accessibility or core coherence |
| Surface adapter | Translate method into an artifact/render contract | canvas, safe zones, export, surface QA | visual authority or product judgment |
| Reference compiler | Derive a local grammar from evidence | local rules with confidence | global built-ins or protected assets |
| Domain + page playbooks | Contextual composition bias | content/order/detail decisions | grammar identity |
| Brand recipe | Apply reusable morphology and component selection | geometry, containment, controls, collections | grammar job, protected brand assets, or accessibility |
| Palette engine | Bind semantic roles to the job; derive ramps, companions, surfaces, and media anchors from a key color | posture, bounded generation inputs, validated project output | contrast, status meaning, or independent hierarchy |
| Aesthetic profile | Coordinated look adjustment | radius, density, tone, motion within bounds | task structure |
| Design lock | Persist selected values and recorded project decisions | known enums, project tokens, decisions, and exceptions to defaults | waive an invariant or apply an unrecorded exception |
| Context compiler | Emit the selected method with provenance | deterministic bundle + manifest | silently invent or merge unknown IDs |
| Build skills | Apply the compiled method | implementation | self-certify without evidence |
| Score + verify | Detect code and pixel drift | fixes needed to comply | redefine the chosen method |
| Local learning | Preserve a generalized, human-approved correction as candidate evidence | local capture, review, and opt-in packaging | scan projects, transmit raw material, or rewrite core rules automatically |
## Grammar sources
### Built-in
Maintained in `RULESETS.md`. Built-ins require independent evidence, counterexamples, rendered
samples, and regression coverage. They are selected by output job: consumer service,
operations console, technical instrument, editorial reading, commerce conversion,
institutional service, or expressive marketing.
### Reference-compiled
`/ss-reference` runs `REFERENCE-COMPILER.md`. It ingests user references, fills the same
twelve-axis schema, cites evidence and confidence, and writes a project-local grammar under
`.styleseed/rulesets/`. A transfer screen proves that the result is a reusable language rather
than a clone of one source screen.
## Runtime compilation
`ss-resolve` resolves conflicts by authority and writes one effective rule set for the agent:
```text
effectiveRules, manifest = compile(
coreJudgment,
outputGrammar,
surfaceAdapter,
domainPlaybook,
pageType,
brandRecipe,
paletteRecipe,
optionalStyleProfile,
boundedDesignLock
)
```
The default output is `.styleseed/effective-rules.md` plus `.styleseed/manifest.json`. A typical
built-in selection is 10–20KB, while `llms-full.txt` remains an archive/debug mirror. The
manifest records the exact selection, source hashes, bundle hash, and byte size; `--check`
fails when the stored bundle no longer matches its sources or lock.
The design lock stores selections; it is not executable policy. Unknown grammar, adapter,
domain, page, recipe, palette, or profile IDs are rejected. Project-local reference grammars
require a maintained built-in fallback.
## Non-web outputs
`ADAPTERS.md` lets the same method drive product UI, social carousels, slide decks, documents,
and single-frame graphics. The companion renderer owns physical production constraints. For
example, StyleSeed supplies the `sequential-story` grammar and brand system while the Claude
`carousel-build` skill owns Instagram canvas, safe zones, crop, PIL rendering, and export QA.
## Verification model
Every renderable artifact uses two auxiliary gates because source correctness and rendered
quality fail in different ways:
- `ss-score` reads implementation evidence: tokens, hierarchy, states, semantics, coherence,
and characteristic grammar tells.
- `ss-verify` renders the result and checks pixels: task-appropriate attention, type loading,
balance, optical rhythm, responsive behavior, and state rendering.
Both gates return to the build loop. Interactive Studio runs add a temporal gate for actual
recording, interruption, and reduced motion, followed by named human acceptance. A static output
may mark temporal as not applicable, but it may not fabricate motion evidence. None of the gates
is the design engine; the composed method is.
Interactive builds also declare required user outcomes in the optional artifact field
`validation.functional.scenarios`. The `ss-score` functional runner executes explicit local
Node tests against declared implementation roots and retains the raw events. Missing, failed,
skipped, or stale functional evidence blocks completion independently of appearance scores.
The field is optional for compatibility; omission reports `not-required`, not functional
verification. See the installed `ss-score/references/functional-checks.md` for coverage and
runner limitations. These tests do not establish production success or expert design quality.
## Extension boundary
- Add a new built-in grammar only after the promotion rule in `RULESETS.md` passes.
- Use `/ss-reference` for project-specific or emerging languages.
- Add a brand recipe only when reusable morphology is supported by independent sources and
transfer tests; never add a company clone.
- Add a palette recipe only when its semantic role pairs pass deterministic contrast checks and
its hierarchy survives both light/dark context and generated-media use.
- Change the palette generator only with deterministic matrix tests across hues, light/dark modes,
perceptual characters, gamut boundaries, and semantic contrast pairs.
- Add a new aesthetic profile only when it is a full coordinated axis contract, not a mood word.
- Keep components and skins downstream. They implement a decision; they do not decide.
- Treat optional `extensions/learning/` `ss-learn` output as candidate evidence only. The extension
is not part of the core install. Promote its output to team or core rules only after
independent-project repetition, counterexamples, accessibility and grammar regressions, benchmark
evidence, and named maintainer approval.
## Scoped spatial roles
Registry product UI can persist optional project/artifact `spacing`: six independent whitespace
roles with base/wide values or existing CSS token references. The compiler includes effective
roles and scoped CSS in the bundle and method hash; application code must consume those variables.
Artifact overrides replace only named roles. Read-only starting proposals never overwrite config,
and numeric compliance does not prove design quality. See
[the spatial contract](.claude/skills/styleseed/workflows/ss-resolve/references/spacing.md) for limits and verification.
## Project decisions
Registry projects keep approved decisions and approved exceptions in `project.json` `decisions`:
each entry has an id, a statement, who approved it and when, and optionally a measured axis with
values, a scope of screens or artifacts, and the catalog rule or decision it refers to. A decision
outranks a catalog default and never an invariant; an exception adds allowed values to a decision or
a default rule, and an exception against an invariant fails the resolve. The compiler lists the
entries that apply to an artifact in its rules section (so they are part of the method hash), and
the drift report measures screens against them: `violates` for a value outside a decision, `approved`
for one an exception covers. See [the decisions ledger](.claude/skills/styleseed/workflows/ss-resolve/references/decisions.md).
## Imported token canon
A project with an existing design system records its token file in `project.json` (`tokens`:
`source`, `format` dtcg · tokens-studio · figma-variables, `modes`, `roles`). The compiler then reads
that file instead of running the palette generator: it resolves aliases, checks the designer's
layering (primitive → semantic fg/bg/bd → type → component) when the file uses it, reads one named
mode per collection, maps the eighteen semantic roles onto imported tokens (canon paths by default,
explicit `roles` otherwise), and measures the eleven contrast gates. Structural problems stop the
resolve; a missing role is an error that names the mapping to add. Only imported values reach the
bundle, the palette JSON and the `--ss-*` CSS; the recipe keeps its posture and withholds its hex.
The token file is a manifest input and part of the method hash, so `--check` reports when it changes.
Presets and generation remain the greenfield path. See
[the token canon guide](.claude/skills/styleseed/workflows/ss-resolve/references/tokens.md).
## Applied color and typography observations
The installed verify workflow includes a read-only browser probe for explicitly bound color
consumers and type specimens. It observes one artifact, viewport, state, and font condition;
unsupported paint and unknown glyph selection are not a visual pass. It reuses the existing
spatial probe for wrapping/overflow and leaves source binding, screenshots, applicable state
coverage, and human judgment with the host workflow. See
[applied checks](.claude/skills/styleseed/workflows/ss-verify/references/applied-checks.md).
These observations introduce no registry fields, aesthetic score, or automatic gate promotion.