> ## Documentation Index
> Fetch the complete documentation index at: https://docs.earthcare.network/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> How Earth Care Network is layered — from portable profiles to the CRM, with a metering gateway across every AI call.

ECN is organized in layers. Each layer builds on the one below it, and a single
cross-cutting **AI Gateway** meters every AI action regardless of where it originates.

```mermaid theme={null}
flowchart TD
  L0["Layer 0 — Murmurations<br/>portable, federated profiles"]
  L1["Layer 1 — Control plane (Django)<br/>Business, Organization, Membership — system of record"]
  L2["Layer 2 — Context<br/>ContextPack + embeddings + provenance"]
  L3["Layer 3 — CRM & Automation<br/>Contacts, Deals, Workflows, Prospecting"]
  GW["AI Gateway — meters every LLM / embedding / paid-data call"]

  L0 --> L1 --> L2 --> L3
  GW -. meters .-> L2
  GW -. meters .-> L3
```

## The layers

<AccordionGroup>
  <Accordion title="Layer 0 — Murmurations (portable profiles)">
    Businesses publish a portable, federated profile to the
    [Murmurations](https://murmurations.network) network. ECN is both a node and an
    aggregator, so a profile is not locked into ECN.
  </Accordion>

  <Accordion title="Layer 1 — Control plane (system of record)">
    A Django control plane owns the canonical records: **Business** (the directory
    listing), **Organization** (the tenant boundary for a workspace), and
    **Membership** (which users belong to which org, with roles). Ownership flows
    through claims and invites. See the [data model](/data-model/overview).
  </Accordion>

  <Accordion title="Layer 2 — Context">
    Each business compiles into a **ContextPack** — a structured, versioned,
    embeddings-backed surface that agents read. AI-authored content enters as
    `seeded` and is never auto-marked verified. Provenance is tracked per claim.
  </Accordion>

  <Accordion title="Layer 3 — CRM & Automation">
    The workspace: Contacts, Accounts, Deals, Tasks, Conversations, Forms, and a
    graph-based **automation engine**. The [Unified Prospecting Engine](/guides/prospecting-engine)
    lives here and powers Sales, Recruiting, and Fundraising.
  </Accordion>
</AccordionGroup>

## The AI Gateway is sacred

Every LLM call, embedding, agent run, and paid external lookup goes through one
gateway (`backend/ai/gateway.py`). It:

1. **Resolves credentials** — managed ECN provider keys for the hosted product.
2. **Preflights cost** against the rate card and the org's budget caps.
3. **Executes** the provider call.
4. **Meters** a `UsageEvent` and records a `CreditTransaction` spend.

This is why metering is trustworthy: there is no path to spend money or call a
model that bypasses the gateway. Read more in
[Metering & credits](/guides/metering-credits).

## Jaguar — the agent layer

**Jaguar** is a proactive, consultative growth partner built as a hierarchical
crew: a master agent that delegates to read-only specialists (Sales, Recruiting,
Operations, Fundraising). Every token the crew spends is routed through the AI
Gateway, and any outbound action (email, post) is held as an approval-gated draft
until a human approves it.
