Full stack clojure project - source dir layout


#1

I’m wondering what is the reasoning behind putting the clj, cljs and cljc files into separate source directories. Is this the best practice today? If yes, why?

I am working on a full stack clojure project and started with this separated layout. Now, I tried to put everything under src/clojure and the app still works fine. I’d like to know if merging the sources into one directory is a good idea or not.

Thanks!


#2

I usually start with the chestnut project, but organize the files differently from what it defaults to. Separating into clj/cljc/cljs can make sense depending on how you build the artifacts (jar/js), have your IDE set up and/or require them.

Personally, I don’t like using folder names for the language I’m using ("clj", "clojure"), because it gives me nothing other than one more level of directories. I much rather use server, common and client for a web app, or backend, auth_service and so on for a server-only thing. Under those, everything is namespaced by the domain:

src/
  backend/
    system/
      - database.clj
      - web_server.clj
      - ...
    domain/
      user/
        - model.clj
        - controller.clj
    - app.clj
    - config.clj
    - ...
  common/
    domain/
      user/
        - model.cljc
  client/
    system/
      - store.cljs
      - dom.cljs
      - ...
    domain/
      user/
        - model.cljs
        - view.cljs
    - app.cljs
    - config.cljs
    - ...

Works pretty well for me! :slight_smile:


#3

Thanks for the feedback. :ok_hand: I ended up with something very similar.


#4

For my projects I’ve largely standardized on a directory structure layout - {src,dev,test}/{lang|resources}/... and it works pretty well. I use arrdem/lein-template to stamp out projects in this pattern and with my usual suite of plugins rapidly. I personally prefer to go down the multiple source trees in one repo road than trying to partition a single source tree into many artifacts but there really isn’t good tooling for one or the other I know of so it’s kinda a moot question.