# Code Organization

**URL:** <https://discourse.elm-lang.org/t/code-organization/2779>\
**Category:** Learn\
**Created:** [December 17, 2018, 3:29pm UTC](https://discourse.elm-lang.org/t/code-organization/2779 "2018-12-17T15:29:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevensonmt](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/stevensonmt/32/889_2.png) [@stevensonmt](https://discourse.elm-lang.org/u/stevensonmt)\
**Post date:** [December 17, 2018, 3:29pm UTC](https://discourse.elm-lang.org/t/code-organization/2779/1 "2018-12-17T15:29:25Z")

</div>

I have been struggling with the best way to organize my code to keep things as simple and readable as possible. I understand apps that have multiple components (though that’s not really an Elmish idiom) can be treated as submodules with their own views and update functions and msgs. In an app that has few UI components but modest complexity with the model, I have recently struck upon the idea of separate update functions and msgs for the view and the data. That is anything that changes the current presentation of data without changing the data itself is handled by a view module, and anything that changes the data without changing the presentation is handled by the data module. In order to avoid circular imports this requires me to set up `Msgs.elm` with a `MainMsg` union type for the data and view msgs. I’m curious what people think about this organization and what suggestions would make it better.

---

<div class="post-metadata">

**Author:** ![mgold](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mgold/32/284_2.png) [@mgold](https://discourse.elm-lang.org/u/mgold)\
**Post date:** [December 18, 2018, 7:03am UTC](https://discourse.elm-lang.org/t/code-organization/2779/2 "2018-12-18T07:03:39Z")

</div>

> [@stevensonmt](#):
>
> In order to avoid circular imports this requires me to set up `Msgs.elm` with a `MainMsg` union type for the data and view msgs.

I think you’re on the right track. Try (as a starting point, adapt as necessary):

- `Common.elm`, defining `Msg`, `Model`, and other types that are used everywhere
- Most of your other files import `Common.Something`
- `Main.elm` imports from everything (and is imported by nothing) and contains the `main` value.

---

<div class="post-metadata">

**Author:** ![Erkal\_Selman](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/erkal_selman/32/269_2.png) [@Erkal\_Selman](https://discourse.elm-lang.org/u/Erkal_Selman)\
**Post date:** [December 18, 2018, 10:42am UTC](https://discourse.elm-lang.org/t/code-organization/2779/3 "2018-12-18T10:42:36Z")

</div>

These three talks helped me a lot with code organization

- [Evan Czaplicki - The life of a file](https://youtu.be/XpDsk374LDE)
- [Richard Feldman - Scaling Elm Apps](https://youtu.be/DoA4Txr4GUs)
- [Richard Feldman - Make Data Structures](https://youtu.be/x1FU3e0sT1I)

in case you haven’t watched them already.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [December 28, 2018, 10:42am UTC](https://discourse.elm-lang.org/t/code-organization/2779/4 "2018-12-28T10:42:40Z")

</div>

Closed on December 28, 2018, 10:42am UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
