# isaqueseneda/shieldfont architecture

> Architecture diagram of the GitHub repository isaqueseneda/shieldfont, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/isaqueseneda/shieldfont
- Repository: https://github.com/isaqueseneda/shieldfont

## Overview

#### Purpose and package surface
ShieldFont protects server/build-time-authored English text from non-rendering scrapers. It substitutes source words with grammatical decoys in HTML, then an OpenType font reverses substitutions visually. Published surfaces are a TypeScript core encoder, React integration, and paste-in font/CDN package: `packages/core/src/index.ts`, `packages/react/src/index.ts`, `packages/font/shieldfont-encoder.js`.

#### Core encoding and mappings
`@shieldfont/core` is the canonical build-time boundary: plaintext must be transformed before browser delivery. Encoding, token/mapping handling, markers, and public types are centered in `packages/core/src/encode.ts`, `packages/core/src/mapping.ts`, `packages/core/src/markers.ts`. Shipped mapping datasets—including default alpha and sibling keys—live at `packages/core/src/mappings/alpha.json`, `packages/core/src/mappings/beta.json`, and `packages/core/src/mappings/gamma.json`.

#### Render-time font reversal
The rendered HTML contains decoy words; shielded font binaries use OpenType substitution rules to display original words to visual readers. The distributable CSS/JS encoder layer is `packages/font/shieldfont.css` and `packages/font/shieldfont-encoder.js`. Font construction is a Python/fontTools pipeline, principally `scripts/generate_font.py`, with mapping material prepared in `scripts/v18alpha_for_font.json` and font auditing in `scripts/audit_font.py`. Neutral/non-shielded font use is architecturally necessary for headings and other unprotected text.

#### React server-rendering integration
`@shieldfont/react` provides the primary application entry points: `<Shield>` emits encoded, shield-font content and integrates safeguards; `<NonShield>` emits unprotected text using the neutral face. These are implemented in `packages/react/src/Shield.tsx`, `packages/react/src/NonShield.tsx`, and exported by `packages/react/src/index.ts`. This package targets React applications that render in Node or at build time; client-only SPA content must instead be pre-encoded through core.

#### Accessibility recovery path
Shielded visible text is hidden from assistive technology, while real text is sealed into the page and recovered client-side after a costly puzzle. The React accessibility/control flow is split across `packages/react/src/Shield.tsx`, `packages/react/src/puzzle.ts` (not present in tree; actual puzzle code is `packages/core/src/puzzle.ts`), and `packages/react/src/solver.ts`. This is an intentional usability/accessibility tradeoff, not WCAG-conformant content.

#### Data/control flow and security boundary
Author plaintext flows: server/build process → core/react encoder → decoy HTML plus shield-font CSS → browser visual font substitution. Accessibility follows a separate encrypted/puzzle-gated recovery path. The critical boundary is server versus client: plaintext must never enter client bundles, APIs, feeds, metadata, or readable browser DOM. Font files are a recoverable codebook, so protection is economic against bulk non-rendering extraction rather than cryptographic secrecy.

#### Delivery, validation, and research assets
The repository uses Node/TypeScript for packages and scripts, Python for font generation/auditing, and GitHub Actions for tests/publishing: `.github/workflows/test.yml`, `.github/workflows/publish.yml`, `package.json`, `requirements.txt`. A Next.js reference consumer is `examples/nextjs-demo/app/page.tsx`. Benchmark datasets and evaluation scripts support claims about semantic disruption and filter behavior: `benchmark/data/v8/scripts/eval_phase1_semdiv.py`, `benchmark/data/v8/scripts/gate_fineweb_edu.py`, `benchmark/data/v8/results/FINAL_REPORT.md`.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core encoding"]
  node_core_index["Core public API<br/>TypeScript package<br/>[index.ts]"]
  node_encode["Encoder<br/>TypeScript module<br/>[encode.ts]"]
  node_mapping["Token mappings<br/>TypeScript module<br/>[mapping.ts]"]
  node_markers["Markers &amp; types<br/>TypeScript module<br/>[markers.ts]"]
  node_datasets[("Mapping datasets<br/>JSON datasets<br/>[alpha.json]")]
  node_puzzle["Puzzle sealing<br/>TypeScript module<br/>[puzzle.ts]"]
