Skip to content

Commit 7a0639b

Browse files
committed
docs: add troubleshooting, cookbook, visual architecture and performance guide
1 parent 5350277 commit 7a0639b

7 files changed

Lines changed: 529 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,16 @@ Use `manifest-only` in production (`autoPinLatestModuleManifest: false`) when yo
367367
## Integration Docs
368368

369369
- Architecture overview: [`docs/architecture.md`](docs/architecture.md)
370+
- Visual architecture diagrams (Mermaid): [`docs/architecture-visual.md`](docs/architecture-visual.md)
370371
- RuntimePlan IR reference: [`docs/runtime-plan-ir.md`](docs/runtime-plan-ir.md)
371372
- Runtime execution engine: [`docs/runtime-execution.md`](docs/runtime-execution.md)
372373
- Dependency verification model: [`docs/runtime-execution.md#verification-model`](docs/runtime-execution.md#verification-model)
373374
- Browser embedding: [`docs/browser-integration.md`](docs/browser-integration.md)
374375
- Security guide: [`docs/security.md`](docs/security.md)
375376
- Plugin system: [`docs/plugin-system.md`](docs/plugin-system.md)
377+
- Troubleshooting & FAQ: [`docs/troubleshooting-faq.md`](docs/troubleshooting-faq.md)
378+
- Cookbook / common integration patterns: [`docs/cookbook.md`](docs/cookbook.md)
379+
- Performance tuning guide: [`docs/performance-tuning.md`](docs/performance-tuning.md)
376380

377381
## Browser Examples
378382

docs/architecture-visual.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Visual Architecture (Mermaid)
2+
3+
This document provides visual diagrams for the main Renderify architecture paths.
4+
5+
## End-to-End Pipeline
6+
7+
```mermaid
8+
flowchart LR
9+
A[Prompt or RuntimePlan] --> B[CodeGen]
10+
B --> C[RuntimePlan IR]
11+
C --> D[Security Checker]
12+
D --> E[Runtime Manager]
13+
E --> F[UI Renderer]
14+
F --> G[DOM Output]
15+
16+
E --> H[JSPM Module Loader]
17+
H --> I[Primary CDN]
18+
H --> J[Fallback CDNs]
19+
```
20+
21+
## Package Dependency Map
22+
23+
```mermaid
24+
graph TD
25+
R[renderify] --> C[@renderify/core]
26+
R --> IR[@renderify/ir]
27+
R --> RT[@renderify/runtime]
28+
R --> S[@renderify/security]
29+
R --> L[@renderify/llm]
30+
31+
C --> IR
32+
C --> RT
33+
C --> S
34+
35+
RT --> IR
36+
RT --> S
37+
38+
S --> IR
39+
40+
CLI[@renderify/cli] --> R
41+
CLI --> C
42+
CLI --> L
43+
CLI --> RT
44+
```
45+
46+
## Runtime Source Execution Path
47+
48+
```mermaid
49+
flowchart TD
50+
A[plan.source code] --> B[Transpile TSX or JSX]
51+
B --> C[Extract imports]
52+
C --> D[Resolve specifiers]
53+
D --> E[Fetch remote modules]
54+
E --> F[Rewrite nested imports]
55+
F --> G[Create blob URLs]
56+
G --> H[dynamic import]
57+
H --> I[Export function or node]
58+
I --> J[Render artifact or RuntimeNode]
59+
```
60+
61+
## Sandbox Decision Flow
62+
63+
```mermaid
64+
flowchart TD
65+
A[Source execution requested] --> B{Sandbox mode}
66+
67+
B -->|none| C[Main thread execution]
68+
B -->|worker| D[Worker sandbox]
69+
B -->|iframe| E[Iframe sandbox]
70+
B -->|shadowrealm| F[ShadowRealm sandbox]
71+
72+
F --> G{ShadowRealm available?}
73+
G -->|yes| H[Execute in ShadowRealm]
74+
G -->|no| I[Fallback chain]
75+
I --> D
76+
I --> E
77+
78+
D --> J{Timeout or abort?}
79+
E --> J
80+
H --> J
81+
82+
J -->|no| K[Return result]
83+
J -->|yes| L[AbortError or timeout error]
84+
```
85+
86+
## Defense-in-Depth Security Layers
87+
88+
```mermaid
89+
flowchart TB
90+
A[Layer 1: Policy pre-check]
91+
B[Layer 2: Module host and manifest constraints]
92+
C[Layer 3: Runtime sandbox isolation]
93+
D[Layer 4: UI sanitization]
94+
95+
A --> B --> C --> D
96+
```
97+
98+
## Notes
99+
100+
- The diagrams intentionally show control flow, not every internal helper.
101+
- For type-level details, see [`docs/api-reference.md`](./api-reference.md).
102+
- For execution semantics, see [`docs/runtime-execution.md`](./runtime-execution.md).

docs/architecture.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This document describes the end-to-end architecture of Renderify, covering the pipeline stages, package responsibilities, data flow, and key design decisions.
44

5+
For Mermaid diagrams of the same architecture, see [`docs/architecture-visual.md`](./architecture-visual.md).
6+
57
## High-Level Pipeline
68

79
```

docs/cookbook.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Cookbook: Common Integration Patterns
2+
3+
This cookbook focuses on production-friendly patterns that appear repeatedly in Renderify integrations.
4+
5+
## Pattern 1: Renderer-Only Embed (No Built-In LLM)
6+
7+
Use when plan generation happens on your backend or another model pipeline.
8+
9+
```ts
10+
import { renderPlanInBrowser } from "renderify";
11+
import type { RuntimePlan } from "@renderify/ir";
12+
13+
const plan: RuntimePlan = {
14+
specVersion: "runtime-plan/v1",
15+
id: "renderer_only_card",
16+
version: 1,
17+
root: {
18+
type: "element",
19+
tag: "section",
20+
children: [{ type: "text", value: "Hello from external plan" }],
21+
},
22+
capabilities: { domWrite: true },
23+
};
24+
25+
await renderPlanInBrowser(plan, { target: "#mount" });
26+
```
27+
28+
## Pattern 2: Manifest-Pinned Production Execution
29+
30+
Use when reproducibility matters and dependency drift is not acceptable.
31+
32+
```ts
33+
import { renderPlanInBrowser } from "renderify";
34+
35+
await renderPlanInBrowser(planWithPinnedManifest, {
36+
target: "#mount",
37+
autoPinLatestModuleManifest: false,
38+
runtimeOptions: {
39+
enforceModuleManifest: true,
40+
enableDependencyPreflight: true,
41+
failOnDependencyPreflightError: true,
42+
},
43+
});
44+
```
45+
46+
Checklist:
47+
48+
- Pin every bare specifier in `moduleManifest`.
49+
- In strict mode, include `integrity` for remote modules.
50+
- Run `probe-plan` in CI before release.
51+
52+
## Pattern 3: Untrusted Source in Browser Sandbox
53+
54+
Use when `plan.source` originates from untrusted prompts.
55+
56+
```ts
57+
import { renderPlanInBrowser } from "renderify";
58+
59+
await renderPlanInBrowser(untrustedPlan, {
60+
target: "#mount",
61+
runtimeOptions: {
62+
browserSourceSandboxMode: "worker",
63+
browserSourceSandboxTimeoutMs: 4000,
64+
browserSourceSandboxFailClosed: true,
65+
},
66+
});
67+
```
68+
69+
Recommended policy posture:
70+
71+
- `RENDERIFY_SECURITY_PROFILE=strict`
72+
- `RENDERIFY_RUNTIME_BROWSER_SANDBOX_FAIL_CLOSED=true`
73+
- `RENDERIFY_RUNTIME_JSPM_ONLY_STRICT_MODE=true` (when you want no fallback CDN path)
74+
75+
## Pattern 4: Streaming Prompt to Progressive UI
76+
77+
Use when chat UX needs preview updates before final render.
78+
79+
```ts
80+
for await (const chunk of app.renderPromptStream(prompt, { previewEveryChunks: 2 })) {
81+
if (chunk.type === "llm-delta") {
82+
appendToken(chunk.delta);
83+
}
84+
85+
if (chunk.type === "preview") {
86+
renderPreviewHtml(chunk.html);
87+
}
88+
89+
if (chunk.type === "final") {
90+
commitFinalHtml(chunk.final.html);
91+
}
92+
93+
if (chunk.type === "error") {
94+
showError(chunk.error.message);
95+
}
96+
}
97+
```
98+
99+
## Pattern 5: Probe Before Execute (CI Gate)
100+
101+
Use when you need deterministic "will this render?" signals without executing source/component code.
102+
103+
```bash
104+
pnpm cli -- probe-plan examples/runtime/recharts-dashboard-plan.json
105+
```
106+
107+
A practical CI flow:
108+
109+
1. Run `probe-plan` for generated plans.
110+
2. Fail pipeline if `securityIssueCount > 0`.
111+
3. Fail pipeline if `preflightIssueCount > 0` in strict production lanes.
112+
113+
## Pattern 6: Controlled Network Scope for Remote Modules
114+
115+
Use when outbound network egress must be restricted.
116+
117+
```ts
118+
await renderPlanInBrowser(plan, {
119+
runtimeOptions: {
120+
allowArbitraryNetwork: false,
121+
allowedNetworkHosts: ["ga.jspm.io", "cdn.jspm.io", "esm.sh"],
122+
remoteFallbackCdnBases: ["https://esm.sh"],
123+
},
124+
});
125+
```
126+
127+
Keep `allowedNetworkHosts` and `remoteFallbackCdnBases` aligned so fallback URLs do not violate runtime host policy.
128+
129+
## Pattern 7: Explicit JSX Helper Behavior
130+
131+
Use when you want stable transpilation behavior across environments.
132+
133+
```ts
134+
await renderPlanInBrowser(planWithSource, {
135+
runtimeOptions: {
136+
runtimeSourceJsxHelperMode: "always", // "auto" | "always" | "never"
137+
},
138+
});
139+
```
140+
141+
- `auto`: runtime decides helper injection based on source/runtime mode.
142+
- `always`: always inject helper path (predictable for heterogeneous input).
143+
- `never`: only for advanced setups where helper wiring is external.
144+
145+
## Pattern 8: Serialized Target Renders (Avoid UI Race Conditions)
146+
147+
Use when multiple concurrent renders target the same mount element.
148+
149+
```ts
150+
await Promise.all([
151+
renderPlanInBrowser(planA, { target: "#mount", serializeTargetRenders: true }),
152+
renderPlanInBrowser(planB, { target: "#mount", serializeTargetRenders: true }),
153+
]);
154+
```
155+
156+
`renderPlanInBrowser` serializes operations per target element by default (`serializeTargetRenders !== false`). Keep it enabled unless you have a custom scheduler.
157+
158+
## Related Docs
159+
160+
- [`docs/getting-started.md`](./getting-started.md)
161+
- [`docs/runtime-execution.md`](./runtime-execution.md)
162+
- [`docs/security.md`](./security.md)
163+
- [`docs/troubleshooting-faq.md`](./troubleshooting-faq.md)

docs/getting-started.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pnpm format # Auto-format code
208208
## Next Steps
209209

210210
- [Architecture Overview](./architecture.md) — understand the full pipeline
211+
- [Visual Architecture (Mermaid)](./architecture-visual.md) — system diagrams for data flow and package boundaries
211212
- [RuntimePlan IR Reference](./runtime-plan-ir.md) — learn the intermediate representation
212213
- [Security Guide](./security.md) — security policies and profiles
213214
- [LLM Integration](./llm-integration.md) — provider configuration and structured output
@@ -216,4 +217,7 @@ pnpm format # Auto-format code
216217
- [CLI & Playground](./cli-playground.md) — CLI commands and playground features
217218
- [Browser Integration](./browser-integration.md) — embedding in web applications
218219
- [API Reference](./api-reference.md) — complete type and function reference
220+
- [Troubleshooting & FAQ](./troubleshooting-faq.md) — failure diagnostics and recovery checklist
221+
- [Cookbook](./cookbook.md) — copy-paste integration patterns
222+
- [Performance Tuning](./performance-tuning.md) — runtime knobs, CI guardrails, and optimization workflow
219223
- [Contributing Guide](./contributing.md) — development workflow and conventions

0 commit comments

Comments
 (0)