How jaimir14/scm-api works
This is a Fastify API for clinic/doctor tenants, with each deployment configured to use its own MySQL schema. The main workflow is a client request reaching the server, passing through registered routes, and—on patient endpoints—JWT authentication and input validation before patient services read or change database records. The API also provides a development token endpoint and health check. The README documents pagination and schema-per-tenant isolation; sampled source confirms route, service, and database-client responsibilities, but not the Prisma client’s internal connection wiring.
Main entry points: app.ts Fastify app · patient.routes.ts Patient routes · server.ts Server startup · jwt.ts JWT plugin
Components 15
API runtime
- Server startup
src/server.ts - Fastify app
src/app.ts - Error handling
src/common/middleware/error-handler.ts
Authentication
- Token endpoint
src/modules/auth/auth.routes.ts - JWT guard
src/modules/auth/auth.guard.ts - JWT plugin
src/plugins/jwt.ts
Patient management
- Patient routes
src/modules/patients/patient.routes.ts - Patient validation
src/modules/patients/patient.schema.ts - Pagination validation
src/common/schemas/pagination.schema.ts - Patient service
src/modules/patients/patient.service.ts
Configuration and data
- Environment config
src/config/env.ts - Prisma client
src/database/prisma.ts - Patient model
prisma/schema.prisma
Other components
- API client
- Tenant MySQL
Connections 17
- API client → Server startup: sends requests
- Server startup → Fastify app: builds app
- Server startup → Environment config: reads settings
- Fastify app → Environment config: reads settings
- Fastify app → Token endpoint: registers routes
- Fastify app → Patient routes: registers routes
- Fastify app → JWT plugin: registers plugin
- Fastify app → Error handling: sets handler
- Token endpoint → JWT plugin: signs token
- Patient routes → JWT guard: checks requests
- JWT guard → JWT plugin: verifies token
- Patient routes → Patient validation: validates input
- Patient routes → Pagination validation: validates query
- Patient routes → Patient service: calls operations
- Patient service → Prisma client: queries records
- Prisma client → Tenant MySQL: accesses tenant schema
- Patient model → Tenant MySQL: defines data shape