# Business Flow

The business flow illustrates how a payroll compliance report is generated and delivered to users.

{% @mermaid/diagram content="flowchart TB
subgraph L1\["Payroll Analyst / Admin"]
UA\["User needs compliance report"]
UM\["Manual trigger via Claudia Chat"]
UR\["Receive email & review report"]
END(\["End"])
START(\["Start"])
end

subgraph L3\["Claudia Orchestrator"]
GW\_TRIGGER{"Trigger type?"}
BC\["Build Payroll Check Context<br>(company, period, cutoff)"]
VR\["Run validation rules<br>FR-001..FR-008"]
AR\["Aggregate results<br>(per rule & risk)"]
GR\["Generate PDF Compliance &<br>Risk Summary Report"]
ES\["Prepare email<br>(subject/body + attach PDF)"]
end

subgraph L2\["Scheduler"]
SC\["Scheduled trigger<br>(cron / config)"]
end

subgraph L4\["Email System"]
SE\["Send email<br>to user"]
end

START --> UA
UA --> GW\_TRIGGER
GW\_TRIGGER -- Manual --> UM
GW\_TRIGGER -- Scheduled --> SC
UM --> BC
SC --> BC
BC --> VR
VR --> AR
AR --> GR
GR --> ES
ES --> SE
SE --> UR
UR --> END" %}

#### Flow Description

| Phase                    | Description                                                                                 |
| ------------------------ | ------------------------------------------------------------------------------------------- |
| **1. Trigger**           | Process starts when a Payroll Analyst/Admin needs a compliance report (manual or scheduled) |
| **2. Context Building**  | Claudia builds the payroll context including company, period, and cutoff date               |
| **3. Validation**        | Runs all validation rules (FR-001 through FR-008) against payroll data                      |
| **4. Aggregation**       | Results are aggregated by rule and risk level (HIGH/MEDIUM/LOW)                             |
| **5. Report Generation** | Generates PDF Compliance & Risk Summary Report                                              |
| **6. Delivery**          | Email system sends the report to the user for review                                        |
