General idea's about melange module architecture, needs work and discussion. git-svn-id: http://soc.googlecode.com/svn/wiki@3170 5fae56a1-394a-0410-ba46-5107137fd53f
diff --git a/MelangeModuleArchitecture.wiki b/MelangeModuleArchitecture.wiki new file mode 100644 index 0000000..b1f389b --- /dev/null +++ b/MelangeModuleArchitecture.wiki
@@ -0,0 +1,209 @@ +#summary Melange Module Architecture +#labels Phase-Implementation,Importance-Useful,Contents-Draft + += General idea = + +This section briefly summarises the functionality and design of the new architecture. +Naming + + * prefix (or at least a pattern somewhere in the url) for all urls that use a module + * (?Pmodule gsoc)/ + * (?Pmodule ghop)/ + * load the appropriate "soc.modules.%(module)s" module + * modules live under soc.modules.* + * everything that is part of Melange should live under soc.* (so no more /app/gsoc, /app/ghop/, /app/soc structure) + * in build.py all modules in soc.modules are loaded, to allow them to register themselves +a top level "module" that is "core" to do site wide stuff, such as "soc/user/create" +generic urls such as 'program/create' are removed and replaced by e.g. 'gsoc/program/create' + +At a pinch we could just go with the naming without introducing a communication structure. However this is a route to spaghetti code and great ambiguity in meaning of objects. For example, what does 'App_task_limit' mean? It could depend on the context, GHOP or GSoC. If we restrict the communication to well designed channels, i.e. if we genuinely keep the design modular, these kinds of problems are less likely. + += Communications = + + * each module has it's own entities, that may inherit from generic entities, e.g., GHOPProgram extends Program. Every item in 'Program' will need a comment to ensure that its meaning is clear and that it is not specific to GHOP or GSoC. + * version compatibility will be achieved with a single API_VERSION number + * modules can register services they offer, which can then be used by other modules + * modules can require the presence of certain services (optionally provided by other modules) and refuse to load if these services are not present +modules talk with the core only, communication with other modules happens through the core by means of services + * the core provides an API for: + * registering new ACL checks + * register new sidebar entries + * register new urls with the sitemap + * registering jobs that the module would like to be schedulable + * registering user preferences the plugin would like added + += Conversion = + +This section describes the conversion process from pre-modules to post-modules. + +== Converting the datastore == + + # push the new models + # convert old models to new models + # remove the old models + += Terminology = + +Core: The code module that runs when Melange starts up. It is responsible for invoking any other modules. It contains a built in 'module' with name 'noplugin' that does things we currently expect to be required in every program. It may turn out that later some of these move out into modules, but that is not planned at this stage. + +Module: A related body of code that can register its services and requirements with 'Core'. + += Registration Order And API = + +The order in which the core invites registrations from the modules is likely to be important at a future date. For GHoP and GSoC the order is unlikely to be important. We can address the issue of 'order' at a later date. + +The precise details of what we want to register are also likely to grow over time. This is our 'plug in API'. This is the correct way to develop - organically. We have a structure in which this can happen. + += Code snippets = + +This section contains some general code snippets that are related to the new architecture. + +== Server side code == + +Some server side code. This lives in the core. + +{{{ +def hasCapability(callback, capability): + """Checks whether a callback support the specified capability. + + Args: + callback: the callback to check if it supports the capability + capability: the capability to check for + """ + + if not hasattr(callback, capability): + return False + + func = getattr(callback, capability) + + if not callable(func): + return False + + return True +}}} + +== Callback API == + +Some callback API code. Variants of this live in each module. + +{{{ +class Callback(object): + """Callback object that handles interaction between the core and a module. + """ + + def __init__(self, core): + """Initializes a new Callback object for the specified core. + """ + + self.core = core + self.core.registerService(...) + + def registerWithSitemap(self): + """Called by the server when sitemap entries should be registered. + """ + + # register our sitemap entries + self.core.registerSitemapEntry(...) + ... + + def registerWithSidebar(self): + """Called by the server when sidebar entries should be registered. + """ + + # require that we had the chance to register the urls we need with the sitemap + self.core.requireService('registerWithSitemap') + + # register our sidebar entries + self.core.registerSidebarEntry() +}}} + +== Bootstrapping == + +In order to get everything running build.py will be extended to load all modules defined in settings.MODULES. The MODULE_FMT is 'soc.modules.%s' for Melange. The module list will be stored in a global and used from a number of places in core for different capabilities. There will also be a subroutine for calling the callbacks for a particular capability (not shown). + +One consequence of the design is that at some date in the future, if a capability has been superseded, the core no longer needs to support it. It will not ask for that capability and callbacks will not need to supply it. + +Core itself should also be part of the callbacks and use the module API to do stuff. + +{{{ +def getModuleCallbacks(): + """Retrieves all callbacks for the modules of this site. + callbacks for modules without a version number or the wrong API_VERSION + number are dropped. They won't be called. + """ + + fmt = settings.MODULE_FMT + modules = [__import__(fmt % i, fromlist=['']) for i in settings.MODULES] + + return [i.getCallback() for i in modules] +}}} + +add in somewhere... core.triggerCapability('registerWithSitemap') + += Sharing of Models = + +Currently many models are shared while they should not be. + +== Shared Models == + +These are all in core + * answer.py + * base.py + * club.py + * club_admin.py + * club_app.py + * club_member.py + * contributor.py + * countries.py + * document.py + * documentation.py + * follower.py + * group.py + * group_app.py + * host.py + * job.py + * licenses.py + * linkable.py + * notification.py + * presence.py + * presence_with_tos.py + * question.py + * quiz.py + * request.py + * response.py + * reviewer.py + * school.py + * site.py + * sponsor.py + * user.py + * work.py + * priority_group.py + +== Shared But Different (Oops) == + +Looks like these need a base class and then to have specialised GHOP and GSoC versions. + + * mentor.py + * org_admin.py + * organization.py + * program.py + * role.py + * timeline.py + * student.py + * seed_db.py + +== GSoC Specific Models == + + * comment.py + * org_app.py + * proposal.py + * proposal_duplicates.py + * ranker_root.py + * review.py + * review_follower.py + * student_project.py + * student_proposal.py + +== GHOP Specific Models == + + * task.py (Needs to be redone because it was wrong)