end

subgraph group_react["React integration"]
  node_react_index["React public API<br/>React package<br/>[index.ts]"]
  node_shield["Shield<br/>React component<br/>[Shield.tsx]"]
  node_nonshield["NonShield<br/>React component<br/>[NonShield.tsx]"]
  node_solver["Accessibility solver<br/>TypeScript module<br/>[solver.ts]"]
end

subgraph group_font["Font pipeline &amp; delivery"]
  node_font_generator["Font generator<br/>Python/fontTools script<br/>[generate_font.py]"]
  node_font_mapping["Font mapping material<br/>JSON input"]
  node_font_assets["Shield font assets<br/>CSS &amp; JS delivery<br/>[shieldfont.css]"]
end

subgraph group_validation["Validation &amp; research"]
  node_ci["CI &amp; publishing<br/>GitHub Actions<br/>[publish.yml]"]
  node_next_demo["Next.js reference consumer<br/>example application<br/>[page.tsx]"]
  node_benchmark["Semantic-disruption evaluation<br/>benchmark scripts &amp; report"]
end

node_author["Author plaintext<br/>input"]
node_browser(("Browser rendering<br/>browser runtime"))

node_core_index -->|"exports"| node_encode
node_encode -->|"uses"| node_mapping
node_encode -->|"uses"| node_markers
node_mapping -->|"loads"| node_datasets
node_author -->|"server/build-time input"| node_encode
node_react_index -->|"exports"| node_shield
node_react_index -->|"exports"| node_nonshield
node_shield -->|"encodes"| node_encode
node_shield -->|"seals real text"| node_puzzle
node_puzzle -.->|"gated recovery payload"| node_solver
node_shield -->|"decoy HTML"| node_browser
node_nonshield -->|"neutral text"| node_browser
node_font_mapping -->|"build input"| node_font_generator
node_font_generator -->|"produces shield font"| node_font_assets
node_font_assets -->|"CSS/font delivery"| node_browser
node_browser -.->|"assistive recovery"| node_solver
node_next_demo -->|"consumes"| node_react_index
node_ci -->|"tests/publishes"| node_core_index
node_ci -->|"tests/publishes"| node_react_index
node_ci -->|"publishes"| node_font_assets
node_benchmark -.->|"evaluates mappings"| node_datasets

