# farahe-elmontaser/etics architecture

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

- Interactive diagram: https://gitdiagram.com/farahe-elmontaser/etics
- Repository: https://github.com/farahe-elmontaser/etics

## Overview

ETICS turns bank-contract PDFs/TXT into clause-level toxicity judgments, contract scores, and a SQLite dataset, using locally hosted Ollama models and legal-reference RAG. The main workflow is orchestrated by `src/pipeline.py`; separate capabilities create annotation samples, evaluate judgments against human annotations, and display results in Streamlit. Relationships below are grounded in the pipeline and sampled modules or explicitly documented in the README; unsampled details are represented only at their supported directory level.

Main entry points: [`src/pipeline.py`](https://github.com/farahe-elmontaser/etics/blob/main/src/pipeline.py) (Pipeline orchestration), [`src/indexation.py`](https://github.com/farahe-elmontaser/etics/blob/main/src/indexation.py) (Legal RAG index), [`src/base.py`](https://github.com/farahe-elmontaser/etics/blob/main/src/base.py) (SQLite data access), [`src/classification.py`](https://github.com/farahe-elmontaser/etics/blob/main/src/classification.py) (Clause classification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Contract ingestion"]
  node_contracts["Contract files"]
  node_extract["Text extraction<br/>[extraction.py]"]
  node_split["Clause splitting<br/>[decoupage.py]"]
  node_pipeline["Pipeline orchestration<br/>[pipeline.py]"]
end

subgraph group_analysis["Legal analysis"]
  node_config["Settings and rubric<br/>[config.py]"]
  node_legal["Legal reference files"]
  node_index["Legal RAG index<br/>[indexation.py]"]
  node_chroma[("ChromaDB")]
  node_classifier["Clause classification<br/>[classification.py]"]
  node_ollama_client["Ollama client<br/>[ollama_client.py]"]
  node_ollama["Local Ollama models"]
  node_examples["Few-shot examples<br/>[exemples.csv]"]
end

subgraph group_storage["Data and scoring"]
  node_scoring["Contract scoring<br/>[score.py]"]
  node_db_access["SQLite data access<br/>[base.py]"]
  node_sqlite[("Contracts and clauses DB")]
end

subgraph group_review["Review and display"]
  node_annotation["Human annotations"]
  node_evaluation["Evaluation metrics<br/>[evaluation.py]"]
  node_dashboard["Results dashboard<br/>[dashboard.py]"]
end

node_operator(("Operator"))
node_viewer(("Analyst"))

node_operator -->|"runs stages"| node_pipeline
node_pipeline -->|"reads contracts"| node_extract
node_contracts -->|"supplies files"| node_extract
node_pipeline -->|"splits text"| node_split
node_extract -->|"provides text"| node_split
node_pipeline -->|"stores clauses"| node_db_access
node_pipeline -->|"indexes references"| node_index
node_legal -->|"supplies legal text"| node_index
node_index -->|"requests embeddings"| node_ollama_client
node_ollama_client -->|"calls model API"| node_ollama
node_index -->|"stores and searches"| node_chroma
node_pipeline -->|"classifies clauses"| node_classifier
node_classifier -->|"retrieves references"| node_index
node_classifier -->|"requests judgment"| node_ollama_client
node_examples -->|"provides examples"| node_classifier
node_pipeline -->|"calculates scores"| node_scoring
node_pipeline -->|"reads and updates records"| node_db_access
node_db_access -->|"reads and writes"| node_sqlite
node_operator -->|"creates sample"| node_pipeline
node_pipeline -->|"writes sample"| node_annotation
node_operator -->|"runs evaluation"| node_evaluation
node_annotation -->|"provides labels"| node_evaluation
node_evaluation -->|"loads predictions"| node_db_access
node_viewer -->|"views results"| node_dashboard
node_dashboard -->|"reads tables"| node_db_access

click node_contracts "https://github.com/farahe-elmontaser/etics/tree/main/contrats"
click node_extract "https://github.com/farahe-elmontaser/etics/blob/main/src/extraction.py"
click node_split "https://github.com/farahe-elmontaser/etics/blob/main/src/decoupage.py"
click node_pipeline "https://github.com/farahe-elmontaser/etics/blob/main/src/pipeline.py"
click node_config "https://github.com/farahe-elmontaser/etics/blob/main/src/config.py"
click node_legal "https://github.com/farahe-elmontaser/etics/tree/main/references"
click node_index "https://github.com/farahe-elmontaser/etics/blob/main/src/indexation.py"
click node_classifier "https://github.com/farahe-elmontaser/etics/blob/main/src/classification.py"
click node_ollama_client "https://github.com/farahe-elmontaser/etics/blob/main/src/ollama_client.py"
click node_examples "https://github.com/farahe-elmontaser/etics/blob/main/annotations/exemples.csv"
click node_scoring "https://github.com/farahe-elmontaser/etics/blob/main/src/score.py"
click node_db_access "https://github.com/farahe-elmontaser/etics/blob/main/src/base.py"
click node_annotation "https://github.com/farahe-elmontaser/etics/tree/main/annotations"
click node_evaluation "https://github.com/farahe-elmontaser/etics/blob/main/src/evaluation.py"
click node_dashboard "https://github.com/farahe-elmontaser/etics/blob/main/dashboard.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_contracts,node_extract,node_split,node_pipeline toneBlue
class node_config,node_legal,node_index,node_chroma,node_classifier,node_ollama_client,node_ollama,node_examples toneAmber
class node_scoring,node_db_access,node_sqlite toneMint
class node_annotation,node_evaluation,node_dashboard toneRose
class node_operator,node_viewer toneIndigo
```

## Components

### Contract ingestion

- [Contract files](https://github.com/farahe-elmontaser/etics/tree/main/contrats): `contrats`
- [Text extraction](https://github.com/farahe-elmontaser/etics/blob/main/src/extraction.py): `src/extraction.py`
- [Clause splitting](https://github.com/farahe-elmontaser/etics/blob/main/src/decoupage.py): `src/decoupage.py`
- [Pipeline orchestration](https://github.com/farahe-elmontaser/etics/blob/main/src/pipeline.py): `src/pipeline.py`

### Legal analysis

- [Settings and rubric](https://github.com/farahe-elmontaser/etics/blob/main/src/config.py): `src/config.py`
- [Legal reference files](https://github.com/farahe-elmontaser/etics/tree/main/references): `references`
- [Legal RAG index](https://github.com/farahe-elmontaser/etics/blob/main/src/indexation.py): `src/indexation.py`
- **ChromaDB**
- [Clause classification](https://github.com/farahe-elmontaser/etics/blob/main/src/classification.py): `src/classification.py`
- [Ollama client](https://github.com/farahe-elmontaser/etics/blob/main/src/ollama_client.py): `src/ollama_client.py`
- **Local Ollama models**
- [Few-shot examples](https://github.com/farahe-elmontaser/etics/blob/main/annotations/exemples.csv): `annotations/exemples.csv`

### Data and scoring

- [Contract scoring](https://github.com/farahe-elmontaser/etics/blob/main/src/score.py): `src/score.py`
- [SQLite data access](https://github.com/farahe-elmontaser/etics/blob/main/src/base.py): `src/base.py`
- **Contracts and clauses DB**

### Review and display

- [Human annotations](https://github.com/farahe-elmontaser/etics/tree/main/annotations): `annotations`
- [Evaluation metrics](https://github.com/farahe-elmontaser/etics/blob/main/src/evaluation.py): `src/evaluation.py`
- [Results dashboard](https://github.com/farahe-elmontaser/etics/blob/main/dashboard.py): `dashboard.py`

### Other components

- **Operator**
- **Analyst**

## Connections

- Operator → Pipeline orchestration: runs stages (evidence: `README.md`)
- Pipeline orchestration → Text extraction: reads contracts (evidence: `src/pipeline.py`)
- Contract files → Text extraction: supplies files (evidence: `README.md`)
- Pipeline orchestration → Clause splitting: splits text (evidence: `src/pipeline.py`)
- Text extraction → Clause splitting: provides text (evidence: `README.md`)
- Pipeline orchestration → SQLite data access: stores clauses (evidence: `src/pipeline.py`)
- Pipeline orchestration → Legal RAG index: indexes references (evidence: `src/pipeline.py`)
- Legal reference files → Legal RAG index: supplies legal text (evidence: `README.md`)
- Legal RAG index → Ollama client: requests embeddings (evidence: `src/indexation.py`)
- Ollama client → Local Ollama models: calls model API (evidence: `src/ollama_client.py`)
- Legal RAG index → ChromaDB: stores and searches (evidence: `src/indexation.py`)
- Pipeline orchestration → Clause classification: classifies clauses (evidence: `src/pipeline.py`)
- Clause classification → Legal RAG index: retrieves references (evidence: `src/classification.py`)
- Clause classification → Ollama client: requests judgment (evidence: `src/classification.py`)
- Few-shot examples → Clause classification: provides examples (evidence: `src/classification.py`)
- Pipeline orchestration → Contract scoring: calculates scores (evidence: `src/pipeline.py`)
- Pipeline orchestration → SQLite data access: reads and updates records (evidence: `src/pipeline.py`)
- SQLite data access → Contracts and clauses DB: reads and writes (evidence: `src/base.py`)
- Operator → Pipeline orchestration: creates sample (evidence: `README.md`)
- Pipeline orchestration → Human annotations: writes sample (evidence: `src/pipeline.py`)
- Operator → Evaluation metrics: runs evaluation (evidence: `README.md`)
- Human annotations → Evaluation metrics: provides labels (evidence: `src/evaluation.py`)
- Evaluation metrics → SQLite data access: loads predictions (evidence: `src/evaluation.py`)
- Analyst → Results dashboard: views results (evidence: `README.md`)
- Results dashboard → SQLite data access: reads tables (evidence: `dashboard.py`)
