Software Engineering
From clean functions to system shape: principles, patterns, architectural styles and enterprise building blocks.
A path from writing readable code to structuring whole systems: clean-code habits, paradigms and OOP, design principles and patterns, then architectural principles, styles and patterns, domain modelling and the enterprise patterns most frameworks are built on. Best taken once you are comfortable in at least one language and have shipped something real.
The subjects follow the roadmap.sh Software Design and Architecture roadmap.
Every line gets reviewed, debugged and extended many times after it is first typed, so the first design skill is making a single file easy to understand and safe to change. These habits are small and local, but they compound: a codebase built from readable functions is one you can still refactor in year three.
The overall goal: code whose intent is obvious to the next reader, with no surprises and no hidden coupling. It is judged by how quickly someone new can make a correct change, not by cleverness or line count.
Pick one way to name, structure and handle errors, and use it everywhere. A consistent codebase lets readers pattern-match; a mix of three conventions forces them to wonder whether each difference means something.
A name like daysUntilExpiry replaces the comment that d would need, and it cannot go stale. Keep comments for the why — a business rule, a workaround, a link to an issue — not the what.
Formatting debates are a waste of review time, so automate them: an .editorconfig, a formatter such as Prettier, gofmt or Black, and a linter in CI. Then style is no longer anyone’s opinion.
A function that fits on a screen and does one thing is easy to name, test and reuse. When a class grows several unrelated groups of methods, it is usually several classes waiting to be extracted.
Same input, same output, no side effects. Pure functions need no mocks to test, are safe to cache and run in parallel, and make the impure edges (I/O, time, randomness) easy to spot.
Each if, loop and case adds an independent path to test. Flatten nesting with guard clauses and early returns, replace long conditionals with lookup tables or polymorphism, and let a linter flag functions over a threshold.
A null argument invites crashes far from the cause, and render(true, false) says nothing at the call site. Use optional/Maybe types, separate methods or a small options object with named fields instead.
Business rules should not import the web framework or the ORM. Keep framework code at the edges (controllers, adapters) so the core can be tested without booting anything and survives a framework upgrade.
Reach for the language feature that says what you mean: map/filter over index loops for transformations, enums over magic strings, const over let, exceptions or result types over sentinel return values.
A suite that runs in seconds gets run on every change; one that takes twenty minutes gets skipped. Each test should set up its own state and pass in any order, or failures become impossible to trust.
Group code by who asks for its changes — billing, support, reporting — rather than by technical type. Then a request from one team touches one area, and two teams never edit the same class for unrelated reasons.
A method should either change state (a command, returning nothing) or answer a question (a query, with no side effects), never both. Queries become safe to call anywhere; commands become easy to find.
Write the simplest code that passes today’s tests, then improve its structure in small, behaviour-preserving steps while the tests stay green. Continuous small refactors beat a big rewrite that never ships.
A paradigm is a set of constraints on how you structure a program: what you are not allowed to do, as much as what you can. Most modern languages mix several, and good design picks the right one per problem — functional for data transformation, objects for long-lived stateful components.
Control flow built only from sequence, selection and iteration, with blocks and subroutines instead of arbitrary goto. It is the reason code can be read top to bottom and reasoned about one block at a time.
Programs built from pure functions over immutable data, with functions passed around as values (map, reduce, composition). Side effects are pushed to the edges, which makes concurrency and testing much simpler.
OOP bundles data with the behaviour that operates on it and lets objects collaborate through messages. Its features — classes, interfaces, visibility — and its four classic principles are the raw material most design patterns and principles are written in.
A class that cannot be instantiated and may leave some methods unimplemented for subclasses. Useful for sharing code among close relatives; prefer an interface when you only need a contract.
A fully implemented class you can instantiate with new. Depending directly on concrete classes is fine for stable value types, but couples callers tightly to anything likely to change or be swapped in tests.
Access modifiers (private, protected, public, package/internal) decide who can touch a member. Start everything as private and widen only when needed: whatever is public becomes a promise you must keep.
A named contract of methods with no implementation. Code that depends on an interface can work with any class that fulfils it, which is what makes substitution, mocking and plug-in designs possible.
A subclass reuses and extends a parent’s fields and methods. It creates the tightest coupling in OOP — changes to the parent ripple into every child — so keep hierarchies shallow and use it only for genuine is-a relationships.
One call, many behaviours: shape.area() runs whichever implementation the object provides. It replaces switch statements on type codes and lets new variants be added without editing the caller.
Exposing what something does while hiding how. A good abstraction has a small surface that matches the caller’s vocabulary; a leaky one forces callers to know the internals anyway.
An object guards its own state and only changes it through methods that keep it valid. Instead of setters for every field, offer intention-revealing operations like order.cancel() that enforce the rules.
Rules of thumb for arranging classes and modules so change stays cheap. None is a law; each trades one cost for another, and the skill is knowing which pressure matters in the code in front of you.
Build behaviour by holding references to small collaborating objects rather than by extending a base class. You can swap parts at runtime and avoid fragile deep hierarchies.
Find the parts of the code most likely to change — a pricing rule, a storage backend — and hide each behind its own boundary, so a change there does not spread through the rest of the system.
Declare parameters and fields as interfaces (PaymentGateway) rather than concrete classes (StripeClient). Callers stop caring which implementation they get, which makes substitution and testing trivial.
"Don’t call us, we’ll call you": a framework calls your code at the right moments instead of your code driving the framework. It is the idea behind inversion of control, callbacks and template methods.
Five class-design principles: Single responsibility, Open/closed, Liskov substitution, Interface segregation and Dependency inversion. Together they aim for classes that change for one reason and depend on stable contracts.
Don’t Repeat Yourself: every piece of knowledge should live in one authoritative place. It is about duplicated rules, not duplicated lines — merging code that only looks alike creates worse coupling than the copy did.
You Aren’t Gonna Need It: do not build hooks, options or abstractions for requirements nobody has asked for yet. Speculative generality costs effort now and complexity forever, and usually guesses wrong.
Talk only to your immediate collaborators. A chain like order.getCustomer().getAddress().getCity() couples you to three classes’ internals; ask order for what you need instead.
Rather than pulling data out of an object to decide something and then pushing results back in, tell the object what to do and let it use its own data. Logic ends up next to the state it depends on.
Named, reusable solutions to problems that recur in object design and system structure. Their biggest value is shared vocabulary: saying "use a strategy here" conveys a whole design in three words. Apply them when the problem appears, not to decorate code.
The 23 patterns from the 1994 "Gang of Four" book, grouped as creational (Factory Method, Builder, Singleton), structural (Adapter, Decorator, Facade) and behavioural (Strategy, Observer, Command). Several are now built into modern languages.
The Pattern-Oriented Software Architecture book series, which works at a larger scale than GoF: Layers, Pipes and Filters, Broker, Blackboard, Reactor and concurrency patterns for networked systems.
The design principles again, applied to modules, services and deployable units instead of classes. The central idea is that dependencies should point toward stable, high-level policy and away from volatile details like databases and UIs.
Rules for what goes in a deployable component and how components depend on each other: release/reuse equivalence, common closure, common reuse, no dependency cycles, and depending in the direction of stability.
Policy is the business rules that make the system valuable; details are the database, web framework and delivery mechanism. Keep policy ignorant of details so you can defer or change those decisions cheaply.
Cohesion is how strongly the parts inside a module belong together; coupling is how much modules depend on each other. Aim for high cohesion and low coupling so a change stays inside one module.
Lines between parts of a system that only interfaces or messages cross — a module API, a port, a service contract. Drawing them well lets each side change, deploy and be tested on its own.
A style is the broad shape of a system: how its parts communicate, where they run and how code is organised. Real systems mix styles — a layered monolith that publishes events, say. The three groups that follow cover communication, distribution and structure.
Components communicate by sending messages rather than calling each other directly. Producers and consumers no longer need to be up at the same time or know each other, at the cost of eventual consistency and harder debugging.
Services announce facts ("OrderPlaced") and other services react on their own. Adding a new reaction needs no change to the producer, but the overall flow is no longer visible in one place, so invest in tracing.
Publishers send messages to a topic; every subscriber to that topic gets its own copy. Kafka, Google Pub/Sub, SNS and Redis Pub/Sub implement it with different delivery and retention guarantees.
Styles for systems whose parts run on different machines and talk over a network. The network is slow, unreliable and insecure by default, so these styles are mostly about who holds data and authority, and what happens when a link fails.
Clients send requests to a central server that owns the data and rules. Simple to secure and update, which is why the web runs on it; the server is a bottleneck and a single point of failure unless replicated.
Every node is both client and server, sharing work and data directly, as in BitTorrent or blockchains. It scales with its users and has no central failure point, but consistency, discovery and trust are hard.
Styles for how the code of a system is divided and deployed. They decide where a change has to be made and how many things have to be released together, which matters more to a team’s speed than most technology choices.
The system is assembled from replaceable components that interact only through well-defined interfaces. Components can be developed and versioned separately while still running in one process.
One codebase, one deployable, one database. Easiest to build, test and debug, and the right default for most new products; the pain comes when many teams must coordinate every release. A modular monolith keeps strong internal boundaries.
Code split into horizontal layers — presentation, application, domain, data access — where each layer only calls the one below. Familiar and easy to start with; watch for changes that cut through every layer at once.
Concrete, proven blueprints for structuring a whole application or a group of services. Each solves a specific problem — scaling teams, separating reads from writes, keeping an audit trail — and brings its own operational costs, so choose for the problem you actually have.
Eric Evans’s approach of modelling software closely on the business domain, built with domain experts. Strategic DDD splits a large domain into bounded contexts; tactical DDD supplies building blocks like entities, value objects and aggregates.
Splits a UI into the model (data and rules), the view (rendering) and the controller (input handling). Rails, Django, Spring MVC and ASP.NET MVC use variants; MVVM and MVP are close relatives.
Small services, each owning its data and deployed independently, organised around business capabilities. They let many teams ship in parallel but add network failures, distributed data and heavy ops; most teams should earn them, not start with them.
Independent specialist modules read from and write partial results to a shared data store until a solution emerges, coordinated by a control component. Used for problems without a fixed algorithm, like speech recognition.
A minimal core provides the essentials and everything else is a plug-in that registers with it. IDEs like VS Code and Eclipse and browsers with extensions follow this shape, which keeps the core stable as features grow.
Code runs as short-lived functions triggered by events, on infrastructure the provider scales and bills per invocation. No servers to manage and near-zero idle cost; cold starts, execution limits and vendor lock-in are the trade-offs.
Queues (RabbitMQ, SQS) hand each message to one consumer and delete it once acknowledged; streams (Kafka, Kinesis) keep an ordered, replayable log many consumers read at their own offsets. Both decouple producers from consumers and absorb load spikes.
Store every state change as an immutable event and derive current state by replaying them. You get a complete audit log and can rebuild projections, but schema evolution of old events and replay performance need planning.
Service-oriented architecture: business functions exposed as reusable services, often wired through an enterprise service bus and shared contracts. Microservices grew out of it, trading central governance for team autonomy.
Command Query Responsibility Segregation uses separate models for writing and reading, so each can be shaped and scaled for its job. Worth it for complex domains or very read-heavy systems; overkill for plain CRUD.
Making the code itself the model of the domain: class names, relationships and methods mirror how experts talk about the business. When the model and the code drift apart, both lose value, so they are refined together.
An object model of the business where data and the rules that act on it live together — an Invoice knows how to apply a discount and refuses invalid states. Pays off when business logic is rich; for simple CRUD it is overhead.
The kinds of objects a domain model is made of — entities with identity, value objects defined by their attributes, services for operations that belong to no single object, and aggregates as consistency boundaries. Choosing the right kind for each concept shapes the whole model.
Isolating the domain layer from UI, application orchestration and infrastructure so the model can be expressed in pure business terms. Variations like hexagonal and onion architecture invert dependencies so infrastructure depends on the domain.
A ubiquitous language shared by developers and domain experts and used verbatim in code, tests and conversation. If the business says "policy lapses", the method should be lapse(), not setStatus(3).
Domain objects that are only getters and setters, with all logic living in service classes. It looks object-oriented but is procedural code in disguise; fine for simple apps, an anti-pattern when rules are complex.
Patterns for the plumbing of business applications: moving data between layers, mapping objects to tables and organising use-case logic. Most come from Martin Fowler’s Patterns of Enterprise Application Architecture and from DDD, and every major framework implements several of them.
Data Transfer Objects are plain shapes with no behaviour used to carry data across a boundary, such as an API response. They decouple the wire format from domain objects so the two can change independently.
A per-session cache keyed by primary key that guarantees each database row is loaded into exactly one object. It prevents two diverging copies of the same record; ORMs such as Hibernate and EF Core keep one in their session or context.
One class or function per application action — PlaceOrder, ResetPassword — that orchestrates domain objects and ports. They make what the system does visible in its folder structure and are the natural unit to test.
A collection-like interface (findById, save) over persistence, so domain and application code never write queries. Swap the implementation for an in-memory one in tests.
Objects whose only job is translating between representations — rows to domain objects (Data Mapper) or domain objects to DTOs — so neither side knows about the other.
Each business operation is one procedure that reads data, applies the rules and writes the result. Simple and perfectly fine for straightforward logic; it duplicates rules once the domain gets complex.
Represent each write request as a command object and each read as a query object, handled by dedicated handlers. It keeps use cases small, makes cross-cutting concerns like logging easy to add, and leads naturally to CQRS.
Small immutable objects compared by value, not identity — Money, EmailAddress, DateRange. They validate themselves on creation, so invalid amounts or emails cannot exist anywhere in the system.
Domain objects defined by a stable identity that persists while their attributes change, such as a Customer with an id. Two entities with identical fields but different ids are still different things.
Object-relational mappers (Hibernate, Entity Framework, Prisma, SQLAlchemy) generate SQL and map rows to objects. They save boilerplate; watch for N+1 queries and know when to drop to raw SQL.