# Structure for a small project?

**URL:** <https://discourse.julialang.org/t/structure-for-a-small-project/14983>\
**Category:** New to Julia\
**Created:** [September 15, 2018, 1:39am UTC](https://discourse.julialang.org/t/structure-for-a-small-project/14983 "2018-09-15T01:39:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fratrik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fratrik/32/678_2.png) [@fratrik](https://discourse.julialang.org/u/fratrik)\
**Post date:** [September 15, 2018, 1:39am UTC](https://discourse.julialang.org/t/structure-for-a-small-project/14983/1 "2018-09-15T01:39:37Z")

</div>

Is there advice for structuring a small project? I see that `Pkg generate` creates a src/ directory, and other things suggest a test/ directory. Is this all written up somewhere?

So far, I’ve made a projects that have a handful of files with various functions, which may include(“func\_file.jl”) as needed. They have a few scripts that actually run the show, and drive the computation. Maybe another one that generates the necessary images.

I’m excited about the Pkg environments, but I wasn’t sure if there was some best practice I should be following.

---

<div class="post-metadata">

**Author:** ![Zach\_Christensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zach_christensen/32/7220_2.png) [@Zach\_Christensen](https://discourse.julialang.org/u/Zach_Christensen)\
**Post date:** [September 15, 2018, 2:19am UTC](https://discourse.julialang.org/t/structure-for-a-small-project/14983/2 "2018-09-15T02:19:33Z")

</div>

I’d read through the [Pkg](https://docs.julialang.org/en/v1/stdlib/Pkg/) section of the documentation. I’m still learning to use it but the utility in using it for a personal project is similar to that of creating a package in R or using pipenv in python to maintain a consistent versioned environment.

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [September 15, 2018, 2:36am UTC](https://discourse.julialang.org/t/structure-for-a-small-project/14983/3 "2018-09-15T02:36:11Z")

</div>

There is a package called `PkgDev`, but it is still under development. In `v0.6` time, it will generate you the following

```julia
Example
├── LICENSE.md
├── .gitignore
├── .travis.yml
├── README.md
├── REQUIRE
├── appveyor.yml
├── src
│ └── Example.jl
└── test
    └── runtests.jl

```

`src` is for your main functionality definitions, it contains a module of the project name.

The LICENSE is your package license, which can be MIT/Apache 2.0/etc.

The REQUIRE is similar to the `Project.toml` now, you can just use `Project.toml` instead

you should have `runtest.jl` to let Julia test your code. And `appveyor.yml` is for windows CI (continuous integration) which will run your tests in `test` dir on windows. `.travis.yml` is for travis CI which run tests on OS X and Linux system

`.gitignore` is what you will need to make your repo clean, make sure those files won’t be upload to your repo.

Finally you will probably want to write a README.md to help people understand what you are doing.

And you might need a `example` folder to run your examples (like tests).

Minimum requirement is just a `Project.toml` and a `src`, if you don’t want to write any tests and set up CI.

**just pick up what you need according to their functionality above**

---

<div class="post-metadata">

**Author:** ![garrison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrison/32/209519_2.png) [@garrison](https://discourse.julialang.org/u/garrison)\
**Post date:** [September 15, 2018, 4:59am UTC](https://discourse.julialang.org/t/structure-for-a-small-project/14983/4 "2018-09-15T04:59:53Z")

</div>

A lot of the above advice is for _packages_. But from the OP’s description of their _project_, I think a slightly different structure is in order. For instance, the “scripts” should probably go in a `bin` directory. I also like to set `JULIA_LOAD_PATH` to be `$PWD/src:` (I do this using [direnv](https://github.com/direnv/direnv)), which allows me to have module files in my `src` directory. (Alternatively, this directory could be called `modules` – in any case, it would be nice to have a standard name for it.)

---

<div class="post-metadata">

**Author:** ![fratrik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fratrik/32/678_2.png) [@fratrik](https://discourse.julialang.org/u/fratrik)\
**Post date:** [September 19, 2018, 5:39pm UTC](https://discourse.julialang.org/t/structure-for-a-small-project/14983/5 "2018-09-19T17:39:16Z")

</div>

Thanks, yeah, I wonder how much differs between a small project and a package for release.

I like the idea of having a `bin` directory. I might start moving the scripts that actually do the work into there, and keep the functions in `src`. Someday, I’ll write some tests.

The other useful hack I came up with was

```julia
file_dir = dirname(@ __FILE__ )
cd("$file_dir/..")
using Pkg
Pkg.activate(".")

```

so that when I `ctrl-enter` in Juno, it puts me locally. I suppose I could make a macro for that instead of copying across projects files?
