Internal tools

Subscription box admin back office in Retool

Retool admin app on Postgres for customer search, pause and skip, refunds, failed payments, and bulk box edits with safe-write checks.

retoolpostgressqlnodejssqlfluff

Built 1 time, downloaded 0 times.

Install from your terminal

Run this in your project folder. It signs you in, shows what changes and asks before it overwrites a file.

npx claude-lab add subscription-box-admin-back-office-in-retool-0a3119
10 filesDownload zip
CLAUDE.md
# Subscription box admin back office

## Purpose

Internal admin app for a subscription box company. Support and ops staff use it to search customers, pause or skip boxes, issue refunds, work failed payments, and bulk-edit next month's box. The team is small and uses Claude Code daily.

Not customer-facing. Do not build customer UI here.

@SPEC.md for requirements. @PLAN.md for phases.

## Stack

- Retool app. Export app JSON to `retool/` using Retool Source Control or Toolscript.
- Postgres. Schema changes are SQL migrations in `db/migrations/`.
- Node 20+ for scripts and tests.
- Payment provider: not chosen yet (see Open questions in SPEC.md). Use `YOUR_PAYMENT_API_KEY` as a placeholder.

## Repo layout

- `db/migrations/`: numbered, additive migrations (`NNN_description.sql`) with a down section.
- `db/queries/`: named `.sql` files, one per Retool query, mirrored from Retool.
- `db/tests/`: SQL tests for constraints and functions.
- `db/seed.sql`: fake data only.
- `retool/`: exported app JSON.
- `scripts/`: helper scripts, including `check-retool-json.js`.
- `docs/`: human docs.
- `.claude/`: skills, agents, hooks, settings.

## Commands

- Migrations (local only): `psql "$DATABASE_URL" -f db/migrations/NNN_description.sql`
- SQL tests: `npm run db:test`
- SQL lint: `npm run lint:sql` (sqlfluff, runs on `db/`)
- Full check: `npm run verify`
- Set the connection with `export DATABASE_URL=YOUR_DATABASE_URL` pointing at a local database. Never a production or staging host.

## Hard rules

- Never run anything against production. Use `DATABASE_URL` pointing at local or staging only, and only when the task says so.
- Secrets never go in the repo. Use placeholders such as `YOUR_DATABASE_URL` and `YOUR_PAYMENT_API_KEY`.
- No real personal data in seeds, tests, fixtures or logs.

## Money rules

- Store amounts as integer cents. No floats, no numeric math in Retool JS.
- Refunds call the payment provider API first. Only after success, insert a `refunds` row.
- Never `UPDATE` an amount column to fix a refund or payment.
- Refund amount cannot exceed paid minus already refunded. Enforce it in the database, not only in the UI.

## Write query rules

Every write query:

- Is parameterized. Retool `{{ }}` bindings go only in value positions, never in SQL identifiers, never concatenated into SQL strings.
- Runs in a transaction.
- Writes an `audit_log` row: actor, action, target, before, after.
- Has a confirm modal before it runs if it is destructive or bulk.

Destructive or bulk actions (refunds, bulk box edits) also need a row-count preview and a row cap. Example: max 500 rows per bulk edit.

## Pause and skip semantics

- Pause sets `subscriptions.status = 'paused'` and `resume_on`.
- Skip inserts a row into `skipped_months`.
- Neither action deletes data. History stays.
- The billing job reads both `subscriptions` and `skipped_months`. Do not change its contract without updating SPEC.md.
- Cannot skip a month that has shipped or is locked for packing.

## Retool gotchas

- Queries share a resource. Use the read-only resource for search and detail views. Use a separate write resource with limited grants for writes.
- Keep transformers small. Move real logic into SQL.
- Name queries `verb_noun`: `search_customers`, `issue_refund`, `preview_box_edit`.
- Export to `retool/` after every change and keep the JSON diff small.

## Role gating

- `support`: search, pause, skip.
- `ops_admin`: refunds above the threshold, failed-payment retries, bulk box edits.
- Gate every write in both Retool (permission group) and SQL (role or check in the function). The UI is not the only control.

## Working habits

- Explore, then plan, then code, then verify.
- Use plan mode before any write to the schema or to queries.
- Run the `verify` skill before saying a task is done.
- Use `/clear` between unrelated tasks.
- Run `/code-review` before merging. Review rules are in @REVIEW.md.
- If a column or business rule is unclear, add it to Open questions in SPEC.md. Do not guess.

## Pointers

- @REVIEW.md: review checklist, imported so `/code-review` applies it.
- @SPEC.md: features, data model, acceptance criteria.
- @PLAN.md: phases and `/goal` prompts.
Use for my project