A practical walkthrough of how one monorepo powers API, web, and admin apps while keeping type safety and tooling in sync. Learn the structure, patterns, and practices that enable consistency, rapid iteration, and automated deployment for a maintainable, scalable setup.
JavaScript Fundamentals — Practice Questions & Implementations
By Rohan Kumar · February 16th, 2026
A practical TypeScript-first guide to JavaScript fundamentals with 15 from-scratch implementations: array and promise polyfills, debounce/throttle, curry, deep clone/equal, data merge, and generator patterns with tests.
From Portfolio App to Production-Grade Frontend: A Senior Engineer’s Before/After Playbook
By Rohan Kuma · February 8th, 2026
Learn how senior frontend engineers evolve feature-complete UIs into production-grade systems. Discover the critical upgrades in reliability, observability, performance, and security that separate hobby projects from scalable products.
Designing Resilient Asynchronous Systems: From Synchronous APIs to Event-Driven Architecture at Scale
By Rohan Kumar · February 7th, 2026
Explore strategies and patterns for evolving synchronous APIs into scalable, resilient event-driven architectures. Learn how to design systems that handle failures gracefully and scale efficiently
Modern full-stack development thrives on consistency, ⚡ rapid iteration, and 🤖 automated deployment.
This repository demonstrates how a single monorepo can power multiple applications — API, Web, and Admin — while keeping type safety and tooling in sync.
Below is an architectural walkthrough that explains the project’s structure, highlights scalability & maintainability practices, and discusses how each piece adds value.
Using pnpm workspaces keeps apps and packages under a single roof, enabling a shared dependency graph, atomic installs, and one-command builds/deploys across the stack. Your root workspace acts as the command center for the entire system. ⚙️
💡 Why it matters: Faster installs, fewer version drifts, and consistent tooling across API, Web, and Admin apps.
🚀 Tip:pnpm --filter lets you target a single app or an entire scope.
The root build runs web & admin in parallel (& … & wait) after building shared types and the API.
###🧩 Shared Types Package
A dedicated @fullstack-lab/types package centralizes domain models (e.g., Blog, Project).
This keeps API responses, frontend components, and admin forms perfectly in sync.
Built with TypeScript, it exports compiled typings for consumption across workspaces. 🔄
🧠 Usage:** import once, rely everywhere — import type { IBlogDto } from '@fullstack-lab/types';
🛡️ Benefit:** single source of truth → fewer runtime mismatches and safer refactors.
2) 🛠️ API Service (apps/api)
The Node/Express backend emphasizes robustness and observability.
🔐 Security & Middleware
CORS configuration with allowlist
Helmet for secure HTTP headers
Express Rate Limit to mitigate abuse
Swagger UI for interactive API docs at /api-docs
ts
app.use(cors({origin: (origin, callback) => {// Allow requests with no origin (like mobile apps or curl)if (!origin) returncallback(null, true); logger.info(`🌍 allowedOrigins: ${allowedOrigins}`);if
🧪 Environment Validation
Joi validates runtime configuration before boot, preventing deploys with missing credentials or misconfigured environments.
Reusable CRUD handlers combine Mongoose queries, pagination, and caching, dramatically reducing boilerplate as new resources are added.
code
⚡ Cache Layer
Upstash Redis via a lightweight helper:
Versioned cache keys
Easy invalidation
Graceful fallback when unavailable
code
// lib/cache.tsimport crypto from 'crypto';import logger from '../utils/logger';import { redisRest } from './redis-rest';const DEFAULT_TTL = 60 * 5; // 5 minutesconst hash = (obj: unknown) => crypto.createHash('sha1').update(JSON.stringify(obj)).digest('hex').slice(0, 16);const nsKey = (ns: string) => `${ns}:version`;async function getVersionNS(ns: string) { if (!redisRest) return 1;
🔏 Access Control
Admin-only routes gated by a token header
Critical endpoints protected with Cloudflare Turnstile to block bots
code
import process from 'process';import { Request, Response, NextFunction } from 'express';export function requireAdmin(req: Request, res: Response, next: NextFunction) { const ADMIN_TOKEN = process.env.ADMIN_TOKEN; const authHeader = req.headers.authorization; if (!authHeader?.startsWith('Bearer ')) { return res.status(401).json({ message: 'Unauthorized: Missing or invalid token' }); } const token = authHeader.replace('Bearer ', ''); if (token !== ADMIN_TOKEN) { return res.status(401).json({ message: 'Unauthorized: Invalid admin token' }); } next();}
code
import type { Request, Response, NextFunction } from "express";const VERIFY_URL = "https://challenges.cloudflare.com/turnstile/v0/siteverify";export async function requireCaptcha(req: Request, res: Response, next: NextFunction) { try { const token = req.body?.captchaToken; if (!token) return res.status(400).json({ msg: "Captcha missing" }); const secret = process.env.TURNSTILE_SECRET_KEY; if (!secret) return res.status(500).json({ msg: "Captcha not configured" }); const form = new URLSearchParams(); form.append("secret", secret); form.append("response", token); if (req.ip) form.append("remoteip", req.ip); const r = await fetch(VERIFY_URL, { method: "POST", body: form }); const data = (await r.json()) as { success: boolean; ["error-codes"]?: string[] }; if (!data.success) { return res.status(403).json({ msg: "Captcha verification failed", error: data["error-codes"] });
✅ Outcome: Safer deploys, less boilerplate, faster responses, and production-ready defaults.
🚀 Deployment
A multi-stage Dockerfile in the repo root installs workspace dependencies, compiles shared types, and produces a lean dist/ artifact for the API.
This image is reproducible and ready to deploy on Fly.io (or any container platform).
🧩 Compiles shared @fullstack-lab/types before bundling the API
🚀 Targets a single, minimal runtime layer for deploys
yaml
# ---------------------------# 🐳 Dockerfile for apps/api# Supports pnpm + monorepo + TypeScript build for Fly.io# ---------------------------# Base Node imageFROM node:18-alpine# Enable Corepack for pnpm supportRUN corepack enable# Set working directory at monorepo rootWORKDIR /app# Copy entire monorepo into the containerCOPY . .# Set working dir to API appWORKDIR /app/apps/api# Install all dependencies in the monorepoRUN pnpm install --frozen-lockfile# Build shared types package firstRUN pnpm --filter @fullstack-lab/types... run build# Build the API (this compiles TypeScript to dist/)RUN pnpm run build# Expose port (adjust if your API uses a different port)EXPOSE 5050
3) 🌐 Web Front-End (apps/web)
The Next.js 15 application serves the public site and consumes the API’s typed interfaces.
⚛️ Modern React Stack
React 19, Radix UI, Tailwind CSS for a clean, accessible UI
Dynamic imports with fallbacks keep critical paths fast
🔍 SEO & Metadata
layout.tsx centralizes meta tags, Open Graph, and JSON-LD schema
Executed at build time for optimal performance and crawlability
🌎 Edge-Friendly Deployment
Cloudflare Pages configured via wrangler.toml
Attaches R2 object storage
Exposes public environment variables for client usage
Dependencies like MUI and react-admin live alongside the shared types package (@fullstack-lab/types), so the dashboard evolves in lockstep with API and Web.
Shared TypeScript interfaces ensure forms, tables, and detail views stay in sync with backend contracts.
💡 Tip: Add feature flags per resource (e.g., ENABLE_CONTACT) to toggle modules across environments without code forks.
5) 📈 Scalability, 🛠️ Maintainability, and 🎯 Value
Dimension
Practices & Benefits
Scalability
Caching and rate limiting in the API, global CDN via Cloudflare Pages, and containerized deployment enable horizontal scaling with minimal friction.
Maintainability
Centralized types, consistent validation, and generic controller patterns reduce code duplication and prevent drift between services.
Observability & Safety
Pino logging, strict environment validation, and defensive middleware (Helmet, captcha) help catch issues early and protect resources.
Developer Velocity
Shared build scripts, pnpm’s workspace install, and automated deploy commands shorten feedback loops and simplify onboarding.
This architecture balances flexibility and discipline, making it easy to add new applications or packages without fragmenting the codebase.
By leveraging a monorepo, the project keeps type definitions, utilities, and deployment tooling in one place—promoting a uniform developer experience and ensuring that every layer of the stack evolves together.
Whether you’re starting a personal portfolio or scaling a production-grade platform, this approach demonstrates how a well-structured monorepo can accelerate full-stack development while preserving clarity, security, and maintainability.
🔑 Key Takeaways / TL;DR
🧱 Monorepo with pnpm — keeps dependencies in sync, enables atomic installs, parallel builds, and a single command center for the stack.
🧩 Shared @fullstack-lab/types package — centralizes domain models, ensuring type safety across API, Web, and Admin with zero drift.
🛠️ API (Express + Mongoose) — secure by default (Helmet, CORS, rate limiting), validated environments (Joi), generic controller patterns, and Redis caching.
🚀 Deployment-ready — multi-stage Docker builds for Fly.io (API) and Cloudflare Pages (Web) with R2 storage.
⚛️ Next.js 15 frontend — edge-friendly, SEO-first, with streaming and dynamic imports for speed.
🗂️ Admin Dashboard (React Admin + MUI) — declarative resources tied to API, powered by shared types for consistent forms & views.
📈 Production-grade practices — caching, structured logging, strict env validation, and observability built in.
🧩 Scalable & maintainable — easy to add new services or packages without fragmentation, while preserving clarity, security, and velocity.
👉 Bottom line: This setup shows how a disciplined monorepo + shared types + modern tooling can deliver fast iteration, safe refactors, and production-grade deployment across a full-stack platform.
:
"cd apps/web && npx wrangler pages dev .vercel/output/static --config wrangler.toml"
}
}
(allowedOrigins.
includes
(origin))
return
callback
(
null
,
true
);
returncallback(newError('Not allowed by CORS'), false);