---
paths:
  - "<src/**/*.ts>"
---
# .claude/rules/code.md — Agent Dev Thai Academy
20 rules from the boards, loaded only when a file matching paths: is touched; the rest of the setup is CLAUDE.md, the hook and CI.

## Boundaries · ขอบเขต
- Read env and create clients only in main. Fail at startup and name the missing variable. · /clean#main
- Use cases take plain data. Convert requests, rows and timezones at the edge. · /clean#boundary
- Files with business rules never import a vendor SDK directly. · /solid#D
- Each external API gets one adapter file. Nothing else imports its SDK. · /patterns#adapter
- Map external responses to our types in one translator. Missing fields become explicit nulls. · /ddd#acl
- This terminal owns billing/ only. Changes that touch learning/ go through a handoff. · /ddd#context
- domain/ never imports from app/ or infra/. CI checks the imports. · /uml#class
- A folder per owner and per context (`report/`, `charge/`, `billing/`), each with its own type holding only the fields it uses; a port is defined on the consumer's side. (solid/S · solid/I · ddd/context)
- Business rules live once in `core/` as pure functions testable without a browser; command types live in `core/`; the outer layers convert in and render. (clean/rule · clean/humble · clean/boundary)

## Extension · เพิ่มของใหม่
- A new channel is a new file that implements the existing interface. Don't add a branch to the shared one. · /solid#O
- A new implementation passes the same contract test as the old one. Compiling is not done. · /solid#L
- A new pricing rule is a new class behind PricingRule. Don't add a case to the switch. · /patterns#strategy
- Emit an event. Don't call email or analytics directly from the code that raised it. · /patterns#observer
- Add logging, caching or retry by wrapping the service, not by editing it. · /patterns#decorator
- Create courses through CourseFactory. Feature code never calls new VideoCourse(). · /patterns#factory
- Feature code calls checkout() on the facade. Don't wire payment, enrollment and email yourself. · /patterns#facade
- Every write command carries an id. An id the server has seen returns the old result. · /patterns#command
- Keep the enrollment steps in the base flow. A new course type overrides only the step that differs. · /patterns#template
- A new thing is a new file, not a new if: one interface file plus a registry, a strategy per file, a listener per named event, a wrapper per concern, a command and a facade per action. (solid/O · patterns/*)

## State and Money · สถานะกับเงิน
- Change an order only through Order methods. Totals are computed inside, never taken from the caller. · /ddd#aggregate
- Status changes go through the transition table. An unknown status throws. It never falls back to a default. · /uml#state
- Write the main flow as numbered steps, then one test that runs those steps through the public API. · /uml#sequence
- Put the money unit in the type, never in a comment or a field name. Convert once, at the provider boundary. · /scars#unit
- Quantity and status change through one entry point such as `Cohort.enroll()`: check and write in one transaction, with a `version` or a row lock. (ddd/aggregate)
