# dinas33/egyptian-civil-code-rag architecture

> Architecture diagram of the GitHub repository dinas33/egyptian-civil-code-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dinas33/egyptian-civil-code-rag
- Repository: https://github.com/dinas33/egyptian-civil-code-rag

## Overview

This is a bilingual Egyptian Civil Code RAG application. Its main workflow is PDF extraction into legal-article records, corpus preparation and indexing, then API question handling through semantic retrieval, context construction, and locally hosted answer generation with sources. Separate evaluation and observability workflows assess retrieval and answers and record runs or traces. The graph includes documented preparation stages whose script internals were not sampled; those links rely on the README, not inspected implementations.

Main entry points: [`src/rag/pipeline.py`](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/pipeline.py) (RAG pipeline), [`src/rag/api.py`](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/api.py) (FastAPI interface), [`scripts/evaluate_ragas_observability.py`](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/evaluate_ragas_observability.py) (RAGAS evaluation), [`src/egyptian_civil_code_rag/extraction.py`](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/egyptian_civil_code_rag/extraction.py) (Article extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_corpus["Corpus preparation"]
  node_extract["Article extraction<br/>[extraction.py]"]
  node_records["Article records"]
  node_chunk["Chunk building<br/>[build_chunks.py]"]
  node_embedbuild["Embedding build<br/>[build_embedding.py]"]
  node_faissbuild["FAISS index build<br/>[build_faiss.py]"]
  node_artifacts[("Chunks and index")]
end

subgraph group_serving["Query serving"]
  node_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_config["RAG configuration<br/>[config.py]"]
  node_embeddingmodel["Query embedding<br/>[embeddings.py]"]
  node_retrieval["Article retrieval<br/>[retriever.py]"]
  node_generator["Answer generation<br/>[generator.py]"]
end

subgraph group_evaluation["Evaluation and tracking"]
  node_evalbasic["RAG evaluation<br/>[evaluate_rag.py]"]
  node_evalragas["RAGAS evaluation"]
end

subgraph group_operations["Service interfaces"]
  node_fastapi["FastAPI interface<br/>[api.py]"]
  node_bento["BentoML service<br/>[bento_service.py]"]
end

node_pdf["Civil Code PDF"]
node_user(("Legal questioner"))
node_ollama{{"Ollama local LLM"}}
node_answer["Grounded answer"]
node_ragas{{"RAGAS metrics"}}
node_mlflow{{"MLflow tracking"}}
node_langfuse{{"Langfuse tracing"}}
node_dvc{{"DVC reproducibility"}}

node_pdf -->|"extracts text"| node_extract
node_extract -->|"writes records"| node_records
node_records -->|"chunks articles"| node_chunk
node_chunk -->|"embeds chunks"| node_embedbuild
node_embedbuild -->|"builds index"| node_faissbuild
node_faissbuild -->|"writes index"| node_artifacts
node_user -->|"submits question"| node_fastapi
node_user -.->|"submits question"| node_bento
node_fastapi -->|"initializes pipeline"| node_pipeline
node_bento -->|"initializes pipeline"| node_pipeline
node_pipeline -->|"loads settings"| node_config
node_pipeline -->|"loads model"| node_embeddingmodel
node_pipeline -->|"loads chunks and index"| node_artifacts
node_pipeline -->|"retrieves articles"| node_retrieval
node_pipeline -->|"generates answer"| node_generator
node_generator -->|"requests completion"| node_ollama
node_pipeline -->|"returns answer"| node_answer
node_evalbasic -.->|"evaluates quality"| node_ragas
node_evalragas -->|"scores responses"| node_ragas
node_evalragas -->|"logs metrics"| node_mlflow
node_evalragas -->|"records traces"| node_langfuse
node_fastapi -->|"logs query metrics"| node_mlflow
node_fastapi -->|"traces requests"| node_langfuse
node_dvc -.->|"versions pipeline"| node_extract

click node_pdf "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/data/raw/egyption-low.pdf.dvc"
click node_extract "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/egyptian_civil_code_rag/extraction.py"
click node_records "https://github.com/dinas33/egyptian-civil-code-rag/tree/di-data/data/processed"
click node_chunk "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/build_chunks.py"
click node_embedbuild "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/build_embedding.py"
click node_faissbuild "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/build_faiss.py"
click node_artifacts "https://github.com/dinas33/egyptian-civil-code-rag/tree/di-data/data/processed"
click node_fastapi "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/api.py"
click node_bento "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/bento_service.py"
click node_pipeline "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/pipeline.py"
click node_config "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/config.py"
click node_embeddingmodel "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/embeddings.py"
click node_retrieval "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/retriever.py"
click node_generator "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/generator.py"
click node_evalbasic "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/evaluate_rag.py"
click node_evalragas "https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/evaluate_ragas_observability.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_extract,node_records,node_chunk,node_embedbuild,node_faissbuild,node_artifacts toneBlue
class node_pipeline,node_config,node_embeddingmodel,node_retrieval,node_generator toneAmber
class node_evalbasic,node_evalragas toneMint
class node_fastapi,node_bento toneRose
class node_pdf toneTeal
class node_user,node_ollama,node_answer,node_ragas,node_mlflow,node_langfuse,node_dvc toneIndigo
```

## Components

### Corpus preparation

- [Article extraction](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/egyptian_civil_code_rag/extraction.py): `src/egyptian_civil_code_rag/extraction.py`
- [Article records](https://github.com/dinas33/egyptian-civil-code-rag/tree/di-data/data/processed): `data/processed`
- [Chunk building](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/build_chunks.py): `scripts/build_chunks.py`
- [Embedding build](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/build_embedding.py): `scripts/build_embedding.py`
- [FAISS index build](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/build_faiss.py): `scripts/build_faiss.py`
- [Chunks and index](https://github.com/dinas33/egyptian-civil-code-rag/tree/di-data/data/processed): `data/processed`

### Query serving

- [RAG pipeline](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/pipeline.py): `src/rag/pipeline.py`
- [RAG configuration](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/config.py): `src/rag/config.py`
- [Query embedding](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/embeddings.py): `src/rag/embeddings.py`
- [Article retrieval](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/retriever.py): `src/rag/retriever.py`
- [Answer generation](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/generator.py): `src/rag/generator.py`

### Evaluation and tracking

- [RAG evaluation](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/evaluate_rag.py): `scripts/evaluate_rag.py`
- [RAGAS evaluation](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/scripts/evaluate_ragas_observability.py): `scripts/evaluate_ragas_observability.py`

### Service interfaces

- [FastAPI interface](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/api.py): `src/rag/api.py`
- [BentoML service](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/src/rag/bento_service.py): `src/rag/bento_service.py`

### Other components

- [Civil Code PDF](https://github.com/dinas33/egyptian-civil-code-rag/blob/di-data/data/raw/egyption-low.pdf.dvc): `data/raw/egyption-low.pdf.dvc`
- **Legal questioner**
- **Ollama local LLM**
- **Grounded answer**
- **RAGAS metrics**
- **MLflow tracking**
- **Langfuse tracing**
- **DVC reproducibility**

## Connections

- Civil Code PDF → Article extraction: extracts text (evidence: `README.md`)
- Article extraction → Article records: writes records (evidence: `README.md`)
- Article records → Chunk building: chunks articles (evidence: `README.md`)
- Chunk building → Embedding build: embeds chunks (evidence: `README.md`)
- Embedding build → FAISS index build: builds index (evidence: `README.md`)
- FAISS index build → Chunks and index: writes index (evidence: `README.md`)
- Legal questioner → FastAPI interface: submits question (evidence: `README.md`)
- Legal questioner → BentoML service: submits question (evidence: `README.md`)
- FastAPI interface → RAG pipeline: initializes pipeline (evidence: `src/rag/api.py`)
- BentoML service → RAG pipeline: initializes pipeline (evidence: `src/rag/bento_service.py`)
- RAG pipeline → RAG configuration: loads settings (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Query embedding: loads model (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Chunks and index: loads chunks and index (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Article retrieval: retrieves articles (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Answer generation: generates answer (evidence: `src/rag/pipeline.py`)
- Answer generation → Ollama local LLM: requests completion (evidence: `src/rag/generator.py`)
- RAG pipeline → Grounded answer: returns answer (evidence: `src/rag/pipeline.py`)
- RAG evaluation → RAGAS metrics: evaluates quality (evidence: `README.md`)
- RAGAS evaluation → RAGAS metrics: scores responses (evidence: `scripts/evaluate_ragas_observability.py`)
- RAGAS evaluation → MLflow tracking: logs metrics (evidence: `scripts/evaluate_ragas_observability.py`)
- RAGAS evaluation → Langfuse tracing: records traces (evidence: `scripts/evaluate_ragas_observability.py`)
- FastAPI interface → MLflow tracking: logs query metrics (evidence: `src/rag/api.py`)
- FastAPI interface → Langfuse tracing: traces requests (evidence: `src/rag/api.py`)
- DVC reproducibility → Article extraction: versions pipeline (evidence: `README.md`)
