# Find where write logic should live

Prompt · Writes and ingestion · PG09

Business rules are split across SQL, triggers, edge functions, server routes and workers.

## Prompt

```text
Trace how records are validated, transformed and written across application code, database functions, triggers and background jobs. Find rules duplicated in different layers or placed where they are difficult to test and maintain. Recommend the simplest ownership boundary for each rule, without assuming that moving more logic into Postgres is automatically better.
```

**What it returns:** Each rule with the layers that enforce it, the current owner, duplicated checks, how testable each place is, transaction limits and what a change would touch.

**Skip it when:** Each rule already lives in exactly one place.

**Avoid:** Automatically favouring stored procedures, or automatically moving everything out of the database.

**Tools:** Repository and read-only database access.

**Works on:** Any PostgreSQL host: Supabase, Neon, RDS, Cloud SQL or self-hosted.

**Changes:** Changes nothing

**Sessions:** Look first, then fix in a new session

## Related

- [Meaning drift across the stack](https://atlasscope.dev/prompts/meaning-drift-across-the-stack): Shows where one word (a task, a fund, a run) means slightly different things in different parts of the app.
- [Map every place that writes to the database](https://atlasscope.dev/prompts/map-every-place-that-writes-to-the-database): Several jobs, functions, APIs or agents change the same data, or nobody is sure who owns it.
- [Is our ingestion process more complicated than necessary?](https://atlasscope.dev/prompts/is-our-ingestion-process-more-complicated-than-necessary): The import pipeline is long, slow to correct, or does the same work at several stages.
- [Which database objects no longer earn their keep?](https://atlasscope.dev/prompts/which-database-objects-no-longer-earn-their-keep): The list of views, functions and triggers has grown hard to reason about.

Source: https://atlasscope.dev/prompts/find-where-write-logic-should-live
