CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/separation-of-concerns

Enforce strict three-layer architecture: thin HTTP routes, pure service logic with domain errors, isolated data access with dependency injection.

94

1.08x
Quality

93%

Does it follow best practices?

Impact

97%

1.08x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-1/

Order Management API — Error Handling

Problem/Feature Description

A small e-commerce startup is building an order management backend using Node.js and TypeScript. The existing prototype works for the happy path, but the team is getting complaints that error responses are inconsistent — sometimes returning stack traces, sometimes returning 500 for every error regardless of the cause, and sometimes returning messages like "404: order not found" directly from deep inside the business logic.

The team lead wants a clean implementation of the order creation endpoint with proper error handling. The endpoint should accept a new order, apply business rules, and return meaningful error responses to the client. The core concern is that the error handling needs to be structured so that it can be reused if the same logic is later called from a background job or a CLI migration tool.

Output Specification

Implement the order creation feature as TypeScript files. Produce:

  • src/errors/domain.ts — Error type definitions
  • src/routes/orders.ts — The HTTP route handler for POST /api/orders
  • src/services/orderService.ts — The business logic for creating an order
  • src/repositories/orderRepo.ts — Data access for orders (can use a simple in-memory store or stub out a db query interface)
  • plan.md — A brief description of how errors flow through the layers in your implementation

The implementation does not need to connect to a real database. Use stub/mock data access that mimics real behavior.

Business rules for order creation:

  • customerName is required
  • items must be a non-empty array
  • Each item must have a productId and quantity > 0
  • Orders for more than 50 items total should be rejected as exceeding the bulk order limit

evals

scenario-1

criteria.json

task.md

tile.json