Gonza

Gonza

Igniter for Express -> Ash rewrite?

Hey, I’m thinking about migrating a NodeJS backend to Ash. It’s one of those times in the life of a project where you start to think a full rewrite would be cheaper and better than fixing everything that’s been breaking up along the way.
Anyways, I was exploring a little the new Igniter project, and it got me thinking: is it a crazy idea if I try to replicate the old API surface via generators? It is a pretty standard REST interface with just a handful of main routes.
I know there’s going to be a lot of manual work migrating the actual core of the app and all the business rules, but the contract with the frontend clients is the one thing that must not change. Is this a good use case for using Igniter?
The general idea is to:

  1. Create and/or update a comprehensive OpenAPI spec of the entire existing backend
  2. Infer from there what the new resources should look like and transform this into Igniter commands (can probably be automated to a degree)
  3. Run the generators and let them create my resources and actions for each
  4. Fill all gaps with actual implementation details
  5. Profit?

Am I making sense here, or did I fundamentally misunderstand what codegen in Ash does and looks like?

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

Something like this is definitely possible. It is a big effort, and hard to say if it’s a good idea or not, I imagine it depends a lot on your domains. One difficulty may be the fact that Ash codegen tasks that you can use with igniter are not comprehensive by any means. They are made to produce useful starter points.

However, there are utilities you can all, like Ash.Resource.Igniter.add_new_action etc. to iteratively build up a resource, but those have basically been added over time as I’ve needed them.

The biggest challenge you may face realistically is that ash_json_api is primarily designed to help users create new JSON:API spec-compliant APIs. It is not necessarily designed to make building an API to an arbitrarily structured spec. You can absolutely write arbitrary API endpoints, generally by using generic actions, but you do end up hand-rolling some logic yourself if you do that.

Something worth pointing out is that if there is “just a handful of main routes”, you may not need to bother w/ all the fancy magic.

Not really a cohesive answer for you, but maybe some food for thought :laughing: Selfishly I love the idea of having something designed to reverse engineer API endpoints into an equivalent-ish internal resource structure and then allowing users to write in their own app logic. Sounds like a useful tool :smile:

Also Liked

Gonza

Gonza

Thanks! Yes, the old code looks standard-ish, but that’s obviously not the same as spec-compliant.
Still, now that I know it’s not a completely crazy idea, I might give it a try, even if just to learn how to work with generators. Thanks again!

Where Next?

Popular in Questions Top

New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

We're in Beta

About us Mission Statement