1 Critical Questions You Must Answer Before Writing Code
In the previous lesson, we resolved a fundamental question: "What must our software achieve?"
Now suppose we are setting out to construct a complete e-commerce platform. Our requirements specify:
- • User accounts and customer authentication
- • Product catalog browsing and full-text search
- • Persistent shopping cart functionality
- • Order placement workflows
- • Online payment processing
- • Administrative dashboards for inventory and order management
If we immediately begin coding, an existential set of structural dilemmas will paralyze development within weeks:
To answer these questions authoritatively, we establish a structured Software Design before writing code.
2 What is Software Design?
Software Design is the engineering process of defining a system's structure, components, interfaces, responsibilities, and data communication paths.
"Requirements specify WHAT we must build.
Design defines HOW we structure and organize it."
Consider civil engineering: If you intend to erect a 20-story building, you never start by stacking bricks on day one.
3 What is Architecture vs. Code Implementation?
Software Architecture is the highest-level structural blueprint of the system. At this altitude, we reason about:
- • The core subsystems and domain boundaries
- • The explicit responsibilities assigned to each component
- • Network protocols and communication contracts between subsystems
- • Data flow vectors and transaction boundaries
- • Integration touchpoints with external services
High-level structural decisions that are exceptionally expensive to undo later.
Concrete internal syntax and logic that can be refactored daily.
A High-Level System Architecture View
PostgreSQL
Stripe / SSLCommerz
Email / SMS Queue
4 Component vs. Module: Establishing Boundaries
The macro logical partitions within a system architecture are known as Components. A component is organized around a cohesive business or technical domain.
Its scope is strictly bounded to order lifecycle:
- • Validating and creating order records
- • Managing order state machine (Pending → Paid → Shipped)
- • Handling order cancellation and order history retrieval
Its scope is strictly bounded to monetary transactions:
- • Initiating charges with external gateways
- • Validating webhook signatures and callbacks
- • Managing retries and refund transactions
A Module is a more granular logical packaging unit within code. A major component typically contains several focused modules:
5 Separation of Concerns (SoC)
The most foundational canon in all software design is Separation of Concerns.
"Never entangle distinct responsibilities and concerns into a single monolithic unit."
Consider an anti-pattern function authored without separation of concerns:
Maintaining this mega-function is a nightmare. Changing the email template risks breaking payment charging! Professional engineering decouples these concerns into distinct architectural tiers:
6 High Cohesion and Low Coupling
The structural health of any software design is judged by two universal metrics:
How closely related the internal responsibilities of a module are to one another.
The degree of dependency and internal knowledge between distinct components.
The Universal Law of Clean Design:
High Cohesion + Low Coupling = Maintainable, Evolvable Software
7 Interfaces & Abstraction: Shields Against Change
An Interface is an explicit contract specifying what methods a component exposes without detailing how they are executed.
Abstraction is the discipline of exposing only necessary capabilities while concealing intricate implementation complexity.
When you depress the accelerator pedal, you are engaging a simple interface. You do not need to calculate piston stroke timings or electronic fuel-injection ratios; that operational complexity is completely abstracted. Similarly, calling `sendEmail()` shields engineers from raw low-level SMTP handshakes.
Case Study: Pluggable Payment Gateways
Suppose our platform originally launched using Stripe. Later, leadership directs engineering to support bKash and PayPal. If the Order component was tightly coupled to Stripe's specific classes, adding bKash would require rewriting core order checkout logic.
By placing a clean interface between them, the Order domain remains completely shielded:
The Order component has zero awareness whether Stripe or bKash is processing the charge. It relies exclusively on the contract, allowing new providers to be swapped in painlessly in hours.
8 🎮 Interactive Simulator: Pluggable Adapter Pattern
Switch payment providers below to see how interface abstraction keeps the core Order Service 100% untouched:
9 Layered Architecture & Modular Monoliths
The most resilient, industry-standard pattern for web backend development is Layered Architecture:
Monolith vs. Microservices
Prematurely adopting microservices on small teams creates distributed system nightmares: network serialization latency, partial failure recovery, distributed tracing, and coordination overhead.
10 💡 Concept Check (Interactive Quiz)
Test your comprehension of software architecture and modular design:
1. What is the overarching objective of clean software architecture?
2. What is the fundamental mandate of Separation of Concerns (SoC)?
3. What is the decisive advantage of relying on an Interface when integrating third-party gateways?
11 🧠 Key Takeaways
- Requirements = WHAT, Design = HOW, Code = Implementation: Establish architectural boundaries before committing lines of code.
- High Cohesion + Low Coupling: Group tightly related responsibilities together and decouple components using clean interfaces.
- Separation of Concerns: Never pollute domain business rules with raw database queries or direct third-party SDK calls.
- Design is not an inflexible prison: The hallmark of great architecture is its capacity to evolve with real-world business needs.
Lesson 10.5 — Code That Can Survive Change: Readability, Coupling & Cohesion
With system architecture defined, how do you author internal code so that future engineers can comprehend, refactor, and evolve it without fear of regression?
Start Lesson 10.5