Skip to main content

Lesson 7 of 8

Practice & Quiz - Full-Stack TypeScript Architecture

Test your mastery of production TypeScript - monorepos, shared types, CI pipelines, performance best practices, and the complete layered architecture - with a capstone exercise and 5 quiz questions.

10 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Practical: Shared Types Monorepo Package

Practical: Shared Types Monorepo Package
// packages/shared/src/index.ts - the single source of truth for API contracts
import { z } from "zod";

// ── Request / Response schemas (used by both server and client) ──
export const CreateTaskSchema = z.object({
  title:    z.string().min(1).max(200),
  priority: z.enum(["low", "normal", "high"]).default("normal"),
  dueDate:  z.string().datetime().optional(),
});

export const TaskSchema = z.object({
  id:        z.number(),
  title:     z.string(),
  status:    z.enum(["PENDING", "IN_PROGRESS", "COMPLETED"]),
  priority:  z.enum(["low", "normal", "high"]),
  dueDate:   z.string().nullable(),
  createdAt: z.string(),
  updatedAt: z.string(),
});

// ── TypeScript types derived from schemas - always in sync ───
export type CreateTaskDTO = z.infer<typeof CreateTaskSchema>;
export type Task          = z.infer<typeof TaskSchema>;

// ── Typed API response envelope ──────────────────────────────
export type ApiSuccess<T> = { ok: true;  data: T;     timestamp: string };
export type ApiError<E>   = { ok: false; error: E;    timestamp: string };
export type ApiResponse<T, E = string> = ApiSuccess<T> | ApiFailure<E>;

// packages/server/src/controllers/TaskController.ts - uses shared types
import { CreateTaskSchema, type CreateTaskDTO } from "@acme/shared";

async function createTask(req: Request, res: Response): Promise<void> {
  const parsed = CreateTaskSchema.safeParse(req.body);
  if (!parsed.success) {
    res.status(422).json({ ok: false, error: parsed.error.flatten() });
    return;
  }
  const dto: CreateTaskDTO = parsed.data; // guaranteed typed ✅
  // ... call service, return ApiResponse<Task>
}

// packages/web/src/api/taskApi.ts - same shared types on the client
import { TaskSchema, type Task } from "@acme/shared";

async function getTask(id: number): Promise<Task> {
  const raw = await fetch(`/api/tasks/${id}`).then(r => r.json());
  return TaskSchema.parse(raw); // runtime validation + type narrowing ✅
}

Module Quiz

Module Quiz
Question 1 of 5

What is the primary benefit of a `packages/shared` types package in a TypeScript monorepo?

Tip

Tip

Practice Practice Quiz FullStack TypeScript Architecture in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

TypeScript = JavaScript + static types → fewer bugs, better tooling

Practice Task

Note

Practice Task - (1) Write a working example of Practice Quiz FullStack TypeScript Architecture from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Common Mistake

Warning

A common mistake with Practice Quiz FullStack TypeScript Architecture is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready typescript code.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/8 done

Final Projects

Congratulations on completing the course! Apply everything you've learned by building one of these real-world projects.

Project 1: Type-Safe API Client

Intermediate

Build a fully typed REST API client library with generics and error handling.

TypeScriptFetch APIGenerics
Key features
Generic request types Error type guards Response validation Auto-complete support
12-16 hoursGoal: A reusable typed API library.

Project 2: TypeScript CLI Tool

Intermediate

Create a command-line tool with TypeScript for file processing and data transformation.

TypeScriptNode.jsCommander.js
Key features
Argument parsing File I/O Progress reporting Error handling
10-14 hoursGoal: A published npm package.

Project 3: Full-Stack TypeScript App

Advanced

Build a full-stack app with TypeScript on both frontend (React) and backend (Express).

TypeScriptReactExpressPrisma
Key features
Shared types Type-safe API Database ORM Authentication
24-32 hoursGoal: End-to-end type safety experience.