# Best way to structure Julia code

**URL:** <https://discourse.julialang.org/t/best-way-to-structure-julia-code/26591>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 20, 2019, 4:59pm UTC](https://discourse.julialang.org/t/best-way-to-structure-julia-code/26591 "2019-07-20T16:59:13Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [July 30, 2019, 11:10pm UTC](https://discourse.julialang.org/t/best-way-to-structure-julia-code/26591/16 "2019-07-30T23:10:57Z")

</div>

> [@ufechner7](#):
>
> Should every module be a package that lives in a separate repo? I think that would be stupid, because it causes lots of unnecessary overhead.
> 
> What do you think?

The structure that I use (and I think hasn’t yet been mentioned here) is having each module be a submodule of the global module associated to your project/package.

Submodules can `use` or `import` one another, provided that they provide either the correct relative path (with the right number of leading dots, which I find cumbersome) or an absolute path starting with the global module.

So something like this works (assuming you are in a project named “Top”):

```julia
module Top

# Potentially in a "A.jl" file
module A
export a
a() = "OK"
end

# Potentially in a "B.jl" file
module B
using Top.A
export b
b() = a()
end

using .B
export check
check() = b()

end # module

```

As already mentioned, this organization in top module + submodules is orthogonal to the organization of source files: using adequately placed `include`s, each submodule could be in its own file, or split in separate files, or all submodules could be grouped in one file.

As far as I know, everything works well with such a setup, including `Revise`, precompilation and so on.

---

_[View the full topic](https://discourse.julialang.org/t/best-way-to-structure-julia-code/26591)._
