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

# Core Domain Map

> The 57 domains inside @cona/core, grouped into bounded contexts, with the dependency edges that actually exist

# Core Domain Map

`@cona/core` holds the business logic: **57 domains**, 517 files, roughly 100,000 lines.

<Note>
  Core is not a monolith behind one entry point. All **674** consumer imports go through subpaths —
  541 via `@cona/core/domains/*` across 53 domains, 133 via named subpaths like `/redis` and
  `/logger`. The barrel export `@cona/core` is imported by **nothing**.
</Note>

## Bounded contexts

Six business contexts sitting on a foundation layer. The foundation domains are imported
by almost everything, so their edges are drawn once here and omitted everywhere else.

```mermaid theme={null}
flowchart TB
    subgraph Business["Business contexts"]
        Documents["Documents<br/>documents · document-format<br/>line_items · document-delivery<br/>number_ranges · object_types<br/>files · mustang · portal"]
        Accounting["Accounting<br/>accounting · general_ledger<br/>deferred-revenue · accounting_periods<br/>gl_memo · subsidiaries"]
        TaxFx["Tax & FX<br/>vat · fx · tax_codes<br/>org-tax-categories"]
        Recon["Reconciliation & payments<br/>reconciliation · reconciliation-agent<br/>payment-matching · bank-matching-handoffs<br/>customer_ibans · payment_methods<br/>payment_terms · finapi · cancellation-reviews"]
        Master["Master data<br/>entities · addresses · items<br/>product-category-assignments<br/>custom_property_definitions<br/>sales_channels"]
        Integrations["Integrations<br/>integrations · integration-entity-mappings<br/>shopify · amazon · stripe · mirakl<br/>paypal · otto-oauth · stripe-app-oauth<br/>csv_import · import_mapping_rules"]
    end

    subgraph Foundation["Foundation — imported by nearly every domain"]
        Utils["utils<br/>in-degree 37"]
        Actors["actors<br/>in-degree 13"]
        Services["services<br/>in-degree 13"]
        Redis["redis<br/>in-degree 8"]
        Statuses["statuses · localization"]
    end

    Platform["Platform<br/>api_keys · notifications<br/>background-activities<br/>copilot-audit · tools"]

    Business --> Foundation
    Platform --> Foundation

    classDef boundary fill:#f8fafc,stroke:#94a3b8,color:#334155

    classDef pkg fill:#e8eafd,stroke:#4967E6,color:#111827
    classDef data fill:#fde8e8,stroke:#c53b3b,color:#111827
    class Documents,Accounting,TaxFx,Recon,Master,Integrations,Platform pkg
    class Utils,Actors,Services,Redis,Statuses data
    class Business,Foundation boundary
```

`actors` having the second-highest in-degree is the structural proof of the
actor-attribution rule — nearly every domain that writes must resolve an actor first.

## Business-to-business edges

Foundation targets removed so the real coupling is visible. Edge labels are import counts.

```mermaid theme={null}
flowchart TB
    ReconAgent["reconciliation-agent"]
    Recon["reconciliation"]
    PayMatch["payment-matching"]
    BankHandoff["bank-matching-handoffs"]
    Ibans["customer_ibans"]
    CopilotAudit["copilot-audit"]

    Documents["documents"]
    Accounting["accounting"]
    ServicesD["services"]
    GL["general_ledger"]
    Deferred["deferred-revenue"]
    Periods["accounting_periods"]
    Subs["subsidiaries"]
    GlMemo["gl_memo"]
    Entities["entities"]
    LineItems["line_items"]
    Fx["fx"]
    Vat["vat"]
    NumberRanges["number_ranges"]

    ReconAgent -->|11| Recon
    ReconAgent -->|7| CopilotAudit
    ReconAgent -->|3| Ibans
    ReconAgent -->|2| PayMatch

    PayMatch -->|3| Recon
    PayMatch -->|2| BankHandoff
    PayMatch -->|2| Ibans

    Documents -->|3| NumberRanges
    Documents -->|3| Vat
    Documents -->|2| Accounting
    Documents -->|2| Periods
    Documents -->|1| GL

    Accounting -->|5| Documents
    Accounting -->|2| Recon
    Accounting -->|2| LineItems
    Accounting -->|1| Deferred
    Accounting -->|1| Periods

    ServicesD -->|3| Entities
    ServicesD -->|2| Documents
    ServicesD -->|2| GL
    ServicesD -->|2| Deferred
    ServicesD -->|1| GlMemo

    Recon -->|4| Documents
    Recon -->|2| Fx
    GL -->|2| Recon
    GL -->|1| Documents
    Deferred -->|3| Subs
    Deferred -->|2| GL
    Vat -->|1| Fx

    classDef pkg fill:#e8eafd,stroke:#4967E6,color:#111827
    class ReconAgent,Recon,PayMatch,BankHandoff,Ibans,CopilotAudit,Documents,Accounting,ServicesD,GL,Deferred,Periods,Subs,GlMemo,Entities,LineItems,Fx,Vat,NumberRanges pkg
```

