-
I have opinion and question about the blitz-generated file structure. I'm primarily a front-end engineer using next.js and also have a modicum of rails experience. My opinion.In Rails, the resources generated by
I think this makes sense because when I write code, I think about whether it's a model or a view first. But there is a known problem with this style: it's hard to represent a model that isn't tied to a table. This causes people unfamiliar with the rails style to write their domain logic in util. Also, with the front-end idea, the problem of not being able to express affiliation comes from the large number of views where no model exists. In the current boilerplate generated by blitz, I am concerned that the domain(resource) and the top level components are mixed in same directory, and that it will be difficult to know what the object we are trying to modify belongs to. For example, imagine a blog post with a bunch of comments. It's up to the implementer to decide which domain's View the CommentForm in the article page will be implemented in. It's more complicated when you have a transaction with multiple resources. In my opinion, the code to generate
reason
It will cause big flat domain. Apart from this, there may be a way to split the domain. See #1141 Question.
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 27 replies
-
Hi @mizchi , thank you for sharing your idea 👍 I personally like domain structure (blitz structure) more than mentioned feature like structure. I found much much more simplier to manage team work, PR, commits, changes when everything what is related is grouped in one folder. So for me the structure like following wins:
But I agree with your comment about:
Before I used Blitz I was used to following structure:
Maybe this could solve potential confusion of mixed app stuff and domain stuff. |
Beta Was this translation helpful? Give feedback.
-
Perhaps we each have our own opinion by scale. How about define them by For example, // this file is js but I wrote types for explanation.
type GenerateContext = {
name: string;
kind: "pages" | "form" | "queries" | "mutations";
fileName: string;
// ...other contexts
}
module.exports = {
// ...
generatePath({name, kind, fileName}: GenerateContext) {
if (kind === "pages") { // my favorite single routes definition
return `app/pages/${name}/${fileName}}`;
}
return `app/${name}/${kind}/${fileName}`; // default
}
} (and blitz can reallocate them if we can) But in this case, |
Beta Was this translation helpful? Give feedback.
-
Thanks for this discussion @mizchi! The reason we have the current file structure is that it's significantly more scalable than how Rails does it. For a lot of smaller apps, it doesn't matter either way. But we want to set you up with a default architecture that will scale very well instead of something that you will have to totally change at some point. All large apps that I'm aware of end up using the file structure we have now in Blitz. Here's an article from Shopify on why they changed away from the default file structure in their Rails app.
And here's an interesting follow-up Shopify article on Enforcing Modularity in Rails Apps with Packwerk. |
Beta Was this translation helpful? Give feedback.
-
So reading through the answers here, and having participated in most of the architecture discussions we've had over the last ~8 months (wow!), I've got a couple of thoughts:
Here's my proposal, let me know how you all feel: // blitz.config.js
{
// ...
// The default directory to nest feature folders within the `app/` directory.
// By default, all feature directories are created immediately inside `app/`.
generatorPath: '.',
// ...
} And then all generator classes that output files must incorporate the |
Beta Was this translation helpful? Give feedback.
-
After trying the So another idea. The root problem is too many disparate files inside So instead of this
Change to this:
|
Beta Was this translation helpful? Give feedback.
-
I think what we're finding with the above comments is:
This is driving me to pretty firmly believe that we should add the config option, set it to |
Beta Was this translation helpful? Give feedback.
-
Having read through previous comments, made me question more:
Sorry if my questions sounds weird, english is not my native 🙏... |
Beta Was this translation helpful? Give feedback.
Thanks for this discussion @mizchi!
The reason we have the current file structure is that it's significantly more scalable than how Rails does it. For a lot of smaller apps, it doesn't matter either way. But we want to set you up with a default architecture that will scale very well instead of something that you will have to totally change at some point.
All large apps that I'm aware of end up using the file structure we have now in Blitz.
Here's an article from Shopify on why they changed away from the default file structure in their Rails app.