Web-ready React client for the Magid server.
This project mirrors an earlier JavaFX desktop client and is designed to make Magid easier to deploy, access, and evolve without requiring a desktop app installation.
Status: this client is currently a prototype.
The Magid server is not yet publicly available, so production deployment/running is not a primary focus yet.
magid-app/— the actual React + TypeScript application (Vite-based)
Note: this client was initially generated with Claude under close human supervision, with parts hand-crafted and refined.
Magid is a declarative storytelling engine centered on XML/Markdown-authored stories.
At runtime, the server exposes an HTTP API and returns JSON responses that describe what the client should render:
- narration/text blocks
- interactive menu choices and standalone commands
- visual transitions
- dynamic theming/CSS configuration
- background music references
This React client is the web counterpart of the JavaFX client and follows the same server contract.
App.tsxis the shell: options access, status feedback, and initial connection/bootstrap flow.MagidRoot.tsxis the central dispatcher that maps parsed protocol elements to concrete UI components.ResponsesContainer.tsxpreserves server response order and handles blocking visual transitions before unlocking later elements.MenuScene.tsx,NarrationText.tsx,CommandButton.tsx, andVisualFade.tsxare focused renderers for protocol element types.OptionsModal.tsxmanages runtime client preferences (server URL, XML selection, toggles, volume).
useMagidCommandexposes a stable command callback that routes user actions into store-driven server requests.useTypewriterimplements timeline-aware progressive text rendering (DCSTP_...) with cleanup-safe timers.useAudioattaches/cleans looping background audio per scene.
magidClient.tscontains all HTTP communication (sendCommand,serverStatus,getXmlList,requestXml).- It also resolves
magid://anchors to the active base URL, including nested response data where needed.
elementFactory.tsconverts server JSON into a typedParsedElementunion and handles protocol aliases/responsesrecursion.textTimeline.tsparses timeline markers for typewriter animation.cssUtils.tsinjects/clears server-provided stylesheets dynamically.renderText.tsxhandles line-break-preserving text rendering helpers.
This project uses Zustand (magidStore.ts) as the single shared state container for connection status, parsed elements, config/env vars, CSS state, and command loading/error flow.
Zustand was selected because it fits the app's protocol-driven architecture:
- lightweight API with minimal boilerplate (faster to evolve during prototype work),
- easy React integration via selectors/hooks without Redux-style ceremony,
- simple colocated actions for async command flow (
sendCommand) and immediate side-effects (config/CSS/app vars), - enough structure for global cross-component state, while keeping components and utility modules small.
- Requests are sent to a base URL using
?cmd=...(for exampleserver-status,list-xmls,reload-xml,set-xml, or story commands). - Responses are JSON objects containing protocol keys such as
menu,narration/text,command,visual,config, or aresponsesarray. magid://anchors in response strings are resolved to the configured base server URL.- Text can include
DCSTP_timeline markers to trigger typewriter-style progressive rendering.
For deeper protocol and architecture details, see CLAUDE.md and magid-app/src/types/protocol.ts.
- Node.js
20.19+or22.12+(Node 22 LTS recommended) - npm
10+
winget install OpenJS.NodeJS.LTSbrew install node@22If needed, link it:
brew link --overwrite --force node@22Use your distro package manager, or install via NVM (recommended for consistent Node versions).
NVM (Ubuntu/Debian/Fedora/Arch and others):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
nvm install 22
nvm use 22Then reopen your terminal so PATH updates are applied.
Verify:
node --version # should be v22.x.x or v20.19+
npm --versionIf you get running scripts is disabled on this system while running npm scripts:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUsercd magid-app
npm installcd magid-app
npm run devDefault local URL: http://localhost:5173
cd magid-app
npm run buildBuild output is generated in magid-app/dist/.
| Command | Description |
|---|---|
npm run dev |
Start the development server with HMR |
npm run build |
Type-check and build for production |
npm run preview |
Preview the production build locally |
npm run lint |
Run ESLint |
npm run test |
Run tests once |
npm run test:watch |
Run tests in watch mode |
This usually means node_modules was installed on a different machine or Node version.
From magid-app/, reinstall cleanly:
Remove-Item -Recurse -Force node_modules, package-lock.json
npm install