Are There Any Ash Framework Starter or Boilerplate Projects?

This question was inspired by this thread: Open Source Projects Using Ash Framework as Learning Resources.

The Ash framework is amazing, but as a newcomer to Elixir, getting started with it can be quite challenging. To build a real application, you need to understand at least five different Ash libraries—such as ash_phoenix, ash_auth, ash_policies, ash_postgres, ash_rbac, and ash_json_api/ash_graphql—along with Phoenix and Phoenix LiveView. While learning these technologies is certainly possible, and the learning curve isn’t the steepest, integrating them all into a working application can be incredibly difficult.

Moreover, different people have different learning styles. Personally, when learning a new technology, I often search for something like a “React boilerplate project” and start hacking away. By the end of the process, not only do I learn the new technology, but I also have something practical to show for it. Unfortunately, I haven’t been able to do the same with Ash—I just get overwhelmed by the number of required libraries.

Another reason why boilerplate projects are valuable is that no one likes reinventing the wheel. While building everything from scratch can be a great learning experience, it becomes tedious when it’s not your first time around.

Note: The closest things to a starter project I could find are these repositories:

GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with backend built with Ash Framework

GitHub - sevenseacat/tunez at end-of-chapter-8

2 Likes

This is definitely something that we’re working towards with igniter. We also heavily dislike reinventing wheels. There is one small usage of the --example flag in Ash core which generates a few resources when you install Ash, like mix igniter.install ash --example. What I would like to do with that is have --example actually be extended and built on top of by the other extensions. So that if you have --example present when installing AshGraphql it will modify the example resources or create new example resources that use GraphQL, that kind of thing.

There are some complexities in making that process fluid, however, and what may instead be likely is that we improve how far our generators go. For example, you can do this today:

mix ash.gen.resource MyApp.Blog.Post --extend graphql,postgres

to get a resource that uses GraphQL and PostgreSQL. However, it doesn’t preconfigure any mutations or queries, and so it has the same discoverability problem.

However we end up solving this, it will almost certainly be accessible as a check box in the new Ash installer at https://ash-hq.org

Also I know an example app isn’t really what you’re looking for vs a boilerplate generator, but decent timing on this other post: Tololo eCommerce: Ash Example

1 Like

Doesn’t that fit the bill of a starter project?

Then just hack away, fleshing out resources with ash admin:

I’m no elixir (or Ash) expert, but I think the Ash learning resources (including the Tunez book) are really great and getting better.

2 Likes

In my eyes a starter project should have the following:

  • configured email signup/login
  • configured third party login (such as Google)
  • CRUD
  • examples of authorization (things a user can access)
  • examples of user facing API (REST/GraphQl)
  • examples of working with sending of emails
  • examples of working with migrations
  • unit tests
  • ui
  • background jobs/queues
  • scheduled jobs
  • i18n

None of this are impossible to figure out on my own, but it will take a long time. Having some ready to read or to copypasted code would be nice

1 Like

I recently purchased the Ash book and have been working through it. It has really helped me understand Ash much better. I’m also planning to use Tunez as a starter project for my next application because I find the code accessible.

I’d like to mention that I wish there were more emphasis on using the terminal and specifically on Igniter in the documentation.

For example, while experimenting with Tunez, I decided to check out ash_admin. I went to the library’s README to see what steps were needed to add the library. There were two sections: “With Igniter (Recommended)” and “Manual.” Naturally, the “Manual” approach had many steps, and I was eager to follow them—especially since I didn’t know what Igniter was and was reluctant to install another global terminal command.

After a quick Google search, I initially assumed that Igniter was simply equivalent to running commands like “npm install some_library” or “dart pub add some_library,” which is common in many ecosystems.

However, I decided to give Igniter a chance, and I was completely blown away. After running the command:

mix igniter.install ash_admin

I was pleasantly surprised to see that around ten files were updated. Everything was configured properly—there was no additional configuration required. All I had to do was start the server and visit http://localhost:4000/admin, and a complete admin page was available.

This single terminal command added an entire admin interface to the application with no extra steps or hidden gotchas. The more I work with Ash and Igniter, the more I appreciate that these tools work consistently across the ecosystem. In contrast to other ecosystems where code generators and terminal tasks can be shallow, the Elixir ecosystem offers powerful, well-integrated tooling.

I really wish the documentation and guides emphasized this strength more clearly. I wish someone had told me upfront that terminal commands in the Elixir ecosystem are robust and that I should embrace them when I see the “Recommended” label.

The reason I am writing all of this is because I think Igniter can be a solution to many of my problems. If I have to simply run some terminal command instead of figuring stuff out I consider that a win.

1 Like

I think that we do emphasize igniter pretty well in the book, using it to install the various components we might need etc. i.e mix igniter.install ash_authentication, mix igniter.install ash_authentication_phoenix and mix ash_authentication.add_strategy.

Igniter & Ash are intended to bring us to a different point than the concept of your standard boilerplate, where you don’t have to opt into the kitchen sink of someone else’s application, you can just install the things you need when you need them.

So if I started out with an application with some example resources:

mix igniter.new my_app --with phx.new --install ash --example

Now if you want authentication in your app, you just say

mix igniter.install ash_authentication_phoenix --auth-strategy magic_link

(these examples are real, you can run them)

And if you realized that you wanted password authentication too, you don’t have to go back to a boilerplate and copy/paste or something, you just mix ash_authentication.add_strategy password.

Honestly there is still a lot more work to do on this front, but I think we’re moving in the right direction.

Some major pieces left:

  • I’d like to do is to make the --example flag do things in other extensions as well. Currently only ash reacts to it to create some example resources.

  • Another thing is to make the mix ash.extend command do more than it currently does, for example: mix ash.extend MyApp.Helpdesk.Ticket graphql will add the AshGraphql extension to a resource, but does not configure any mutations and queries etc.

  • mix ash.gen.resource MyApp.MyResource should merge things into the resource in question instead of just ignoring if the resource already exists.

I was thinking of this yesterday, I’d love to add simple generators like ash.gen.calculation and ash.gen.change that generates skeleton modules. They’d be super small, but I think it’d be pretty convenient

That’s a cool idea :+1: mix ash.gen.calculation Name.Of.Calc --resource MyApp.Foo.Bar could also add it to the resource module. I think you might be surprised at just how actually doable that is.

For an adventurous soul:

  • mix igniter.gen.task ash.gen.calculation
  • update the docs of the task
  • modify the positional and schema keys to have the described options
  • use Igniter.Project.Module.create_module to create the module
  • go to Ash.Resource.Igniter and copy the add_new_attribute logic into a add_new_calculation function and adjust it accordingly
  • call that new function from the igniter task if the resource flag is set.

Alternatively, there are plans to make mix ash.gen.resource merge into existing resources, so we could add --calculation foo:type:Module to that task, and if the module doesn’t exist it is created as a shell (by delegating to mix ash.gen.calculation) meaning that the calculation gen task doesn’t know about resources it just creates the shell of a calculation.

2 Likes