← Identity Desk domain iddesk

Identity Desk: the ADL it runs on

This is the whole definition of Identity Desk: 341 lines. The server reads it at start-up and builds the database, the API, the permissions, the rules and the workflows from it.

# identity-desk/backend/domain.yaml
#
# Identity Desk — KYC / identity verification review.
#
#   applicant → onboarding (submitted → in review)
#     ← verifications: document, selfie match, database, address, device
#       (AI, vendor or analyst), sanctions / PEP screening (pass | review | hit)
#     ← AI risk assessment (model, tier, factors) → analyst accepts or overrides it
#     → approve, decline (with the reason the applicant is told),
#       request information, or escalate to compliance (enhanced due diligence)
#     → escalation: cleared (false positive) | confirmed (blocks approval)
#   Nightly: onboardings waiting on information for 30 days expire.
#
# The AI checks and scores; people decide. A watchlist hit can't be
# approved until compliance clears it, and a confirmed hit can't be approved
# at all.
#
# An ISDG product for fintechs, banks, exchanges and marketplaces.
# All applicants are invented; no government ID numbers are stored.
# query() filter keys are single lowercase words.

domain:
  name: iddesk
  version: "1.0.0"
  description: >
    KYC and identity verification review: AI document checks and risk scores,
    analyst decisions, sanctions hits blocked, compliance escalations, and
    declines that always state their reason.

  resources:

    applicant:
      description: "A person applying for an account."
      object:
        id:        { type: uuid, primaryKey: true, protected: true, allowUserProvided: true }
        fullName:  { type: string, required: true, maxLength: 120 }
        birthDate: { type: date, required: true }
        country:   { type: string, required: true, pattern: "^[A-Z]{2}$" }
        email:     { type: email, required: true }
        phone:     { type: phone, required: true }
      permissions:
        list:   [analyst, compliance, admin]
        get:    [analyst, compliance, admin]
        create: [admin]
        update: [analyst, admin]
        delete: [admin]
      features: { audit: true }

    onboarding:
      description: "One application for one product, from submission to decision."
      object:
        id:            { type: uuid, primaryKey: true, protected: true, allowUserProvided: true }
        number:        { type: string, required: true, unique: true, maxLength: 20 }
        applicant:
          type: reference
          references: "adl.iddesk.iddesk.applicant"
          required: true
        product:       { type: string, required: true, enum: [checking, card, crypto_wallet, business_account, brokerage] }
        submittedAt:   { type: datetime, required: true }
        analyst:       { type: string, maxLength: 100 }
        infoRequested: { type: text }
        declineReason: { type: text }
        decidedAt:     { type: datetime }
        status:        { type: string, required: true, default: submitted }
      stateMachine:
        field: status
        initial: submitted
        states:
          submitted:
            transitions:
              assign: { to: in_review, guards: [analyst, admin], requiredFields: [analyst] }
          in_review:
            transitions:
              approve:     { to: approved, guards: [analyst, compliance, admin], sets: { decidedAt: now() } }
              decline:     { to: declined, guards: [analyst, compliance, admin], requiredFields: [declineReason], sets: { decidedAt: now() } }
              requestInfo: { to: info_requested, guards: [analyst, admin], requiredFields: [infoRequested] }
              escalate:    { to: escalated, guards: [analyst, admin] }
          info_requested:
            transitions:
              infoReceived: { to: in_review, guards: [analyst, admin] }
              expire:       { to: expired, guards: [admin] }
          escalated:
            transitions:
              approve: { to: approved, guards: [compliance, admin], sets: { decidedAt: now() } }
              decline: { to: declined, guards: [compliance, admin], requiredFields: [declineReason], sets: { decidedAt: now() } }
          approved: {}
          declined: {}
          expired: {}
      permissions:
        list:   [analyst, compliance, admin]
        get:    [analyst, compliance, admin]
        create: [admin]
        update: [analyst, compliance, admin]
        delete: [admin]
      features: { audit: true }
      history:
        events:
          approved:  { trigger: transition, transition: approve, severity: success }
          declined:  { trigger: transition, transition: decline, capture: [declineReason], label: "Declined: {declineReason}", severity: warning }
          escalated: { trigger: transition, transition: escalate, label: "Escalated to compliance", severity: warning }
          infoAsked: { trigger: transition, transition: requestInfo, capture: [infoRequested], label: "Asked for: {infoRequested}", severity: info }
      indexes:
        - { fields: [applicant] }
        - { fields: [status] }

    verification:
      description: "One identity check on an applicant."
      object:
        id:        { type: uuid, primaryKey: true, protected: true, allowUserProvided: true }
        applicant:
          type: reference
          references: "adl.iddesk.iddesk.applicant"
          required: true
        kind:      { type: string, required: true, enum: [document, selfie_match, database, address, device, sanctions, pep] }
        source:    { type: string, required: true, enum: [ai, vendor, analyst] }
        result:    { type: string, required: true, enum: [pass, fail, review, hit] }
        score:     { type: percentage }
        detail:    { type: text, required: true }
        checkedAt: { type: datetime, required: true }
      validation:
        hitsAreScreenings:
          rule: "result != 'hit' || kind == 'sanctions' || kind == 'pep'"
          message: "Only sanctions and PEP screenings produce hits."
      permissions:
        list:   [analyst, compliance, admin]
        get:    [analyst, compliance, admin]
        create: [analyst, admin]
        update: [admin]
        delete: [admin]
      features: { audit: true }
      indexes:
        - { fields: [applicant] }

    assessment:
      description: "The AI's risk score for an applicant. An analyst accepts it or overrides the tier."
      object:
        id:        { type: uuid, primaryKey: true, protected: true, allowUserProvided: true }
        applicant:
          type: reference
          references: "adl.iddesk.iddesk.applicant"
          required: true
        model:     { type: string, required: true, maxLength: 60 }
        score:     { type: integer, required: true, min: 0, max: 100 }
        aiTier:    { type: string, required: true, enum: [low, medium, high] }
        factors:   { type: text, required: true }
        finalTier: { type: string, enum: [low, medium, high] }
        reviewNote: { type: text }
        reviewedBy: { type: string, maxLength: 100 }
        status:    { type: string, required: true, default: draft }
      stateMachine:
        field: status
        initial: draft
        states:
          draft:
            transitions:
              accept:   { to: accepted, guards: [analyst, compliance], requiredFields: [finalTier], sets: { reviewedBy: $user.id } }
              override: { to: overridden, guards: [analyst, compliance], requiredFields: [finalTier, reviewNote], sets: { reviewedBy: $user.id } }
          accepted: {}
          overridden: {}
      permissions:
        list:   [analyst, compliance, admin]
        get:    [analyst, compliance, admin]
        create: [analyst, admin]
        update: [analyst, compliance, admin]
        delete: [admin]
      features: { audit: true }
      indexes:
        - { fields: [applicant] }

    escalation:
      description: "Enhanced due diligence by compliance, assigned to someone other than the escalating analyst."
      object:
        id:          { type: uuid, primaryKey: true, protected: true, allowUserProvided: true }
        onboarding:
          type: reference
          references: "adl.iddesk.iddesk.onboarding"
          required: true
        reason:      { type: string, required: true, enum: [watchlist_match, high_risk_tier, document_concern, source_of_funds] }
        escalatedBy: { type: string, required: true, maxLength: 100 }
        assignee:    { type: string, required: true, maxLength: 100 }
        finding:     { type: text }
        status:      { type: string, required: true, default: open }
      stateMachine:
        field: status
        initial: open
        states:
          open:
            transitions:
              clear:   { to: cleared, guards: [compliance, admin], requiredFields: [finding] }
              confirm: { to: confirmed, guards: [compliance, admin], requiredFields: [finding] }
          cleared: {}
          confirmed: {}
      permissions:
        list:   [analyst, compliance, admin]
        get:    [analyst, compliance, admin]
        create: [analyst, admin]
        update: [compliance, admin]
        delete: [admin]
      features: { audit: true }
      history:
        events:
          cleared:   { trigger: transition, transition: clear, capture: [finding], label: "Cleared: {finding}", severity: success }
          confirmed: { trigger: transition, transition: confirm, capture: [finding, onboarding], label: "Confirmed: {finding}", severity: error }
      indexes:
        - { fields: [onboarding] }

  rules:

    approveNeedsCoreChecks:
      description: "Approval needs a passing document check, selfie match and sanctions screening."
      trigger: { resource: onboarding, events: [transition], transition: approve }
      condition: "len(query('verification', { applicant: $record.applicant, kind: 'document', result: 'pass' })) == 0
                  || len(query('verification', { applicant: $record.applicant, kind: 'selfie_match', result: 'pass' })) == 0
                  || len(query('verification', { applicant: $record.applicant, kind: 'sanctions', result: 'pass' }))
                     + len(query('verification', { applicant: $record.applicant, kind: 'sanctions', result: 'hit' })) == 0"
      action: reject
      severity: error
      message: "Document, selfie match and sanctions screening must be on file and passing."

    noApprovalOverFailedChecks:
      description: "A failed check blocks approval."
      trigger: { resource: onboarding, events: [transition], transition: approve }
      condition: "len(query('verification', { applicant: $record.applicant, result: 'fail' })) > 0"
      action: reject
      severity: error
      message: "A verification failed."

    hitsNeedClearance:
      description: "A sanctions or PEP hit blocks approval until compliance clears it as a false positive."
      trigger: { resource: onboarding, events: [transition], transition: approve }
      condition: "len(query('verification', { applicant: $record.applicant, result: 'hit' })) > 0
                  && len(query('escalation', { onboarding: $record.id, status: 'cleared' })) == 0"
      action: reject
      severity: error
      message: "A watchlist hit must be cleared by compliance first."

    confirmedBlocks:
      description: "A confirmed escalation can never be approved."
      trigger: { resource: onboarding, events: [transition], transition: approve }
      condition: "len(query('escalation', { onboarding: $record.id, status: 'confirmed' })) > 0"
      action: reject
      severity: error
      message: "Compliance confirmed a concern. Decline instead."

    decideOnlyOnAReviewedScore:
      description: "No approval while the AI risk score is unreviewed, or without one."
      trigger: { resource: onboarding, events: [transition], transition: approve }
      condition: "len(query('assessment', { applicant: $record.applicant, status: 'draft' })) > 0
                  || (len(query('assessment', { applicant: $record.applicant, status: 'accepted' }))
                      + len(query('assessment', { applicant: $record.applicant, status: 'overridden' }))) == 0"
      action: reject
      severity: error
      message: "Review the AI risk assessment first."

    highRiskNeedsCompliance:
      description: "A high final risk tier needs a compliance clearance before approval."
      trigger: { resource: onboarding, events: [transition], transition: approve }
      condition: "some(query('assessment', { applicant: $record.applicant }), a => a.finalTier == 'high')
                  && len(query('escalation', { onboarding: $record.id, status: 'cleared' })) == 0"
      action: reject
      severity: error
      message: "High-risk applicants need compliance clearance."

    escalateToSomeoneElse:
      description: "Enhanced due diligence is done by someone other than the analyst who escalated."
      trigger: { resource: escalation, events: [create] }
      condition: "$record.assignee == $record.escalatedBy"
      action: reject
      severity: error
      message: "Assign the escalation to a different person."

  schedules:

    expireUnansweredRequests:
      description: "Onboardings waiting on information for 30 days expire."
      recurrence: daily at 03:30
      source:
        resource: onboarding
        filter: "status == 'info_requested' && submittedAt < dateSub(now(), 30, 'day')"
      action: transition
      transition: expire

  # ADL §37 (needs kalos with #2142). Once compliance confirms an escalation, the
  # account is declined in the same breath, so a confirmed match can't sit in a
  # queue where someone might approve it. The applicant is told only the neutral
  # notice: the finding stays internal, because telling someone they matched a
  # watchlist is tipping-off. Runs as the compliance officer who confirmed.
  workflows:

    confirmedEscalationDeclines:
      description: "A confirmed escalation declines its onboarding with the neutral notice."
      trigger:
        resource: escalation
        event: transition
        transition: confirm
      steps:
        - name: decline
          action: transition
          resource: onboarding
          transition: decline
          target: $trigger.record.onboarding
          input:
            declineReason: "We are unable to open this account. You may contact us for more information about this decision."   # plain text is a literal (no $ ( + -)

  views:

    reviewQueue:
      description: "Applications waiting for an analyst."
      source: onboarding
      filter: "status == 'submitted' || status == 'in_review' || status == 'info_requested'"
      permissions: [analyst, compliance, admin]
      columns:
        - { field: number,      label: "Application" }
        - { field: product,     label: "Product" }
        - { field: analyst,     label: "Analyst" }
        - { field: submittedAt, label: "Submitted" }
        - { field: status,      label: "State" }
      defaultLimit: 500

    complianceQueue:
      description: "Open escalations."
      source: escalation
      filter: "status == 'open'"
      permissions: [compliance, admin]
      columns:
        - { field: reason,      label: "Reason" }
        - { field: escalatedBy, label: "Escalated by" }
        - { field: assignee,    label: "Assignee" }
      defaultLimit: 200

    aiRiskAgreement:
      description: "Where analysts kept or changed the AI's risk tier."
      source: assessment
      filter: "status != 'draft'"
      permissions: [compliance, admin]
      columns:
        - { field: model,      label: "Model" }
        - { field: aiTier,     label: "AI tier" }
        - { field: finalTier,  label: "Final tier" }
        - { field: reviewNote, label: "Why changed" }
      defaultLimit: 500