Conventions around package extensions

Hi all, are there any popular conventions around writing package extensions in Elixir projects and where to put them? Example extensions that come to mind are: custom Ecto.Query macros and Ecto.Type/Phoenix.HTML.Safe implementations for project-specific or 3rd-party data types.

Perhaps something like this would make sense?

lib/my_app/my_module/ecto.ex # or putting Ecto-specific code at the end of lib/my_app/my_module.ex
lib/ecto/custom_query_macros.ex # Ecto.CustomQueryMacros

Btw, this topic reminds me a little bit of an old DockYard blog post by @bcardarella Love your lib directory for organizing lib in Rails apps.

Really courious how other people are structuring extensions in their own projects.

Don’t put anything into namespaces you don’t own though, otherwise you can have conflicts in the future. The only exception is Mix.Tasks.

1 Like

I usually go with things like MyApp.Query, MyApp.Changeset or MyApp.Conn that have functions operating on the particular data structure. I usually don’t include the lib name in there.