# flango2023/intelliway_enterprise_challenge_sprint2 architecture

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

## Overview

GuardRail PT-BR detects prompt injection in Portuguese: clients submit text or documents, the API extracts and analyzes content, then returns a risk decision and records an event. The repository also includes dataset/model development and evaluation, plus a robot that submits email and document contents to the API and routes items by decision. Edges are limited to relationships supported by the README or source index; several implementation details are unsampled.

Main entry points: [`src/api/main.py`](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/api/main.py) (Analysis API), [`src/engine/engine.py`](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/engine.py) (Detection orchestrator), [`src/robot/ingest.py`](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/robot/ingest.py) (Ingestion robot), [`scripts/evaluate.py`](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/scripts/evaluate.py) (Model evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingress["Submission and ingestion"]
  node_robot["Ingestion robot<br/>[ingest.py]"]
  node_api["Analysis API<br/>[main.py]"]
  node_ocr["File extraction<br/>[pipeline.py]"]
end

subgraph group_analysis["Detection engine"]
  node_engine["Detection orchestrator<br/>[engine.py]"]
  node_preprocess["Text normalization<br/>[preprocess.py]"]
  node_regex["Regex signals<br/>[regex_layer.py]"]
  node_tfidf["TF-IDF model<br/>[tfidf_layer.py]"]
  node_lora["LoRA training<br/>[finetune_lora.py]"]
  node_registry["Model registry<br/>[registry.py]"]
end

subgraph group_lifecycle["Data and model lifecycle"]
  node_dataset["Dataset builder<br/>[build_dataset.py]"]
  node_seed["PT-BR examples<br/>[seed_pt.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_metrics["Threshold metrics<br/>[metrics.py]"]
end

subgraph group_persistence["Events and review"]
  node_events[("Event store<br/>[db.py]")]
end

node_consumer(("API client"))

node_consumer -->|"submits analysis"| node_api
node_api -->|"extracts files"| node_ocr
node_api -->|"analyzes text"| node_engine
node_api -->|"records events"| node_events
node_api -->|"reads events"| node_events
node_robot -->|"sends requests"| node_api
node_robot -->|"extracts documents"| node_ocr
node_engine -->|"normalizes text"| node_preprocess
node_engine -->|"collects signals"| node_regex
node_engine -->|"scores baseline"| node_tfidf
node_tfidf -->|"cleans text"| node_preprocess
node_dataset -->|"uses examples"| node_seed
node_evaluation -->|"computes metrics"| node_metrics
node_evaluation -->|"selects thresholds"| node_metrics
node_api -->|"returns decision"| node_engine

click node_robot "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/robot/ingest.py"
click node_api "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/api/main.py"
click node_ocr "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/ocr/pipeline.py"
click node_engine "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/engine.py"
click node_preprocess "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/preprocess.py"
click node_regex "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/regex_layer.py"
click node_tfidf "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/tfidf_layer.py"
click node_lora "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/finetune_lora.py"
click node_registry "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/registry.py"
click node_events "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/api/db.py"
click node_dataset "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/scripts/build_dataset.py"
click node_seed "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/data/seed_pt.py"
click node_evaluation "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/scripts/evaluate.py"
click node_metrics "https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/metrics.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_robot,node_api,node_ocr,node_consumer toneBlue
class node_engine,node_preprocess,node_regex,node_tfidf,node_lora,node_registry toneAmber
class node_dataset,node_seed,node_evaluation,node_metrics toneMint
class node_events toneRose
```

## Components

### Submission and ingestion

- [Ingestion robot](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/robot/ingest.py): `src/robot/ingest.py`
- [Analysis API](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/api/main.py): `src/api/main.py`
- [File extraction](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/ocr/pipeline.py): `src/ocr/pipeline.py`

### Detection engine

- [Detection orchestrator](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/engine.py): `src/engine/engine.py`
- [Text normalization](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/preprocess.py): `src/engine/preprocess.py`
- [Regex signals](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/regex_layer.py): `src/engine/regex_layer.py`
- [TF-IDF model](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/tfidf_layer.py): `src/engine/tfidf_layer.py`
- [LoRA training](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/finetune_lora.py): `src/engine/finetune_lora.py`
- [Model registry](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/registry.py): `src/engine/registry.py`

### Data and model lifecycle

- [Dataset builder](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/scripts/build_dataset.py): `scripts/build_dataset.py`
- [PT-BR examples](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/data/seed_pt.py): `src/data/seed_pt.py`
- [Model evaluation](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/scripts/evaluate.py): `scripts/evaluate.py`
- [Threshold metrics](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/engine/metrics.py): `src/engine/metrics.py`

### Events and review

- [Event store](https://github.com/flango2023/intelliway_enterprise_challenge_sprint2/blob/main/src/api/db.py): `src/api/db.py`

### Other components

- **API client**

## Connections

- API client → Analysis API: submits analysis (evidence: `README.md`)
- Analysis API → File extraction: extracts files (evidence: `README.md`)
- Analysis API → Detection orchestrator: analyzes text (evidence: `src/api/main.py`)
- Analysis API → Event store: records events (evidence: `src/api/main.py`)
- Analysis API → Event store: reads events (evidence: `src/api/main.py`)
- Ingestion robot → Analysis API: sends requests (evidence: `src/robot/ingest.py`)
- Ingestion robot → File extraction: extracts documents (evidence: `src/robot/ingest.py`)
- Detection orchestrator → Text normalization: normalizes text (evidence: `src/engine/engine.py`)
- Detection orchestrator → Regex signals: collects signals (evidence: `src/engine/engine.py`)
- Detection orchestrator → TF-IDF model: scores baseline (evidence: `src/engine/engine.py`)
- TF-IDF model → Text normalization: cleans text (evidence: `src/engine/tfidf_layer.py`)
- Dataset builder → PT-BR examples: uses examples (evidence: `scripts/build_dataset.py`)
- Model evaluation → Threshold metrics: computes metrics (evidence: `scripts/evaluate.py`)
- Model evaluation → Threshold metrics: selects thresholds (evidence: `scripts/evaluate.py`)
- Analysis API → Detection orchestrator: returns decision (evidence: `README.md`)
