# croncl/legia0ff architecture

> Architecture diagram of the GitHub repository croncl/legia0ff, 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/croncl/legia0ff
- Repository: https://github.com/croncl/legia0ff

## Overview

LegIA0ff is a Streamlit assistant for questions about Brazilian disciplinary and corporate liability proceedings (PAD/PAR). The main workflow is a user question entering the LangGraph agent, which applies input guardrails, invokes retrieval or other tools when needed, and returns a guarded answer with citations; conversations are saved by the interface. Separate product capabilities include PDF ingestion, web/transparency tools, and a knowledge-graph view. The README documents the overall flow; sampled source confirms key retrieval, citation, ingestion, and UI responsibilities, while some integrations are documented but not sampled in full.

Main entry points: [`src/cgu_rag/agente/grafo.py`](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/grafo.py) (Conversation graph), [`app/app.py`](https://github.com/croncl/legia0ff/blob/main/app/app.py) (Chat interface), [`src/cgu_rag/legado/rag_cgu_pipeline.py`](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/legado/rag_cgu_pipeline.py) (Corpus pipeline), [`src/cgu_rag/agente/modelo.py`](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/modelo.py) (Chat model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Chat experience"]
  node_streamlit["Chat interface<br/>[app.py]"]
  node_visuals["UI styling<br/>[ui_estilo.py]"]
  node_knowledge_map["Knowledge map<br/>[ui_grafo.py]"]
  node_chat_history[("Chat history")]
end

subgraph group_agent["Agent and tools"]
  node_orchestrator["Conversation graph<br/>[grafo.py]"]
  node_answer_model["Chat model<br/>[modelo.py]"]
  node_guardrail_skills["Prompt skills<br/>[skills.py]"]
  node_citations["Citation handling<br/>[citacao.py]"]
  node_rag_tool["Base consultation<br/>[ferramentas.py]"]
end

subgraph group_knowledge["Legal knowledge"]
  node_retrieval["Hybrid retrieval<br/>[busca.py]"]
  node_legacy_pipeline["Corpus pipeline"]
  node_database[("RAG database")]
  node_ingestion["PDF ingestion<br/>[ingestao.py]"]
  node_source_catalog["PDF sources<br/>[fontes.py]"]
  node_configuration["Runtime settings<br/>[config.py]"]
end

subgraph group_integrations["External services"]
  node_mcp_cgu["CGU tools<br/>[mcp_cgu.py]"]
  node_community_tools["Web tools<br/>[mcp_comunidade.py]"]
  node_transparency_tools["Transparency tools"]
  node_local_llm["Local LLM client<br/>[llm_local.py]"]
end

subgraph group_assessment["Evaluation"]
  node_answer_key["Reviewed answer set<br/>[gabarito.py]"]
  node_retrieval_metrics["Retrieval metrics<br/>[metricas.py]"]
end

node_user(("Questioner"))

node_user -->|"asks question"| node_streamlit
node_streamlit -->|"submits turn"| node_orchestrator
node_streamlit -->|"renders with"| node_visuals
node_streamlit -->|"offers view"| node_knowledge_map
node_streamlit -->|"persists chats"| node_chat_history
node_orchestrator -->|"requests response"| node_answer_model
node_orchestrator -->|"applies skills"| node_guardrail_skills
node_orchestrator -->|"dispatches tools"| node_rag_tool
node_orchestrator -->|"adds citations"| node_citations
node_rag_tool -->|"queries"| node_retrieval
node_retrieval -->|"delegates search"| node_legacy_pipeline
node_legacy_pipeline -.->|"reads chunks"| node_database
node_ingestion -->|"loads sources"| node_source_catalog
node_ingestion -->|"delegates ingest"| node_legacy_pipeline
node_legacy_pipeline -->|"writes chunks"| node_database
node_answer_model -->|"reads settings"| node_configuration
node_answer_model -->|"checks privacy policy"| node_local_llm
node_local_llm -->|"reads settings"| node_configuration
node_orchestrator -.->|"uses domain tools"| node_mcp_cgu
node_orchestrator -.->|"offers web lookup"| node_community_tools
node_orchestrator -.->|"offers transparency lookup"| node_transparency_tools
node_retrieval_metrics -->|"evaluates results"| node_retrieval
node_retrieval_metrics -.->|"groups questions"| node_answer_key

click node_streamlit "https://github.com/croncl/legia0ff/blob/main/app/app.py"
click node_visuals "https://github.com/croncl/legia0ff/blob/main/app/ui_estilo.py"
click node_knowledge_map "https://github.com/croncl/legia0ff/blob/main/app/ui_grafo.py"
click node_chat_history "https://github.com/croncl/legia0ff/tree/main/data/historico_chats"
click node_orchestrator "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/grafo.py"
click node_answer_model "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/modelo.py"
click node_guardrail_skills "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/skills.py"
click node_citations "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/citacao.py"
click node_rag_tool "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/ferramentas.py"
click node_mcp_cgu "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/mcp_cgu.py"
click node_community_tools "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/mcp_comunidade.py"
click node_transparency_tools "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/mcp_transparencia.py"
click node_retrieval "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/busca.py"
click node_legacy_pipeline "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/legado/rag_cgu_pipeline.py"
click node_database "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/legado/rag_cgu_pipeline.py"
click node_ingestion "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/ingestao.py"
click node_source_catalog "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/fontes.py"
click node_configuration "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/config.py"
click node_local_llm "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/llm_local.py"
click node_answer_key "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/gabarito.py"
click node_retrieval_metrics "https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/metricas.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_streamlit,node_visuals,node_knowledge_map,node_chat_history toneBlue
class node_orchestrator,node_answer_model,node_guardrail_skills,node_citations,node_rag_tool toneAmber
class node_retrieval,node_legacy_pipeline,node_database,node_ingestion,node_source_catalog,node_configuration toneMint
class node_mcp_cgu,node_community_tools,node_transparency_tools,node_local_llm toneRose
class node_answer_key,node_retrieval_metrics,node_user toneIndigo
```

## Components

### Chat experience

- [Chat interface](https://github.com/croncl/legia0ff/blob/main/app/app.py): `app/app.py`
- [UI styling](https://github.com/croncl/legia0ff/blob/main/app/ui_estilo.py): `app/ui_estilo.py`
- [Knowledge map](https://github.com/croncl/legia0ff/blob/main/app/ui_grafo.py): `app/ui_grafo.py`
- [Chat history](https://github.com/croncl/legia0ff/tree/main/data/historico_chats): `data/historico_chats`

### Agent and tools

- [Conversation graph](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/grafo.py): `src/cgu_rag/agente/grafo.py`
- [Chat model](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/modelo.py): `src/cgu_rag/agente/modelo.py`
- [Prompt skills](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/skills.py): `src/cgu_rag/agente/skills.py`
- [Citation handling](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/citacao.py): `src/cgu_rag/agente/citacao.py`
- [Base consultation](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/ferramentas.py): `src/cgu_rag/agente/ferramentas.py`

### Legal knowledge

- [Hybrid retrieval](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/busca.py): `src/cgu_rag/busca.py`
- [Corpus pipeline](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/legado/rag_cgu_pipeline.py): `src/cgu_rag/legado/rag_cgu_pipeline.py`
- [RAG database](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/legado/rag_cgu_pipeline.py): `src/cgu_rag/legado/rag_cgu_pipeline.py`
- [PDF ingestion](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/ingestao.py): `src/cgu_rag/ingestao.py`
- [PDF sources](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/fontes.py): `src/cgu_rag/fontes.py`
- [Runtime settings](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/config.py): `src/cgu_rag/config.py`

### External services

- [CGU tools](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/mcp_cgu.py): `src/cgu_rag/agente/mcp_cgu.py`
- [Web tools](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/mcp_comunidade.py): `src/cgu_rag/agente/mcp_comunidade.py`
- [Transparency tools](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/agente/mcp_transparencia.py): `src/cgu_rag/agente/mcp_transparencia.py`
- [Local LLM client](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/llm_local.py): `src/cgu_rag/llm_local.py`

### Evaluation

- [Reviewed answer set](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/gabarito.py): `src/cgu_rag/gabarito.py`
- [Retrieval metrics](https://github.com/croncl/legia0ff/blob/main/src/cgu_rag/metricas.py): `src/cgu_rag/metricas.py`

### Other components

- **Questioner**

## Connections

- Questioner → Chat interface: asks question (evidence: `README.md`)
- Chat interface → Conversation graph: submits turn (evidence: `app/app.py`)
- Chat interface → UI styling: renders with (evidence: `app/app.py`)
- Chat interface → Knowledge map: offers view (evidence: `app/app.py`)
- Chat interface → Chat history: persists chats (evidence: `app/app.py`)
- Conversation graph → Chat model: requests response (evidence: `README.md`)
- Conversation graph → Prompt skills: applies skills (evidence: `src/cgu_rag/agente/grafo.py`)
- Conversation graph → Base consultation: dispatches tools (evidence: `README.md`)
- Conversation graph → Citation handling: adds citations (evidence: `src/cgu_rag/agente/grafo.py`)
- Base consultation → Hybrid retrieval: queries (evidence: `src/cgu_rag/agente/ferramentas.py`)
- Hybrid retrieval → Corpus pipeline: delegates search (evidence: `src/cgu_rag/busca.py`)
- Corpus pipeline → RAG database: reads chunks (evidence: `src/cgu_rag/legado/rag_cgu_pipeline.py`)
- PDF ingestion → PDF sources: loads sources (evidence: `src/cgu_rag/ingestao.py`)
- PDF ingestion → Corpus pipeline: delegates ingest (evidence: `src/cgu_rag/ingestao.py`)
- Corpus pipeline → RAG database: writes chunks (evidence: `src/cgu_rag/legado/rag_cgu_pipeline.py`)
- Chat model → Runtime settings: reads settings (evidence: `src/cgu_rag/agente/modelo.py`)
- Chat model → Local LLM client: checks privacy policy (evidence: `src/cgu_rag/agente/modelo.py`)
- Local LLM client → Runtime settings: reads settings (evidence: `src/cgu_rag/llm_local.py`)
- Conversation graph → CGU tools: uses domain tools
- Conversation graph → Web tools: offers web lookup
- Conversation graph → Transparency tools: offers transparency lookup
- Retrieval metrics → Hybrid retrieval: evaluates results (evidence: `src/cgu_rag/metricas.py`)
- Retrieval metrics → Reviewed answer set: groups questions
