mythik-react
v0.1.5
Published
React runtime and primitives for rendering Mythik JSON-native app contracts.
Maintainers
Readme
mythik-react
The React rendering surface for Mythik, the AI-first JSON-native app
framework. Turns validated JSON specs into rendered UI: mount a
multi-screen app via MythikApp, or embed a single spec via
MythikRenderer. Both consume the same spec format and resolve
expressions, actions, and primitives at render time.
See the framework README on GitHub for the full Mythik architecture and design philosophy. This file documents what
mythik-reactgives you and how to use it.
What Mythik is, briefly
Mythik is an AI-first JSON-native app framework. Most of your app lives as validated JSON specs loaded at runtime from your database, not source code that must be regenerated and redeployed for every change. AI agents compose those specs from a documented vocabulary; Mythik validates the shape, references, actions, state paths, and cross-contract assumptions before the change reaches runtime. This package is the React rendering surface: it turns those same validated JSON contracts into web app screens.
Install
npm install mythik mythik-reactmythik is a peer dependency: it ships the spec types, validators,
and runtime engines. mythik-react adds the React renderer on top.
What you get
<MythikApp>— full multi-screen app shell. Reads anAppSpec(navigation, screens, theme, app-level layout) plus aSpecStoreand renders the active screen, handles navigation, manages auth context, and coordinates editor sessions.<MythikRenderer>— single-spec renderer for embedding Mythik inside an existing React app. Useful for islands and demos where you don't need the full app shell.38 built-in primitives — form fields, layout, lists, modals, charts, and more. Each primitive maps a spec
typevalue (e.g."button") to a React component with a strict prop schema. Seeai-context-primitives.md(bundled in themythikpackage) for the full catalog.Customization hooks — register custom primitives, expressions, and action handlers via
MythikApp.onPlugins. The icon renderer is hookable viaplugins.setIconRenderer.Auth provider re-exports — convenience surface sourced from
mythikcore, so your app can import everything auth-related from one place.
Minimal example
A two-screen app, all behavior described in JSON:
import { MemorySpecStore, type AppSpec, type Spec } from 'mythik';
import { MythikApp } from 'mythik-react';
const appSpec: AppSpec = {
type: 'app',
name: 'Demo App',
navigation: { type: 'tabs', initialScreen: 'home' },
screens: {
home: { label: 'Home' },
profile: { label: 'Profile' },
},
layout: {
root: 'app-shell',
elements: {
'app-shell': {
type: 'box',
props: { style: { minHeight: '100vh', padding: 24 } },
children: ['outlet'],
},
outlet: { type: 'screen-outlet' },
},
},
};
const homeSpec: Spec = {
root: 'root',
elements: {
root: {
type: 'box',
props: { style: { padding: 24 } },
children: ['title', 'go-profile'],
},
title: {
type: 'text',
props: { content: 'Hello from Mythik', variant: 'heading' },
},
'go-profile': {
type: 'button',
props: { label: 'View profile' },
on: { press: [{ action: 'navigateScreen', params: { screen: 'profile' } }] },
},
},
};
const profileSpec: Spec = {
root: 'root',
elements: {
root: { type: 'text', props: { content: 'Profile screen' } },
},
};
const specStore = new MemorySpecStore({
home: homeSpec,
profile: profileSpec,
});
export default function App() {
return <MythikApp appSpec={appSpec} specStore={specStore} />;
}Replace MemorySpecStore with SupabaseSpecStore or a SqlSpecStore
from mythik/server backed by SQL Server, PostgreSQL, MySQL, or
SQLite. The host file does not change as the app grows from 2 screens
to 200.
How the renderer works
When MythikApp mounts:
- It loads the active spec from the
SpecStore. - It walks the spec's element tree starting from
root. - For each element, it instantiates the React component registered
for that element's
typevalue (built-in primitive or custom). - It resolves
$token,$state,$template, and other expressions at render time, against the current state and AppSpec tokens. - It wires
onaction handlers to the action dispatcher. - When state changes or a new spec version arrives, only affected subtrees re-render.
The renderer's contract: same spec + same plugins + same state = identical render. This determinism is what lets AI agents iterate on specs with confidence.
Customization
Register custom primitives, expressions, and action handlers through the plugin hook:
<MythikApp
appSpec={appSpec}
specStore={specStore}
onPlugins={(plugins) => {
plugins.registerPrimitive('my-custom-card', MyCustomCard);
plugins.registerExpression('uppercase', (args, ctx) => String(args[0]).toUpperCase());
plugins.registerAction('analyticsTrack', async (params) => { /* ... */ });
plugins.setIconRenderer(MyIconRenderer);
}}
/>Custom primitives become available as a type value in any spec
loaded from your store. Custom expressions and actions can be
referenced from any spec. Use these sparingly — every custom hook is
code that lives outside the spec store and outside the version-control
audit trail.
Related packages
mythik— the runtime this renderer consumes (peer dependency)mythik-cli— author and patch the specs you're renderingmythik-server— declarative REST server from anApiSpecmythik-react-native— render supported Mythik primitives in Expo and React Native
Status
Public release line. APIs are documented for real-world feedback as the framework evolves.
Releases
Release notes and patch details are published in the CHANGELOG and on GitHub Releases.
License
Apache-2.0.
