RP Lite Engine is a roleplay-focused application for running immersive character chat with optional image generation and play-mode world simulation.
It combines:
- a React frontend (
vite) - an Express API backend
- model providers (Ollama + OpenAI-compatible)
- ComfyUI workflow-based image generation
- portrait-trait extraction to keep character visuals consistent across generated images
- Features
- Tech Stack
- Project Structure
- Quick Start
- Configuration
- API Endpoints
- How The Main Flows Work
- Development Workflow
- Testing
- Troubleshooting
- Contributing
- Multi-character roleplay chat
- Provider selection between:
- Ollama (
/api/chatthrough Ollama API) - OpenAI-compatible servers
- Ollama (
- Auto and manual image generation from chat turns
- Character portrait upload/generation
- Portrait trait extraction (
hair/face/look/accessorysummary) used in chat image prompts - Personality profile generation/repair pipeline with strict contract checks
- Roleplay world/theme setup generation pipeline with validation and repair
- Play mode with world state, items, locations, and progression
- Persistent local state for settings, chat, characters, images, and play world
- Frontend: React 18, Vite
- Backend: Express 4
- Styling: CSS + Tailwind tooling available
- Runtime: Node.js 18+
- Testing: Node test runner (
node --test)
src/
components/
chat/
tabs/
hooks/
play-mode/
lib/
server/
routes/
*.ts
tests/
lib/
server/
- Frontend shell/orchestration:
src/App.tsx - Frontend helper module:
src/lib/appHelpers.ts - Portrait actions hook:
src/hooks/useCharacterPortraitActions.ts - Prompt utilities and normalization:
src/lib/rpUtils.ts - Backend bootstrap:
server/index.ts - Backend route modules:
server/routes/chatRoutes.tsserver/routes/personalityRoutes.tsserver/routes/roleplayRoutes.tsserver/routes/imageRoutes.ts
- Node.js
>=18 - npm
- Optional external services:
- Ollama
- OpenAI-compatible inference endpoint
- ComfyUI for images
npm cinpm run dev- Frontend:
http://localhost:5173 - API:
http://localhost:8787
npm run build
npm run startdocker compose up -dStop:
docker compose downRebuild image when dependencies change:
docker compose up --build -dConfiguration is managed in the UI and persisted in localStorage.
provider:ollamaoropenai-compatibleollamaBaseUrl: defaulthttp://127.0.0.1:11434openaiBaseUrl: defaulthttp://127.0.0.1:8000/v1apiKey: optional for compatible endpointsmodel: selected model name
temperaturetopPmaxTokensinstructtemplate controls
comfyBaseUrl: defaulthttp://127.0.0.1:8188workflow: ComfyUI API workflow JSONnegativePromptwidth,height,steps,cfg,seed
Supported workflow placeholders:
{{PROMPT}}{{NEGATIVE_PROMPT}}{{WIDTH}},{{HEIGHT}}{{STEPS}},{{CFG}},{{SEED}}
rp-lite:settings:v1rp-lite:characters:v1rp-lite:active-character:v1rp-lite:personality-profiles:v1rp-lite:active-personality:v1rp-lite:messages:v1rp-lite:images:v1rp-lite:play-mode:v1rp-lite:ui-console-logs:v1- and related UI state keys
GET /api/healthPOST /api/models
POST /api/chat
POST /api/personality/generate
POST /api/roleplay/generate
POST /api/image/generatePOST /api/portrait/traits
- Frontend composes chat context/history.
- Backend applies runtime tuning (
rpTuning) and prompt composition (prompting). - Provider adapter runs model request.
- Frontend stores reply and optional auto image prompt.
- Prompt is built from current chat message in
buildChatImagePrompt. - If portrait traits exist, they are prefixed as appearance reference.
- Frontend calls
/api/image/generate. - Backend resolves ComfyUI workflow placeholders and returns image URL/data URL.
- User uploads or generates a portrait in Characters tab.
- Frontend calls
/api/portrait/traits. - Backend submits image to selected provider in provider-specific format.
- Trait text is normalized and stored in
character.portraitTraits. - Chat image prompts reuse those traits for visual consistency.
npm run dev- run web + API in watch modenpm run dev:web- run Vite onlynpm run dev:server- run Express server onlynpm run test- run all testsnpm run test:watch- watch mode testsnpm run lint- syntax + build checksnpm run build- production build
make installmake devmake testmake lintingmake buildmake upmake up-buildmake downmake logs
- Keep route registration in
server/routes/*and business logic in domain modules. - Keep component files focused; move non-UI logic to hooks/helpers.
- Prefer reusable pure helpers in
src/lib. - Add tests for behavior changes under
tests/libortests/server.
Run full test suite:
npm testTests are grouped by domain:
tests/lib/*for frontend shared logictests/server/*for backend/provider/prompt contracts
- Verify provider base URL.
- Ensure model service is running.
- Check API key for OpenAI-compatible endpoints.
- Confirm ComfyUI is reachable at configured base URL.
- Confirm workflow JSON is valid API export.
- Ensure checkpoint names and node IDs match your local setup.
- Ensure selected model endpoint supports image input.
- Re-upload/regenerate portrait after selecting a compatible model.
- Check UI console logs for
/api/portrait/traitserrors.
In Docker mode, host loopback addresses are remapped through host.docker.internal. Make sure the host service is bound and reachable from Docker.
- Use small, focused pull requests.
- Prefer Conventional Commits:
feat: ...fix: ...chore: ...
- Include:
- what changed
- why it changed
- test evidence (
npm test,npm run lint, etc.)
If you plan a large refactor, split it into mechanical + behavioral commits so reviews stay clear.