Want to learn Duct? Check out this guide from CircleCI!

I’ve been trying to get a grip on web development with Clojure for a while. And I’ve found Duct to be great, in general. It provides a structured whole that makes it simple to write clear, reloadable code. At the same time, I don’t think it gets in your way.

But getting started has been … challenging. I’ve been scratching my head lots of times, not really understanding how all of Duct’s parts fit together. Because Duct spans broadly – it’s a dependency injection framework [**] that abstracts away lots of things, and at the same time, it’s a foundation for doing web development, with handlers and routing, for APIs and web pages.

Recently, a lot of the small things have clicked for me, thanks a solid guide by CircleCI. Advantages:

  • It works with a clear, realistic web application task
  • It doesn’t take “very clever shortcuts” when you need to figure out the normal path regardless
  • It follows up on deployment, showing you how to set up continuous integration (obviously, that’s what they do), and put your application into a running state.

In short, it bridges the gap between “Duct is a powerful platform with lots of potential” to “See how well Duct performs with this web application”.

So if you’re interested to learn about how you could work with a reloaded workflow where dependencies like the database are passed in for you, you might want to have a look at Duct with this guide.

[**] Technically, that’s not Duct, but Integrant

6 Likes

Hey thanks for sharing this article, i think it’s very important to help people who want’s to take the grasp of web development using clojure, and if it’s the 1st time touching back-end technologies and you are using clojure, i know how challenging this is.

I want to know why you choose Duct for this, i’ve also tried in the past using frameworks to learn clojure for web development and didn’t worked for me, so i used plain Ring+Compojure approach who worked very fine by reading docs and real code.

Hello @matthewlisp, and welcome to Clojureverse!

My experience has been similar. I wrote my first real web server with Compojure and HTTP-kit following very good (at least at the time) HTTP-kit docs. That’s when Clojure really clicked for me. I got a REPL set up, and when I understood that I could just hook into a request and play with the real data I sent from my own browser, well, that felt good.

Since then, I’ve looked into Luminus and Duct for

  1. Helping me structure my application, to separate out the “common web parts” from my business logic
  2. Learning web development.

This is what I really like about Duct:

1. You hook your application up with pure data. Once you understand how your application config (data) is used to initialize your application, the structure is very clear. That gives transparency, and helps avoid a mess of function calls referring to function calls all around, where you have to trace down the entire stack to understand what happens.

2. Application configuration and reloading is of very high quality. You naturally pull out configuration, which lets you write pure code. And Duct uses your configuration to infer how to reload your application. If I change the configuration for a part of my system and ask Duct to refresh, it will refresh just the component and any downstream components that depend on it. It extends this system to other resources like database migrations, which means that if I change one of my database migrations and (refresh), Duct will roll back the database migration, and apply the new one.

The end result I’m getting is that I’m not really afraid to let my Duct app grow, since the configuration helps me avoid coupling, and just add new components next to the old ones. Think open/closed principle.

Let’s strive to be pragmatic, so here are some downsides. (a) The documentation isn’t as clear as it could be. I’ve struggled with having to figure out how certain things fit together. This far, however, I’ve been able to figure things out. (b) It leaves more questions open than Luminus. How do I implement authentication? How should I handle HTML templating? How should I secure my routes?

In conclusion, I think Duct is one of the highest-quality pieces of the Clojure ecosystem, but it could use some fleshing out, primarily for (a) cohesive, documentation and (b) a “cookbook” of handling common web application tasks “the Duct way”.

2 Likes

I think i got what you mean by

Helping me structure my application, to separate out the “common web parts” from my business logic

I was in the same shoes, my app’s felt like i was doing something wrong or creating business logic too tightly coupled. I’ve addressed this issue using an opinionated architecture: GitHub - tengstrand/lein-polylith: Libraries and tools for Polylith component based architecture.

I might as well try duct in the future

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.