-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC for Blitz App File Structure #3
Conversation
I think I disagree with this. Perhaps you mean "The file structure of a project is something that adds zero value to your users"? File structure in any app must not be arbitrary or you end up with code that is impossible to work on and maintain. Good file structure can:
... and other things I cannot think of right now. |
Some initial thoughts on this. Some of this might be mitigated by a bit more clarity on how we are managing dependency injection. I feel like having a firm understanding of the magic we are planning for blitz might inform file structure and vice versa.
So I guess from my suggested changes might look something like this:
|
Yes, you're exactly right. And I love those points on file structure. They will be very good to add to the RFC. |
I'm mostly curious why we're logically separating
And in the build tools we specify that we'll only look for files that match the pattern Since the Blitz context is kind of abstract since we're still iterating on this, I can use a standard React/Redux app as an example. I find this:
...significantly harder to grok (especially for newcomers) than this:
...which, at a glance, gives a very clear picture of what's happening, how different files interact with each other, etc. IMO, as long as good naming conventions are followed (something we can enforce in our build tooling), it makes understanding the full set of files that make up a page much easier. It does have the advantage of also making integration tests much easier to manage, if a test breaks or has to be updated, you have a single place to look, no need to go spelunking across your entire repository. |
This is a convention from Next.js. I agree it shouldn't be separated. |
@aem I agree on all "user" files living in the same place. My initial proposal was this, with the exception of a Quoted for reference:
Now for the actual file naming, I'll be honest, I don't like the verbosity of duplicating the folder name inside the file name ( Why do you want |
Is our goal for users to have to know about Next? If we'd like them to be aware of the underlying framework then that's fine, but maybe we go with the flat file structure everywhere except the Or, maybe for more transparency, as a part of the build we generate
|
@aem That is a technique I have used before with next. I am looking into setting this up in an example over the next few days that uses this sort of thing. It should allow us to use next under the hood but not be bound by some of its design flaws. |
The simpler While you can type the file path to filter down the file list, because of how IDEs' search relevance works, the actual file you need might be a few entries down the list. While the verbosity isn't ideal, if your file is just named |
Alright, great point let's do that. So,
I initially went with plural because routes are plural. But if the folder name is now in the file name, I think singular would read and look better. And it could be a nice distinguisher from routes. Routes are plural, code is singular.
For reference, Ruby on Rails has singular models, plural controllers, and plural routes.
I think all React components should always be PascalCase, but for app files:
My vote is for kebab-case. |
Ultimately it doesn't matter so long as it is consistent but a couple of points worth mentioning:
import CandidateApplicationController from '../CandidateApplicationController'; |
@ryardley point 1 is true for TS projects, but not JS projects which we'll certainly have. |
Should users have to know about Next?I suggest that the goal should be, explicitly, users should not need any knowledge of Next, since I think it'll be better for the long-term:
Expanding a bit on the first of these (with based off observations about Redux and forecasting parallels for Blitz - I've never actually used Next before): As a brief summary of what I can reconstruct from the historical record: Redux was written as one of the many 'Flux' libraries that popped up, and followed Flux conventions in doing so, e.g. opting for the terminology of 'actions', with a view to being easier for those familiar with Flux. Since time has gone on, a significant proportion of users - probably the overwhelming majority, in the maintainer's estimate - are now coming to Redux without the historical knowledge of Flux. The Redux documentation and API, originally perhaps written for a Flux-literate audience to get them to choose Redux over other Flux library, weren't optimised to work for users arriving into the ecosystem later on (understandably). Newcomers are impatient and just want to learn this library that everybody keeps talking about - the "learn the concepts of this strange thing called Flux which you have never heard of before, and then you can learn this library you really want to learn" behaviour is difficult to motivate and guide. I think this is likely to be one of the main reasons why Redux has gained a bit of a reputation as being hard to learn. Additionally, there's some terminology baggage that has come with the Flux roots. There's been discussion on whether Redux 'actions' should really be called 'events' - and the official Redux recommendation is now that actions are better modelled in an event-style, rather than the imperative command style that most devs use. They're sticking with the 'actions' terminology (which I think is sensible - it's too late to change it now), but that terminology does lead people down the imperative command style path which was not intended. I don't know if similar things will arise with Blitz, but I think it's something to be conscious of. I reckon that the rate of new people coming into web development is large enough that "people gingerly stepping out into the world of programming" is worth considering as an important audience who need to be able to work with Blitz. File location
I agree with the principle of co-locating together files that change frequently together, or which are conceptually related - as my two-cents, though, on this comment from the Slack group:
I am a fan of this, and I think that's not as immediately achieved by the second Redux pattern - so I'd personally do something more like grouping An additional advantage of this, to my mind, is that putting all user-related files (frontend and backend) in the same folder seems to imply, or at least suggest, that it is only these particular components in this folder that ought to be interacting with this part of the backend API, and so I feel a bit dirty if I dispatch an action to change |
Great thoughts @richardcrng! I think you're suggesting something like this, correct?
Both components & data would support nested contexts. |
Yes, exactly @flybayer |
I still feel as though that's being too prescriptive about what the file structure should look like. If we just dictate that "every folder needs to have these |
I know this might be an unpopular opinion but how do you feel about extending the "files that change together should live together" rule to tests? In a very large project I've always found the convention to put |
@aem we have to have So far, I don't see any actual requirements to follow this file structure (aside from having I strongly think we need a scalable file structure by default as the recommended path. "How should I organize my react app files?" is one of the most common questions junior/mid people have. Blitz is in the business of eliminating mundane decisions like this. But at the same time, if at all possible, one should be able to organize files in their own custom way. |
@quirk0o yeah — I did a survey on twitter the other week, and the vast majority of people have a top level tests folder for integration tests but then use |
Not if we use the POC where we use some basic codegen and files are served from a temporary |
@aem I get what you're saying, but I'm not following the solution. With the I.e.
|
One thing I think I like that is worth mentioning around file structure was that whilst I was playing around with the implementation of the "compile to next" idea I discovered we could probably set up Blitz so that you can simply decorate a working next app and "upgrade" it to blitz. Trying to make this possible would be quite worthwhile as it could see much larger adoption of blitz as it should make it easier for people to gradually adopt blitz into their next projects to handle their data fetching. So in my head what that means for file structure is that :
Upgrade could be easy manually: just install Also generally one of the things I like about React and annoys me about more prescriptive systems is that you can organise them however you want. Having a canonical way is super important to eliminate decision fatigue but being able to do whatever you want is important too. Ultimately the user should be able to configure how the pages folders are found to taylor it for their needs.
Being able to do configuration based routing could be super useful too btw. With large apps a file system based approach can be unwieldy to have the option of either will be well received I think. |
@ryardley yeah, I think that's a really good idea. I want it to be as easy as possible for folks to migrate a next app to Blitz.
|
I guess that means they will be supporting both or will they be making a breaking change? |
I'm sure they'll support both for some time, so we probably should too, eh? :) |
Sounds like a good default starting point. I still think it would be good to have this configurable at some point. We still would need to select a canonical name for the generator so the config might be something like: {
routeFolderName: '✨',
routeFolderMatcher: /(\/(pages|routes|views|✨)\/.+)$/
} NOTE: not the default config 😉 |
I've made some major updates to this file structure RFC, including rolling the routing RFC into this since they are so closely related. Please review and provide feedback! It certainly still needs more work and explanation, but it's making progress. |
View Rendered