# ABACUS Learning

## 1. Essential Resources

* The ABACUS [Product Manual](./product_manual.md)
* The ABACUS [Ops Support](../operations/readme.md) page
* The current [Roadmap](https://docs.google.com/spreadsheets/d/1h2xo3fVKgS1mrKH5U1Vi8e_bMFZn4D47sSi0IocyIVE/edit?gid=484987765#gid=484987765)

### Topics

* [Transfer of Product Ownership (Accounting view)](./transfer-of-product-ownership.md) - what
  happens to Abacus contracts and revenue when a product moves between accounts.
* [Coda (agentic workflows)](./coda/README.md) - how Coda runs agentic workflows over the Abacus
  API, starting with [contract creation](./coda/contract-creation.md).



## 2. System References

### System Architecture Sketch
![System Architecture Sketch](../operations/assets/abacus_v1.svg)

### Data Flows

```mermaid
flowchart TD

    %% Styling Definitions for high contrast and GitHub light/dark mode compatibility
    classDef default fill:#f9f9f9,stroke:#666,stroke-width:1px,color:#000;
    classDef db fill:#e1f5fe,stroke:#0288d1,stroke-width:2px,color:#000;
    classDef app fill:#fff3e0,stroke:#e65100,stroke-width:2px,color:#000;
    classDef input fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#000;
    classDef external fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px,color:#000;
    classDef analytic fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px,color:#000;
    
    style ABACUS fill:#fafafa,stroke:#9e9e9e,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style SNOWFLAKE fill:#f3f6f9,stroke:#1565c0,stroke-width:2px,stroke-dasharray: 5 5,color:#000
    style ACCOUNTING fill:#fdfefe,stroke:#9e9e9e,stroke-width:1px,color:#000
    style DATA_PLATFORMS fill:#fdfefe,stroke:#9e9e9e,stroke-width:1px,color:#000
    style SLAUGHTERHOUSE fill:#fdfefe,stroke:#9e9e9e,stroke-width:1px,color:#000
    style ACCOUNTS_AND_IDENTITIES_PLATFORM fill:#fdfefe,stroke:#9e9e9e,stroke-width:1px,color:#000

    subgraph ABACUS
        frontend([Front End]):::app
        click frontend "http://abacus.qaorch.com/" "abacus.theorchard.com"
        
        backend[[Back End: GQL/Lambdas/DAGs]]:::app
        
        art_relations[(Art Relations RDS)]:::db
        royalty_accounting[(Royalty Accounting RDS)]:::db

        frontend -- "INPUT: Manual Adjustments<br/>INPUT: Accounting Periods" --> backend

        backend -- "WRITE" --> royalty_accounting

        backend -- "WRITES limited to:<br/>1. Create first acct contract<br/>2. Create vendor contract distro types<br/>3. Set contract new store default = 'N'<br/>4. Routinely sync collection territories" --> art_relations

        art_relations -- "READ" --> backend
    end
    
    db_pr([INPUT: DB PR Process]):::input
    db_pr -.-> art_relations 
    db_pr -.-> royalty_accounting
    
    subgraph ACCOUNTING 
        tap([INPUT: Taxes & Payments, TAP]):::input
        collabs([INPUT: Collabs]):::input
        ca([INPUT: Customer Accounting]):::input
    end
    
    tap --> royalty_accounting_prod
    collabs --> royalty_accounting_prod
    ca -- "DBT Rollups" --> royalty_accounting_prod
    tap --> backend
    collabs --> backend
    
    subgraph DATA_PLATFORMS
        data_platforms[(Data Platforms)]:::db
    end
    
    subgraph SNOWFLAKE
        
        subgraph FACTS_DB 
            facts_db[(FACTS DB)]:::analytic
        end
        
        subgraph ORCHARD_APP_REPORTING_V2
            orchard_app_prod_royalty_accounting[(Prod Royalty Accounting)]:::analytic
            orchard_app_prod_art_relations[(Prod Art Relations)]:::analytic
        end
        
        subgraph ROYALTY_ACCOUNTING
            royalty_accounting_prod[(Royalty Accounting PROD)]:::analytic
            royalty_accounting_qa[(Royalty Accounting QA)]:::analytic
            royalty_accounting_uat[(Royalty Accounting UAT)]:::analytic
        end
        
        subgraph ROYALTY_ACCOUNTING_REPORTING
            royalty_accounting_reporting_prod[(Reporting PROD views/cached)]:::analytic
            royalty_accounting_reporting_qa[(Reporting QA)]:::analytic
            royalty_accounting_reporting_uat[(Reporting UAT)]:::analytic
        end
        
        orchard_app_prod_royalty_accounting --> royalty_accounting_reporting_prod
        orchard_app_prod_art_relations -- "derive*" --> royalty_accounting_reporting_prod
        orchard_app_prod_royalty_accounting -- "derive*" --> royalty_accounting_prod
        royalty_accounting_prod -- "enrich*" --> royalty_accounting_prod
        royalty_accounting_prod -- "transform*" --> royalty_accounting_reporting_prod
        data_platforms --> facts_db
        facts_db --> royalty_accounting_reporting_prod
    end
    
    art_relations -. "fivetran replication" .-> orchard_app_prod_art_relations
    royalty_accounting -. "fivetran replication" .-> orchard_app_prod_royalty_accounting
    
    subgraph SLAUGHTERHOUSE
        statement_db[(Statement DB)]:::db
    end

    statement_db -- "Jenkins - Get Eligible Sales<br/>STMT_DB_SALES_NR_STAGING,<br/>STMT_DB_SALES_DISTRO_STAGING" --> royalty_accounting_prod

    subgraph Looker_Platform [LOOKER]
        looker{{Looker}}:::external
        royalty_accounting_reporting_prod --> looker
        orchard_app_prod_royalty_accounting --> looker
        orchard_app_prod_art_relations --> looker
        royalty_accounting_prod --> looker
        facts_db --> looker
    end
    
    subgraph ACCOUNTS_AND_IDENTITIES_PLATFORM
       account360([Account360]):::app
       ows_accounts([Ows Accounts]):::app
    end

    subgraph KAFKA
        kafka_system{Kafka System}:::external
        backend -- "ACCT Creation" --> kafka_system
    end

    subgraph SAP
        sap_system[[SAP System]]:::external
        backend -. "EXPORT ROYALTY DATA" .-> sap_system
    end

    subgraph ROB_SHIELDS_TEAM
        rob_shields_team([Rob Shields Team]):::input
        sap_system -- "EXPORT SALES DATA" --> rob_shields_team
    end
    
    subgraph OWS_SERVICE
        ows_service[[OWS Service]]:::app
    end
    
    account360 -- "Create Accounts" --> ows_accounts
    
    backend --> ows_service
    ows_service --> kafka_system
    kafka_system --> other_consumers([Other Consumers]):::input
    
    ows_accounts -- "Create Account" --> art_relations
    
    account360 -. "account_created" .-> kafka_system
    kafka_system -. "Create" .-> royalty_accounting
    
```

