GithubHelp home page GithubHelp logo

Comments (11)

joshmorel avatar joshmorel commented on August 9, 2024 3

Yes I think an example would help a lot with getting on the same page. πŸ™‚ I'll apply it to a small feature with documentation and we can discuss around a PR.

from software-engineering-daily-api.

TheHollidayInn avatar TheHollidayInn commented on August 9, 2024 2

Yep! You are in the right path. I mentioned both of those architectures above. But you do grow into them for small projects. The main guides are keeping the SOLID patterns, removing code smells and keeping business logic out of MVC. They both have books on the subjects

from software-engineering-daily-api.

joshmorel avatar joshmorel commented on August 9, 2024 1

Cool I'll do some more research but leave this on the back-burner/low-priority for now.

from software-engineering-daily-api.

edgar971 avatar edgar971 commented on August 9, 2024

I think that's a good idea.

from software-engineering-daily-api.

edgar971 avatar edgar971 commented on August 9, 2024

Perhaps we should consider Git Flow as the workflow for Git and branching. It's recommended for open source projects to keep high quality and fewer bugs.

In the Git flow development model, you have one main development branch with strict access to it. It’s often called the develop branch.

Developers create feature branches from this main branch and work on them. Once they are done, they create pull requests. In pull requests, other developers comment on changes and may have discussions, often quite lengthy ones.

from software-engineering-daily-api.

TheHollidayInn avatar TheHollidayInn commented on August 9, 2024

Ah yea! We should. I use that at work now, and it is great.

from software-engineering-daily-api.

joshmorel avatar joshmorel commented on August 9, 2024

From looking through everything I have a few comments about structuring of the api code with regards to controllers, routes and models.

  • It seems like there is repetition across the model and controller methods as well as inconsitency in terms of usage. For example vote.controller.list uses vote.model.list but vote.controller.upvote uses just mongoose methods. It would be helpful for contributors (and maintenance) if we had a defined best practice for what code goes where. Perhaps, IMHO, the model could include only methods for revealing specific instances as JSON (toJSON, toJSONFor(post/user/etc)) with everything else (get, query, etc) in the controllers? I can provide an example through a PR but am very open for other ideas.
  • For simplicity of organization, would it make sense to co-locate controllers and routes?

from software-engineering-daily-api.

TheHollidayInn avatar TheHollidayInn commented on August 9, 2024

Yea, I agree for the most part. We will want to expand to one of the better clean/hex patterns.

The controllers are separated from the routes, which was the main point, but have the repetition on the model doesn't make much sense as the controller is kind of like a repository. It does keep express separated from mongoose though, which is good.

By co locate, do you mean organize by entity? As in have a folder for post, favorites, etc? I think that is something we can go ahead with.

from software-engineering-daily-api.

joshmorel avatar joshmorel commented on August 9, 2024

It might help to define the responsibilities of each component. From my understanding:

  • controllers: provide logic for responding to requests to each route (or more, basically, the route callback function)
  • models: provide relationship between app and database with data access methods
  • routes: the actual http routes

I'm fine with the route/controller separation because it's consistent, although I do struggle with it a bit because of the one-to-one mapping between routes and controllers (should they not be combined?). More importantly would be to consistently separate the models and controllers. You could define a lot of the logic in mongoose methods but if it's better for scalability/maintenance to make the mongoose implementations indepedent of the controller logic we should do that and consistently (with exceptions allowed where it makes sense).

I'd be willing to provide a stab at doing so, either with a new request (user profile? - an open issue) or with existing code. Let me know your thoughts and I'll go ahead.

Also, what's the status on implementing flow type checking? Is it stalled?

from software-engineering-daily-api.

TheHollidayInn avatar TheHollidayInn commented on August 9, 2024

I'm not really following what improvements you are wanting to make. Are you just saying there is too much connection between one to one methods? As in, route list -> list method on controller -> list method on the model.

Currently things are in a standard MVC/Express flow. Your responsibilities are pretty much correct, but as we expand, we introduce layers in between controllers and models (Domain Layer, Interactors, Entities, Repositories)

  • If you want to reorganize the folders, that is fine.
  • If you want to provide an example of your suggested flow, feel free to make a PR on an existing feature. Just make sure it is small in scope and has a reference to a proven architecture pattern/code refactor

Type checking has a PR open and a contributor working. It isn't a high priority, and they have requested time.

from software-engineering-daily-api.

joshmorel avatar joshmorel commented on August 9, 2024

I don't have anything yet to share unfortunately... I've been doing a bit of research while trying out different things and this seems like the most appealing option, applying Uncle Bob's clean architecture with similarities also to Alistair Cockburn's hex architecture.

Basically the idea is that you put the core of the app and business logic in something called a "user-case interactor". This then has interfaces or ports to the implementation stuff - so the ORM/ODM, the REST framework, etc.

So assuming we keep everything else the same, you'd basically have the following sections:

  • app: the core logic (user-case interactors)
  • controller: the delivery mechanism or REST API (Express) stuff
  • route: the exposed end-point of the controller (keeping it separate from controller seems like it could still be helpful for versioning etc)
  • model: the database (Mongoose) stuff

However at this stage in the app, the added layer is probably more effort than value given the early stage and smaller team. Perhaps something to keep in mind in the future as the complexity grows?

In the interim... some improvements to separation could be made by keeping all the mongoose stuff in the model (a decent chunk is in the controllers). But just refactoring would be low value at this point - maybe addressing this while fixing a small issue or implementing something new might provide the most value? Let me know if there's low hanging fruit you'd want work on and I can take a stab.

from software-engineering-daily-api.

Related Issues (20)

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.