# Mapa de Contextos — Mud Sentinel

**Documento:** `dominio/02-mapa-de-contextos.md`  
**Versão:** 1.0.0

---

## 1. Diagrama textual (Context Map)

Relações DDD usadas:

- **U** = Customer-Supplier (seta aponta do cliente para o supplier / upstream)
- **OHS** = Open Host Service (API pública estável do contexto)
- **ACL** = Anti-Corruption Layer
- **PL** = Published Language (eventos/contratos versionados)
- **SK** = Shared Kernel (mínimo)
- **CF** = Conformist (cliente adota modelo do upstream)
- **Partnership** = co-evolução alinhada

```text
                            ┌──────────────────────────────┐
                            │         PLUGINS (OHS)         │
                            │   ConnectorPlugin / Install   │
                            └──────────────┬───────────────┘
                                           │ U/PL
                                           ▼
┌────────────┐   U/PL    ┌────────────────┴───────────────┐
│  CRAWLER   │ ────────► │              ETL                │
│ CrawlJob   │           │ SourceSystem Raw Transform Run  │
└────────────┘           └───────┬─────────────┬───────────┘
                                 │ PL          │ PL
                 ┌───────────────┼─────────────┼──────────────────────────┐
                 ▼               ▼             ▼                          ▼
          ┌────────────┐  ┌──────────┐  ┌────────────┐            ┌────────────┐
          │    CORE    │  │COMPANIES │  │   PEOPLE   │            │ GOVERNMENT │
          │Party/ID/SRC│◄─┤ Sharehd. │  │ Person/PEP │            │   Bodies   │
          └─────┬──────┘  └────┬─────┘  └──────┬─────┘            └──────┬─────┘
                │ SK/OHS        │              │                           │
                │               ▼              ▼                           ▼
                │         ┌──────────────────────────────────────────────────────┐
                │         │     CONTRATOS PÚBLICOS / TRANSAÇÕES (PL eventos)      │
                │         │ Contracts │ Procurement │ Transfers │ Transparency   │
                │         │              │ Sanctions                               │
                │         └───────┬───────────────┬───────────────┬──────────────┘
                │                 │               │               │
                │                 ▼               ▼               ▼
                │          ┌───────────┐   ┌───────────┐   ┌────────────┐
                └─────────►│   GRAPH   │◄──│ TIMELINE  │◄──│    MAPS    │
                  CF/PL    │ Nodes/Edges│   │  Events   │   │ Geo/Layers │
                           └─────┬─────┘   └───────────┘   └────────────┘
                                 │
                    ┌────────────┼────────────────┐
                    ▼            ▼                ▼
             ┌────────────┐ ┌─────────┐    ┌────────────┐
             │ INTEGRITY  │ │  WATCH  │    │PARLIAMENT  │
             │Rules/Score │ │ Alerts  │    │ Mandates   │
             └─────┬──────┘ └────┬────┘    └─────┬──────┘
                   │             │               │
                   │             ▼               │
                   │      ┌─────────────┐        │
                   │      │NOTIFICATIONS│        │
                   │      └─────────────┘        │
                   │             ▲               │
                   ▼             │               ▼
             ┌─────────────────────────────────────────┐
             │                 CASES                    │
             │     Notes / Findings / EntityLinks       │
             └───────┬─────────────┬───────────┬───────┘
                     │             │           │
                     ▼             ▼           ▼
              ┌────────────┐ ┌──────────┐ ┌─────────┐
              │ DOCUMENTS  │ │ EVIDENCE │ │ REPORTS │
              └──────┬─────┘ └────┬─────┘ └────┬────┘
                     │            │            │
                     ▼            │            ▼
                ┌─────────┐       │     (Audit via Administration)
                │   RAG   │───────┘
                └────┬────┘
                     │
                     ▼
                ┌─────────┐     ┌───────────┐
                │   AI    │◄────│ KNOWLEDGE │
                └────┬────┘     │ Ontology  │
                     │          └───────────┘
                     ▼
                ┌───────────┐
                │ANALYTICS  │──► ADMINISTRATION (Quotas/Entitlements)
                └───────────┘
                     ▲
                     │
                ┌───────────┐     ┌────────────────┐
                │  SEARCH   │◄────│ IDENTITY       │
                └───────────┘     │ Users/Sessions │
                                  └────────┬───────┘
                                           │
                                  ┌────────▼───────┐
                                  │ ADMINISTRATION │◄── SETTINGS
                                  │ Tenant/Audit   │
                                  └────────────────┘
```

---

## 2. Fluxo de valor principal (end-to-end)

```text
Fonte pública
   → Plugins/Crawler (ACL contra HTML/API caóticos)
   → ETL (normalize + quality + IngestRun)
   → Core + Companies/People/Government/... (fatos tipados)
   → Graph + Timeline + Search + Integrity (projeções)
   → Analista (Search/Graph) → Cases + Evidence
   → AI/RAG (interpretação citada) → Reports/Export
   → Watch (monitor contínuo) → Notifications
   → Analytics/Quotas + Audit
```

---

## 3. Mapa de alinhamento (quem é upstream)

| Upstream | Downstream típicos | Padrão |
|----------|--------------------|--------|
| Plugins / Crawler | ETL | Customer-Supplier + ACL |
| ETL | Core, Companies, People, Government, Contracts, … | Published Language (ingest events) |
| Core | Graph, Search, Cases, Watch, Integrity | OHS / CF seletivo |
| Fatos tipados | Graph, Timeline, Integrity, Watch | PL eventos |
| Integrity | Search (signals), Cases, AI grounding | PL |
| Cases | Evidence, Reports, AI | Partnership |
| Documents/Knowledge | RAG → AI | Customer-Supplier |
| Watch | Notifications | PL |
| Analytics | Administration (quotas) | PL |
| Identity / Administration | Todos os contextos tenant-aware | SK + OHS auth |

---

## 4. Conflitos de linguagem resolvidos

| Termo ambiguo | Contexto A | Contexto B | Resolução |
|---------------|------------|------------|-----------|
| Entity | Genérico legado | Core usa **Party** | Ubiquitous language: Party no catálogo; Entity só em UI genérica com mapping |
| User vs Person | Identity **UserAccount** | People **Person** | Nunca sinônimos |
| Document | Documents upload | Transparency publication | Nomes distintos: Document vs TransparencyPublication |
| Case | Cases dossiê | Jurídico externo | Aqui = dossiê analítico |
| Event | Domain event | TimelineEvent | Prefixo de contexto |
| Client | ApiClient | Cliente comercial (Tenant) | Tenant = organização cliente; ApiClient = M2M |

---

## 5. Justificativa do particionamento

1. **Atores** separados de **transações** — ciclos de vida e donos de dados diferentes.
2. **Integrity** separado de fatos — regras do tenant não contaminam o catálogo global.
3. **Graph/Timeline/Search** como projeções — evitam SoR duplicada.
4. **Cases/Evidence/Reports** privados ao tenant — LGPD e segredo de investigação.
5. **ETL/Crawler/Plugins** isolam volatilidade de fontes.
6. **AI/RAG/Knowledge** isolam governança de modelos e grounding.
