There are many ways to become a programmer. Most people start at home, learning a given language or technology, enjoying it and simply trying to bring their ideas to life. Along the way you pick up more language constructs, more complex topics and the possibilities a technology offers, and that translates into better and faster "achievements" in the field. That matters. But without a good mentor or a chance to work professionally, it is easy to forget something else: software architecture and the efficient design of IT systems.
Don't get me wrong, these topics do come up in tutorials. But they often come up in passing, because they are simply needed to complete particular exercises (unlike, for example, a coding standard, which is not essential at that level). Depending on how well it is explained, the student may absorb the various patterns or skip over them, if nobody points out that a concept has just been introduced that matters not only for the given technology but for designing any software and for the programmer's further growth. Such topics are later covered at university or in courses, and it happens that the student thinks "hey, I know this."
And although software architecture is a much broader concept, and the ways of organizing the components of IT systems are more complex today, it is worth going back to the basics to understand them. That is why today we will talk about fundamental architectural concepts, with people in mind who are only now getting serious about this world and have not yet had a chance to design any software on their own. There is nothing shameful in that, of course, because sometimes someone does it for us or the framework itself imposes a certain way of thinking. But do we then know exactly why we do things the way we do?
Client-server architecture
Well, more experienced programmers will realize after this section that we really are going to explain just the basics. I don't encourage them to stop reading, quite the opposite: make some tea, read the rest of the text and suggest in the comments other fundamental concepts of software architecture that, in their opinion, a beginner should know.
Imagine we are using a web application for communicating with other users. It could be a social network, an online messenger or even a comment system under articles. One person writes a message that a specific other user or everyone can read, and can reply to. Of course, the information is not sent directly to other users' browsers. Just as with the real-world postal service or a courier company, there is an intermediary that coordinates the data passed between the parties. The intermediary is the server, and the parties are the clients. This is client-server architecture, in which many clients can use a single server (though not always) that acts as a data store and a synchronizer of communication.
Put another way, the client is the application the user opens on their own device. For a web application, that is the web browser, which downloads the page files from the server (as a machine, not as a component) and displays them to the user, using the resources of their computer. This is even clearer in desktop applications and mobile apps, where you install the software (or at least download an executable) and run it directly in the device's operating system. The server, in turn, is software running on a server machine, and clients communicate with it through an interface, such as an API.
This means there is one common point of contact for different users, but also that the most security-critical information should be kept in the server application. Users have direct access to the files of client applications, so in theory they can modify the code and expose the system to unauthorized actions. On the other hand, client applications are usually faster: since they run directly on users' machines, those calculations do not load the server, and where possible it is worth taking advantage of that without straining the communication with the server application. This is used, for example, in online games, where the server synchronizes only the critical information, while details such as card or weapon animations are calculated right on the player's computer. That makes sense, considering that at any moment the server handles not only our match but thousands of others, and, especially in fast-paced games, it has to be efficient and respond quickly.
Client-server architecture is so widely used that nobody talks about it much anymore, taking the solution for granted. Still, it is worth mentioning its opposite, which users of so-called torrents may recognize: peer-to-peer (sometimes written as P2P). In this architecture every computer in the network (a node) is both a client and a server. It can use the resources of other servers, but also provides resources to the rest. This bypasses the idea of a central server and makes the network more resilient to failure, but on the other hand puts more "duties" on each user. Both approaches have their pros and cons, but P2P is specific enough that in the age of web applications and clouds it is not used very often. It should definitely not be the first choice when designing "general-purpose" software that uses a network.
An important note: the client-server approach is something quite different from master-slave. The latter refers to a situation where a node that is to perform some calculations (understood very broadly) splits the data and uses other units, each of which performs part of the computation. In short, one server synchronizes the work of other servers, not clients. A bit like a product owner in a team of programmers.
Frontend and backend
The client-server idea is often tied to the concepts of frontend and backend, which are mentioned in articles and even on this blog. In a simplified way, the frontend is what the user sees, and the backend is what they don't.
The frontend is generally associated with the graphical interface and controls. In web applications it is the part downloaded by the user's browser, whose job is to present data and let the user operate the system. That frontend communicates with the backend, which is the part of the system responsible for computational logic and for communication with the database. So the frontend is often treated as the client application, and the backend as the server application.
It is worth knowing, however, that there can be an application with client-server architecture in which the frontend and backend live in a single piece of software. Many older websites (especially those built in PHP by people who did not spend much time on it or had no other option) are so-called monoliths, and it is hard to separate the two layers clearly. The split into "front" and "back" is meant not only to create two separate applications, but also to separate responsibilities and to improve development by assigning different teams to the two parts, especially in larger companies. We often hear that someone is a frontend developer, a backend developer or a full stack developer who combines both worlds. This comes from the fact that different technologies suit the frontend and the backend, and someone who likes building interfaces will not necessarily do well on the server side, and vice versa. The two parts require solving different architectural problems and come with different nonfunctional requirements.
Model View Controller (MVC)
Let's start this section with one important thing: MVC is not an architecture. It is a design pattern (one of really many) that can be a component of an architectural design. Let's see what hides behind this well-known abbreviation.
You can write application code in one big file, and many years ago that is how beginners often started. But it quickly turns out that this is not the most efficient way to build software. Not only because one big pile of lines is hard to handle and modify, but also because at first glance you cannot see where the part that presents the interface is, where the logic is, where the database connection is, and so on. As the software grows, such code gets harder to change and to find your way around, both for a new person and even for the author. The fix is simple: split the file into several files, or better still into several "sections." But what should those be?
In 1979 the Norwegian Trygve Reenskaug proposed a concept that, after a little "rebranding," describes three parts of software:
- Model (M): classes that hold the application logic, manipulate data or act as entities representing various sets of information.
- View (V): classes that represent what the user sees and handle communication with the user.
- Controller (C): classes that accept the user's request, validate it and call the model classes so that they update the view classes.
The concept is simple, but it lets you divide code in a logical way. It also has several other advantages, among them "looser" classes that are easier to extend and make code reuse easier, which avoids duplication. There is one more, less obvious advantage, tied to how software is actually written. Let's not pretend otherwise: forms or controllers in a given application are often very similar to each other, and programmers usually do not write each new class of this kind from scratch but lean on existing pieces of code. That is easier when everything is neatly split into different files.
As with such concepts, people enjoyed it for a while but soon stopped using the classic form. Versions with an additional presenter (which restructures data between the model and the view) appeared, as did the MVVM approach, where the controller becomes a View-Model that mostly handles updating the data in the view according to the state of the logic. You can see this approach in Angular or WPF (in .NET technology). The M layer itself can be split into several subtypes, because it holds forms (their logic), computational logic, repositories (which manipulate data in the database directly) and DAO classes (Data Access Object, which carry data). Also, MVC is not an approach meant for the whole application. Obviously we don't have a single model class, one controller and one view, but many files, and not even in one folder. Such MVC-like structures can appear many times in a piece of software, which we will come back to today.
Three-layer architecture
The MVC concept and three-layer architecture (three-tier architecture) are different things, but you cannot deny that they share some similar elements. The layers in question are presentation, logic and data, which looks strikingly like the parts of the pattern discussed above. However, there are three huge differences.
First, only two adjacent layers can communicate with each other: presentation talks to logic, logic to data, data passes values back to logic and finally logic to presentation. This gives us a certain order and a limited area to search, which helps with debugging.
Second, other layers can be added to these "from the outside," such as an interface layer or a core, meaning the main shared tools used by the whole system. It is no accident that we speak in general of n-tier architecture, which we will mention again shortly.
Third, by design each layer is a separate application. So there is room here not only for client-server architecture, but also for separating the frontend (the presentation layer) from the backend (the rest). Of course, nothing stops you from building an example that contains all three layers in one application, but this architectural concept goes much further.
Of course, in this pure form three-layer architecture is also something of a classic. The number of layers depends on needs, and today we would add a controller layer that accepts requests on the backend side, and it all really depends on the application. Still, this traditional description helps us understand the general idea of designing architectures, even today: carefully separated parts (often programmed by different people), keeping things in order, room to grow as needed, and even preparation for scaling individual layers separately. Many frameworks support this way of building and it becomes natural, following the principle of loosely coupled components that are internally cohesive. Of course, it depends on many other factors: you can just as well create an application that follows this concept and is immediately ready to be rewritten. Likewise, tools should fit the task. Nobody will build a three-layer solution (not to be confused with a three-field system) for a simple script that, say, deletes orphaned files on a disk. Still, this topic is one of the fundamental ones that make other, more specific constructions easier to understand.
Modular architecture
Above we mentioned that an application using the MVC concept does not usually have three folders for the individual layers, containing all the model files, all the controller files and so on. It can be done that way, but it is not the way of writing recommended today. Instead, it is recommended to divide the software even further, into modules.
A module can be a cohesive area of the software that contains the controller, views, models and other classes belonging to that part. For an online store, for example, a module could be product, cart, order or supplier. Then, when a programmer wants to modify the part responsible for calculating the order value, the quickest way will probably be to find the order module and then the logic class inside it. That is, by the way, the first and most important advantage of this approach: it separates smaller pieces of software from each other even more, making it easier to move around within them and limiting the effect of changes in one module on another (though, of course, you can spectacularly break that too, like everything else). In a big simplification, each module can contain its own MVC, although in practice it does not necessarily look that way.
The second advantage is an even more visible effect of what I mentioned in the previous section: high internal cohesion, low external coupling, which makes the modules a bit like separate islands that do not affect each other, while still being part of one application. The idea of islands leads us to another consequence: when one module turns out to be more important or more heavily loaded than the others, you can either split it further or move it out into a separate sub-application, which makes modules a good introduction to the concept of microservices.
Again: in very simple applications there is no point in dividing them into modules, because there will usually not be many of them or they will become too tightly coupled. In large software, however, it is almost mandatory and serves as an introduction to even greater separation.
Summary
Of course, the concepts presented here do not exhaust the range of basic notions in software architecture. But they are terms you need to know anyway when working as a programmer, because they are either used directly or serve as an introduction to other, more complex structures. Knowing the information above will certainly not hurt anyone, and it may help organize the mind of a young programmer who until now has met fragments in articles that did not let them put whole concepts together. Each of them can of course be developed further and given an article of its own. Let us know whether any of the topics should be expanded, or whether the article is missing some other "classic."
Best regards and thank you, Jakub Rojek.


