LoreSpring is a full-stack storytelling platform for generating, reviewing, and refining long-form narrative chapters with the help of an LLM-driven multi-agent pipeline and a persistent story memory graph.
The product is built around a simple authoring loop:
- Create a story project.
- Describe the next chapter direction.
- Generate a chapter draft through the backend pipeline.
- Review and approve or reject the draft.
- Persist the accepted chapter and expand the story memory graph for future chapters.
LoreSpring combines:
- A FastAPI backend for authentication, project management, chapter generation, review, and graph endpoints.
- A LangGraph-based generation pipeline with specialized agents for writing, continuity checking, revision, summarization, human review, and lore persistence.
- A LightRAG-style memory layer that indexes completed chapters into persistent storage for later retrieval.
- A React + TypeScript + Vite frontend for the project dashboard, chapter editor, review flow, and story graph visualization.
The backend lives under api and src.
- api/main.py creates the FastAPI app, wires CORS, and initializes the LangGraph checkpointer and graph service.
- api/routes exposes the main HTTP endpoints for auth, projects, generation, review, chapters, health, and graph visualization.
- src/graph defines the LangGraph workflow and state model that orchestrates the chapter-generation pipeline.
- src/agents contains the individual agents:
- writer: generates a draft chapter
- continuity: checks for logical contradictions against prior lore
- revision: scores the draft and requests rewrites when needed
- summarizer: creates chapter summaries and structured plot memory
- human_review: pauses for human approval
- lore_keeper: indexes accepted chapters into the memory system
The application uses several persistence layers:
- PostgreSQL for users, projects, chapters, and chapter summaries.
- Neo4j for graph storage used by the lore memory layer.
- Local project storage under lore_db for LightRAG-related artifacts and indexes.
- SQLAlchemy async models are defined in database.
The frontend lives under frontend and uses React, TypeScript, and Vite.
- frontend/src/pages contains the dashboard, project page, review page, login/register screens, and graph page.
- frontend/src/api wraps the backend API calls.
- frontend/src/components contains reusable UI pieces such as the project modal and sidebar.
- api — FastAPI application and routes
- config — runtime settings and environment loading
- database — SQLAlchemy models and session management
- frontend — React/Vite client application
- src/agents — LLM-powered narrative agents
- src/graph — LangGraph workflow and narrative state
- src/llm — LLM client wiring and prompt helpers
- src/memory — LightRAG and embedding integration
- src/schemas — request/response and agent payload schemas
- src/services — service layer for projects, chapters, graph storage, auth, and persistence
- alembic — database migrations
- lore_db — persisted lore memory artifacts
- Register or log in.
- Create a project with genre, tone, and style.
- Open a project and provide a chapter direction.
- Generate a chapter draft.
- Review the generated draft in the review screen.
- Approve to persist the chapter, or reject to discard it and regenerate.
- Explore the resulting story graph from the graph view.
You will need:
- Python 3.11+
- Node.js 18+
- PostgreSQL access
- A Groq API key
- Access to a Neo4j instance for the graph-backed memory layer
Create a file named .env at the repository root and provide the values below.
GROQ_API_KEY=your_groq_key
POSTGRES_URL=postgresql+asyncpg://user:password@host:5432/dbname
POSTGRES_URL_SYNC=postgresql+psycopg://user:password@host:5432/dbname
SECRET_KEY=replace-with-a-long-random-secret
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
JINA_API_KEY=your_jina_key
# Optional observability
LANGSMITH_TRACING=false
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_API_KEY=your_langsmith_key
LANGSMITH_PROJECT=lorespring
# Optional frontend API override for local development
VITE_API_URL=http://localhost:8000Notes:
- The backend reads configuration from config/settings.py.
- The app expects both async and sync PostgreSQL connection strings because the backend uses async SQLAlchemy while Alembic and startup tasks need a sync-capable connection.
- The project is currently wired for managed or external Postgres and Neo4j services rather than local-only containers.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
alembic upgrade head
uvicorn api.main:app --reloadThe API will be available at http://localhost:8000.
cd frontend
npm install
npm run devThe frontend dev server will usually run at http://localhost:5173.
The repository includes a Docker setup for the backend and frontend.
docker compose up --build- Backend: http://localhost:8000
- Frontend: http://localhost:3000
The container entrypoint runs Alembic migrations before starting the FastAPI app.
Migrations are managed with Alembic.
alembic upgrade headIf you add or change the SQLAlchemy models under database/models, generate a new migration with:
alembic revision --autogenerate -m "describe your change"- POST /auth/register
- POST /auth/login
- POST /auth/logout
- POST /projects
- GET /projects
- GET /projects/{project_id}
- GET /chapters/{project_id}
- POST /generate
- GET /review/{thread_id}
- POST /resume/{thread_id}
- GET /graph?project_id=...
When a chapter is generated, the app runs a LangGraph workflow that performs the following steps:
- The writer agent creates an initial draft from the project metadata, chapter direction, and prior summaries.
- The continuity agent checks the draft for contradictions against previously established lore.
- The revision agent scores the draft and may trigger rewrites until the minimum quality threshold is met or the revision limit is reached.
- The summarizer agent produces structured summary data for future context.
- The human review step pauses for approval.
- If approved, the lore keeper indexes the chapter into the story memory layer and the chapter is saved to PostgreSQL.
- The project is intentionally backend-first and uses structured memory to improve continuity across chapters.
- The frontend is currently focused on the core authoring loop rather than a full publishing workflow.
- Some parts of the repository still contain TODOs or experimental hooks, so expect ongoing refinement as the product evolves.
- If the backend fails to start, verify that Postgres and Neo4j are reachable and that the .env values are valid.
- If the frontend cannot contact the API, confirm that VITE_API_URL points to the backend URL and that the backend is running on port 8000.
- If migrations fail, check the PostgreSQL connection strings and ensure the database user has permission to create tables.
Yea I got License