# Ads Billing Service Architecture

## Overview

```mermaid
graph TB
    SERVE[ads-serving] -->|Charges| MQ[RabbitMQ]
    MQ --> BILL[ads-billing]
    BILL -->|Debit| WALLET[Wallet Service]
```

## Domain Aggregates

- **BillingAccount**: Payment settings, thresholds
- **CreditLine**: Postpaid limits
- **Invoice**: Monthly/threshold invoices
- **AdCharge**: Individual costs

## Billing Flow

| Type | Flow |
|------|------|
| **Prepaid** | Add Funds → Run Ads → Deduct → Pause when $0 |
| **Postpaid** | Run Ads → Accumulate → Threshold → Auto-charge |

## Thresholds

| Level | Condition |
|-------|-----------|
| $25 | New account |
| $50 | 2 payments on-time |
| $250 | 5 payments on-time |
| $500 | High trust |

## Integration

| Service | Purpose |
|---------|---------|
| **ads-serving** | Consume charges |
| **Wallet Service** | Process payments |
