Layers, ports & adapters - Part 2, Layers
The first key concept of what I think is a very simple, at the very least “clean” architecture, is the concept of a layer. A layer itself is actually nothing, if you think about it. It’s simply determined by how it’s used. Let’s stay a bit philosophical, before we dive into some concrete architectural advice.
Qualities of layers
A layer in software serves the following (more or less abstract) purposes:
Layers, ports & adapters - Part 1, Foreword
Looking back at my old blog posts, I think it’s good to write down a more balanced view on application architecture than the one that speaks from some of the older posts from 2013 and 2014. Before I do, I allow myself a quick self-centered trip down memory lane.
Why Symfony? Seven facts
The archive tells an interesting story about how my thoughts about software development changed over time. It all started with my first post in October 2011, How to make your service use tags. Back in those days, version 2 of the Symfony framework was still quite young. I had been working with symfony (version 1, small caps) for a couple of years and all of a sudden I was using Symfony2, and I absolutely loved this new shiny framework. I learned as much as I could about it (just as I had done with version 1), and eventually I became a Certified Symfony Developer, at the first round of exams held in Paris, during a Symfony Live conference. During those years I blogged and spoke a lot about Symfony, contributed to the documentation, and produced several open source bundles. I also wrote a book about it: A Year With Symfony.
Designing a JSON serializer
Workshop utilities
For the workshops that I organize, I often need some “utilities” that will do the job, but are as simple as possible. Examples of such utilities are:
- Something to dispatch events with.
- Something to serialize and deserialize objects with.
- Something to store and load objects with.
- Something to use with event sourcing (an event store, an event-sourced repository).
I put several of these tools in a code base called php-workshop-tools
. These utilities should be small, and very easy to understand and use. They will be different from the frameworks and libraries most workshop participants usually use, but they should offer more or less the same functionality. While designing these tools, I was constantly looking for the golden mean:
How to make Sculpin skip certain sources
Whenever I run the Sculpin generate
command to generate a new version of the static website that is this blog, I notice there are a lot of useless files that get copied from the project’s source/
directory to the project’s output/
directory. All the files in the output/
directory will eventually get copied into a Docker image based on nginx
(see also my blog series on Containerizing a static website with Docker). And since I’m on a hotel wifi now, I realized that now was the time to shave off any unnecessary weight from this Docker image.
Making a Docker image ready for use with Swarm Secrets
Here’s what I wanted to do:
- Run the official
redis
image as a service in a cluster set up with Docker Swarm. - Configure a password to be used by connecting clients. See also Redis’s
AUTH
command. The relevant command-line option when starting the redis server would be--requirepass
.
This is just a quick post, sharing what I’ve figured out while trying to accomplish all of this. I hope it’s useful in case you’re looking for a way to make a container image (an official one or your own) ready to be used with Docker Secrets.
The case for singleton objects, façades, and helper functions
Last year I took several Scala courses on Coursera. It was an interesting experience and it has brought me a lot of new ideas. One of these is the idea of a singleton object (as opposed to a class). It has the following characteristics:
- There is only one instance of it (hence it’s called a “singleton”, but isn’t an implementation of the Singleton design pattern).
- It doesn’t need to be explicitly instantiated (it doesn’t have the traditional static
getInstance()
method). In fact, an instance already exists when you first want to use it. - There doesn’t have to be built-in protection against multiple instantiations (as there is and can only be one instance, by definition).
Converting this notion to PHP is impossible, but if it was possible, you could do something like this:
Docker build patterns
The “builder pattern”
As a programmer you may know the Gang-of-Four Builder design pattern. The Docker builder pattern has nothing to do with that. The builder pattern describes the setup that many people use to build a container. It involves two Docker images:
- a “build” image with all the build tools installed, capable of creating production-ready application files.
- a “service” image capable of running the application.
Sharing files between containers
At some point the production-ready application files need to be copied from the build container to the host machine. There are several options for that.
Making money with open source, etc.
So, here’s a bit of a personal blog post for once.
Symfony trademark policy
I saw this tweet:
Suite à une mise en demeure, j’ai retiré les tutoriels qui concernent Symfony du Site. Il n’y aura pas de futures vidéos sur le Framework.
— Grafikart (@grafikart_fr) March 11, 2017
Meaning: “Following a formal notice, I removed the tutorials that are related to Symfony from the Site. There will be no future videos on the Framework.”
Microservices for everyone - The introduction
I’m happy to share with you the first chapter of my new book, Microservices for everyone. I’m still in the process of writing it and intend to release parts of it during the next weeks. If you’re interested, sign up on the book’s landing page and receive a 25% discount when the first chapter gets released.
If you’re curious about the table of contents so far: you’ll find it in the PDF version of the introduction.
Bash practices - Part 2: CQS and return values
As I promised in my previous “Bash practices” post, I would discuss a query function in this article. Here you have it:
function create_temporary_directory() {
directory=$(mktemp -d "$1/XXXXX")
}
create_temporary_directory
echo "$directory"
That’s a bad query function!
This function is supposed to return the path of a temporary directory. It accepts one argument: an existing directory we want to create the temporary directory in. It uses the mktemp utility to do the “heavy” lifting. It accepts as an argument a kind of a template for directory names (XXXXX
will be replaced by 5 random characters). After creating the directory, mktemp
echos the full path of the directory to stdout
, meaning we can copy it into a variable by using the $(...)
syntax.