As the popularity of Elixir and Phoenix continues to grow, we find ourselves spinning up more and more Phoenix apps for our clients and side projects. At Carbon Five, we have a pretty good consensus on our favorite practices and tools. With each new app, we find ourselves repeating the same steps to bring in many of the same resources and processes.
We created Razor, an opinionated app generator, to save ourselves this time and trouble. Razor isn’t the only one out there, but it captures our common needs and preferences at Carbon Five pretty comprehensively. It also provides a great platform for discussion; we hope to watch Razor evolve as the Elixir ecosystem grows and we continue to learn.
Razor is a CLI interface built to an escript binary. When you run
razor new YourAppName, it downloads a copy of the Carbon Five razor-phoenix app skeleton, renames everything for your app, and walks you through the remaining install steps. It also initializes a new git repo, ready to be pushed to an origin of your own.
Full instructions are here, but here’s the tldr:
.tool-versionsfiles to ease version management if you use asdf.
mix escript.install https://github.com/carbonfive/razor/raw/master/razor_archives/razor.
ln -s /path/to/razor /usr/local/bin/
razor new YourAppName
mix test, and spin up the app with any of these .env-friendly methods:
source .env; mix phoenix.server
Now you can visit http://localhost:4000 to see your fully-featured new app.
That’s it! You’re straight on to building the fun stuff. You can remove the demo bits (or keep them).
Your new app can be deployed to Heroku Pipelines with both
production environments, in just a couple minutes by following the deployment instructions. If you use CircleCI, you get continuous integration testing right out of the box. The baked-in deployment configuration is also agnostic enough to be used in many modern deployment environments.
We’ve used these tools & processes on small fun projects and large production apps, and they’ve proven themselves reliable and useful in the majority of them. The Elixir ecosystem is evolving pretty rapidly, so it’s likely Razor will also change significantly over time. It’s worth noting that changes to Razor will not require changes to the generated apps themselves.
We’d also like to see Razor adopt more options (some listed below) so it can land in the sweet spot of ease, flexibility, and power.
Razor makes it a little too easy to spin up a Phoenix app with a fair amount of complexity (many say Phoenix itself is guilty of this too). The Elixir ecosystem is strong due largely to its dedication to depth of understanding, so we recommend spinning up a Phoenix app or two yourself first, and come back to Razor once you have a clear idea of how everything works. It’s also good to review the razor-phoenix source to learn how it’s all baked in.
Help us sharpen Razor! Try it on your system. If you find issues or have ideas, please put up issues and pull requests. Here are a few suggestions to get you started:
Most importantly, enjoy using Razor!