The user wants an "Architect" for a "contextual help composer."
This implies a system design or a high-level conceptual framework, not just a single piece of code.
The system needs to link three specific components:
Heuristics: Logic to determine when and what help to show (e.g., user is stuck, hovering over a button for too long, error occurred).
Macros: Reusable templates or logic blocks to generate dynamic content (e.g., "Hello {username}", "Click the {Red Button}").
Localization Ready Content: Strings that support translation (i18n) and formatting (pluralization, gender, etc.).
Goal: Create a robust architecture that allows non-technical writers (or developers) to compose help messages that appear at the right time, in the right language, with dynamic data inserted.
Content Authoring/Storage (The "Macros" & "Localization"):
Needs a structured format (JSON/YAML/Database).
Macros aren't just text snippets; they are template functions.
Localization means separating the key from the value and supporting ICU message format (or similar).
The Composer Engine (The "Brain"):
This sits between the triggers and the display.
It takes a trigger ID -> looks up logic -> fetches template -> resolves macros -> interpolates variables -> localizes -> renders.
The Delivery Layer (UI):
Tooltips, Modals, Beacoons, Banners.
Structuring the Answer:
High-Level Concept: Define what this system actually is (Headless CMS + Rule Engine).
System Architecture Diagram (Mental or ASCII): Visualizing the flow.
Component Deep Dive:
Heuristics Engine: How to detect context.
Macro System: Templating and dynamic data.
Localization Layer: i18n strategy.
Data Structure Example: Show what the JSON/Taxonomy looks like.
Workflow: How a user interacts with it.
Tech Stack Recommendations: Practical tools to build this.
Refining the "Macro" aspect:
The prompt mentions "linking heuristics, macros, and localization."
A "Macro" in this context could be:
A standard text block ("Welcome").
A dynamic variable insertion ("Welcome back, {User}").
A conditional logic block within the text (Plurals, Gender).
Maybe even "Action Macros" (e.g., a button that triggers a JS function).
Refining the "Heuristics" aspect:
This is the "Contextual" part. It needs to track state.
State Source: URL, DOM state, Redux/Store, API response, User Interaction logs.
Drafting the Architecture:
Input: User Action + App State.
Processor: Heuristic Matcher (Rules Engine).
Content Resolver: Fetches content ID based on match.
Composer:
Loads i18n string.
Applies Macros (Template Literal parsing).
Injects Context (Variables).
Output: Rendered UI component.
Let's build a specific schema example.
Trigger:checkout_fail
Content:
Key:help.checkout.error
Macro:{{format_currency(total)}}
Loc: English: "Payment failed for {{total}}."
Self-Correction during thought process:
Don't just list technologies. The user asked to Architect it. I need to provide a structural design.
I should define the contracts/interfaces between these systems.
Let's organize the response into logical layers: The Data Layer (Content/Macros), The Logic Layer (Heuristics), and The Integration Layer (The Composer).
Special focus: "Localization Ready Content"
This usually means ICU Message Format. The macros need to play nice with i18n.
Example: "You have {count, plural, one {# apple} other {# apples}}."
The "Composer" must handle this parsing.
Final Polish:
Ensure the distinction between "Static Macros" (reusable snippets) and "Dynamic Macros" (variables) is clear. The architecture should allow a help text to include another help text (nesting).
Plan:
Executive Summary: Define the goal.
Architecture Diagram: ASCII flow.
Core Modules:
The Context Observer (Heuristics).
The Template Engine (Macros).
The Translation Service (i18n).
The Data Schema: JSON structure.
The "Composer" Logic: Pseudo-code for the assembly.
Implementation Guide.
This looks solid. I will write the response following this structure.
This architecture defines a system for generating dynamic, context-aware user assistance. It moves beyond static FAQs by treating help content as a function of User State (Context), System Logic (Heuristics), Reusability (Macros), and Globalization (i18n).
Here is the architectural blueprint for the Contextual Help Composer.
1. High-Level Architecture
The system operates as a pipeline: Sensing → Decision → Composition → Rendering.
Context Aggregator: Gathers raw data (UI state, user profile, API errors).
Heuristic Engine: Applies rules to the context to determine intent (e.g., "User is confused").
Content Resolver: Selects the appropriate content ID based on the intent.
Composer: Inflates macros and localizes strings.
Presenter: Renders the UI element (Tooltip, Modal, Beacon).
2. Component Breakdown
A. The Context Aggregator (The Sensors)
This module creates a standardized Context Object. It abstracts the specific frontend framework (React, Vue, etc.) into a generic state.
Inputs:
DOM Events: Hover time, click patterns, focus state.
Route State: Current URL, query parameters.
Data State:is_loaded, is_empty, error_code.
User Profile:role, preferences, language_tag.
Output:ContextSnapshot
B. The Heuristic Engine (The Brain)
This layer determines if and when to interrupt the user. It uses a rule-based system (which can be extended to ML later).
Logic: A rule consists of a Trigger and a Condition.
Error Context: API 403 error on /admin route → Trigger "Permission Intent".
Feature Discovery: User logged in > 30 days + never used "Export" feature → Trigger "Nudge Intent".
C. The Localization Strategy (i18n)
We do not store static strings. We store ICU Message Formats. This allows the logic to handle gender, plurals, and complex sentence structures dynamically.
Structure: Content is keyed by a semantic ID, not a UI path.
Fallback Chain:en-US→en→default_key.
D. The Macro System (The Composer)
Macros allow for dynamic content insertion. They prevent the need for hard-coding every variation of a help message.
Variable Injection:{{user.name}}
Functional Macros:{{format_date last_login}}
Component Macros:{{button action="navigate" label="Go to Settings"}}
3. The Data Schema
To link these components, we need a unified data structure. We will use a JSON-based definition file.
This represents the "Source of Truth" for the text, stored in a database or flat files.
json
{
"content_id": "help.dashboard.intro",
"variants": {
"en-US": {
"message": "Welcome back, {userName}! It looks like you haven't created any {macro:link_to_projects} yet. {macro:emoji_wave}",
"context": "Displayed when the project list is empty."
},
"es-ES": {
"message": "¡Bienvenido, {userName}! Parece que aún no has creado ningún {macro:link_to_projects}. {macro:emoji_wave}"
}
}
}
4. The Composition Workflow
When the Heuristic Engine fires, the Composer takes over to assemble the final string.
Step 1: Fetch Template
Retrieve the string: "Welcome {user.name}, you have {count} items."
Step 2: Resolve Macros (Pre-i18n)
Some macros must be resolved before translation (e.g., dynamic nouns).
Input: {{project_name}}→ Output: "Project Alpha"
Step 3: Localization Interpolation
Inject variables into the ICU string.
Handle pluralization logic (e.g., "1 item" vs "5 items").
Step 4: Sanitize & Render
Sanitize HTML/Markdown.
Render the final React/Vanilla JS component.
5. Implementation Logic (Pseudo-code)
Here is the core HelpComposer class logic linking the systems.
javascript
class HelpComposer {
constructor(heuristicDb, i18nStore, macroRegistry) {
this.heuristics = heuristicDb;
this.i18n = i18nStore;
this.macros = macroRegistry;
}
// 1. Receive Context from the App
evaluateContext(contextSnapshot) {
const triggeredActions = this.heuristics.match(contextSnapshot);
triggeredActions.forEach(action => {
if (action.type === 'render_tooltip') {
this.composeAndRender(action.content_id, contextSnapshot, action.target_element);
}
});
}
// 2. The Composition Pipeline
composeAndRender(contentId, context, targetEl) {
// A. Load Localization
const template = this.i18n.getLocalizedMessage(contentId, context.user.locale);
// B. Extract & Resolve Macros
// Regex finds {macro:function args} or {variable}
const parsedContent = this.resolveMacros(template, context);
// C. Final Interpolation (Variables)
// Replaces {user.name} with "Alice"
const finalString = this.interpolate(parsedContent, context.variables);
// D. Render
UI.renderTooltip(targetEl, finalString);
}
resolveMacros(template, context) {
// Custom logic to replace macro placeholders with complex components or logic
return template.replace(/{macro:(\w+)}/g, (match, macroName) => {
return this.macros.execute(macroName, context);
});
}
}
6. Directory Structure
A proposed file structure to keep this maintainable:
text
/src
/help-system
/heuristics
rules.yaml # Defines the logic triggers
engine.js # Logic matcher
/content
/en-US
dashboard.json # Localization keys
common.json # Shared macros/text
/es-ES
dashboard.json
/macros
index.js # Registry of available macros (e.g., link resolver)
composer.js # The main class above
context-aggregator.js # Gathers app state
7. Best Practices for this Architecture
Asynchronous Loading: Load the heavy localization files and heuristic rules only when the Help System is initialized, not on initial app load.
Editor UI: Build a visual editor where non-technical writers can edit the YAML/JSON content. They should see the macros as clickable "tokens" rather than raw code.
A/B Testing: The Heuristic Engine should support probability weights (e.g., "Show Version A to 50% of users") to test which help content reduces support tickets.
Context Hydration: Ensure the contextSnapshot includes a hash of the UI layout version. If the UI changes, the help targeting (DOM selectors) might break.