# Strata Framework Architecture
**Strata** = Static Template Rendering Architecture
A compile-time web framework that resolves templates to pure HTML at build time.
```
╔═══════════════════════════════════════════════════════════════════╗
║ ║
║ Code Faster. Load Quick. Deploy ASAP. ║
║ ║
╚═══════════════════════════════════════════════════════════════════╝
```
---
## Table of Contents
1. [Core Principles](#core-principles)
2. [Design Pattern: STRC](#design-pattern-strc)
3. [Compilation Flow](#compilation-flow)
4. [File Types & Layers](#file-types--layers)
5. [Template Syntax](#template-syntax)
6. [Import Hierarchy](#import-hierarchy)
7. [Runtime Architecture](#runtime-architecture)
8. [Dev Server Architecture](#dev-server-architecture)
9. [Future: Shared Worker](#future-shared-worker-architecture)
10. [Future: Smart Fetch](#future-smart-fetch-system)
11. [Future: Encrypted Store](#future-encrypted-store)
12. [Performance Targets](#performance-targets)
---
## Core Principles
| # | Principle | Description |
|---|-----------|-------------|
| 1 | **Static First** | All templates resolved at build time, not runtime |
| 2 | **Zero Runtime Overhead** | Output is pure HTML with no framework code |
| 3 | **Strict Separation** | Each file type has exactly one responsibility |
| 4 | **Go Compiler** | Fast builds with native performance |
| 5 | **Compartmentalized Layers** | Clear boundaries between template, data, and logic |
---
## Design Pattern: STRC
**STRC** = **S**tatic **T**emplate **R**esolution with **C**ompartmentalized Layers
### Pattern Overview
```
┌─────────────────────────────────────────────────────────────────────┐
│ BUILD TIME │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ SOURCE FILES STATIC COMPILER │
│ ════════════ ═══════════════ │
│ │
│ ┌─────────────┐ │
│ │ .strata │─────┐ │
│ │ (Template) │ │ │
│ └─────────────┘ │ ┌────────────────────────────────┐ │
│ │ │ │ │
│ ┌─────────────┐ ├─────────▶│ STRATA STATIC COMPILER │ │
│ │ .compiler │─────┤ │ │ │
│ │ .sts │ │ │ 1. Parse .strata to AST │ │
│ │ (Variables) │ │ │ 2. Load .compiler.sts exports │ │
│ └─────────────┘ │ │ 3. Resolve { variables } │ │
│ │ │ 4. Expand { s-for } loops │ │
│ ┌─────────────┐ │ │ 5. Evaluate { s-if } blocks │ │
│ │ .service │─────┘ │ 6. Output pure HTML │ │
│ │ .sts │ │ │ │
│ │ (Logic) │ └──────────────┬─────────────────┘ │
│ └─────────────┘ │ │
│ │ │
│ ┌─────────────┐ │ │
│ │ .scss │───────────────────────────────┤ │
│ │ (Styles) │ │ │
│ └─────────────┘ │ │
│ │ │
└─────────────────────────────────────────────────┼────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────┐
│ RUNTIME │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ OUTPUT │
│ ══════ │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ PURE HTML │ │
│ │ │ │
│ │ • No { } syntax │ │
│ │ • No s-for directives │ │
│ │ • No s-if conditionals │ │
│ │ • No framework JavaScript (unless .service.sts defines) │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ Optional: Runtime JavaScript from .service.sts │ │
│ │ (Event handlers, interactivity, etc.) │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
```
### Layer Responsibilities
```
┌─────────────────────────────────────────────────────────────────────┐
│ STRC LAYERS │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ LAYER 1: TEMPLATE (.strata) │
│ ═══════════════════════════ │
│ • Pure HTML structure │
│ • Strata directives ({ }, s-for, s-if) │
│ • No logic, no JavaScript │
│ • Variables injected from compiler layer │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ LAYER 2: COMPILER (.compiler.sts) │
│ ═════════════════════════════════ │
│ • Variable definitions │
│ • Data structures (arrays, objects) │
│ • Build-time constants │
│ • Executed during compilation │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ LAYER 3: SERVICE (.service.sts) │
│ ════════════════════════════════ │
│ • Business logic │
│ • API calls (build-time or runtime) │
│ • Event handlers │
│ • Optional browser interactivity │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ LAYER 4: API CONTRACT (.api.sts) │
│ ════════════════════════════════ │
│ • Declarative endpoint definitions │
│ • Request/response schemas │
│ • Cache policies │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ LAYER 5: UTILITIES (.sts) │
│ ═════════════════════════ │
│ • Pure functions │
│ • No side effects │
│ • Shared helpers │
│ │
└─────────────────────────────────────────────────────────────────────┘
```
---
## Compilation Flow
### Step-by-Step Process
```
┌─────────────────────────────────────────────────────────────────────┐
│ COMPILATION PIPELINE │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ STEP 1: PARSE TEMPLATE │
│ ══════════════════════ │
│ │
│ Input: Output: │
│ ┌──────────────────────┐ ┌──────────────────────┐ │
│ │ │ │ AST │ │
│ │ { title }
│ ────▶ │ ├─ TemplateNode │ │
│ │ { s-for ... } │ │ │ └─ ElementNode │ │
│ │ │ │ │ └─ Interp... │ │
│ └──────────────────────┘ └──────────────────────┘ │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ STEP 2: LOAD COMPILER SCOPE │
│ ═══════════════════════════ │
│ │
│ Input: Output: │
│ ┌──────────────────────┐ ┌──────────────────────┐ │
│ │ export const title │ │ scope = { │ │
│ │ = 'Hello'; │ ────▶ │ title: 'Hello', │ │
│ │ export const items │ │ items: [...] │ │
│ │ = [...]; │ │ } │ │
│ └──────────────────────┘ └──────────────────────┘ │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ STEP 3: RESOLVE TEMPLATE │
│ ════════════════════════ │
│ │
│ Process: │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ For each AST node: │ │
│ │ │ │
│ │ • InterpolationNode { var } → Look up in scope, output │ │
│ │ • ForBlockNode { s-for } → Iterate, create loop scope │ │
│ │ • IfBlockNode { s-if } → Evaluate, include/exclude │ │
│ │ • ElementNode
Strata - Static Template Rendering Architecture