<Warning>
  **These cycles are real.** `documents ↔ accounting`, `documents ↔ reconciliation`, and
  `general_ledger ↔ reconciliation` each have edges in both directions. Do not read this as a clean
  layered architecture — it is not one, and forcing the diagram into layers would misrepresent the
  code.
</Warning>

## The accounting hub

One file joins five domains: `services/create-accounting-impact.ts` imports `documents`,
`general_ledger`, `deferred-revenue`, `entities`, and `gl_memo`. It is the convergence
point of the accounting engine and the reason `services` has an in-degree of 13 despite
holding only 11 files. See [Accounting Engine](/architecture/accounting-engine).

## Domain sizes

The five largest warrant their own diagrams:

| Domain                 | Files |  Lines | Diagram                                                            |
| ---------------------- | ----: | -----: | ------------------------------------------------------------------ |
| `documents`            |    56 | 11,682 | [Document Lifecycle](/architecture/document-lifecycle)             |
| `reconciliation-agent` |    26 |  7,376 | [Reconciliation & Payments](/architecture/reconciliation-payments) |
| `document-format`      |    24 |  5,246 | [Document Lifecycle](/architecture/document-lifecycle)             |
| `general_ledger`       |    19 |  7,708 | [Accounting Engine](/architecture/accounting-engine)               |
| `reconciliation`       |    18 |  7,499 | [Reconciliation & Payments](/architecture/reconciliation-payments) |
| `deferred-revenue`     |    17 |  5,049 | [Accounting Engine](/architecture/accounting-engine)               |

## Entry points

`packages/core/package.json` declares 13 export entries including a `./domains/*` wildcard.

| Entry                                                                                                       |               Imports |
| ----------------------------------------------------------------------------------------------------------- | --------------------: |
| `@cona/core/domains/*`                                                                                      | 541 across 53 domains |
| `@cona/core/redis`                                                                                          |                    46 |
| `@cona/core/logger`                                                                                         |                    40 |
| `@cona/core/localization`                                                                                   |                    13 |
| `@cona/core/finapi`                                                                                         |                    12 |
| `@cona/core/csv-parsers`                                                                                    |                    12 |
| `import-mapping-rules`, `amazon/types`, `logo`, `rules`, `gl-relevance`, `payment-matching/remittance-memo` |               8 total |
| **`@cona/core` (barrel)**                                                                                   |                 **0** |

The most-imported single domain is `documents` (48), followed by `integrations` (34) and
`subsidiaries` (32).

## Notes

**The barrel is dead code.** `packages/core/src/index.ts` is 182 lines with 54 outgoing
imports — the largest fan-out in the package — and nothing imports it. It is still built
and published via the `.` export. A deletion candidate, once external consumers are ruled
out.

**`finapi` is isolated but not dead.** Zero in-degree and zero out-degree *within* core,
yet 12 imports via the `@cona/core/finapi` subpath. A self-contained bank-connection
module.

**Domain folders use mixed casing.** `snake_case` (`general_ledger`, `line_items`,
`number_ranges`) and `kebab-case` (`deferred-revenue`, `payment-matching`,
`document-format`) both appear. The webapp action folders mirror the same split.
