           doall))))
 
 
-(defn figwheel-process [project]
+(defn figwheel-process []
   (let [out-writer (java.io.StringWriter.)]
     {:thread (.start
               (Thread. (bound-fn []
                          (binding [*out* out-writer]
-                           (figwheel/figwheel project)))))
+                           (figwheel/figwheel (get-project*))))))
      :out-writer out-writer}))
 
-(defn start-figwheel! [name]
-  (let [project (get-project* "lein-ui")]
-    (swap! (-> project ::run-state)
-           assoc :figwheel (figwheel-process project))))
+(defn start-figwheel! []
+  (swap! (-> (get-project*) ::run-state)
+         assoc :figwheel (figwheel-process)))
 
 ;;; Util
-(defn base-url []
-  (str "http://" "localhost" ":8000/"))
+(defn base-api-url []
+  (str "http://" "localhost" ":8000/api/project"))
 
 (defn url-for [path]
-  (str (base-url) path))
+  (str (base-api-url) path))
 
 
 ;;; API
-(defn url-for-project [name]
-  (url-for (str "api/projects/" name)))
 
-
-(defn get-repl-data [name]
-  (let [process (-> name get-project* ::run-state deref :repl)
-        url (str (url-for-project name) "/repl")]
+(defn get-repl-data []
+  (let [process (-> (get-project*) ::run-state deref :repl)
+        url (url-for "/repl")]
     (merge
      {:url url}
      (if process
        {:state :started
         :host (:host process)
         :port (:port process)
-        :stop-url (str (url-for-project name) "/repl/stop")
-        :eval-url (str (url-for-project name) "/repl/eval")}
+        :stop-url (url-for "/repl/stop")
+        :eval-url (url-for "/repl/eval")}
        {:state :stopped
-        :start-url (str (url-for-project name) "/repl/start")}))))
+        :start-url (url-for "/repl/start")}))))
 
 
 

    ::run-state
    ::raw})

(defn get-readable-project [project-name]
  (apply dissoc (get-project* project-name)
         non-data-keys))

(defn get-readable-raw-project [project-name]
  (apply dissoc (::raw (get-project* project-name))
         non-data-keys))

(defn project-summary [project]
  {:url (url-for-project (:name project))
   :name (:name project)
   :version (:version project)
   :root (:root project)})

(defn get-projects []
  {:projects (for [[name project] @projects]
               (project-summary project))})

(defn add-project [project-root]
  (load-project! project-root))


(defn bootstrap-self []
  (load-project! ".")
  (swap! (-> "lein-ui" (get-project*) ::run-state)
         assoc :repl self-repl
               :figwheel (figwheel-process (get-project* "lein-ui"))))


;;; Server

       (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/project" []
       (let [project (get-project*)
             run-state @(project ::run-state)]
         {:body (pprint-str
                 (merge (project-summary project)
                        ;; TODO just include these in the summary?
                        {:map-url (url-for "/map")
                         :raw-map-url (url-for "/raw-map")
                         :repl (get-repl-data)}))
          :status 200}))
  (GET "/api/project/map" []
       {:body (pprint-str (get-readable-project))
        :status 200})
  (GET "/api/project/raw-map" []
       {:body (pprint-str (get-readable-raw-project))
        :status 200})
  (POST "/api/project/repl/eval" {{:keys [code]} :params}
        {:body (pprint-str (repl-eval! code))
         :status 200})
  (route/resources "/")
  (route/not-found "<p>Page not found.</p>"))

