rea-analysis-optimization
MOmorluto/rea441k近 7 天新增 25,484 个 star
Use when working in apps/backend — new endpoints, controllers, services, models, queues/workers, or integrations. Covers the Router to Controller to Service to Model architecture, Zod validation, Prisma/PostgreSQL data access, Winston logging, BullMQ jobs, and FHIR/IDEXX/Merck integrations.
Use this skill when working on apps/backend. Covers Express.js architecture, service/controller patterns, validation, error handling, and healthcare-specific integrations.
TRIGGER: any task in apps/backend — new endpoints, services, models, or integrations.
apps/backend/src/
routers/ ← Express route definitions (thin — just register handlers)
controllers/ ← Request/response handling, input validation
services/ ← Business logic (no req/res objects here)
models/ ← legacy data models; no new files here (use Prisma via packages/database)
queues/ ← BullMQ job definitions
workers/ ← BullMQ worker processors
integrations/ ← External services (IDEXX, Merck, Stripe, Firebase, AWS)
Pattern: Router → Controller → Service → Model
Controllers call services. Services call models. Never put business logic in controllers or routers.
Use Zod for request validation. Never trust raw req.body.
import { z } from 'zod';
const CreateAppointmentSchema = z.object({
patientId: z.string().uuid(),
date: z.string().datetime(),
});
// In controller:
const data = CreateAppointmentSchema.parse(req.body);
@yosemite-crew/database).packages/database); do not add new files under src/models/ — this matches apps/backend/AGENTS.md.SuperTokens is the auth provider behind the provider-neutral boundary in
packages/auth (#1672), initialized by initSuperTokens in app.ts. Product
code uses the session guards in src/middlewares/auth.ts and never imports a
provider SDK (eslint-enforced). Pick the guard by product surface:
requireWebAuth - staff / PIMS web routes.requireMobileAuth - pet-parent mobile routes.requireAnyAuth - routes genuinely shared by both.Never roll custom auth.
Authentication only proves who is calling. withOrgPermissions() then proves
the caller belongs to the organisation named by the request (route param,
x-org-id, query, or body). On a route addressed by a resource id that is not
enough on its own - a caller can name an organisation they legitimately belong
to while addressing another tenant's record.
withAppointmentOrgPermissions,
withInvoiceOrgPermissions, withPaymentOrgPermissions,
withPaymentIntentOrgPermissions, withTaskOrgPermissions,
withInventoryItemOrgPermissions, withEncounterOrgPermissions,
withCaseOrgPermissions, withRenderedDocumentOrgPermissions,
withRoomUnitOrgPermissions, withRoomUnitGroupOrgPermissions. Add a new
one via withResourceOrgPermissions rather than hand-rolling a lookup.(req as OrgRequest).organisationId - the value
the middleware authorized. If the request also carries an organisation, it
must agree with that value; reject a mismatch rather than preferring it.organisationId?. Prisma drops undefined where-fields, so an optional
scope silently becomes an unfiltered, cross-tenant query. Required turns
that into a build error.Document has no organisation column - scope document queries through
documentWhereForOrg() (src/services/document-scope.ts), which expresses
the patientOrganisation join and the PMS visibility flag once.requirePermission([a, b]) is any-of. That is the intended idiom for an
:any/:own pair of the same resource. An array naming two different
resources grants each to holders of the other - require both instead.req.userId). Do not use
resolveUserIdFromRequest for an authorization decision: it falls back to a
client-supplied x-user-id header. It is fine for attribution only.BullMQ is the queue system. Jobs go in queues/, processors in workers/.
// Never process jobs inline in a request handler
// Always enqueue and let a worker handle async operations
await emailQueue.add('send-reminder', { appointmentId });
@yosemite-crew/fhir — use these, never invent custom health data shapes.src/integrations/ — extend there, never inline.Use Winston for all logging. Never use console.log in production code.
import logger from 'src/utils/logger';
logger.info('Appointment created', { appointmentId });
logger.error('Payment failed', { error, userId });
.parse() throws on invalid input — use .safeParse() when you want to handle errors gracefully.MOmorluto/rea441k近 7 天新增 25,484 个 star
MAmattpocock/skills318k近 7 天新增 9,301 个 star
MAmattpocock/skills318k近 7 天新增 9,301 个 star
MAmattpocock/skills318k近 7 天新增 9,301 个 star
MAmattpocock/skills318k近 7 天新增 9,301 个 star
MAmattpocock/skills318k近 7 天新增 9,301 个 star