Internals
CalibrateDS (ptb) operates as a pipeline. It extracts data, normalizes it, and passes it to generators.
Pipeline Architecture
- Figma API: The raw data source.
- Scanner & Normalizer: The
packages/corelogic that reads the raw JSON and creates theDesignSystemModel. - Diff & Plan: Compares the snapshot against the previous version to identify affected components and determine the dependency order.
- Generator Registry: Dispatches the model to a framework-specific generator plugin (like React).
Generator Plugins
Generators are framework plugins registered at CLI startup.
Every generator implements IGenerator:
interface IGenerator {
writeComponents(model, config, options?): Promise<WriteComponentsReport>;
writeTokens(model, config, options?): Promise<WriteTokensReport>;
writeScaffold(args: ScaffoldArgs): Promise<ScaffoldWriteReport>;
pruneComponents(config, staleEntries): Promise<PruneResult>;
}
The current implementation is ptbReactGenerator. To add support for Vue or Svelte, a new package implementing IGenerator would be registered.
Inline Metadata Headers
Every file written by PTB includes a PTB_METADATA comment header. This is how PTB detects user-modified files to avoid accidentally overwriting manual code.
// PTB_METADATA {"componentId":"...","contextHash":"abc123","generatedAt":"...","framework":"react"}
If you remove this header, PTB assumes you want to take over ownership of the file and will never overwrite it without the --force flag.
Next Steps
Learn how to enforce design drift in CI in the CI Integration guide.