# meet-patel-2112/orion---world-state-engine architecture

> Architecture diagram of the GitHub repository meet-patel-2112/orion---world-state-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meet-patel-2112/orion---world-state-engine
- Repository: https://github.com/meet-patel-2112/orion---world-state-engine

## Overview

Orion is a world-state engine for writers: users manage fictional worlds and manuscripts, inspect extracted entities, relationships and events, resolve contradictions, and ask questions about the world. The principal workflow runs from the web interface through the API and asynchronous processing into structured world state, where consistency checks support later inspection and chat. The tree and excerpts confirm the UI routes, API routing, extraction stages and parts of state/consistency handling; several backend route-to-service and worker links are unsampled, so those relationships are left unasserted or marked unverified.

Main entry points: [`extractor/extractor/pipeline.py`](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/pipeline.py) (Story extraction), [`backend/app/api/v1/routes`](https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/api/v1/routes) (World API routes), [`Frontend/src/App.tsx`](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/App.tsx) (Application routes), [`backend/app/services/world_state_service.py`](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/world_state_service.py) (World state service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Writer interface"]
  node_app["Application routes<br/>[App.tsx]"]
  node_worldpages["World workspace"]
  node_writingroom["Writing room<br/>[WritingRoom.tsx]"]
  node_worldstore["World client state<br/>[useWorldStore.ts]"]
  node_apiclient["HTTP client<br/>[client.ts]"]
end

subgraph group_api["Backend API"]
  node_api_router["API router<br/>[router.py]"]
  node_api_routes["World API routes"]
end

subgraph group_processing["Extraction processing"]
  node_jobworkers["Job workers"]
  node_extract_task["Extraction task<br/>[extraction_task.py]"]
  node_extract_pipeline["Story extraction<br/>[pipeline.py]"]
  node_mentions["Mention extraction<br/>[mentions.py]"]
  node_coref["Coreference<br/>[coref.py]"]
  node_events["Event extraction<br/>[events.py]"]
  node_temporal["Temporal extraction<br/>[temporal.py]"]
  node_relations["Facts and relations<br/>[relations.py]"]
  node_extract_llm["Extractor LLM<br/>[llm.py]"]
end

subgraph group_worldstate["World state"]
  node_worldstate_service["World state service"]
  node_repositories["World repositories"]
  node_models["World records"]
  node_database[("SQL database<br/>[database.py]")]
end

subgraph group_intelligence["World intelligence"]
  node_consistency_service["Consistency service"]
  node_consistency_engine["Consistency rules engine<br/>[engine.py]"]
  node_chat_service["World assistant<br/>[chat_service.py]"]
  node_chat_llm["Chat LLM client<br/>[llm_client.py]"]
end

node_writer(("Writer"))

node_writer -.->|"uses"| node_app
node_app -->|"routes to"| node_worldpages
node_app -->|"routes to"| node_writingroom
node_worldpages -.->|"uses"| node_worldstore
node_writingroom -->|"uses"| node_worldstore
node_worldstore -->|"requests through"| node_apiclient
node_apiclient -->|"calls"| node_api_routes
node_api_router -->|"registers"| node_api_routes
node_api_routes -.->|"dispatches jobs"| node_jobworkers
node_jobworkers -.->|"runs"| node_extract_task
node_extract_task -.->|"invokes"| node_extract_pipeline
node_extract_pipeline -->|"runs stage"| node_mentions
node_extract_pipeline -->|"runs stage"| node_coref
node_extract_pipeline -->|"runs stage"| node_events
node_extract_pipeline -->|"runs stage"| node_temporal
node_extract_pipeline -->|"runs stage"| node_relations
node_relations -->|"generates with"| node_extract_llm
node_extract_pipeline -.->|"returns extraction data"| node_worldstate_service
node_worldstate_service -->|"reads and writes"| node_repositories
node_repositories -->|"persists records"| node_models
node_models -->|"uses metadata"| node_database
node_worldstate_service -->|"checks changes"| node_consistency_service
node_consistency_service -->|"evaluates"| node_consistency_engine
node_api_routes -.->|"serves chat"| node_chat_service
node_chat_service -->|"queries"| node_chat_llm

click node_app "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/App.tsx"
click node_worldpages "https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/Frontend/src/pages"
click node_writingroom "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/pages/WritingRoom.tsx"
click node_worldstore "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/store/useWorldStore.ts"
click node_apiclient "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/api/client.ts"
click node_api_router "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/api/v1/router.py"
click node_api_routes "https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/api/v1/routes"
click node_jobworkers "https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/workers"
click node_extract_task "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/workers/tasks/extraction_task.py"
click node_extract_pipeline "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/pipeline.py"
click node_mentions "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/mentions.py"
click node_coref "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/coref.py"
click node_events "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/events.py"
click node_temporal "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/temporal.py"
click node_relations "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/relations.py"
click node_extract_llm "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/llm.py"
click node_worldstate_service "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/world_state_service.py"
click node_repositories "https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/repositories"
click node_models "https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/models"
click node_database "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/core/database.py"
click node_consistency_service "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/consistency_service.py"
click node_consistency_engine "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/consistency/engine.py"
click node_chat_service "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/chat_service.py"
click node_chat_llm "https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/pipeline/llm_client.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_worldpages,node_writingroom,node_worldstore,node_apiclient toneBlue
class node_api_router,node_api_routes toneAmber
class node_jobworkers,node_extract_task,node_extract_pipeline,node_mentions,node_coref,node_events,node_temporal,node_relations,node_extract_llm toneMint
class node_worldstate_service,node_repositories,node_models,node_database toneRose
class node_consistency_service,node_consistency_engine,node_chat_service,node_chat_llm,node_writer toneIndigo
```

## Components

### Writer interface

- [Application routes](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/App.tsx): `Frontend/src/App.tsx`
- [World workspace](https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/Frontend/src/pages): `Frontend/src/pages`
- [Writing room](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/pages/WritingRoom.tsx): `Frontend/src/pages/WritingRoom.tsx`
- [World client state](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/store/useWorldStore.ts): `Frontend/src/store/useWorldStore.ts`
- [HTTP client](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/Frontend/src/api/client.ts): `Frontend/src/api/client.ts`

### Backend API

- [API router](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/api/v1/router.py): `backend/app/api/v1/router.py`
- [World API routes](https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/api/v1/routes): `backend/app/api/v1/routes`

### Extraction processing

- [Job workers](https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/workers): `backend/app/workers`
- [Extraction task](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/workers/tasks/extraction_task.py): `backend/app/workers/tasks/extraction_task.py`
- [Story extraction](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/pipeline.py): `extractor/extractor/pipeline.py`
- [Mention extraction](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/mentions.py): `extractor/extractor/mentions.py`
- [Coreference](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/coref.py): `extractor/extractor/coref.py`
- [Event extraction](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/events.py): `extractor/extractor/events.py`
- [Temporal extraction](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/temporal.py): `extractor/extractor/temporal.py`
- [Facts and relations](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/relations.py): `extractor/extractor/relations.py`
- [Extractor LLM](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/extractor/extractor/llm.py): `extractor/extractor/llm.py`

### World state

- [World state service](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/world_state_service.py): `backend/app/services/world_state_service.py`
- [World repositories](https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/repositories): `backend/app/repositories`
- [World records](https://github.com/meet-patel-2112/orion---world-state-engine/tree/main/backend/app/models): `backend/app/models`
- [SQL database](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/core/database.py): `backend/app/core/database.py`

### World intelligence

- [Consistency service](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/consistency_service.py): `backend/app/services/consistency_service.py`
- [Consistency rules engine](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/consistency/engine.py): `backend/app/consistency/engine.py`
- [World assistant](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`
- [Chat LLM client](https://github.com/meet-patel-2112/orion---world-state-engine/blob/main/backend/app/pipeline/llm_client.py): `backend/app/pipeline/llm_client.py`

### Other components

- **Writer**

## Connections

- Writer → Application routes: uses
- Application routes → World workspace: routes to (evidence: `Frontend/src/App.tsx`)
- Application routes → Writing room: routes to (evidence: `Frontend/src/App.tsx`)
- World workspace → World client state: uses (evidence: `Frontend/src/pages/WritingRoom.tsx`)
- Writing room → World client state: uses (evidence: `Frontend/src/store/useWorldStore.ts`)
- World client state → HTTP client: requests through (evidence: `Frontend/src/store/useWorldStore.ts`)
- HTTP client → World API routes: calls (evidence: `Frontend/src/api/client.ts`)
- API router → World API routes: registers (evidence: `backend/app/api/v1/router.py`)
- World API routes → Job workers: dispatches jobs
- Job workers → Extraction task: runs
- Extraction task → Story extraction: invokes
- Story extraction → Mention extraction: runs stage (evidence: `extractor/extractor/pipeline.py`)
- Story extraction → Coreference: runs stage (evidence: `extractor/extractor/pipeline.py`)
- Story extraction → Event extraction: runs stage (evidence: `extractor/extractor/pipeline.py`)
- Story extraction → Temporal extraction: runs stage (evidence: `extractor/extractor/pipeline.py`)
- Story extraction → Facts and relations: runs stage (evidence: `extractor/extractor/pipeline.py`)
- Facts and relations → Extractor LLM: generates with (evidence: `extractor/extractor/relations.py`)
- Story extraction → World state service: returns extraction data
- World state service → World repositories: reads and writes (evidence: `backend/app/services/world_state_service.py`)
- World repositories → World records: persists records (evidence: `backend/app/repositories/fact_repo.py`)
- World records → SQL database: uses metadata (evidence: `backend/app/models/fact.py`)
- World state service → Consistency service: checks changes (evidence: `backend/app/services/world_state_service.py`)
- Consistency service → Consistency rules engine: evaluates (evidence: `backend/app/services/consistency_service.py`)
- World API routes → World assistant: serves chat
- World assistant → Chat LLM client: queries (evidence: `backend/app/services/chat_service.py`)
