<!-- Generated by scripts/generate_ai_collab_docs.py. Edit metadata in that script. -->

# Backend Service: promo

This file adds local guidance for `src/api/flaskr/service/promo`. Read the
repository root and `src/api/AGENTS.md` first, then use this file for
module-specific ownership and risk points.

## Scope

- This service owns promotion campaigns, coupon and redemption models, and
  promo application or rollback logic tied to order lifecycles.

- Primary checked-in entry files today:
  `src/api/flaskr/service/promo/funcs.py`,
  `src/api/flaskr/service/promo/models.py`,
  `src/api/flaskr/service/promo/consts.py`

- Keep behavior in this module unless the concern is clearly cross-service and
  shared by multiple backend domains.

- Preferred pytest location: `src/api/tests/service/promo/` does not exist
  yet; create it when this service gains or changes behavior.

## Do

- Start from the local entry files and preserve how this service already
  structures helpers, models, routes, and DTO-like helpers.

- Keep promo application, rollback, and redemption behavior idempotent with
  respect to order retries and timeout recovery.

- Preserve centralized discount calculation inside promo helpers so coupon
  math does not drift across callers.

- Treat campaign and redemption rows as audit records that should stay
  coherent when business rules evolve.

## Avoid

- Do not split promo rollback logic between order code and promo code in ways
  that make eventual state ambiguous.

- Do not duplicate discount calculations or eligibility filters in frontend
  code or neighboring services.

- Do not change redemption semantics without reviewing order and coupon
  interactions together.

- Avoid scattering service-specific rules upward into root docs when the
  behavior only matters inside this module.

## Commands

- `rg -n "promo" src/api/flaskr/service src/api/tests` to locate all backend
  call sites and tests before editing.

- `cd src/api && pytest -q` until `src/api/tests/service/promo/` exists;
  create that directory first when this service gains behavior that needs
  focused regression coverage.

- `cd src/api && FLASK_APP=app.py flask db migrate -m "message"` and review
  the generated revision if schema or indexed business-key changes are made.

- `cd src/api && pytest -q` when a change touches shared DTOs, auth, streaming
  contracts, or other services in addition to this module.

## Tests

- Add or update focused tests around `src/api/tests/service/promo/` for the
  happy path and the highest-risk validation, permission, or failure case.

- Expand coverage when payload shapes, error codes, or shared helper contracts
  used outside this module change.

- Review persistence-related changes manually for indexing, business-key
  semantics, and migration output whenever models move.

- Document any skipped provider, network, or credential-dependent checks in
  the final task summary.

## Related Skills

- `src/api/SKILL.md`

- `SKILL.md`

- Create a new backend skill under `src/api/skills/<topic>/SKILL.md` when this
  module grows a repeatable multi-step debugging workflow.
