Where to place embedded schemas?

So I have a bunch of embedded schemas for validating incoming JSON bodies. Where would you put them in your project? I’m thinking between lib/someapp_web/schemas/account.ex or lib/someapp_web/controllers/account_schema.ex, having a slight preference towards the latter (assuming I have a controller called AccountController; the preference comes from the fact that Phoenix itself put views in account_json.ex or account_html.ex alongside with the controller).

It’s quite fine to put them in schema/ or schemas/ directory together with all other non-embedded schema modules. Thinking of putting them in controllers/ is strange though, IMO anyway. This is not where I’d look for them.

1 Like

I think it depends a bit on whether these are considered common internal shapes, or edge shapes. Validating types close to the edge is often a good pattern so if your embedded schemas only exist to model those specific controller inputs I think having it there is just fine.

3 Likes

Sure. Most of the conventions on where to put files in Elixir projects are a part of the project’s or company’s culture – and is something you get used to during onboarding.

Impossible to claim it’s a good or bad practice either way. Just saying that I’d be initially confused.

1 Like

That’s the issue - it’s my personal project without any company guidelines so I’m pretty much on my own. So I’m just collecting some input on how others do that :smile: