mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-05-29 11:18:46 -04:00
2.6 KiB
2.6 KiB
backend/shared
Backend-only utilities used by backend/api, backend/scripts, and backend/email. Things that need
Node-only deps (pg-promise, firebase-admin, monitoring SDKs) but are reused across backends.
See the root CLAUDE.md for monorepo context.
Import rules
- Anything under
backend/*may import from here. - This package never imports from
backend/api,backend/scripts, orbackend/email. Cross-cutting code lives here; package-specific code stays in its package. - It may import from
common/*.
Layout
backend/shared/src/
├── supabase/
│ ├── init.ts createSupabaseDirectClient() — pg-promise client (backend SQL)
│ ├── utils.ts insert / update / updateData / bulkUpsert / bulkUpdate helpers
│ ├── sql-builder.ts renderSql / select / from / where / orderBy / limit (sanitized)
│ ├── users.ts, messages.ts, notifications.ts, options.ts Domain queries
├── websockets/
│ ├── server.ts, switchboard.ts
│ └── helpers.ts broadcastUpdatedUser, broadcastUpdatedPrivateUser, ...
│ (topics here are what the web `useApiSubscription` listens to)
├── monitoring/
│ ├── log.ts log.info / log.error — use everywhere on the backend
│ ├── metrics.ts, metric-writer.ts, context.ts, instance-info.ts
├── init-admin.ts Firebase Admin init
├── encryption.ts Message encryption helpers
├── analytics.ts, audit-events.ts
└── profiles/, compatibility/, helpers/
Conventions
- SQL: never string-concatenate. Use the helpers in
supabase/utilsfor inserts/updates, or compose withsql-builderfor reads. Lowercase SQL by convention. - New websocket topic: add a
broadcastXfunction inwebsockets/helpers.tsso the frontend has a typed topic to subscribe to. - Logging:
logfrommonitoring/log.debug()fromcommon/loggeris fine for verbose dev logs butlogcarries structured context to Cloud Logging. - Adding a domain helper: if a query is reused by more than one API endpoint, lift it into
supabase/<domain>.tshere rather than duplicating it.
Build / test
yarn --cwd=backend/shared typecheck
yarn --cwd=backend/shared lint[-fix]
yarn --cwd=backend/shared test