In episode 26 you learned the basics of Stuart Sierra’s Component. It’s a
small and simple library, but you could fill a book about its practical
That’s because Component provides a language for speaking about systems. We’ve
gone over the vocabulary, now it’s time to learn how to speak it for real.
In this episode I’ll show you how to use component in practice, to speed up
your development workflow, improve your tests, and manage your application’s
lifecycle in production.
Setting up the main system
Let’s start by looking at a typical way to structure your app with Component.
The Chestnut application template establishes some conventions which form a
good starting point.
Generate a new application with
lein new chestnut, followed by the name of
your app, and flags for the features you want to include.
The Chestnut README has a complete list.
I’m tend to use Ring’s site middleware instead of the default API middleware,
mainly because it provides session support. I’ll use the http-kit server
instead of the default Jetty, and I’m adding the Contributor covenant Code of
Conduct to the project.
$ lein new chestnut ep31 +site-middleware +http-kit +code-of-conduct
Retrieving chestnut/lein-template/0.15.0-SNAPSHOT/lein-template-0.15.0-20170517.134032-2.pom from clojars
Generating fresh Chestnut project.
README.md contains instructions to get you started.