When I design a software system, I don’t just look at UI components or buttons. I look at latency, architecture, and data flow.
Over the past year, my approach to system design has undergone a fundamental transformation. Moving from traditional backend monoliths to modern, edge-native, type-safe architectures taught me a hard truth: good architecture eliminates accidental complexity before it ever reaches production.
Here is a deep structural dive into how I used to design systems, and how I build resilient, high-performance applications today.
The Architectural Evolution: A Structural Deep Dive
To understand how I build systems today, we have to look at the structure. Below is the “Tree” view of my transition from a traditional MERN Monolith to a modern, Edge-Native Modular system.
1. The Legacy Architecture (BazarBhai)
When I built BazarBhai, a hyper-local multi-vendor marketplace ecosystem handling customers, sellers, and admin workflows, I relied on the classic Layered Monolith pattern. In this pattern, code is grouped by technical function rather than business domain:
bazarbhai-backend/ (The Monolith)
├── src/
│ ├── config/ # Environment-specific settings
│ ├── models/ # Database definitions (MongoDB schemas)
│ │ ├── userModel.js
│ │ └── productModel.js
│ ├── routes/ # API Endpoints
│ │ ├── userRoutes.js
│ │ └── productRoutes.js
│ ├── middleware/ # Global security & auth
│ │ └── checkAuth.js
│ └── helper/ # Business logic scattered across folders
│ ├── order/ # Logic detached from the API layer
│ └── products/
└── server.js # Central point of failure
The Flaw: As the application scales, this pattern quickly breeds “Spaghetti Code.” If you modify a field in userModel.js, you are forced to manually hunt across helper/, routes/, and controllers to ensure no runtime errors are triggered. There is no automated safety net, and data drift between database models and API payloads becomes an ongoing maintenance tax.
2. The Modern Architecture PayTrack & TrackFlow
Today, my design philosophy centers on “Schema-First, Performance-Always.” I build systems that execute globally on the Edge (via Cloudflare Workers and Hono) while maintaining strict type-safety from database to client SDK.
Instead of scattering files by technical layer, everything related to a specific feature is self-contained inside a Domain-Driven Module:
paytrack/ (The Modular Edge System)
├── src/
│ ├── modules/ # Self-Contained Domain Modules
│ │ ├── auth/ # Better Auth & Integration
│ │ │ ├── components/ # UI components
│ │ │ ├── server/ # Service, Middleware & Storage
│ │ │ ├── auth-schema.ts # Validation rules
│ │ │ └── auth-service.ts # Domain logic
│ │ ├── category/ # Domain Feature Module
│ │ │ ├── components/ # Feature UI components
│ │ │ ├── server/ # Edge Server Logic
│ │ │ │ ├── __tests__/ # Integration & Unit Tests (Vitest)
│ │ │ │ ├── category-app.ts # Hono OpenAPI Sub-App
│ │ │ │ ├── category-controller.ts # Route Handlers
│ │ │ │ ├── category-repository.ts # Drizzle ORM Data Access
│ │ │ │ ├── category-route.ts # OpenAPI Route Specs
│ │ │ │ ├── category-service.ts # Core Domain Logic
│ │ │ │ └── category-table.ts # Drizzle Table Schema
│ │ │ ├── category-schema.ts # Zod Validation & OpenAPI Contract
│ │ │ └── category-types.ts # Inferred TypeScript Types
│ │ └── upload/ # Direct-to-R2 Pre-signed Storage
│ ├── server/ # Core API Entry Points
│ │ ├── schemas/ # Standardized API Error & Response Schemas
│ │ ├── api.ts # Hono Central API Router
│ │ └── app.ts # Hono OpenAPI Factory
│ ├── lib/
│ │ └── openapi-sdk/ # Auto-Generated End-to-End Client SDK
│ └── db/
│ ├── client.ts # Drizzle D1/Postgres Connection
│ └── schema.ts # Central Drizzle Export
├── drizzle/ # Versioned Migration Files
├── wrangler.jsonc # Cloudflare Workers & Bindings Config
└── vitest.config.ts # Miniflare / Cloudflare Pool Test Config
The Strength: This pattern provides bulletproof Type-Safety and Edge Performance:
- Single Source of Truth (Schema-First): By defining tables in Drizzle (
category-table.ts) and combining them withdrizzle-zodand Hono-OpenAPI (category-schema.ts), the database schema automatically drives input validation, runtime checks, and API documentation. If a database column changes, TypeScript instantly flags breaking changes across repositories, services, and UI forms. - Decoupled Asset Uploads & Secure Auth:
- Better Auth: Handles robust multi-tenant authentication securely with persistent session storage and KV caching.
- Cloudflare R2 Storage: Large files bypass server compute entirely using direct-to-bucket pre-signed upload URLs.
- Edge-Native Performance & Isolation: Logic runs globally on Cloudflare Workers, achieving sub-second latency worldwide. Every module includes co-located unit and integration tests (
__tests__/) running on Miniflare via Vitest, ensuring high test coverage and predictable deployments.
Comparison: Why I Switched
| Design Dimension | Legacy Monolith (BazarBhai) | Modern Modular Edge (PayTrack / TrackFlow) |
|---|---|---|
| Organization | Grouped by technical layer (models/, routes/) |
Grouped by business domain (modules/[feature]/) |
| Type Safety | Manual checks and runtime drift risks | End-to-end type safety via Drizzle, Zod, and OpenAPI SDK |
| Infrastructure | Centralized server (Single point of failure) | Global Edge Network (Cloudflare Workers, D1/PostgreSQL, R2) |
| Documentation | Manual updates / external docs | Auto-generated OpenAPI contracts and SDKs |
| Testing | Monolithic integration tests | Isolated domain unit and integration test suites |
Summary of my Design Goal
I design for predictability. By structuring systems with strict modular boundaries and edge-native primitives, I ensure that an application is easy to upgrade, impossible to “break” by accident, robust against technical debt, and runs with sub-second latency globally on the edge.
