Main Concepts
System Architecture
1┌────────────────────────────────────────────────────────────────┐2│ Reface │3│ │4│ ┌─────────────┐ ┌────────────┐ │5│ │ Deno │ │ Router │ │6│ │ Server │─────────▶│ System │ │7│ └─────────────┘ └────────────┘ │8│ │ │ │9│ ▼ ▼ │10│ ┌─────────────┐ ┌────────────┐ │11│ │ Static │ │ Layouts │ │12│ │ Files │ │ │ │13│ └─────────────┘ └────────────┘ │14│ │ │15│ ▼ │16│ ┌─────────────────────────────────────────────────────┐ │17│ │ RefaceComposer │ │18│ │ │ │19│ │ ┌──────────┐ ┌─────────────────────────┐ │ │20│ │ │ Plugin │───▶│ Template Process │ │ │21│ │ │ System │ │ │ │ │22│ │ └──────────┘ │ 1. createTemplateFactory │ │23│ │ │ │ ↓ │ │ │24│ │ │ │ 2. createTemplate │ │ │25│ │ │ │ ↓ │ │ │26│ │ └─────────▶│ 3. Template(attrs) │ │ │27│ │ │ ↓ │ │ │28│ │ │ 4. Template`content` │ │ │29│ │ │ ↓ │ │ │30│ │ │ 5. HTML Output │ │ │31│ │ └─────────────────────────┘ │ │32│ └─────────────────────────────────────────────────────┘ │33└────────────────────────────────────────────────────────────────┘
Core Concepts
1. Template System
The template system is built on a chain of transformations, with plugins able to hook into each step:
Two main ways to work with templates:
Attributes - via function call:
1div({ class: "container", id: "main" });
Content - via template literals:
1div`Hello world`;
2. Component Architecture
Components in Reface are functions that create and return templates. They can be created in two ways:
Elements API - native approach
JSX - developer-friendly wrapper
Both approaches are translated into the same Template API calls.
3. Plugin System
Plugins extend template capabilities through a transformation system:
1interface TemplatePlugin {2 // Transform during creation3 create?: (template: Template) => Template;45 // Transform during rendering6 render?: (html: string) => string;7}
4. Islands Architecture
Islands Architecture enables interactive components without excessive JavaScript:
Partials - components with HTMX updates
Islands - isolated micro-applications with RPC
1Server ← HTMX/RPC ← Island Component2 ↓ ↓3Static HTML Isolated Interactivity
Framework vs Core
RefaceComposer (Core)
Basic template engine
Plugin system
HTML rendering
Reface (Framework)
Ready-to-use ecosystem
Routing and layouts
Islands Architecture
Built-in plugins
Best Practices
Template Composition
Use components for reusability
Mix Elements API and JSX where appropriate
Keep template nesting manageable
Performance
Minimize JavaScript usage
Use HTMX for simple updates
Islands only for complex interactivity
Type Safety
Define interfaces for props
Use TypeScript for components
Validate types in templates