Search code examples
crystal-lang

Crystal Lang project directory structure conventions


Are there any conventions regarding project directory structure?

I have a project that was initialized with crystal init app [project-name]. Inside of that is the src directory which has the folders for modules and classes. However, now I want to add an ORM which will require a models directory. What conventions are there for laying this out?

Right now I've created a sub-directory inside of src called modules where classes and modules are going.


Solution

  • There is no direct answer here. It very much depends on the pattern you want to follow. If you are using a framework like lucky or amber, I would suggest referring to their documentation as both prefer a conventional (rather than configurable) approach. Both follow a rails'esque convention.

    [root]
      ⌙ /src
        ⌙ /models
        ⌙ /controllers
        ⌙ /views
    

    If you are implementing services DDD like modules, then I would suggest:

    [root]
      ⌙ /src
        ⌙ /[service/module a]
        ⌙ /[service/module b]