I'm a little pressed for time, but I'll try to give a general architecture outline that works really well for us. Our primary elm SPA is a customer facing administrative control panel that communicates with a backend api server and amazon S3. The app manages authentication, authorization, subscription status, and currently has 17 'pages'. This particular app is a Static SPA (currently served from s3-cloudfront combo).
We have an api client written in elm that resides with the api server. The api-client elm module can be pulled into any elm project that needs to communicate with the backend server, and includes all http requests, model types, model json decoders, and any necessary model helpers. Importantly, this is where authorization and authentication is handled as well. A user who successfully signs-in via the api will be granted an authorization token. The authorization token must be provided with each following request to the api.
SPA
The folder structure for the majority of our elm SPA's end up as follows:
- Component (folder)
- Pages (folder)
- Main.elm
- Route.elm
- Routing.elm
.. any other app/infrastructure related modules
Route.elm
Module encapsulating functions relating to routes:
Routing.elm
The routing module holds the state of the current page, and isolates logic pertaining to which page is displayed for each route
Main.elm
This is where the top level modules are wired together. It's difficult to create a generate example for this since your Main.elm will be application specific. Here is a hacked together example of a Main that you can sift through and try to understand what's going on in this specific application:
Some things to note: The client configuration is stored in the main model and passed down into the pages. When a page triggers a logout or login, that fact must travel back up to the main module so the client configuration state can be adjusted accordingly. If you need to know how to do this, I'm happy to explain.
Pages
Here is an example page:
Components
There are mostly shared headers, footers,menus, that are shared across various pages. Some have their own state, but most are simple reusable view helpers.
Sorry for being short on descriptions. Hopefully the examples are enough to give you a sense of direction and organization. Happy to answer any questions.