# rayane-kahlaoui/souls-overlay architecture

> Architecture diagram of the GitHub repository rayane-kahlaoui/souls-overlay, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rayane-kahlaoui/souls-overlay
- Repository: https://github.com/rayane-kahlaoui/souls-overlay

## Overview

Souls Overlay is an Electron desktop companion backed by a FastAPI service: players can chat for lore-aware guidance, maintain character context, and track bosses and NPC quests. The chat handler owns retrieval and response generation; account/profile endpoints persist player data and chat history in SQLite. A separate wiki-ingestion path scrapes and cleans lore, while the RAG service provides retrieval. The README documents hybrid retrieval and frontend checklist capabilities beyond the sampled implementation. Frontend-to-API wiring and some ingestion internals were not shown, so those links are left unverified.

Main entry points: [`backend/main.py`](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py) (FastAPI service), [`backend/core/scraper.py`](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/scraper.py) (Wiki scraper), [`backend/core/rag.py`](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/rag.py) (Hybrid lore retrieval), [`frontend/scripts/chat.js`](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/chat.js) (Companion chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop companion"]
  node_electron["Floating overlay<br/>[main.js]"]
  node_chat_ui["Companion chat<br/>[chat.js]"]
  node_profile_ui["Character profile<br/>[profile.js]"]
  node_boss_ui["Boss checklist<br/>[bosses.js]"]
  node_npc_ui["NPC questlines<br/>[npcs.js]"]
end

subgraph group_api["API and player state"]
  node_api_service["FastAPI service<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_player_state["Player profile<br/>[main.py]"]
  node_chat_flow["Chat orchestration<br/>[main.py]"]
  node_sqlite[("Account and chat store<br/>[database.py]")]
end

subgraph group_knowledge["Lore and AI"]
  node_rag["Hybrid lore retrieval<br/>[rag.py]"]
  node_chroma[("Lore vector store<br/>[rag.py]")]
  node_souls_ai["Persona response generation<br/>[llm.py]"]
  node_openrouter["OpenRouter models"]
end

subgraph group_ingestion["Lore ingestion"]
  node_wiki["Wiki source"]
  node_scraper["Wiki scraper<br/>[scraper.py]"]
  node_lore_files["Scraped lore files"]
  node_processing["Lore cleaning and extraction<br/>[processing.py]"]
end

node_player(("Player"))

node_player -->|"uses"| node_electron
node_electron -.->|"hosts"| node_chat_ui
node_player -->|"asks"| node_chat_ui
node_player -->|"updates"| node_profile_ui
node_player -->|"tracks"| node_boss_ui
node_player -->|"follows"| node_npc_ui
node_chat_ui -.->|"sends chat"| node_api_service
node_profile_ui -.->|"updates profile"| node_api_service
node_api_service -->|"validates identity"| node_auth
node_api_service -->|"serves profile"| node_player_state
node_api_service -->|"routes chat"| node_chat_flow
node_api_service -->|"starts scraping"| node_scraper
node_auth -->|"loads users"| node_sqlite
node_api_service -->|"reads and writes"| node_sqlite
node_chat_flow -->|"retrieves lore"| node_rag
node_chat_flow -->|"generates answer"| node_souls_ai
node_chat_flow -->|"loads history"| node_sqlite
node_souls_ai -->|"streams completion"| node_openrouter
node_rag -->|"reads documents"| node_chroma
node_wiki -.->|"provides pages"| node_scraper
node_scraper -->|"saves pages"| node_lore_files
node_scraper -.->|"cleans and extracts"| node_processing
node_processing -->|"processes files"| node_lore_files
node_rag -.->|"ingests corpus"| node_lore_files

click node_electron "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/main.js"
click node_chat_ui "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/chat.js"
click node_profile_ui "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/profile.js"
click node_boss_ui "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/bosses.js"
click node_npc_ui "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/npcs.js"
click node_api_service "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py"
click node_auth "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/auth.py"
click node_player_state "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py"
click node_chat_flow "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py"
click node_sqlite "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/database.py"
click node_rag "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/rag.py"
click node_chroma "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/rag.py"
click node_souls_ai "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/llm.py"
click node_scraper "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/scraper.py"
click node_lore_files "https://github.com/rayane-kahlaoui/souls-overlay/tree/main/backend/data"
click node_processing "https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/processing.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_electron,node_chat_ui,node_profile_ui,node_boss_ui,node_npc_ui toneBlue
class node_api_service,node_auth,node_player_state,node_chat_flow,node_sqlite toneAmber
class node_rag,node_chroma,node_souls_ai,node_openrouter toneMint
class node_wiki,node_scraper,node_lore_files,node_processing toneRose
class node_player toneIndigo
```

## Components

### Desktop companion

- [Floating overlay](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/main.js): `frontend/main.js`
- [Companion chat](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/chat.js): `frontend/scripts/chat.js`
- [Character profile](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/profile.js): `frontend/scripts/profile.js`
- [Boss checklist](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/bosses.js): `frontend/scripts/bosses.js`
- [NPC questlines](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/frontend/scripts/npcs.js): `frontend/scripts/npcs.js`

### API and player state

- [FastAPI service](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py): `backend/main.py`
- [Authentication](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/auth.py): `backend/core/auth.py`
- [Player profile](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py): `backend/main.py`
- [Chat orchestration](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/main.py): `backend/main.py`
- [Account and chat store](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/database.py): `backend/core/database.py`

### Lore and AI

- [Hybrid lore retrieval](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/rag.py): `backend/core/rag.py`
- [Lore vector store](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/rag.py): `backend/core/rag.py`
- [Persona response generation](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/llm.py): `backend/core/llm.py`
- **OpenRouter models**

### Lore ingestion

- **Wiki source**
- [Wiki scraper](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/scraper.py): `backend/core/scraper.py`
- [Scraped lore files](https://github.com/rayane-kahlaoui/souls-overlay/tree/main/backend/data): `backend/data`
- [Lore cleaning and extraction](https://github.com/rayane-kahlaoui/souls-overlay/blob/main/backend/core/processing.py): `backend/core/processing.py`

### Other components

- **Player**

## Connections

- Player → Floating overlay: uses (evidence: `README.md`)
- Floating overlay → Companion chat: hosts
- Player → Companion chat: asks (evidence: `README.md`)
- Player → Character profile: updates (evidence: `README.md`)
- Player → Boss checklist: tracks (evidence: `README.md`)
- Player → NPC questlines: follows (evidence: `README.md`)
- Companion chat → FastAPI service: sends chat
- Character profile → FastAPI service: updates profile
- FastAPI service → Authentication: validates identity (evidence: `backend/main.py`)
- FastAPI service → Player profile: serves profile (evidence: `backend/main.py`)
- FastAPI service → Chat orchestration: routes chat (evidence: `backend/main.py`)
- FastAPI service → Wiki scraper: starts scraping (evidence: `backend/main.py`)
- Authentication → Account and chat store: loads users (evidence: `backend/core/auth.py`)
- FastAPI service → Account and chat store: reads and writes (evidence: `backend/main.py`)
- Chat orchestration → Hybrid lore retrieval: retrieves lore (evidence: `backend/main.py`)
- Chat orchestration → Persona response generation: generates answer (evidence: `backend/main.py`)
- Chat orchestration → Account and chat store: loads history (evidence: `backend/main.py`)
- Persona response generation → OpenRouter models: streams completion (evidence: `backend/core/llm.py`)
- Hybrid lore retrieval → Lore vector store: reads documents (evidence: `backend/core/rag.py`)
- Wiki source → Wiki scraper: provides pages
- Wiki scraper → Scraped lore files: saves pages (evidence: `backend/core/scraper.py`)
- Wiki scraper → Lore cleaning and extraction: cleans and extracts
- Lore cleaning and extraction → Scraped lore files: processes files
- Hybrid lore retrieval → Scraped lore files: ingests corpus
