This repository is a production-shaped reference implementation for server-driven UI.
It demonstrates how to author screens in an admin dashboard, store them in PostgreSQL, compose user-specific UI in a NestJS backend, and render the final JSON contract in a React Native mobile app.
This is a strong reference implementation, not a drop-in production system yet.
Implemented:
- Database-backed screen templates and revisions with Prisma/PostgreSQL
- Draft and publish workflow for authored screens
- Shared SDUI contracts with DTOs and Zod schemas
- Backend composition engine with data sources, targeting, dynamic values, actions, and fallbacks
- Admin dashboard for editing layouts, targeting, source bindings, and item actions
- React Native renderer with component registry, navigation actions, caching, and client-side targeting guard
- iOS simulator workflow through Expo dev client
Still needed before real production:
- Real admin authentication and RBAC
- Automated tests and CI
- Observability, audit depth, rollback UX, and alerting
- Hardened action registry and source-query governance
- Production deployment configuration and secrets management
See Production Readiness for the full checklist.
apps/
api/ NestJS API, Prisma, composition engine, admin APIs
admin/ Next.js admin dashboard for authoring screens
mobile/ Expo React Native app and SDUI renderer
packages/
sdui-contracts/ Shared schemas, DTOs, template contracts, targeting, composition catalog types
docs/
architecture/ System and composition architectureflowchart LR
Admin[Next.js Admin] -->|Save draft / publish| API[NestJS API]
API -->|Store revisions| DB[(PostgreSQL)]
Mobile[React Native Mobile] -->|GET screen JSON| API
API -->|Load published template| DB
API -->|Compose user-specific ScreenDto| Composer[Composition Engine]
Composer --> Mobile
The database stores authored screen templates. The mobile app only receives the currently published screen after the backend resolves:
- user context
- client OS and app version targeting
- data sources such as products, promos, and categories
- dynamic text tokens
- actions and navigation routes
- fallback components
Start with Architecture Overview, then read Composition Engine for the backend internals.
- Node.js 20 or newer
- pnpm 9 or newer
- Docker Desktop
- Xcode, if running the iOS app
- CocoaPods, installed through the React Native/Expo toolchain
Install dependencies:
pnpm installStart PostgreSQL:
docker compose up -d postgresPrepare the API environment:
cp apps/api/.env.example apps/api/.envRun Prisma migration and seed demo data:
pnpm --filter @sdui/api exec prisma migrate dev
pnpm --filter @sdui/api db:seedStart the three apps:
pnpm dev:api
pnpm dev:admin
pnpm dev:mobileDefault URLs:
- API:
http://localhost:3000/api - Admin:
http://localhost:3001 - Metro:
http://localhost:8081 - PostgreSQL:
localhost:5432
For iOS, open apps/mobile/ios/SDUIDemo.xcworkspace in Xcode or run:
pnpm --filter @sdui/mobile iosMore detail is in Development Guide.
- Open the admin dashboard at
http://localhost:3001. - Select the
homescreen. - Drag sections, edit fields, targeting, source bindings, and item actions.
- Save draft.
- Publish when ready.
- Open the mobile app and refresh the screen.
Drafts are not visible to mobile clients. Mobile reads only the latest published revision.
Mobile screen requests send:
x-ui-schema-version: 1
x-user-id: u_42
x-client-os: ios
x-client-os-version: 18.0
x-client-app-version: 1.0.0Admin API requests use:
x-admin-secret: dev-only-secretThat admin secret is development-only and must be replaced before production.
The backend exposes dynamic values through:
GET /api/admin/composition/catalogExamples:
{{user.firstName}}
{{user.segment}}
{{client.os}}
{{product.id}}
{{category.id}}
{{promo.id}}Unknown tokens fail admin preview/save with a clear validation error, instead of leaking invalid content into a published mobile screen.
Useful checks:
pnpm --filter @sdui/contracts build
pnpm --filter @sdui/api build
pnpm typecheckSmoke-test the screen API:
curl -sS \
-H 'x-ui-schema-version: 1' \
-H 'x-user-id: u_42' \
-H 'x-client-os: ios' \
-H 'x-client-os-version: 18.0' \
-H 'x-client-app-version: 1.0.0' \
http://localhost:3000/api/v1/screens/home- Development Guide
- Architecture Overview
- Composition Engine
- Database-Backed Architecture
- API Reference
- Admin Guide
- Mobile Renderer
- Production Readiness
This codebase is intentionally small enough to study and demo. It models production concerns, but some production systems are deliberately simplified:
- Admin auth is a shared secret header.
- The data model uses demo products, promos, categories, and users.
- There is no full CI pipeline yet.
- There is no automated test suite yet.
- Deployment, monitoring, and incident workflows are documented as next steps, not implemented.