CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/fastify-best-practices

Fastify patterns — always apply schema-first validation, plugin encapsulation, structured error handling, hooks lifecycle, decorators, TypeScript type providers, production hardening (CORS, helmet, rate limiting), pino logging, graceful shutdown, and correct async handler patterns

89

2.75x
Quality

89%

Does it follow best practices?

Impact

91%

2.75x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-1/

Auth Gateway Service

Build a Fastify API that acts as an authentication gateway. The service manages user sessions using JWT tokens.

Endpoints

  • POST /api/auth/register -- Register a new user. Accepts email, password, and displayName. Stores the user in memory (hash the password with bcrypt or similar).
  • POST /api/auth/login -- Authenticate a user. Accepts email and password. Returns a JWT access token.
  • GET /api/auth/me -- Get the current user's profile. Requires a valid JWT in the Authorization header (Bearer token).
  • POST /api/auth/logout -- Invalidate the current session (add token to a blocklist).

The JWT secret should come from an environment variable JWT_SECRET. Tokens should expire in 1 hour.

Protected routes (/me, /logout) should return 401 if no valid token is provided.

Output

Produce TypeScript files in a src/ directory:

  • src/app.ts -- Fastify app setup
  • src/plugins/auth.ts -- Authentication plugin with hooks and helpers
  • src/plugins/users.ts -- User management routes
  • src/services/userService.ts -- User storage and password hashing
  • src/services/tokenService.ts -- JWT creation and verification
  • src/server.ts -- Server startup

Do not include test files or build configuration.

evals

scenario-1

criteria.json

task.md

tile.json