   (go-loop []
     (<! (timeout 500))
     (doseq [[project subscribers] @figwheel-receivers]
-      (let [output (-> (get-project* project)
+      (let [output (-> (get-project*)
                        ::run-state
                        deref
                        :figwheel

       (server/with-channel request channel
         (swap! figwheel-receivers assoc "lein-ui" channel)
         (server/on-close channel (fn [status] (swap! figwheel-receivers dissoc "lein-ui" channel)))))
  (GET "/api/projects" []
       {:body (pprint-str (get-projects))
        :status 200})
  (GET "/api/projects/:project-name" [project-name]
       (let [project (get-project* project-name)
             run-state @(project ::run-state)]
         {:body (pprint-str
                 (merge (project-summary project)
                        ;; TODO just include these in the summary?
                        {:map-url (str (url-for-project project-name)
                                                "/map")
                         :raw-map-url (str (url-for-project project-name)
                                           "/raw-map")
                         :repl (get-repl-data project-name)}))
          :status 200}))
  (GET "/api/projects/:project-name/map" [project-name]
       {:body (pprint-str (get-readable-project project-name))
        :status 200})
  (GET "/api/projects/:project-name/raw-map" [project-name]
       {:body (pprint-str (get-readable-raw-project project-name))
        :status 200})
  (POST "/api/projects/:project-name/repl/start" [project-name]
        (start-repl! project-name)
        {:body (pprint-str (get-repl-data project-name))
         :status 201})
  (POST "/api/projects/:project-name/repl/eval" {{:keys [project-name
                                                         code]} :params}
        {:body (pprint-str (repl-eval! project-name code))
         :status 200})
  (POST "/api/projects" [root]
        (let [name (load-project! root)]
          {:status 201
           :body (pprint-str (project-summary (get-project* name)))}))
  (DELETE "/api/projects/:project-name" [project-name]
          (unload-project! project-name)
          {:status 204})
  (route/resources "/")
  (route/not-found "<p>Page not found.</p>"))



;;; Projects

(defonce project (atom nil))

(defn get-project* []
  (if-let [project @project]
    project
    (throw (ex-info "Project doesn't exist" {:name name}))))

(defn new-project [project-map raw-project-map]
  (assoc project-map
    ::run-state (atom {})
    ::raw raw-project-map))

(defn load-project! [root]
  (let [path (->>  (io/file root "project.clj")
                      (.getAbsolutePath))
        project-map (project/read path)
        raw-project-map (project/read-raw path)
        ui-project (new-project project-map raw-project-map)
        name (-> ui-project :name)
        root (-> ui-project :root)]
    (reset! project ui-project)
    name))


(def self-repl {:host "localhost"
                :port 7888})


;; TODO remove this for nrepl.client-manager
(defn repl-eval! [code]
  (let [{:keys [host port]} (-> (get-project*) ::run-state deref :repl)]
    (with-open [conn (nrepl/connect :host host
                                    :port port)]
      (-> (nrepl/client conn 1000)
