express-prisma-patterns

Applies Express and Prisma coding patterns for the HealthGuard admin backend.

Updated Mar 3, 2026
One-click install
npx skills add https://github.com/manhthien2005/PM_REVIEW --skill express-prisma-patterns-manhthien2005
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: express-prisma-patterns
Source: https://github.com/manhthien2005/PM_REVIEW/tree/main/tooling/.windsurf-template/shared/skills/express-prisma-patterns
Command: npx skills add https://github.com/manhthien2005/PM_REVIEW --skill express-prisma-patterns-manhthien2005

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Express + Prisma backend code without consistent conventions leads to connection pool exhaustion, leaked stack traces, missing authorization checks, and unbounded Socket.IO broadcasts. This Skill encodes the exact architectural patterns used in the VSmartwatch HealthGuard admin backend so generated or modified code follows the project's layering, error model, and security rules. ## Core Features & Use Cases - Layered architecture enforcement: Routes map URLs, controllers parse and delegate, services hold business logic with Zod validation and Prisma transactions. - Security patterns: PrismaClient singleton, JWT auth middleware with role checks, resource ownership verification, pre-signed S3 URLs, and room-scoped Socket.IO emissions. - Error handling and testing: Centralized error handler mapping Prisma P2002/P2025 and ZodError codes, plus Jest service tests using jest-mock-extended. - Use Case: When adding a new device-management endpoint to HealthGuard/backend, apply this Skill to generate the route, thin controller, transactional service with audit logging, and a focused Jest test that all match the existing codebase conventions. ## Quick Start Use the express-prisma-patterns skill to create a new Express route, controller, and Prisma service for managing patient devices in the HealthGuard backend.

Frequently Asked Questions about express-prisma-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure an Express and Prisma backend project?▼

Structure it in layers: routes map URLs to controllers, controllers parse requests and delegate, and services hold business logic with Prisma queries. Keep the PrismaClient in a singleton module and handle errors through one centralized middleware.

How to implement JWT authentication middleware in Express?▼

Verify the Bearer token with jsonwebtoken using a secret from environment variables, then attach the decoded user id, email, and role to the request object. Combine it with a requireRole middleware that rejects requests lacking the needed role with a 403 error.

Why does creating multiple PrismaClient instances cause problems?▼

Each PrismaClient opens its own connection pool, so instantiating it per route or service exhausts database connections under load. Export a single shared instance from a lib module and import it everywhere instead.

How do I handle Prisma errors like P2002 and P2025 in Express?▼

Map them in a global error-handling middleware: P2025 becomes a 404 not-found response and P2002 becomes a 409 duplicate response. Never forward raw Prisma errors or stack traces to the client; log details internally and return a generic message.

Can Socket.IO broadcast realtime updates to all connected clients?▼

Broadcasting to all clients leaks data across users. Authenticate each socket with JWT, join user- or device-specific rooms after verifying ownership, and emit only to those rooms rather than using io.emit.

Should file uploads be proxied through the Express backend to S3?▼

No, proxying files through the backend causes memory bloat. Generate a pre-signed S3 PUT URL with the AWS SDK and let the client upload directly to S3, storing only the object key in the database.