---
config:
    fontFamily: '"Source Sans 3", Verdana, Helvetica, Arial, sans-serif'
---
flowchart LR
    subgraph input["Inputs"]
    QUERY[/"Query<br>(<tt>query: QueryInput</tt>)"/]
    ITEMS[/"Candidate Items<br>(<tt>items: ItemList</tt>)"/]
    N[/"List Length<br>(<tt>n: int</tt>)"/]
    class ITEMS optional;
    class N optional;
    end

    subgraph prep["Data Preparation"]
    HLOOK["History Lookup"]
    CSEL["Candidate Selector"]
    CPICK(["Pick Cand. Source"])
    end

    subgraph rank["Scoring and Ranking"]
    SCORE["Scorer"]
    RANK["`Top-*N* Ranker`"]
    class SCORE config;
    end

    RESULT[\"Recommendations<br>(ordered <tt>ItemList</tt>)"\]

    QUERY --> HLOOK
    HLOOK -- RecQuery --> CSEL
    CSEL -.->|"ItemList<br>(if needed)"| CPICK
    ITEMS --> CPICK

    HLOOK -- RecQuery --> SCORE
    CPICK -- ItemList --> SCORE
    SCORE -- ItemList --> RANK
    N --> RANK

    RANK --> RESULT

    classDef optional stroke-dasharray: 5 5;
    classDef config font-weight:bold,stroke-width:4px;
