Viktor Berczeli’s Post

🚀 Late night architecture sessions always yield the best breakthroughs! Today on the Siege of Eger project, I tackled a massive milestone: creating an unbreakable data contract between Angular 21 frontend and NestJS backend. 🏗️ Working in a TypeScript Monorepo is powerful, but it comes with a common trap. TypeScript types like the DTOs disappear completely at runtime. If a client sends a malformed payload, the backend will not catch it until it crashes or corrupts the database. 🛠️ The Architectural Fix: Used a Zod Validation Pipe(thanks nestjs-zod) right in the shared workspace. Now, every single HTTP request is intercepted by the Pipe and validated against a strict Zod schema before it even sniffs the controller logic. 🛡️ The result? Total Type Safety. If the frontend sends an action that is not explicitly defined in the enums, the Pipe automatically intercepts it and returns a 400 Bad Request. The core service logic never has to deal with dirty data. 🧠 Two quick architectural tips for my fellow full-stack devs: 👉 1. Centralize your Zod schemas and inferred types in a shared workspace library. Single source of truth is king! 👉 2. Keep an eye on your async keywords. If a service method does not pause for an external operation using await, drop the async keyword. Do not add overhead by wrapping synchronous code in unnecessary Promises. 👇 I am curious, how do you handle runtime payload validation in your Node backends? Do you prefer class-validator, Zod, or another library entirely? Drop your thoughts below! ⚙️ #NestJS #Angular #TypeScript #Zod #SoftwareArchitecture #Monorepo #WebDevelopment #Backend #Frontend

To view or add a comment, sign in

Explore content categories