Storyforge
StoryForge Server Backend server for StoryForge AI story generation using Ollama. Prerequisites 1. Node.js (v18 or higher) 2. Ollama installed and running locally Install Ollama ``...
Technical Architecture & Engineering Overview
Detailed system design and core implementation
The core architecture follows a clear separation of concerns: the API layer (server/routes/stories.js) handles HTTP requests, delegating to service modules such as storyGenerator.js for outline and chapter creation, ollama.js for LLM interaction, and storage.js for file‑based persistence. Each story is stored as a JSON object, enabling quick reads/writes without a traditional database.
Data ingestion is supported through a RAG (Retrieval‑Augmented Generation) pipeline. Uploaded documents (e.g., PDFs) are processed by the index-document endpoint, which renames and forwards the file to services/rag.js for chunking and indexing, expanding the model's knowledge base. The clear-knowledge endpoint allows administrators to reset this vector store.
Execution flow for story creation begins with a POST /api/stories/generate request containing metadata (title, theme, genre, etc.). The request is validated, then generateOutline constructs a high‑level structure via Ollama. Subsequent chapter generation (POST /api/stories/:id/chapters/:chapterNumber) invokes generateChapter, updates word counts, estimates read time, and persists changes. The frontend uses React Query to cache and synchronize this data, while UI components like the Carousel provide keyboard‑accessible navigation (ArrowLeft/ArrowRight).
Security and guardrails include input validation on required fields, content moderation via services/moderator.js to enforce the explicitness setting, and error handling that returns consistent JSON error objects. Environment variables (PORT, OLLAMA_URL, OLLAMA_MODEL) are loaded from .env, allowing flexible deployment configurations.
Build and deployment topology is straightforward: a Node.js server (npm start or npm run dev) runs on port 3001, and the React client is bundled with Vite (or similar) for static serving. The system relies on the local Ollama service (ollama serve) for model inference, making it self‑contained without external cloud dependencies.
System Diagrams & Flow Visualizations
Interactive Mermaid architecture & execution flows
Core System Features
Key capabilities & architectural features
Generate full story outlines from user‑provided metadata
Generate full story outlines from user‑provided metadata
Iterative chapter generation with word count and read‑time estimation
Iterative chapter generation with word count and read‑time estimation
Upload and index external documents for Retrieval‑Augmented Generation
Upload and index external documents for Retrieval‑Augmented Generation
Content moderation based on explicitness settings
Content moderation based on explicitness settings
CRUD operations for stories via JSON storage
CRUD operations for stories via JSON storage
Keyboard‑navigable carousel UI for browsing story elements
Keyboard‑navigable carousel UI for browsing story elements
Responsive design powered by TailwindCSS
Responsive design powered by TailwindCSS
React Query integration for automatic caching and refetching
React Query integration for automatic caching and refetching
Configurable Ollama model and endpoint through environment variables
Configurable Ollama model and endpoint through environment variables
Health check endpoint for service monitoring
Health check endpoint for service monitoring
Engineering Challenges & Solutions
Problem statements & resolution strategies
Balancing model size versus generation speed – larger models like `dolphin‑mistral` produce richer narratives but increase latency and memory usage
Balancing model size versus generation speed – larger models like `dolphin‑mistral` produce richer narratives but increase latency and memory usage
Managing file‑based storage without a database – requires careful concurrency handling to avoid race conditions
Managing file‑based storage without a database – requires careful concurrency handling to avoid race conditions
Ensuring reliable RAG indexing for various document formats while keeping the temporary file lifecycle clean
Ensuring reliable RAG indexing for various document formats while keeping the temporary file lifecycle clean
Providing robust input validation without over‑restricting creative flexibility
Providing robust input validation without over‑restricting creative flexibility
Handling Ollama service failures gracefully and exposing meaningful error messages to the client
Handling Ollama service failures gracefully and exposing meaningful error messages to the client
API Reference & Endpoints
REST API surface & route documentation
| METHOD | ENDPOINT PATH | DESCRIPTION | COPY |
|---|---|---|---|
| GET | /health | Endpoint defined in server/index.js | |
| POST | /index-document | Endpoint defined in server/routes/stories.js | |
| POST | /clear-knowledge | Endpoint defined in server/routes/stories.js | |
| POST | /generate | Endpoint defined in server/routes/stories.js | |
| POST | /:id/chapters/:chapterNumber | Endpoint defined in server/routes/stories.js | |
| GET | / | Endpoint defined in server/routes/stories.js | |
| GET | /:id | Endpoint defined in server/routes/stories.js | |
| DELETE | /:id | Endpoint defined in server/routes/stories.js |
Key Code Modules & Architecture
Core file entrypoints and service responsibilities
clientModule component managing client source logic
client/srcModule component managing src source logic
client/src/componentsModule component managing components source logic
client/src/components/uiModule component managing ui source logic
client/src/hooksModule component managing hooks source logic
client/src/libModule component managing lib source logic
client/src/pagesModule component managing pages source logic
serverModule component managing server source logic
server/routesModule component managing routes source logic
server/servicesModule component managing services source logic
server/utilsModule component managing utils source logic
User Journey Pipeline
- 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
- 2Client Payload Dispatch: Front-end components (React, TailwindCSS) serialize input objects and send HTTP/WebSocket requests to `/health`.
- 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
- 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
- 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.
Execution Code Flow
- 1Client or caller initiates request to application entrypoint
- 2Backend router validates request parameters and applies middleware
- 3Application serializes JSON/audio/data response back to client
System FAQ & Technical Specifications
Frequently asked questions and core architecture details
Q: What technologies are used in Storyforge?
Storyforge is engineered using modern full-stack frameworks.
Q: What core engineering problem does Storyforge solve?
StoryForge Server Backend server for StoryForge AI story generation using Ollama. Prerequisites 1. Node.js (v18 or higher) 2. Ollama installed and running locally Install Ollama ``...
Q: How is 'Balancing model size versus generation speed – larger models like `dolphin‑mistral` produce richer narratives but increase latency and memory usage' resolved in Storyforge?
Resolved through specialized system architecture and resilient state handling.
Related Systems & Case Studies
Explore similar technical architectures and projects