# Scalable TypeScript Monorepo Architecture with AI

Canonical page: https://get-vaastu.vercel.app/guides/scalable-typescript-monorepo

A worked architecture exercise: turn web and operations requirements into application boundaries, shared contracts, and one verified vertical slice.

## Begin with requirements

This is an illustrative design exercise, not a production benchmark or a customer case study. Assume a product needs a customer web app and a separate operations console, both using the same order workflow. The operations team has different permissions and may deploy its console independently.

Ask the agent to read SKILL.md and your requirements before creating files. Record the user roles, workflows, deployment constraints, data owners, and expected load. If a single application meets those constraints, keep it; a monorepo is a decision to justify.

## Choose boundaries with a reason

In this example, apps/web owns the customer experience and apps/operations owns internal workflows. Neither application imports the other application’s source. A shared contracts package owns runtime request and response schemas that both consumers actually need.

Order rules belong to the owning feature on the trusted backend. UI code calls a public contract instead of querying the database directly. Extract shared UI only when it has real consumers and compatible platform requirements. Avoid creating empty packages for hypothetical future clients.

## Request a reviewable proposal

Prompt: Read .agents/skills/vaastu/SKILL.md and REQUIREMENTS.md. Inspect this repository. Propose the simplest topology that supports the customer and operations workflows. Explain every application and package, allowed dependencies, authorization boundaries, state ownership, persistence, deployment, and verification. Do not implement yet.

Review why each deployment boundary exists, who may mutate an order, where authorization is enforced, and which package owns the request schema. Remove abstractions with no concrete requirement before scaffolding.

## Prove one order workflow

Implement one path: the authorized customer submits an order, the backend validates input and permissions, the owning feature applies its rules, persistence commits the change, and the UI receives a typed result. Include a denied-request case and an invalid-payload case.

Run relevant typechecks, contract and integration tests, and dependency checks. Confirm that shared packages do not import applications and that the operations app cannot bypass trusted authorization. Report untested deployment or device behavior separately.

## Scale from observed pressure

Write down the signals that would justify change: request latency, queueing delay, database contention, throughput, and team ownership conflicts. Set thresholds from your actual workload rather than copying universal numbers.

Add a worker for measured asynchronous work or extract a service for a concrete isolation need. Revisit boundaries after measuring the first slice. The goal is a system that can evolve with evidence.

## Related architecture guides

- [Review and Fix Architecture with an AI Coding Agent](https://get-vaastu.vercel.app/guides/review-existing-architecture)
- [Plan Frontend and Backend Architecture with AI](https://get-vaastu.vercel.app/guides/frontend-backend-architecture)

[Architecture protocol](https://get-vaastu.vercel.app/docs)
[Source repository](https://github.com/KOUSHIKG04/scalable-architecture-skill)
