# Restructuring code from modules to package

**URL:** <https://discourse.julialang.org/t/restructuring-code-from-modules-to-package/69819>\
**Category:** General Usage\
**Tags:** packages\
**Created:** [October 15, 2021, 11:45am UTC](https://discourse.julialang.org/t/restructuring-code-from-modules-to-package/69819 "2021-10-15T11:45:24Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 15, 2021, 1:02pm UTC](https://discourse.julialang.org/t/restructuring-code-from-modules-to-package/69819/5 "2021-10-15T13:02:45Z")

</div>

> [@Philippe\_Maincon1](#):
>
> I have edited my question #2: would the loadpath be a way _of making the secondary modules available_

This is maybe a question, maybe an answer, but doesn’t something like

```julia
module Main
    include("./module1/Module1.jl")
    include("./module2/Module2.jl")
    using .Module1, .Module2
    ...
end

```

just works if `Main` is in `src` and ` module1` and `module2` are subdirs of ` src` ?

But in Julia this is more of a headeach. Modules are more useful to separate a set of structures and functions all that define a more or less closed set of functionalities.

You probably find the answer to the second question here:

> [@Usage of subdirectories to store multiple packages in a single repo](https://discourse.julialang.org/t/usage-of-subdirectories-to-store-multiple-packages-in-a-single-repo/55534/2):
>
> Many/most of these questions can probably be answerd by this: Packages in subdirectories are just regular packages. They just happen to live in the same git repo. Yes they need to be packages on their own with Project.toml, src/Package.jl entrypoint etc. Probably this structure makes the most sense: $ tree . . ├── PackageA │ ├── Project.toml │ └── src │ └── PackageA.jl └── PackageB ├── Project.toml └── src └── PackageB.jl 4 directories, 4 files or perhaps $ tree …

though I think it is unlikely that this will be a good alternative to that of simply flattening the package, unless your package is already really big.

---

_[View the full topic](https://discourse.julialang.org/t/restructuring-code-from-modules-to-package/69819)._
