# How to structure project in julia

**URL:** <https://discourse.julialang.org/t/how-to-structure-project-in-julia/99458>\
**Category:** New to Julia\
**Created:** [May 26, 2023, 7:12pm UTC](https://discourse.julialang.org/t/how-to-structure-project-in-julia/99458 "2023-05-26T19:12:59Z")\
**Posts on this page:** 1\
**Showing post:** 44

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 28, 2023, 6:53pm UTC](https://discourse.julialang.org/t/how-to-structure-project-in-julia/99458/44 "2023-05-28T18:53:06Z")

</div>

Sorry, late for the discussion, but let me give my two cents:

**The best option is a mix of options 2 and 4, which by themselves are not really options I see someone considering.**

> [@MacKa](#):
>
> ### 2. Use include
> 
> Include file followed by .using
> 
> ```julia
> #file ModuleB.jl
> module ModuleB.jl
> include("ModuleA.jl")
> using .ModuleA
> ...
> end
> 
> ```
> 
> This doesn’t work when more than one dependency includes the same file due to lack of include once semantics, there is no `#pragma once` or `#ifdef` to my knowledge, I rate this option as worse than C.

> [@MacKa](#):
>
> ### 4. Create one monolithic file
> 
> Create one main julia file per project, all files are included into the monolith:
> 
> ```julia
> #file ModuleB.jl
> module ModuleB.jl
> # no dependencies declared here
> ...
> end
> #file Monolith.jl
> include("ModuleA.jl")
> include("ModuleB.jl")
> 
> ```
> 
> Only downsides:
> 
> - modules can’t declare their dependencies
> - files must be included in topological order
> - files/modules become just inlines, they can’t be executed/tested in julia
> - worse than C, it’s not 1970 anymore
> - over my dead body option

A submodule should only be `include`d where it appears in the hierarchy for an external user. If a package `Graphs.jl` has `Graphs.Algorithms` then `Algorithms.jl` should be `include`d inside `Graphs.jl`, if it is `Graphs.Utilities.Algorithms` then then `Algorithms.jl` should be `include`d inside `Utilities.jl` which is `include`d inside `Graphs.jl`. In other words, `include` should be only used to build the unique hierarchy of the modules in the project, it is not a tool to load code that will just be called. What however, if `Graphs.Experimental.Search` needs to use some methods from `Graphs.Utilities.Algorithms`? Simple, in `Search.jl` you do:

```julia
import ...Utilities.Algorithms

```

See [Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/#Submodules-and-relative-paths) about the relative import syntax.

I structured a rather large package with all my code from my PhD following this system. Here is the main file: [https://github.com/henriquebecker91/GuillotineModels.jl/blob/master/src/GuillotineModels.jl](https://github.com/henriquebecker91/GuillotineModels.jl/blob/master/src/GuillotineModels.jl) and here is the file of `GuillotineModels.PPG2KP`: [https://github.com/henriquebecker91/GuillotineModels.jl/blob/master/src/PPG2KP/PPG2KP.jl](https://github.com/henriquebecker91/GuillotineModels.jl/blob/master/src/PPG2KP/PPG2KP.jl) Note that I did also started a new subfolder for each submodule that had submodules themselves to avoid clashes like two `Algorithm.jl` in a `Graphs.Utilities.Algorithms` and a `Graphs.Experimental.Algorithms`.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-structure-project-in-julia/99458)._
