# JSON-First Architecture ## Overview This low-code platform uses a **JSON-first architecture** where the entire application is defined declaratively in JSON, eliminating React boilerplate and enabling visual editing, version control, and runtime customization. ## Core Principles ### 1. Everything is JSON - **Pages**: All 35 application pages defined in JSON schemas - **Components**: Atomic design library (atoms, molecules, organisms) in JSON - **Themes**: Complete theming system configurable via JSON - **Data**: State, bindings, and data sources declared in JSON - **Actions**: Event handlers and side effects defined in JSON ### 2. Composition via $ref JSON files reference each other using JSON Schema `$ref`: ```json { "id": "dashboard", "components": [ { "$ref": "./molecules/dashboard-header.json" }, { "$ref": "./molecules/stats-grid.json" } ] } ``` ### 3. One Definition Per File Following single-responsibility principle: - 1 function per TypeScript file - 1 type per TypeScript file - 1 component definition per JSON file - Compose larger structures via $ref ## Architecture Layers ``` ┌─────────────────────────────────────┐ │ pages.json (35 pages) │ ← Router configuration └──────────────┬──────────────────────┘ │ references ┌──────────────▼──────────────────────┐ │ Page Schemas (55 .json files) │ ← Page definitions └──────────────┬──────────────────────┘ │ compose via $ref ┌──────────────▼──────────────────────┐ │ Organisms (8 .json files) │ ← Complex layouts └──────────────┬──────────────────────┘ │ compose via $ref ┌──────────────▼──────────────────────┐ │ Molecules (23 .json files) │ ← Composed components └──────────────┬──────────────────────┘ │ compose via $ref ┌──────────────▼──────────────────────┐ │ Atoms (23 .json files) │ ← Base components └──────────────┬──────────────────────┘ │ reference ┌──────────────▼──────────────────────┐ │ React Components (68 .tsx) │ ← Implementation │ Component Registry (100+ mapped) │ └─────────────────────────────────────┘ ``` ## File Structure ``` src/config/pages/ ├── atoms/ # 23 base components │ ├── button-primary.json │ ├── heading-1.json │ ├── text-muted.json │ └── ... ├── molecules/ # 23 composed components │ ├── dashboard-header.json │ ├── stats-grid.json │ ├── stat-card-base.json │ └── ... ├── organisms/ # 8 complex layouts │ ├── app-header.json │ ├── navigation-menu.json │ └── ... ├── layouts/ # Layout templates │ └── single-column.json ├── data-sources/ # Data source templates │ └── kv-storage.json └── *.json # 55 page schemas ├── dashboard-simple.json ├── settings-page.json └── ... ``` ## JSON Schema Features ### Page Schema ```json { "$schema": "./schema/page-schema.json", "id": "dashboard-simple", "name": "Project Dashboard", "description": "Overview of your project", "icon": "ChartBar", "layout": { "$ref": "./layouts/single-column.json" }, "dataSources": [ { "id": "projectStats", "$ref": "./data-sources/kv-storage.json", "key": "project-stats", "defaultValue": { "files": 0, "models": 0 } } ], "components": [ { "$ref": "./molecules/dashboard-header.json" }, { "$ref": "./molecules/stats-grid.json" } ] } ``` ### Data Binding ```json { "id": "files-value", "type": "div", "props": { "className": "text-2xl font-bold", "children": "0" }, "dataBinding": { "source": "projectStats", "path": "files" } } ``` ### Actions ```json { "type": "Button", "events": [ { "event": "onClick", "actions": [ { "type": "setState", "target": "selectedTab", "value": "colors" }, { "type": "toast", "title": "Tab changed", "variant": "success" } ] } ] } ``` ### Conditionals ```json { "type": "div", "conditional": { "source": "customColorCount", "operator": "eq", "value": 0 }, "children": [ { "type": "p", "children": "No custom colors" } ] } ``` ## Theming System ### JSON Theme Definition The entire theming system is JSON-based (theme.json): ```json { "sidebar": { "width": "16rem", "backgroundColor": "oklch(0.19 0.02 265)", "foregroundColor": "oklch(0.95 0.01 265)" }, "colors": { "primary": "oklch(0.58 0.24 265)", "accent": "oklch(0.75 0.20 145)", "background": "oklch(0.15 0.02 265)" }, "typography": { "fontFamily": { "body": "'IBM Plex Sans', sans-serif", "heading": "'JetBrains Mono', monospace" } }, "spacing": { "radius": "0.5rem" } } ``` ### Runtime Theme Editing Users can create theme variants and customize colors/fonts via JSON: ```json { "activeVariantId": "dark", "variants": [ { "id": "dark", "name": "Dark Mode", "colors": { "primary": "#7c3aed", "secondary": "#38bdf8", "customColors": { "success": "#10b981", "warning": "#f59e0b" } } } ] } ``` ## Data Sources ### KV Storage ```json { "id": "userData", "type": "kv", "key": "user-settings", "defaultValue": { "theme": "dark" } } ``` ### Computed Sources ```json { "id": "totalFiles", "type": "computed", "compute": "(data) => data.files.length", "dependencies": ["files"] } ``` ### Static Sources ```json { "id": "tabs", "type": "static", "defaultValue": ["colors", "typography", "preview"] } ``` ## Benefits Over Traditional React ### Traditional React Component (~50 lines) ```tsx import { useState } from 'react' import { Card } from '@/components/ui/card' interface DashboardProps { initialData?: { files: number } } export function Dashboard({ initialData }: DashboardProps) { const [stats, setStats] = useState(initialData || { files: 0 }) return (