estack-architecture
Phoenix architecture
Read project instructions, neighboring modules, and mix.lock. Preserve the existing context layout; Phoenix generators commonly place a context at lib/my_app/orders.ex and schemas under lib/my_app/orders/.
Put behavior behind a public interface
Keep business rules, schemas, and durable job orchestration in the domain application. Keep HTTP, LiveView, serialization, and transport authentication at the web boundary. Call public context functions from web code; avoid reaching into context internals or querying Repo directly from an event handler.
Use modules to organize code. Add a GenServer only when a runtime requirement justifies one.
If Boundary is already installed, check its configuration and exported interfaces before changing dependencies. Propose it for a project that needs enforced boundaries; do not add it to every app automatically. Exporting everything from the top-level application does not enforce isolation between individual contexts.
Use the project's authorization contract
For Phoenix scope-based apps, pass the existing scope struct into context functions. For older apps, preserve their authenticated-user or policy interface. Do not mechanically replace %User{} with %Scope{} without adapting callers and tests.
Stamp ownership server-side and authorize the operation inside the public boundary so REST, LiveView, and jobs do not accidentally enforce different policies.