# Abacus Data Flow Diagram

The following diagram illustrates the data flow within the Abacus system, highlighting key components and their interactions.

```mermaid
graph TD

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

        frontend --INPUT: Manual Adjustments,
                    INPUT: Accounting Periods
        --> backend

        backend --WRITE--> royalty_accounting

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

        art_relations --READ--> backend
    end
    
    db_pr[INPUT: DB PR Process]
    db_pr -..-> art_relations 
    db_pr -..-> royalty_accounting
    
    subgraph ACCOUNTING 
        tap[INPUT: Taxes & Payments, TAP]
        collabs[INPUT: Collabs]
        ca[INPUT: Customer Accounting]
    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]
    end
    
    subgraph SNOWFLAKE
        
        subgraph FACTS_DB 
            facts_db[FACTS DB]
        end
        
        subgraph ORCHARD_APP_REPORTING_V2
            orchard_app_prod_royalty_accounting[Prod Royalty Accounting]
            orchard_app_prod_art_relations[Prod Art Relations]
        end
        
        subgraph ROYALTY_ACCOUNTING
            royalty_accounting_prod[Royalty Accounting PROD]
            royalty_accounting_qa[Royalty Accounting QA]
            royalty_accounting_uat[Royalty Accounting UAT]
        end
        
        subgraph ROYALTY_ACCOUNTING_REPORTING
            royalty_accounting_reporting_prod[Reporting PROD views/cached]
            royalty_accounting_reporting_qa[Reporting QA]
            royalty_accounting_reporting_uat[Reporting UAT]
        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]
    end

    statement_db --Jenkins - Get Eligible Sales
        STMT_DB_SALES_NR_STAGING,
        STMT_DB_SALES_DISTRO_STAGING--> royalty_accounting_prod

subgraph Looker
        looker[Looker]
        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] 
       ows_accounts[Ows Accounts]
    end

    subgraph KAFKA
        kafka_system[Kafka System]
        backend --ACCT Creation--> kafka_system
    end

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

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