S
Web App2026CompletedFeatured Project

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 ``...

RoleSole Developer
Classificationhigh
Client / ContextOpen Source Project
Development TimelineCompleted

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

Architectural Visualizer · System Architecture

Core System Features

Key capabilities & architectural features

FEATURE 01

Generate full story outlines from user‑provided metadata

Generate full story outlines from user‑provided metadata

FEATURE 02

Iterative chapter generation with word count and read‑time estimation

Iterative chapter generation with word count and read‑time estimation

FEATURE 03

Upload and index external documents for Retrieval‑Augmented Generation

Upload and index external documents for Retrieval‑Augmented Generation

FEATURE 04

Content moderation based on explicitness settings

Content moderation based on explicitness settings

FEATURE 05

CRUD operations for stories via JSON storage

CRUD operations for stories via JSON storage

FEATURE 06

Keyboard‑navigable carousel UI for browsing story elements

Keyboard‑navigable carousel UI for browsing story elements

FEATURE 07

Responsive design powered by TailwindCSS

Responsive design powered by TailwindCSS

FEATURE 08

React Query integration for automatic caching and refetching

React Query integration for automatic caching and refetching

FEATURE 09

Configurable Ollama model and endpoint through environment variables

Configurable Ollama model and endpoint through environment variables

FEATURE 010

Health check endpoint for service monitoring

Health check endpoint for service monitoring

Engineering Challenges & Solutions

Problem statements & resolution strategies

Challenge #1

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

Challenge #2

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

Challenge #3

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

Challenge #4

Providing robust input validation without over‑restricting creative flexibility

Providing robust input validation without over‑restricting creative flexibility

Challenge #5

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

METHODENDPOINT PATHDESCRIPTIONCOPY
GET/healthEndpoint defined in server/index.js
POST/index-documentEndpoint defined in server/routes/stories.js
POST/clear-knowledgeEndpoint defined in server/routes/stories.js
POST/generateEndpoint defined in server/routes/stories.js
POST/:id/chapters/:chapterNumberEndpoint defined in server/routes/stories.js
GET/Endpoint defined in server/routes/stories.js
GET/:idEndpoint defined in server/routes/stories.js
DELETE/:idEndpoint defined in server/routes/stories.js

Key Code Modules & Architecture

Core file entrypoints and service responsibilities

ClientMODULE 01
client

Module component managing client source logic

SrcMODULE 02
client/src

Module component managing src source logic

ComponentsMODULE 03
client/src/components

Module component managing components source logic

UiMODULE 04
client/src/components/ui

Module component managing ui source logic

HooksMODULE 05
client/src/hooks

Module component managing hooks source logic

LibMODULE 06
client/src/lib

Module component managing lib source logic

PagesMODULE 07
client/src/pages

Module component managing pages source logic

ServerMODULE 08
server

Module component managing server source logic

RoutesMODULE 09
server/routes

Module component managing routes source logic

ServicesMODULE 010
server/services

Module component managing services source logic

UtilsMODULE 011
server/utils

Module component managing utils source logic

User Journey Pipeline

  1. 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
  2. 2Client Payload Dispatch: Front-end components (React, TailwindCSS) serialize input objects and send HTTP/WebSocket requests to `/health`.
  3. 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
  4. 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
  5. 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.

Execution Code Flow

  1. 1Client or caller initiates request to application entrypoint
  2. 2Backend router validates request parameters and applies middleware
  3. 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

View All Systems