dodil/erp-brick-contracts

src/brick_contracts/domain/__init__.py

"""The contracts domain — rules in plain Python. No SQLAlchemy, FastAPI, MCP, identity or PDF engine here.

UBIQUITOUS LANGUAGE (modules/contracts domain_model; these words are the names in the code):

  contract type     what kind of agreement (employment_contract, freelance_agreement, nda, …): a ROW carrying the
                    allowed counterparty roles, execution (SIMPLE | DEED), esign_allowed, sensitivity
                    (commercial | employment), the retention rule and the approval policy  → contract_type.py
  counterparty      ALWAYS a business partner (bp_id), holding a role the type allows; read through
                    business-partner at draft, refreshed once at send, then frozen                → contract.py
  clause            a standing piece of wording in a FAMILY at a POSITION (Preferred | Alternate | Fallback),
                    versioned; a version a contract or an approved template holds is frozen      → library.py
  template          one shape per type: ordered SLOTS (required | optional | alternative-of) pinning
                    clause_id@version, and typed VARIABLE DEFINITIONS; DRAFT → APPROVED → RETIRED  → library.py
  variable          the resolved, typed value of a definition on one contract, with its source  → values.VariableValue
  section           a COPY of a clause version inside one contract, with its position, deviation level and
                    whether it was overridden; the library never alters a contract                 → contract.Section
  draft fingerprint sha256 over the ordered sections, the resolved variables and the signers     → values.Fingerprint
  deviation         a Fallback (or a deviating Alternate), an override, or a variable outside its bounds → services.DeviationCheck
  approval          a decision on ONE draft fingerprint by the group a policy row names, with a mandatory
                    fallback group; an edit voids it                                              → contract.Approval
  version           the frozen rendering made at send (PDF bytes + sha256); every signature binds to one
  signer            who signs for a side (US | THEM), in a signing order; INTERNAL (our side, signs in the app as
                    their pool identity) or EXTERNAL (the counterparty, signs through a public link)
  signature event   an append-only, hash-chained record (INVITED, DELIVERED, OPENED, CONSENTED, SIGNED, DECLINED,
                    CHANGES_REQUESTED, REVOKED, REISSUED, SIGNED_ELSEWHERE)                      → contract.SignatureEvent
  executed copy     the signed version plus a certificate page, with its own sha256; or an uploaded copy
                    (provenance UPLOADED, the contract SIGNED_ELSEWHERE — never confused with SIGNED)
  signed electronically   the ONLY claim this module makes about a signature                    → services.CLAIM
  amendment         AMENDMENT | RENEWAL | TERMINATION (each its own signed contract) or ADMINISTRATIVE (recorded)
  key date          a dated obligation (START, END, NOTICE_DEADLINE, …) with an owner and reminders → values.KeyDate
  source_ref        the opaque id of what asked for the contract; its namespace (hr:, crm:, manual:) names the
                    ORIGINATOR — the only consumer given the executed copy

AGGREGATES: Contract (contract.py), Clause and Template (library.py), ContractType (contract_type.py). Each keeps its
invariants here; the application layer loads one, asks it, saves it.
"""