Code standards
The checks each app has, the patterns the backend and the web app follow, and the commit message format.
Each app has its own lint, format and type-check settings, and the two share none. Nothing enforces them: there is no pre-commit hook, and CI runs only the backend tests. Run the checks yourself on the files you change, in this order:
- 1 Format Prettier rewrites the files
- 2 Lint ESLint, on the files you touched
- 3 Types The build type-checks the app
- 4 Tests The unit suite
- 5 Message A Conventional Commits subject
| Backend | Web app | |
|---|---|---|
| Format | bun run format | bun run format |
| Lint | bun run lint, which also fixes and rewrites files | bun run lint (any warning fails), or bun run lint:fix |
| Types | bun run build | bun run build |
| Tests | bun run test | bun run test |
Backend
Settings
| Setting | Value |
|---|---|
| TypeScript | Null checks strict; implicit any and uninitialised class fields allowed |
| Lint | The recommended type-aware rules with Prettier. any is allowed; promises nobody awaits, unsafe arguments and unused variables warn; a formatting difference is an error. |
| Format | Single quotes, trailing commas everywhere, two-space indent, LF line endings |
Patterns
- Domain rules live in the area’s services. HTTP routes, bus subscribers, agent tools and campaign steps all call the same services, so tagging a person from the agent and from a campaign step goes through one set of tag rules.
- Each area declares its errors once, each with an HTTP status, a stable snake_case code and a message template. One error filter turns them into the same JSON body everywhere: status, code and message. A validation failure gets the code
validationwith the failing fields. An error can be marked retryable, and a campaign step then retries it like an infrastructure failure. - Each kind of input has one validation library: class-validator for HTTP bodies and queries, Zod for settings and agent tool inputs, TypeBox for campaign step inputs and outputs. HTTP validation drops unknown fields and converts query values to the types the schema declares.
- Every route needs the access token unless it is marked public. Webhook routes are public and check the caller themselves, with a signature or a shared secret. The Telegram webhook is the exception and checks nothing.
- An area that needs another area to react publishes an event on the bus instead of calling it. The area declares its events next to its code, and the other area subscribes when it starts. A debounced event needs a record id and collapses repeats for that id into one delivery.
- The database is reached through one shared client. Raw SQL binds its values as parameters. The only text spliced into a query is a checked vector size and a column key taken from a fixed list.
- Settings are read through the settings service inside a provider, never at import time. A setting read at import time runs before the settings file loads, which is how the upload limits end up empty on a host run (see Local development).
- Comments are in English or Vietnamese, and both appear in the same files. A new comment states a constraint or a reason the code cannot show.
Web app
Settings
| Setting | Value |
|---|---|
| TypeScript | Strict, with unused locals and parameters as errors; test files excluded |
| Lint | Recommended JavaScript, TypeScript, React and React hooks rules. Unused variables warn, except arguments starting with an underscore. |
| Format | Semicolons, single quotes in code and JSX, 100 columns, imports sorted in groups: React, other packages, then the app’s own shared code from the lowest layer up, then relative imports |
The package file configures a lint and format pass over staged files, but no git hook runs it.
Patterns
- Code for one area stays in that area’s feature folder. Each entity there has its API calls, its query keys and hooks, and its types, side by side.
- Every HTTP call goes through the one API client, which adds the token, refreshes it, and sends array parameters as repeated keys because the backend ignores the bracket form. The inbox stream is the one exception, read with the same token.
- Server data lives in the TanStack Query cache. Two small Zustand stores hold the rest: the session, and the campaign builder’s working graph.
- Styles are Tailwind with the redesign B colour tokens. Component variants and class merging each go through one small helper.
- Icons are Iconify names written out in full. The build bundles only the names it finds as complete strings in the source, so a name assembled at runtime renders nothing.
- The agent’s display name, Kit, is defined once and screens read it from there. The empty state of the Deals page still spells it out in two places.
- Screens use the app’s own words: Person and People, Channel, Audience, Step, Draft, Knowledge, Fit score, Unassigned pool and Claim. The redesign B design system in the
.superdesignfolder has the glossary and the list of things the product does not have. - Each page loads lazily. When a tab asks for a page chunk from an older build that is gone, the app reloads the tab once, at most every 30 seconds.
Commits
Commit messages follow Conventional Commits, as the web app’s commitlint settings describe. No hook runs commitlint, so the format is kept by hand.
| Rule | Value |
|---|---|
| Types | feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert |
| Scope | The app or the piece of work: backend, frontend, agent, inbox, redesign-b |
| Subject | Lowercase start, at most 100 characters |
Recent history reads like this:
fix(frontend): reload a stale tab when a page chunk is gone after a deploy
feat(backend): back the remaining redesign B promises
fix(agent): abort a stalled model stream instead of hanging the sessionThe subject says what changed in behaviour. Older history has many commits titled update; do not add more.
Never commit an env file or anything from the uploads folder. Git ignores every env file except the examples, and the web app also lets through one screenshot env file that holds no secret.