-
Notifications
You must be signed in to change notification settings - Fork 643
Propose new MVC module layout #1155
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
Conversation
Thanks for your work on this PR @jtgeibel! Even though the crates.io backend could use some cleaning and refactoring, I'm not sure that grouping things as you're proposing is ideal. IMO, I think it is better to group elements by functionnlity rather than usage. Which means that instead of having top-level .
├── category
│ ├── controllers.rs
│ ├── mod.rs
│ ├── models.rs
│ └── views.rs
. Grouping things like this brings up a big pro: it is far easier to encapsulate internal behavior, and it will even get more powerful with the incoming Controllers
I don't think that this is necessary right now, there probably is more urgent matters than a new API version. It would complicate things for no obvious benefits at the moment.
👍 on this one, I think ViewsI think that
Collaboration probably should happen with the Cargo team, which is currently maintaining the crates-io crate.
If I'm not mistaken, all of our current endpoints currently return JSON, it doesn't seem to be necessary to introduce such specific nesting right now. Models👍 Nothing to add. Future workBuilding on what said earlier, I think that grouîng things by functionality/service/domain would help a lot in growing the crates.io codebase, and would help avoid putting stuff where it doesn't belong. |
ControllersI'll rename to
Under my scheme, Views and modelsI don't understand why we wouldn't want to have Multiple endpoints may access the same view, and multiple views may access a model, so I don't think restricting visibility within say, the |
A downside to a layout like this: .
├── category
│ ├── controllers.rs
│ ├── mod.rs
│ ├── models.rs
│ └── views.rs
. is that while working on, say, something that involves the krate model and the version model, i'll have 2 tabs in my editor open with the title "models.rs" and that would make me sad :( I already have enough of a problem with multiple open |
I was going to figure out what the new file+module layout would be once the TODOs in this PR were done, and I started doing it and I think I like it. I agree that |
Sounds good to me @carols10cents. I've had this on the back burner for a while now, but I have off next week for the holidays and definitely intend to get this cleaned up soon. |
c6fbfbf
to
3d7e7e8
Compare
3d7e7e8
to
59b14d1
Compare
59b14d1
to
005e800
Compare
@carols10cents I've finally rebased this PR and renamed the modules to the more standard |
The bors: r+ |
1155: Propose new MVC module layout r=carols10cents This pull request proposes a new module layout following a model-view-controller style. For now, the functionality is re-exported from the new locations and the `use` statements have been updated to use the new locations. If we define where things should be moved to now, it should be easier to split future changes into small, reviewable PRs. ## Controllers - `src/api/*` For now, this is an empty placeholder, but the api route declarations and endpoints would be moved here. (In a [separate branch](jtgeibel/crates.io@master...mvc-example) I have some examples where the existing logic is moved.) ## Views - `src/views/*` Currently this is JSON only and most existing types are prefixed with `Encodable`. The major exception to this is the types from the `cargo publish` endpoint, which has been moved to `views::krate_publish`. ## Models - `src/models/*` All of the Diesel types would move to here. Many of these were previously reexported from the crate root. Going forward, I think many of the `New*` structs can go away using the new syntax as shown in: https://github.com/rust-lang/crates.io/blob/e0e57b9843c2fb244997a2e47d8cedc40fa9b516/src/boot/categories.rs#L105-L109 # Future work We can consider additional top level modules. For instance, the outgoing email and github_auth functionality could be moved to a module for `external` services. Additionally, `src/pagination.rs` could be moved into `src/api/mod.rs` and a few more things could probably move to `util`. I'm not sure yet where something like the README rendering would fit in.
Build succeeded |
1247: Split keyword and category functionality into MVC units r=carols10cents This PR is based on #1155 which is not yet merged to master. This [comparison](jtgeibel/crates.io@add-mvc-modules...jtgeibel:mvc-keyword-and-category) shows just the changes built on top of that branch. This PR moves the request handlers for keyword and category functionality to the `controllers` module. I extracted the common `use` statements into a `controllers::prelude`. `Encodable*` structs and the rfc3339 tests are moved under `views` and the remaining model structs, impls, and tests are moved under `models`.
This pull request proposes a new module layout following a model-view-controller style. For now, the functionality is re-exported from the new locations and the
use
statements have been updated to use the new locations. If we define where things should be moved to now, it should be easier to split future changes into small, reviewable PRs.Controllers -
src/api/*
For now, this is an empty placeholder, but the api route declarations and endpoints would be moved here. (In a separate branch I have some examples where the existing logic is moved.)
Views -
src/views/*
Currently this is JSON only and most existing types are prefixed with
Encodable
. The major exception to this is the types from thecargo publish
endpoint, which has been moved toviews::krate_publish
.Models -
src/models/*
All of the Diesel types would move to here. Many of these were previously reexported from the crate root.
Going forward, I think many of the
New*
structs can go away using the new syntax as shown in:crates.io/src/boot/categories.rs
Lines 105 to 109 in e0e57b9
Future work
We can consider additional top level modules. For instance, the outgoing email and github_auth functionality could be moved to a module for
external
services. Additionally,src/pagination.rs
could be moved intosrc/api/mod.rs
and a few more things could probably move toutil
. I'm not sure yet where something like the README rendering would fit in.