click node_core_index "https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/index.ts"
click node_encode "https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/encode.ts"
click node_mapping "https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/mapping.ts"
click node_markers "https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/markers.ts"
click node_datasets "https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/mappings/alpha.json"
click node_puzzle "https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/puzzle.ts"
click node_react_index "https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/index.ts"
click node_shield "https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/Shield.tsx"
click node_nonshield "https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/NonShield.tsx"
click node_solver "https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/solver.ts"
click node_font_generator "https://github.com/isaqueseneda/shieldfont/blob/main/scripts/generate_font.py"
click node_font_mapping "https://github.com/isaqueseneda/shieldfont/blob/main/scripts/v18alpha_for_font.json"
click node_font_assets "https://github.com/isaqueseneda/shieldfont/blob/main/packages/font/shieldfont.css"
click node_ci "https://github.com/isaqueseneda/shieldfont/blob/main/.github/workflows/publish.yml"
click node_next_demo "https://github.com/isaqueseneda/shieldfont/blob/main/examples/nextjs-demo/app/page.tsx"
click node_benchmark "https://github.com/isaqueseneda/shieldfont/blob/main/benchmark/data/v8/scripts/eval_phase1_semdiv.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core_index,node_encode,node_mapping,node_markers,node_datasets,node_puzzle toneBlue
class node_react_index,node_shield,node_nonshield,node_solver toneAmber
class node_font_generator,node_font_mapping,node_font_assets toneMint
class node_ci,node_next_demo,node_benchmark toneRose
class node_author,node_browser toneNeutral
```

## Components

### Core encoding

Canonical server/build-time transformation boundary.

- [Core public API](https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/index.ts): TypeScript package · Published @shieldfont/core surface. · `packages/core/src/index.ts`
- [Encoder](https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/encode.ts): TypeScript module · Transforms plaintext into grammatical decoys before delivery. · `packages/core/src/encode.ts`
- [Token mappings](https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/mapping.ts): TypeScript module · Handles substitution mappings and tokens. · `packages/core/src/mapping.ts`
- [Markers & types](https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/markers.ts): TypeScript module · Defines shielding markers and public types. · `packages/core/src/markers.ts`
- [Mapping datasets](https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/mappings/alpha.json): JSON datasets · Default alpha plus beta and gamma substitution codebooks. · `packages/core/src/mappings/alpha.json`
- [Puzzle sealing](https://github.com/isaqueseneda/shieldfont/blob/main/packages/core/src/puzzle.ts): TypeScript module · Seals real text for gated assistive-technology recovery. · `packages/core/src/puzzle.ts`

### React integration

Server-rendered React entry points and accessibility recovery.

- [React public API](https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/index.ts): React package · Published @shieldfont/react surface. · `packages/react/src/index.ts`
- [Shield](https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/Shield.tsx): React component · Emits encoded shield-font content and accessibility safeguards. · `packages/react/src/Shield.tsx`
- [NonShield](https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/NonShield.tsx): React component · Renders unprotected text with the neutral font face. · `packages/react/src/NonShield.tsx`
- [Accessibility solver](https://github.com/isaqueseneda/shieldfont/blob/main/packages/react/src/solver.ts): TypeScript module · Client-side puzzle-gated recovery flow. · `packages/react/src/solver.ts`

### Font pipeline & delivery

OpenType reversal generation and browser assets.

- [Font generator](https://github.com/isaqueseneda/shieldfont/blob/main/scripts/generate_font.py): Python/fontTools script · Builds OpenType substitution fonts from mapping material. · `scripts/generate_font.py`
- [Font mapping material](https://github.com/isaqueseneda/shieldfont/blob/main/scripts/v18alpha_for_font.json): JSON input · Prepared mapping input for font construction. · `scripts/v18alpha_for_font.json`
- [Shield font assets](https://github.com/isaqueseneda/shieldfont/blob/main/packages/font/shieldfont.css): CSS & JS delivery · Distributable encoder and shield/neutral font styling. · `packages/font/shieldfont.css`

### Validation & research

CI, reference consumer, and evaluation assets.

- [CI & publishing](https://github.com/isaqueseneda/shieldfont/blob/main/.github/workflows/publish.yml): GitHub Actions · Tests and publishes package surfaces. · `.github/workflows/publish.yml`
- [Next.js reference consumer](https://github.com/isaqueseneda/shieldfont/blob/main/examples/nextjs-demo/app/page.tsx): example application · Server-rendering integration example. · `examples/nextjs-demo/app/page.tsx`
- [Semantic-disruption evaluation](https://github.com/isaqueseneda/shieldfont/blob/main/benchmark/data/v8/scripts/eval_phase1_semdiv.py): benchmark scripts & report · Measures semantic disruption and filter behavior. · `benchmark/data/v8/scripts/eval_phase1_semdiv.py`

### Other components

- **Author plaintext**: input · English source text authored only on trusted server/build systems.
- **Browser rendering**: browser runtime · Displays original words through OpenType substitutions; decoys remain in DOM.

## Connections

- Core public API → Encoder: exports
- Encoder → Token mappings: uses
- Encoder → Markers & types: uses
- Token mappings → Mapping datasets: loads
- Author plaintext → Encoder: server/build-time input
- React public API → Shield: exports
- React public API → NonShield: exports
- Shield → Encoder: encodes
- Shield → Puzzle sealing: seals real text
- Puzzle sealing → Accessibility solver: gated recovery payload
- Shield → Browser rendering: decoy HTML
- NonShield → Browser rendering: neutral text
- Font mapping material → Font generator: build input
- Font generator → Shield font assets: produces shield font
- Shield font assets → Browser rendering: CSS/font delivery
- Browser rendering → Accessibility solver: assistive recovery
- Next.js reference consumer → React public API: consumes
- CI & publishing → Core public API: tests/publishes
- CI & publishing → React public API: tests/publishes
- CI & publishing → Shield font assets: publishes
- Semantic-disruption evaluation → Mapping datasets: evaluates mappings
