Skip to content
Leiningen template for a new component based app implementing the reloaded workflow
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A Leiningen template for a component based app using Stuart Sierra's component library and reloaded workflow.

For an introduction to component based systems, please see the documentation for component and Stuart's talk from Clojure West 2014.

Components- Just Enough Structure


This is a very simple template with no special options. Simply run

lein new reloadable-app my_project

This will create a new Leiningen project with 2 files:


(ns my-project.system
  (:require [com.stuartsierra.component :as component]))

(defn new-system []
   :a-component "Add your components here"))

An empty system with no components and a placeholder for the system map to get you started.


(ns user
  ;; Prevent warning when replaced by tools.namespace
  (:refer-clojure :exclude [refresh])
   [com.stuartsierra.component :as component]
   [ :refer (refresh refresh-all)]
   [my-project.system :refer (new-system)]))

(def system nil)

(defn init
  "Constructs the current development system."
  (alter-var-root #'system
    (constantly (new-system))))

(defn start
  "Starts the current development system."
  (alter-var-root #'system component/start))

(defn stop
  "Shuts down and destroys the current development system."
  (alter-var-root #'system
                  (fn [s] (when s (component/stop s)))))

(defn go
  "Initializes the current development system and starts it running."

(defn reset []
  (refresh :after 'user/go))

This file contains REPL functions so you can use Stuart Sierra's reloaded workflow as described in the documentation for the component library.

user.clj is ready loaded for you in the development profile.

(defproject my_project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License"
            :url ""}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [com.stuartsierra/component "0.2.1"]]
  :profiles {:dev {:dependencies [[org.clojure/tools.namespace "0.2.4"]]
                   :source-paths ["dev"]}})

Emacs Users

Note that this is copied directly from Malcolm Sparks' jig library documentation

You should find yourself typing (reset) rather a lot, and soon even that becomes burdensome. Here's some Emacs code you can paste into your $HOME/.emacs.d/init.el to provide a shortcut.

(defun nrepl-reset ()
  (set-buffer "*nrepl*")
  (goto-char (point-max))
  (insert "(user/reset)")

(global-set-key (kbd "C-c r") 'nrepl-reset)

or, if you are using cider:

(defun cider-repl-reset ()
  (with-current-buffer (cider-current-repl-buffer)
    (goto-char (point-max))
    (insert "(user/reset)")

(global-set-key (kbd "C-c r") 'cider-repl-reset)


Copyright © 2014 Adrian Mowat

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

You can’t perform that action at this time.