# ExeiBit OS — Developer Brief (v5.0)

## The pitch in one paragraph

ExeiBit OS is a federated AI Business OS. It exposes six primitives —
**Bits, Avatars, Teams, Workflows, Templates, Store** — over a sovereign
runtime with cryptographic identity, integer-exact economics (1/16 CR),
deterministic dispatch, and immune-system-grade drift defense.

## Architecture at a glance

```
Client (React 18 + Vite 5 + Tailwind v3 + TS 5)
   │
   ├── Sovereign session (JWT · Supabase auth)
   │
   └── Edge runtime (Deno · Supabase functions)
          │
          ├── Movement canon (5 rails)
          ├── Universal adapter (PIT + OAuth 2.0)
          ├── BitStore engine (bigint 1/16 CR)
          ├── Drift sentinel (audit-chain reconciliation)
          └── Federation layer (multi-tenant + mesh)
```

## Six primitives

| Primitive  | Purpose                                        | Route base                |
| ---------- | ---------------------------------------------- | ------------------------- |
| Bits       | Composable capabilities                        | `/app/bitstore`           |
| Avatars    | Non-human identities acting on behalf of users | `/app/studio/avatars`     |
| Teams      | Groups of avatars                              | `/app/studio/teams`       |
| Workflows  | Deterministic processes                        | `/app/studio/workflows`   |
| Templates  | Reusable configuration bundles                 | `/app/studio/templates`   |
| Store      | Marketplace + payouts                          | `/app/bitstore`           |

## Integration paths

### 1. Bring your own CRM (GHL, HubSpot)

1. Complete OAuth flow at `/app/onboard/tenant` (GHL) or paste API key
   (HubSpot).
2. Payloads normalise through `payloadTransform.ts` into a `CanonicalEvent`.
3. Events post to `canonical-event-ingest` — this writes `billing_events`
   with a `1/16 CR` gross/net/fee split.
4. Royalty router (`royaltyRouter.ts`) allocates payouts against active
   `royalty_splits`.

### 2. Publish a Bit to the marketplace

1. Sign in and go to `/app/bitstore/creator`.
2. Create a listing (title, muscle, min-tier, price in CR).
3. Define royalty splits (must sum to `16/16`).
4. Ship — `bitstore-publish` seals the listing and it becomes visible.

### 3. Run a drift-sentinel check

```bash
curl -X POST https://www.exeibit.com/functions/v1/drift-sentinel-monitor \
  -H "Authorization: Bearer <service-role or admin JWT>"
# → 200 { ok: true, drift: "0" }
# → 451 SQLSTATE_42501_VIOLATION on any drift > 0n
```

## Non-negotiable invariants

- **1/16 CR integer math** — all economic values are `bigint sixteenths`;
  no floats.
- **Royalty splits sum to exactly 16** — enforced client, server, and DB.
- **Deterministic dispatch hash** — every canonical event produces a
  reproducible `dsp_...` hash.
- **RLS on every public table** — no anon writes without an explicit
  policy.
- **Zero TypeScript errors** — CI blocks merges otherwise.

## Docs

- Engine: https://www.exeibit.com/engine
- Constitution (11 layers): https://www.exeibit.com/governance/constitution
- Ecosystem: https://www.exeibit.com/ecosystem
