-
Notifications
You must be signed in to change notification settings - Fork 137
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
v5.0.0 - Overall project restructuring & refactoring #205
Conversation
the code is getting much nicer |
Absolutely love how's cmyui learning new things and me catchig them from him, good work and i really like this new api, really restfull and easy to understand, also the usecases makes feel code more consistant and logicaly sorted(?), i mean you can easy understand what file you need to edit for that module or function, very cool. Keep it up! |
5adb1e3
to
1030729
Compare
hm the example i gave for beatmaps doesn't work so well in the usecase since the usecases i showed are just 1:1 with the repositories lol.. maybe will think of a better example - it's certainly not always like this |
this was a way for admins to not show up in spectator list that required other players to be speccing first. removing as it's not very well thought out
while this has helped with orienting my vision for the project more accurately - it's not worth the time to try finishing this at the moment i'll slowly be merging the ideas explored in this pr into the master branch in smaller, more atomized parts over time - the motivations still hold strong |
v5.0.0 - Overall project restructuring & refactoring
This one comes with quite a few updates and improvements to the codebase.
(implementing more of my learnings from time away)
decoupling of logic & data into separate (functional) api layers
One of the main issues facing the codebase is it's tight coupling of logic & data.
Let's take the Beatmap class as an example - it;
If you look through bancho.py's codebase, you'll see this recurring theme implemented in many inconsistent ways.
(see if you can find the similarities & differences in the Player class for example)
This PR aims to decouple structural representation, data providers, and business logic into 3 separate api levels.
data structures will be represented as "models"
Models represent the format of a resource.
They allow you to think only about the structure of a resource - the attributes within it and its properties.
An example of a model may be the representation of a beamtap - for example;
(you may also define simple properties, but nothing involving complex logic or external data points)
data providers will be represented as "repositories"
Repositories are an abstraction around the interaction with a resource.
They allow you to think of the interactions with the data providing service, as opposed to the actual implementation details of the underlying services - proving a standardized API for your business-logic layers.
Continuing with the theme of beatmaps, a simple repository may look something like
(you may also have functions to fetch by other means, update, or create beatmaps)
business logic will be represented by specific "usecases"
Usecases define the logical interface exposed by a resource.
They allow you to interact with & make complex calculations & modifications possibly depending on multiple resources simultaneously.
Building on our previous examples further, some use cases of a beatmap may look something like
Splitting the objects into layers like this allows us to implement a standardized API across the codebase's multiple resources.
With this sort of orthogonal design, we can increase code reuse significantly, increase the level of abstraction the programmer works at, and use this api as a framework for writing unit & smoke tests for the regular user flow in the application trivially.
restful api restructuring
This PR also resolves the paths provided by the v1 API to be restful -- we've updated the paths to fit a resource-driven design.
assume developers will use cloudflare (flex) for ssl
This simplifies the server setup itself quite significantly - no need for an ssl certificate, complex nginx setup or anything - just listen on port 80 and have cloudflare do the rest - implemented here.
disclaimer
Note that the examples provided in this are simplifications, and the exact implementation details of the PR are still being actively worked on - nothing is final!