CtrlK
BlogDocsLog inGet started
Tessl Logo

simon/skills

Auto-generated tile from GitHub (10 skills)

92

1.16x
Quality

94%

Does it follow best practices?

Impact

92%

1.16x

Average score across 44 eval scenarios

SecuritybySnyk

Advisory

Suggest reviewing before use

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-15/

Order Management API with PostgreSQL

Problem/Feature Description

A logistics startup is building an order management microservice on Fastify with PostgreSQL as the database. The team is starting from scratch and wants to set up the database layer correctly from day one, following patterns they can scale as the service grows.

The engineering lead has set three ground rules. First, the database client must integrate cleanly with Fastify's plugin and lifecycle system — when the server shuts down the database connection must also be released properly, and the database accessor must be available to all route plugins without passing it around manually. Second, route handlers must not contain raw database queries. Instead, data access must be encapsulated in repository objects that can be tested independently. Third, the database connection must be configured for production load: connection pool size and timeout values must be explicitly set rather than left at library defaults.

The service manages orders and order line items. An order has an id, a customer_id, a status (one of: pending, confirmed, shipped, delivered, cancelled), and a created_at timestamp. A line item has an id, an order_id, a product_id, a quantity, and a unit_price.

You do not need a running PostgreSQL instance. Implement the code correctly for when one would be present — the focus is on the architecture and integration patterns, not on producing queryable results.

Output Specification

Produce the following files:

  • package.jsontype: "module", dependencies, and a start script
  • src/app.ts — Fastify application factory. Export buildApp()
  • src/plugins/database.ts — database plugin that integrates PostgreSQL with the Fastify lifecycle, exposes the connection to the rest of the application, and properly handles shutdown
  • src/repositories/orders.ts — a repository module that implements at minimum: findById(id), findByCustomer(customerId), create(data), and updateStatus(id, status) operations
  • src/repositories/line-items.ts — a repository module with at minimum findByOrder(orderId) and create(data) operations
  • src/plugins/repositories.ts — a Fastify plugin that creates the repository instances and makes them accessible to route handlers
  • src/routes/orders.ts — a route plugin with at minimum GET /orders/:id, GET /orders?customerId=..., POST /orders, and PUT /orders/:id/status. Handlers must use the repository layer — no direct database queries in route files
  • src/server.ts — the entry point that starts the server
  • schema.sql — a SQL file with CREATE TABLE statements for the orders and line_items tables

evals

README.md

tile.json