# What it looks like in code

Sketches of how the pieces sit in their files. Each piece's own page gives
its full syntax.

A library with its documentation comment, in
`shared/libraries/rounding.jadpo`:

```jadpo
/// Rounds to the nearest whole penny, ties to the even penny.
library rounding {
    function half_even(amount: Price) -> Price { ... }
}
```

A call to it from another domain, in
`domains/ordering/actions/checkout.jadpo`
([Constants](constants.md) covers libraries' constants too):

```jadpo
var total: Price = rounding.half_even(subtotal)
```

A public action, in `domains/inventory/actions/reserve_for_cart.jadpo`:

```jadpo
public action reserve_for_cart(cart_id: Cart.id) fails OutOfStock -> Reservation { ... }
```

Another domain calls it inside its own transaction, in
`domains/ordering/actions/checkout.jadpo`
([Reads and writes](reads-and-writes.md)):

```jadpo
action checkout(cart_id: Cart.id) fails OutOfStock, CartEmpty -> Order {
    var reservation: Reservation = attempt inventory.reserve_for_cart(cart_id)
    var order: Order = attempt place_order(cart_id, reservation)
    return order
}
```

A named route group with a checked prefix, in
`domains/planning/routes/todos.jadpo` ([HTTP](http.md)):

```jadpo
routes Todos {
    prefix: /todos

    GET / { ... }
    GET /{todo_id} { ... }
    PATCH /{todo_id} { ... }
}
```

A schedule, in `domains/planning/schedules/overdue_reminders.jadpo`
([Jobs and events](jobs-and-events.md)):

```jadpo
schedule overdue_reminders {
    every: 15m
    run: send_due_reminders()
}
```

A subscriber in another domain, in
`domains/notifications/subscribers/send_order_confirmation.jadpo`:

```jadpo
subscriber send_order_confirmation {
    on: OrderPlaced
    run: send_order_confirmation_email(event)
}
```

A connection to a provider package, pinned to the provider's API version,
in `app.jadpo` ([Integrations](external-services.md)):

```jadpo
connections: {
    stripe: {
        package: Stripe.v2024_06_20
        credential: config.stripe_secret_key
        domains: [payments]
    }
}
```
