# wajih1234/legaltun architecture

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

- Interactive diagram: https://gitdiagram.com/wajih1234/legaltun
- Repository: https://github.com/wajih1234/legaltun

## Overview

LexTN is a French-language JORT legal-question chatbot with a React interface and two retrieval approaches. The shown frontend sends questions to the classical RAG endpoint; that API delegates retrieval and answer generation, returning answers and source chunks. A separate Flask GraphRAG API generates read-only Cypher and summarizes Neo4j results. The README also documents PDF ingestion into Qdrant and knowledge-graph construction. Those corpus-building links are documented, but their runtime details were not sampled; the UI’s shown endpoint does not select GraphRAG.

Main entry points: [`legal-chat-front/src/components/ChatArea.jsx`](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/ChatArea.jsx) (Chat workflow), [`back/app.py`](https://github.com/wajih1234/legaltun/blob/master/back/app.py) (Graph query API), [`back/neo4j_client.py`](https://github.com/wajih1234/legaltun/blob/master/back/neo4j_client.py) (Neo4j connection), [`legal-chat-front/src/App.jsx`](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/App.jsx) (Application shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Chat interface"]
  node_app["Application shell<br/>[App.jsx]"]
  node_chat["Chat workflow<br/>[ChatArea.jsx]"]
  node_input["Question input<br/>[InputBar.jsx]"]
  node_bubble["Answer display<br/>[MessageBubble.jsx]"]
  node_sidebar["Conversation sidebar<br/>[Sidebar.jsx]"]
  node_history["Conversation state"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_classical["Classical RAG"]
  node_rag_api["RAG API<br/>[app.py]"]
  node_pipeline["RAG orchestration<br/>[pipeline.py]"]
  node_retriever["Vector retrieval<br/>[retriever.py]"]
  node_qdrant[("Qdrant collection")]
  node_generator["Answer generation<br/>[generator.py]"]
end

subgraph group_graph["GraphRAG"]
  node_graph_api["Graph query API<br/>[app.py]"]
  node_entity["Entity resolution"]
  node_cypher["Cypher generation<br/>[llm_cypher.py]"]
  node_schema["Schema discovery<br/>[schema_fetcher.py]"]
  node_validator_runner["Query validation and execution<br/>[cypher_runner.py]"]
  node_neo_client["Neo4j connection<br/>[neo4j_client.py]"]
  node_graph_answer["Result summarization"]
end

subgraph group_corpus["Corpus preparation"]
  node_pdfs["JORT PDF corpus"]
  node_loader["PDF extraction and chunking<br/>[document_loader.py]"]
  node_embeddings["Embedding preparation<br/>[embd.py]"]
  node_triplets["Triplet extraction"]
end

node_user(("Questioner"))
node_groq{{"LLM service"}}
node_neo4j[("Knowledge graph")]

node_user -->|"asks"| node_chat
node_chat -->|"renders"| node_input
node_chat -->|"submits question"| node_api_client
node_api_client -->|"HTTP POST"| node_rag_api
node_rag_api -->|"calls"| node_pipeline
node_pipeline -->|"retrieves chunks"| node_retriever
node_pipeline -->|"generates answer"| node_generator
node_retriever -->|"searches vectors"| node_qdrant
node_retriever -->|"returns chunks"| node_generator
node_generator -->|"generates response"| node_groq
node_chat -->|"renders messages"| node_bubble
node_app -->|"renders"| node_chat
node_app -->|"renders"| node_sidebar
node_app -->|"uses state"| node_history
node_sidebar -->|"manages conversations"| node_history
node_chat -->|"updates messages"| node_history
node_user -.->|"asks"| node_graph_api
node_graph_api -->|"resolves entities"| node_entity
node_graph_api -->|"generates query"| node_cypher
node_graph_api -->|"validates and runs"| node_validator_runner
node_graph_api -->|"summarizes results"| node_graph_answer
node_cypher -->|"uses schema"| node_schema
node_schema -->|"queries through"| node_neo_client
node_validator_runner -->|"runs queries through"| node_neo_client
node_neo_client -.->|"connects"| node_neo4j
node_entity -.->|"resolves against"| node_neo_client
node_cypher -->|"uses LLM API"| node_groq
node_graph_answer -.->|"uses LLM"| node_groq
node_pdfs -.->|"provides documents"| node_loader
node_loader -.->|"chunks for embeddings"| node_embeddings
node_embeddings -.->|"stores vectors"| node_qdrant
node_pdfs -.->|"source corpus"| node_triplets
node_triplets -.->|"builds graph"| node_neo4j

click node_app "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/App.jsx"
click node_chat "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/ChatArea.jsx"
click node_input "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/InputBar.jsx"
click node_bubble "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/MessageBubble.jsx"
click node_sidebar "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/Sidebar.jsx"
click node_history "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/hooks/useConversations.js"
click node_api_client "https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/services/api.js"
click node_rag_api "https://github.com/wajih1234/legaltun/blob/master/ragclassi/app.py"
click node_pipeline "https://github.com/wajih1234/legaltun/blob/master/ragclassi/pipeline.py"
click node_retriever "https://github.com/wajih1234/legaltun/blob/master/ragclassi/retriever.py"
click node_qdrant "https://github.com/wajih1234/legaltun/tree/master/ragclassi/qdrant_storage"
click node_generator "https://github.com/wajih1234/legaltun/blob/master/ragclassi/generator.py"
click node_graph_api "https://github.com/wajih1234/legaltun/blob/master/back/app.py"
click node_entity "https://github.com/wajih1234/legaltun/blob/master/back/entity_extractor.py"
click node_cypher "https://github.com/wajih1234/legaltun/blob/master/back/llm_cypher.py"
click node_schema "https://github.com/wajih1234/legaltun/blob/master/back/schema_fetcher.py"
click node_validator_runner "https://github.com/wajih1234/legaltun/blob/master/back/cypher_runner.py"
click node_neo_client "https://github.com/wajih1234/legaltun/blob/master/back/neo4j_client.py"
click node_graph_answer "https://github.com/wajih1234/legaltun/blob/master/back/answer_generator.py"
click node_pdfs "https://github.com/wajih1234/legaltun/tree/master/ragclassi/docs"
click node_loader "https://github.com/wajih1234/legaltun/blob/master/ragclassi/document_loader.py"
click node_embeddings "https://github.com/wajih1234/legaltun/blob/master/ragclassi/embd.py"
click node_triplets "https://github.com/wajih1234/legaltun/blob/master/back/entity_extractor.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_chat,node_input,node_bubble,node_sidebar,node_history,node_api_client toneBlue
class node_rag_api,node_pipeline,node_retriever,node_qdrant,node_generator,node_neo4j toneAmber
class node_graph_api,node_entity,node_cypher,node_schema,node_validator_runner,node_neo_client,node_graph_answer toneMint
class node_pdfs,node_loader,node_embeddings,node_triplets toneRose
class node_user,node_groq toneIndigo
```

## Components

### Chat interface

- [Application shell](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/App.jsx): `legal-chat-front/src/App.jsx`
- [Chat workflow](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/ChatArea.jsx): `legal-chat-front/src/components/ChatArea.jsx`
- [Question input](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/InputBar.jsx): `legal-chat-front/src/components/InputBar.jsx`
- [Answer display](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/MessageBubble.jsx): `legal-chat-front/src/components/MessageBubble.jsx`
- [Conversation sidebar](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/components/Sidebar.jsx): `legal-chat-front/src/components/Sidebar.jsx`
- [Conversation state](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/hooks/useConversations.js): `legal-chat-front/src/hooks/useConversations.js`
- [API client](https://github.com/wajih1234/legaltun/blob/master/legal-chat-front/src/services/api.js): `legal-chat-front/src/services/api.js`

### Classical RAG

- [RAG API](https://github.com/wajih1234/legaltun/blob/master/ragclassi/app.py): `ragclassi/app.py`
- [RAG orchestration](https://github.com/wajih1234/legaltun/blob/master/ragclassi/pipeline.py): `ragclassi/pipeline.py`
- [Vector retrieval](https://github.com/wajih1234/legaltun/blob/master/ragclassi/retriever.py): `ragclassi/retriever.py`
- [Qdrant collection](https://github.com/wajih1234/legaltun/tree/master/ragclassi/qdrant_storage): `ragclassi/qdrant_storage`
- [Answer generation](https://github.com/wajih1234/legaltun/blob/master/ragclassi/generator.py): `ragclassi/generator.py`

### GraphRAG

- [Graph query API](https://github.com/wajih1234/legaltun/blob/master/back/app.py): `back/app.py`
- [Entity resolution](https://github.com/wajih1234/legaltun/blob/master/back/entity_extractor.py): `back/entity_extractor.py`
- [Cypher generation](https://github.com/wajih1234/legaltun/blob/master/back/llm_cypher.py): `back/llm_cypher.py`
- [Schema discovery](https://github.com/wajih1234/legaltun/blob/master/back/schema_fetcher.py): `back/schema_fetcher.py`
- [Query validation and execution](https://github.com/wajih1234/legaltun/blob/master/back/cypher_runner.py): `back/cypher_runner.py`
- [Neo4j connection](https://github.com/wajih1234/legaltun/blob/master/back/neo4j_client.py): `back/neo4j_client.py`
- [Result summarization](https://github.com/wajih1234/legaltun/blob/master/back/answer_generator.py): `back/answer_generator.py`

### Corpus preparation

- [JORT PDF corpus](https://github.com/wajih1234/legaltun/tree/master/ragclassi/docs): `ragclassi/docs`
- [PDF extraction and chunking](https://github.com/wajih1234/legaltun/blob/master/ragclassi/document_loader.py): `ragclassi/document_loader.py`
- [Embedding preparation](https://github.com/wajih1234/legaltun/blob/master/ragclassi/embd.py): `ragclassi/embd.py`
- [Triplet extraction](https://github.com/wajih1234/legaltun/blob/master/back/entity_extractor.py): `back/entity_extractor.py`

### Other components

- **Questioner**
- **LLM service**
- **Knowledge graph**

## Connections

- Questioner → Chat workflow: asks (evidence: `legal-chat-front/src/components/ChatArea.jsx`)
- Chat workflow → Question input: renders (evidence: `legal-chat-front/src/components/ChatArea.jsx`)
- Chat workflow → API client: submits question (evidence: `legal-chat-front/src/components/ChatArea.jsx`)
- API client → RAG API: HTTP POST (evidence: `legal-chat-front/src/services/api.js`)
- RAG API → RAG orchestration: calls (evidence: `ragclassi/app.py`)
- RAG orchestration → Vector retrieval: retrieves chunks (evidence: `ragclassi/pipeline.py`)
- RAG orchestration → Answer generation: generates answer (evidence: `ragclassi/pipeline.py`)
- Vector retrieval → Qdrant collection: searches vectors (evidence: `ragclassi/retriever.py`)
- Vector retrieval → Answer generation: returns chunks (evidence: `ragclassi/pipeline.py`)
- Answer generation → LLM service: generates response (evidence: `README.md`)
- Chat workflow → Answer display: renders messages (evidence: `legal-chat-front/src/components/ChatArea.jsx`)
- Application shell → Chat workflow: renders (evidence: `legal-chat-front/src/App.jsx`)
- Application shell → Conversation sidebar: renders (evidence: `legal-chat-front/src/App.jsx`)
- Application shell → Conversation state: uses state (evidence: `legal-chat-front/src/App.jsx`)
- Conversation sidebar → Conversation state: manages conversations (evidence: `legal-chat-front/src/App.jsx`)
- Chat workflow → Conversation state: updates messages (evidence: `legal-chat-front/src/App.jsx`)
- Questioner → Graph query API: asks
- Graph query API → Entity resolution: resolves entities (evidence: `back/app.py`)
- Graph query API → Cypher generation: generates query (evidence: `back/app.py`)
- Graph query API → Query validation and execution: validates and runs (evidence: `back/app.py`)
- Graph query API → Result summarization: summarizes results (evidence: `back/app.py`)
- Cypher generation → Schema discovery: uses schema (evidence: `back/llm_cypher.py`)
- Schema discovery → Neo4j connection: queries through (evidence: `back/schema_fetcher.py`)
- Query validation and execution → Neo4j connection: runs queries through (evidence: `back/cypher_runner.py`)
- Neo4j connection → Knowledge graph: connects
- Entity resolution → Neo4j connection: resolves against (evidence: `back/entity_extractor.py`)
- Cypher generation → LLM service: uses LLM API (evidence: `README.md`)
- Result summarization → LLM service: uses LLM
- JORT PDF corpus → PDF extraction and chunking: provides documents (evidence: `README.md`)
- PDF extraction and chunking → Embedding preparation: chunks for embeddings (evidence: `README.md`)
- Embedding preparation → Qdrant collection: stores vectors (evidence: `README.md`)
- JORT PDF corpus → Triplet extraction: source corpus (evidence: `README.md`)
- Triplet extraction → Knowledge graph: builds graph (evidence: `README.md`)
