Coder Social home page Coder Social logo

Comments (4)

devonestes avatar devonestes commented on June 30, 2024 1

The idea of a model directory is generally not the encouraged practice with Phoenix applications these days. It's not wrong, per se, but it would be very different from the norm. I just did a quick count, and it looks like if we were to move all of those files that define Ecto schemas into a single directory, it would have ~75 files in it, with at least a few naming conflicts.

Personally, I think this moves us further away from that goal we spoke about the other day of trying to find pieces of the system that can be isolated a bit more and thought about independently so there are fewer interconnections between contexts and domains.

Maybe we could try and enforce that at any given directory level that either all files at that level are Ecto schemas, or that none are? Basically the rule would be "no file that defines an Ecto schema can be in the same directory as a file that does not define an Ecto schema."

So, something like this would pass:

├── lib
│   ├── organizations.ex
│   ├── mailer.ex
│   ├── organizations
│   │   ├── organization.ex
│   │   ├── membership.ex
│   │   ├── organization_membership.ex
│   │   ├── invite.ex
│   ├── documents.ex
│   ├── documents
│   │   ├── document.ex
│   │   ├── downloadable_asset.ex
│   │   ├── file.ex
│   │   ├── thumbnail.ex
├── README.md
├── mix.lock
└── mix.exs

In that case, mailer.ex, organizations.ex and documents.ex do not define Ecto schemas, but all the rest of the .ex files do. I know that's a vast simplification, but honestly this is the best automatically enforceable rule I could come up with that is still fairly close to the idea of contexts that are present in Phoenix apps.

This is also not really the kind of check that would fit very well to being incrementally applied. It seems like this sort of thing would be best suited to having someone (or a couple people) sit down, analyze what is there, and come up with some ideas for a design of contexts that would best fit the application as it exists today.

from nicene.

devonestes avatar devonestes commented on June 30, 2024

@mz2 What sort of structure are you looking to create here? Can you explain the pattern you have in mind so we can identify when a file is not in its correct place?

from nicene.

mz2 avatar mz2 commented on June 30, 2024

I imagined concretely lib/sketchql/model for all Ecto model based types (ones that define a schema I suppose?). But as long as it's a file where all model modules (and no other modules) are intended to go, happy with alternative directory structures.

from nicene.

mz2 avatar mz2 commented on June 30, 2024

I just did a quick count, and it looks like if we were to move all of those files that define Ecto schemas into a single directory, it would have ~75 files in it, with at least a few naming conflicts.

Good point. Yeah, I agree that the solution is indeed not that they'd all need to be in the same flat directory. Given your example, I would still prefer to mandate a joint root directory under which those model directories would be (such as "schema"), but I did not mean to imply that that would need to be flat -- in part because we have these other modules that have names that are the same or very similar (such as the GraphQL schema files, or the utility stuff that often has the name as the model type, only in plural form).

Maybe we could try and enforce that at any given directory level that either all files at that level are Ecto schemas, or that none are? Basically the rule would be "no file that defines an Ecto schema can be in the same directory as a file that does not define an Ecto schema."

This is indeed a better definition 👍 I'd be happy with this already, but in addition would prefer also a joint root directory to schemas / models (whatever the term would be).

from nicene.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.