Lab 15: Capstone — Enterprise Platform

Time: 60 minutes | Level: Advanced | Docker: docker run -it --rm node:20-alpine sh

Build a production-grade TypeScript platform wiring together all advanced concepts: Drizzle ORM with typed schema, Zod validation, fp-ts error handling, tsyringe DI, and a Vitest test suite — all with strict: true and zero type errors.


Step 1: Environment Setup

docker run -it --rm node:20-alpine sh
apk add --no-cache python3 make g++
npm install -g typescript ts-node
mkdir enterprise && cd enterprise
npm init -y
npm install drizzle-orm better-sqlite3 @types/better-sqlite3 \
            zod fp-ts tsyringe reflect-metadata vitest
echo '{
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES2020",
    "strict": false,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": "node"
  }
}' > tsconfig.json

💡 This capstone integrates: Drizzle (type-safe SQL) + Zod (runtime validation) + fp-ts (functional error handling) + tsyringe (dependency injection) + Vitest (type-safe testing). Each layer enforces correctness at a different boundary.


Step 2: Domain Schema (Drizzle ORM)

Define the database schema — TypeScript types are inferred automatically:


Step 3: Validation Layer (Zod)


Step 4: Typed Error System


Step 5: DI Container Setup (tsyringe)


Step 6: Service Layer (fp-ts Either)


Step 7: Test Suite (Vitest)

Run tests:


Step 8: Capstone — End-to-End Verification

Full integration test combining all components:

Run verification:

📸 Verified Output:


Architecture Diagram


Summary — All Technologies Integrated

Layer
Technology
Guarantees

Database schema

Drizzle ORM sqliteTable

Typed rows, zero manual types

Input validation

Zod schemas + safeParse

Runtime type safety

Error handling

fp-ts Either<AppError, T>

No unhandled throws

Dependency injection

tsyringe @injectable/@inject

Swappable implementations

Exhaustive errors

never + assertNever

All error cases handled

Testing

Vitest + child containers

Isolated, reproducible

Type strictness

strict: true throughout

No any, no implicit types

Last updated