# bhoomisurve/narrativeiq architecture

> Architecture diagram of the GitHub repository bhoomisurve/narrativeiq, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bhoomisurve/narrativeiq
- Repository: https://github.com/bhoomisurve/narrativeiq

## Overview

NarrativeIQ is a writing-intelligence SaaS: users sign in, submit narrative text for enhancement or analysis, and view generated results; the frontend also exposes story, document, history, mindmap, profile, and credit workflows. The checked-in backend is a FastAPI application using Supabase, not the Flask/MongoDB stack described in the README, and several README capabilities have no matching backend router in the supplied tree. Edges reflect sampled imports, calls, or documented frontend requests; unsampled feature implementations are left unverified.

Main entry points: [`src/App.tsx`](https://github.com/bhoomisurve/narrativeiq/blob/main/src/App.tsx) (App routing), [`src/lib/api.ts`](https://github.com/bhoomisurve/narrativeiq/blob/main/src/lib/api.ts) (API client), [`app/db/supabase.py`](https://github.com/bhoomisurve/narrativeiq/blob/main/app/db/supabase.py) (Supabase access), [`app/routers/enhance.py`](https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/enhance.py) (Text enhancement)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app_shell["App routing<br/>[App.tsx]"]
  node_auth_state["Auth state<br/>[AuthContext.tsx]"]
  node_dashboard["Writing workspace<br/>[Dashboard.tsx]"]
  node_analysis_panel["Analysis results<br/>[AnalysisPanel.tsx]"]
  node_diff_view["Text diff<br/>[DiffView.tsx]"]
  node_story_page["Story completion<br/>[StoryPage.tsx]"]
  node_mindmap_page["Mindmap view<br/>[MindmapPage.tsx]"]
  node_docs_page["Documents<br/>[DocumentsPage.tsx]"]
  node_history_page["History<br/>[HistoryPage.tsx]"]
  node_account_pages["Account and credits"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and access"]
  node_api_server["FastAPI app<br/>[main.py]"]
  node_auth_guard["Token verification<br/>[auth.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
  node_legacy_module["Additional app module<br/>[app.py]"]
end

subgraph group_analysis["Narrative processing"]
  node_enhance["Text enhancement<br/>[enhance.py]"]
  node_consistency["Consistency analysis<br/>[consistency.py]"]
  node_evolution["Character evolution<br/>[evolution.py]"]
  node_mindmap["Mindmap generation<br/>[mindmap.py]"]
  node_llm["Language model<br/>[llm.py]"]
  node_diff["Diff computation<br/>[diff.py]"]
  node_graph["Graph processing<br/>[graph.py]"]
  node_nlp["Entity processing<br/>[nlp.py]"]
end

subgraph group_state["Account and persistence"]
  node_credits["Credit operations<br/>[credits.py]"]
  node_supabase[("Supabase access<br/>[supabase.py]")]
  node_settings["Runtime settings<br/>[config.py]"]
end

node_writer(("Writer"))
node_external_api{{"API service"}}

node_writer -->|"uses"| node_app_shell
node_app_shell -->|"provides auth"| node_auth_state
node_app_shell -->|"routes to"| node_dashboard
node_app_shell -->|"routes to"| node_story_page
node_app_shell -->|"routes to"| node_mindmap_page
node_app_shell -->|"routes to"| node_docs_page
node_app_shell -->|"routes to"| node_history_page
node_app_shell -->|"routes to"| node_account_pages
node_auth_state -->|"calls"| node_api_client
node_dashboard -->|"requests analysis"| node_api_client
node_dashboard -->|"renders"| node_analysis_panel
node_dashboard -->|"renders"| node_diff_view
node_mindmap_page -->|"requests graph"| node_api_client
node_story_page -.->|"requests completion"| node_api_client
node_docs_page -.->|"requests documents"| node_api_client
node_history_page -.->|"requests history"| node_api_client
node_account_pages -.->|"requests account"| node_api_client
node_api_client -->|"sends HTTP"| node_external_api
node_api_server -->|"registers router"| node_credits
node_api_server -->|"registers router"| node_enhance
node_api_server -->|"registers router"| node_mindmap
node_api_server -->|"registers router"| node_consistency
node_api_server -->|"registers router"| node_evolution
node_enhance -->|"uses"| node_auth_guard
node_consistency -->|"uses"| node_auth_guard
node_evolution -->|"uses"| node_auth_guard
node_mindmap -->|"uses"| node_auth_guard
node_credits -->|"uses"| node_auth_guard
node_enhance -->|"reads and writes"| node_supabase
node_consistency -->|"reads and writes"| node_supabase
node_evolution -->|"reads and writes"| node_supabase
node_mindmap -->|"reads and writes"| node_supabase
node_credits -->|"manages credits"| node_supabase
node_enhance -->|"calls"| node_llm
node_enhance -->|"computes diff"| node_diff
node_consistency -->|"calls"| node_llm
node_evolution -->|"calls"| node_llm
node_mindmap -->|"builds graph"| node_graph
node_graph -->|"uses"| node_nlp
node_graph -->|"calls"| node_llm
node_llm -->|"reads provider config"| node_settings
node_supabase -->|"reads credentials"| node_settings
node_auth_guard -->|"verifies token"| node_supabase
node_credits -->|"reads pricing"| node_settings
node_enhance -->|"validates requests"| node_schemas
node_consistency -->|"validates requests"| node_schemas
node_evolution -->|"validates requests"| node_schemas
node_mindmap -->|"validates requests"| node_schemas

click node_app_shell "https://github.com/bhoomisurve/narrativeiq/blob/main/src/App.tsx"
click node_auth_state "https://github.com/bhoomisurve/narrativeiq/blob/main/src/contexts/AuthContext.tsx"
click node_dashboard "https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/Dashboard.tsx"
click node_analysis_panel "https://github.com/bhoomisurve/narrativeiq/blob/main/src/components/AnalysisPanel.tsx"
click node_diff_view "https://github.com/bhoomisurve/narrativeiq/blob/main/src/components/DiffView.tsx"
click node_story_page "https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/StoryPage.tsx"
click node_mindmap_page "https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/MindmapPage.tsx"
click node_docs_page "https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/DocumentsPage.tsx"
click node_history_page "https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/HistoryPage.tsx"
click node_account_pages "https://github.com/bhoomisurve/narrativeiq/tree/main/src/pages"
click node_api_client "https://github.com/bhoomisurve/narrativeiq/blob/main/src/lib/api.ts"
click node_api_server "https://github.com/bhoomisurve/narrativeiq/blob/main/app/main.py"
click node_auth_guard "https://github.com/bhoomisurve/narrativeiq/blob/main/app/middleware/auth.py"
click node_schemas "https://github.com/bhoomisurve/narrativeiq/blob/main/app/models/schemas.py"
click node_legacy_module "https://github.com/bhoomisurve/narrativeiq/blob/main/app/app.py"
click node_enhance "https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/enhance.py"
click node_consistency "https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/consistency.py"
click node_evolution "https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/evolution.py"
click node_mindmap "https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/mindmap.py"
click node_llm "https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/llm.py"
click node_diff "https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/diff.py"
click node_graph "https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/graph.py"
click node_nlp "https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/nlp.py"
click node_credits "https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/credits.py"
click node_supabase "https://github.com/bhoomisurve/narrativeiq/blob/main/app/db/supabase.py"
click node_settings "https://github.com/bhoomisurve/narrativeiq/blob/main/app/config.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_shell,node_auth_state,node_dashboard,node_analysis_panel,node_diff_view,node_story_page,node_mindmap_page,node_docs_page,node_history_page,node_account_pages,node_api_client toneBlue
class node_api_server,node_auth_guard,node_schemas,node_legacy_module toneAmber
class node_enhance,node_consistency,node_evolution,node_mindmap,node_llm,node_diff,node_graph,node_nlp,node_external_api toneMint
class node_credits,node_supabase,node_settings toneRose
class node_writer toneIndigo
```

## Components

### Web client

- [App routing](https://github.com/bhoomisurve/narrativeiq/blob/main/src/App.tsx): `src/App.tsx`
- [Auth state](https://github.com/bhoomisurve/narrativeiq/blob/main/src/contexts/AuthContext.tsx): `src/contexts/AuthContext.tsx`
- [Writing workspace](https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/Dashboard.tsx): `src/pages/Dashboard.tsx`
- [Analysis results](https://github.com/bhoomisurve/narrativeiq/blob/main/src/components/AnalysisPanel.tsx): `src/components/AnalysisPanel.tsx`
- [Text diff](https://github.com/bhoomisurve/narrativeiq/blob/main/src/components/DiffView.tsx): `src/components/DiffView.tsx`
- [Story completion](https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/StoryPage.tsx): `src/pages/StoryPage.tsx`
- [Mindmap view](https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/MindmapPage.tsx): `src/pages/MindmapPage.tsx`
- [Documents](https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/DocumentsPage.tsx): `src/pages/DocumentsPage.tsx`
- [History](https://github.com/bhoomisurve/narrativeiq/blob/main/src/pages/HistoryPage.tsx): `src/pages/HistoryPage.tsx`
- [Account and credits](https://github.com/bhoomisurve/narrativeiq/tree/main/src/pages): `src/pages`
- [API client](https://github.com/bhoomisurve/narrativeiq/blob/main/src/lib/api.ts): `src/lib/api.ts`

### API and access

- [FastAPI app](https://github.com/bhoomisurve/narrativeiq/blob/main/app/main.py): `app/main.py`
- [Token verification](https://github.com/bhoomisurve/narrativeiq/blob/main/app/middleware/auth.py): `app/middleware/auth.py`
- [Request schemas](https://github.com/bhoomisurve/narrativeiq/blob/main/app/models/schemas.py): `app/models/schemas.py`
- [Additional app module](https://github.com/bhoomisurve/narrativeiq/blob/main/app/app.py): `app/app.py`

### Narrative processing

- [Text enhancement](https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/enhance.py): `app/routers/enhance.py`
- [Consistency analysis](https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/consistency.py): `app/routers/consistency.py`
- [Character evolution](https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/evolution.py): `app/routers/evolution.py`
- [Mindmap generation](https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/mindmap.py): `app/routers/mindmap.py`
- [Language model](https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/llm.py): `app/services/llm.py`
- [Diff computation](https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/diff.py): `app/services/diff.py`
- [Graph processing](https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/graph.py): `app/services/graph.py`
- [Entity processing](https://github.com/bhoomisurve/narrativeiq/blob/main/app/services/nlp.py): `app/services/nlp.py`

### Account and persistence

- [Credit operations](https://github.com/bhoomisurve/narrativeiq/blob/main/app/routers/credits.py): `app/routers/credits.py`
- [Supabase access](https://github.com/bhoomisurve/narrativeiq/blob/main/app/db/supabase.py): `app/db/supabase.py`
- [Runtime settings](https://github.com/bhoomisurve/narrativeiq/blob/main/app/config.py): `app/config.py`

### Other components

- **Writer**
- **API service**

## Connections

- Writer → App routing: uses (evidence: `src/App.tsx`)
- App routing → Auth state: provides auth (evidence: `src/App.tsx`)
- App routing → Writing workspace: routes to (evidence: `src/App.tsx`)
- App routing → Story completion: routes to (evidence: `src/App.tsx`)
- App routing → Mindmap view: routes to (evidence: `src/App.tsx`)
- App routing → Documents: routes to (evidence: `src/App.tsx`)
- App routing → History: routes to (evidence: `src/App.tsx`)
- App routing → Account and credits: routes to (evidence: `src/App.tsx`)
- Auth state → API client: calls (evidence: `src/contexts/AuthContext.tsx`)
- Writing workspace → API client: requests analysis (evidence: `src/pages/Dashboard.tsx`)
- Writing workspace → Analysis results: renders (evidence: `src/pages/Dashboard.tsx`)
- Writing workspace → Text diff: renders (evidence: `src/pages/Dashboard.tsx`)
- Mindmap view → API client: requests graph (evidence: `src/pages/MindmapPage.tsx`)
- Story completion → API client: requests completion
- Documents → API client: requests documents
- History → API client: requests history
- Account and credits → API client: requests account (evidence: `src/pages/Dashboard.tsx`)
- API client → API service: sends HTTP (evidence: `src/lib/api.ts`)
- FastAPI app → Credit operations: registers router (evidence: `app/main.py`)
- FastAPI app → Text enhancement: registers router (evidence: `app/main.py`)
- FastAPI app → Mindmap generation: registers router (evidence: `app/main.py`)
- FastAPI app → Consistency analysis: registers router (evidence: `app/main.py`)
- FastAPI app → Character evolution: registers router (evidence: `app/main.py`)
- Text enhancement → Token verification: uses (evidence: `app/routers/enhance.py`)
- Consistency analysis → Token verification: uses (evidence: `app/routers/consistency.py`)
- Character evolution → Token verification: uses (evidence: `app/routers/evolution.py`)
- Mindmap generation → Token verification: uses (evidence: `app/routers/mindmap.py`)
- Credit operations → Token verification: uses (evidence: `app/routers/credits.py`)
- Text enhancement → Supabase access: reads and writes (evidence: `app/routers/enhance.py`)
- Consistency analysis → Supabase access: reads and writes (evidence: `app/routers/consistency.py`)
- Character evolution → Supabase access: reads and writes (evidence: `app/routers/evolution.py`)
- Mindmap generation → Supabase access: reads and writes (evidence: `app/routers/mindmap.py`)
- Credit operations → Supabase access: manages credits (evidence: `app/routers/credits.py`)
- Text enhancement → Language model: calls (evidence: `app/routers/enhance.py`)
- Text enhancement → Diff computation: computes diff (evidence: `app/routers/enhance.py`)
- Consistency analysis → Language model: calls (evidence: `app/routers/consistency.py`)
- Character evolution → Language model: calls (evidence: `app/routers/evolution.py`)
- Mindmap generation → Graph processing: builds graph (evidence: `app/routers/mindmap.py`)
- Graph processing → Entity processing: uses (evidence: `app/services/graph.py`)
- Graph processing → Language model: calls (evidence: `app/services/graph.py`)
- Language model → Runtime settings: reads provider config (evidence: `app/services/llm.py`)
- Supabase access → Runtime settings: reads credentials (evidence: `app/db/supabase.py`)
- Token verification → Supabase access: verifies token (evidence: `app/middleware/auth.py`)
- Credit operations → Runtime settings: reads pricing (evidence: `app/routers/credits.py`)
- Text enhancement → Request schemas: validates requests (evidence: `app/routers/enhance.py`)
- Consistency analysis → Request schemas: validates requests (evidence: `app/routers/consistency.py`)
- Character evolution → Request schemas: validates requests (evidence: `app/routers/evolution.py`)
- Mindmap generation → Request schemas: validates requests (evidence: `app/routers/mindmap.py`)
