# How can I structure a project in multiple modules and have code run in them?

**URL:** https://discourse.julialang.org/t/how-can-i-structure-a-project-in-multiple-modules-and-have-code-run-in-them/100286
**Category:** General Usage
**Tags:** development, module, modules, code-organization, project
**Created:** [June 13, 2023, 3:16pm UTC](https://discourse.julialang.org/t/how-can-i-structure-a-project-in-multiple-modules-and-have-code-run-in-them/100286 "2023-06-13T15:16:00Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)
#### Post date: [June 14, 2023, 10:01am UTC](https://discourse.julialang.org/t/how-can-i-structure-a-project-in-multiple-modules-and-have-code-run-in-them/100286/5 "2023-06-14T10:01:14Z")

</div>

> [@bertulli](#):
>
> 1. This way I need to load all the submodules at once inside `ARMCortexM4Model`. Can I selectively load just some of them, without modifying `ARMCortexM4Model.jl` every time? In other words, can I just say

Yes. The `export Utils` inside `ARMCortexM4Model.jl` only exports the name `Utils`, but does not export all the names `Utils` it self would export.  
Hence, when you write `using ARMCortexM4Model` you can then use `Utils.greet()` instead of `ARMCortexM4Model.Utils.greet()`. If you also add `export greet` inside `Utils.jl` then you could write

```julia
julia> using ARMCortexM4Model

julia> using Utils

julia> greet()

```

> [@bertulli](#):
>
> 1. Is there a way to declare more than one module in a single project?

Yes and no: A **package** (as generated by running `Pkg.generate("MyPackage")`) defined as a folder with a name `MyProject` containing a `Project.toml` file referring to `MyProject` (and optionally a `Manifest.toml`) and then a `src/MyProject.jl` file. Let’s call this a toplevel package, although it really is an `environment` (or `project`), I think, because it tracks all the dependencies used in it and it happens so that one if it is also called `MyProject`. Think of a `project` like a `virtualenv` in python, if you happen to know that …  
There are then two ways to add more modules:

1. Recommended: Add submodules to `MyProject` as I did it above, which you can optionally re`export`. See also the `@reexport` macro from [`Reexport.jl`](https://github.com/simonster/Reexport.jl).
2. Add another package with `Pkg.generate("MyPackage/Utils")`. You must then tell your toplevel package to `develop` this package, e.g. run `Pkg.develop(path="./Utils")`.

> [@bertulli](#):
>
> 1. I read `] dev` is used to [develop a package](https://pkgdocs.julialang.org/v1/managing-packages/#Adding-a-local-package). But now I don’t understand how: if I am bounded to develop a single package at a time, there’s actually no need to `dev` it in the first place. I thought I could `dev` all the modules I was working on, so that I can independently include them in my working scripts, and use Revise if I needed to modify the modules’ code.

The `dev` is needed so that `Revise.jl` can track its code. The other alternative is to `add` a package, but for that to work the package needs to be `git` repository. The way of adding another module through `dev` is really only meant for local development of packages and its dependencies and/or mono repos like [Makie](https://github.com/MakieOrg/Makie.jl) where they develop multiple packages inside one toplevel package.

In case you haven’t discovered it yet, here is a link to the docs of `Pkg` which talks `packages, environments` a bit more: [1. Introduction · Pkg.jl](https://pkgdocs.julialang.org/v1/)

I also must admit I am not a big fan of this kind of project organization and I feel like I am seeing this question being asked way too often. Perhaps this is an indication that things could be simplified or made more user friendly, but then I did not think how …

> [@bertulli](#):
>
> Thanks, IIUC this also has the advantage of allow the re-loading of the data at your discretion. But just to better understand how modules work, can I do the same using “just” them?

Sorry, didn’t understand the question.

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-structure-a-project-in-multiple-modules-and-have-code-run-in-them/100286)._
