Comments (4)
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.
@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.
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.
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
from nicene.
Related Issues (16)
- Group aliases and imports
- Guard against hyphens in sourcecode filenames HOT 3
- Nicene documentation missing from hexdocs.pm
- Parsing error while running ConsistentFunctionDefinitions with macros HOT 1
- FileTopToBottom fails with macro-constructed module
- Check for Ecto models to be minimally documented HOT 5
- `TestsInTestFolder` is over-agressive HOT 5
- PublicFunctionsFirst does not take into account nested modules
- Group functions with the same name together.
- Credo rule to only allow importing Ecto.Query in X.Query HOT 2
- Add rules for more composable queries
- Add CI build
- Elixir code conventions: mandate at least some content in @doc entries
- Check for @desc fields in GraphQL schema type definitions HOT 1
- Ensure that test like modules match expected filename pattern
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nicene.