My Failed Student Housing App
Tags: elixir, liveview, startup, ash
Published: 2024-04-23 16:53:55

tldr; I have a moderate sized PoC elixir code base collecting dust that will never be used again, and hopefully it has something someone will need.

## Background

I've been looking into different markets for my next startup. One that stood out was Student Housing software for colleges and universities. What intrigued me initially was that _the #1 company bought #2 and #3 in 2022_, so the options for colleges dwindled to just a few. And the #1 can now charge 4-5x resulting in 6 figure yearly bills!

Certainly I can build something that I could charge significantly less that would benefit the few thousand smaller colleges that couldn't afford that price gouging.

While I was deep in customer discovery, I figured I would also build out a PoC to show directors at the school to let them know I deeply understood the problems they faced. If they could see that, then maybe they would give me a shot.

## The Stack

- Elixir
- Phoenix + LiveView
- TailwindCSS (with [Flowbite](https://flowbite.com/))
- Postgres
- [Ash](https://ash-hq.org/) (2.0, 3.0 wasn't out yet)

I always need to be learning, so I took the chance to finally learn Ash. Something about it screamed "Yes!" to me.

My previous passion project was [ClickDuel](https://clickduel.com) and I used that to really dive into Elixir and LiveView. Take a look, my kids and I still love using it. So the housing app was my chance to take a deep dive into Ash.

## Ash

As with any new tool, there is a ramp up period. Ash was no different. During the 4 months I worked on this project, as I struggled with doing some basic stuff (like Phoenix Forms using Ash) I kept asking myself, "Is Ash _really_ gonna make me faster in the long run?" Now that I am on 2 other new projects, both using the same stack as above, I can confidently say yes. I am glad I had the time to learn Ash. The speed at which I got the new stuff up was crazy fast. And 3.0 introduces domains, which encapsulate code so much better.

I have used ORMs in PHP, C#, Ruby, and NodeJS, so I am well versed in the problems of figuring out your domain and data structures and mapping that to the tool du jour. Ash is not an ORM, but it serves the problem, and I like Ash's approach so much better than others.

The team is really responsive answering questions in their [forum](https://elixirforum.com/c/ash-framework-forum/123).

For my deployment model, every school would need to be isolated in the database, and Ash's multi-tenancy approach made this dead-a$$ simple to implement. Like, a few lines of code.

Ash also has a powerful policy system to enforce access to data, but it was just too much to learn, so I constantly just disabled it.

## User Defined Schemas

The thing with Student Housing is that an immense amount of it is based on dozens of forms. A form to request housing, a form for your profile, a form to be an RA, a form to switch rooms, a form to submit a maintenance ticket. You get the picture.

But the problem is that every single school has their own fields and structure and workflow for these forms. So I went with our buddy, JSON Schema. There is a decent chunk of code dealing with that. Chances are, I ran into the same problem as you, if you're using JSON Schema...

![Forms](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkl1w4ei2vfkhq33glv7.png)

## Other tools

Don't reinvent the wheel!

### Flowbite

One of the things that I am happy to drop $ on are good looking UI components. Flowbite does a great job with theirs. Dark mode just works. Finally got a good looking sidebar to quickly view an item; always wanted to implement that. Though I will say their dropdown logic is flaky.

### AG Grid

I made extensive use of [AG Grid](https://ag-grid.com/). There are LiveView hooks and whatnot showing how I loaded data, and stylized different types like bools, links, and status.

### [JSON Editor](https://github.com/josdejong/jsoneditor)

This provided a simple drop-in to edit JSON Schemas. Visual drag n drop was out of scope for the PoC, though I did try some out. O' lord did I try them out. Days of my life I want back.


![Profile fields](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atbqq1xpeqhvnmpdetld.png)


### [ExJsonSchema](https://hexdocs.pm/ex_json_schema/0.10.2/readme.html)

Great JSON schema validator.

### [SortableJS](https://github.com/SortableJS)

This allowed me to provide a way to sort items in the UI.

![Sorting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yh72eat2thplij2x12c.png)

### [react-querybuilder](https://react-querybuilder.js.org/)

There is no chance I am using this properly. I don't understand React at all (I'm a Vue dev). But I needed to allow users to build complex queries, and this is a no-brainer tool to use for that purpose. The challenge was using it in LiveView.

### JSX

I think it was just changing to `--target=es2020` and I was able to use `.jsx` files alongside `.js` which made some of the Javascript work easier.

## Finally, the code

Please keep in mind that this was implemented as a proof of concept. I just needed to get some stuff working, and not necessarily working well, and certainly not with any tests.

Many times, I went with whatever approach worked, and moved on with life, so please be mindful of that if you browse the code. Though, if I did something stupid, please let me know so I can fix it in future projects I work on.

[https://github.com/lardcanoe/housing-app](https://github.com/lardcanoe/housing-app)

If I get 10 likes, or some comments, I'll take the time to document how to get it running locally. It's should be pretty typical for an elixir app though...

I am more than happy to expand on any topic above, or others. Just leave a comment.

![Example of Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5ydvz1cako58mowa4nc.png)