The Server is based on Django framework, a high-level Python Web framework. The reasons that has led us base our development on this framework are:
A more detailed discussion of the options can be found here.
Each piece of functionality is split into different applications. An app should be focused and follow the Unix philosophy of “do one thing and do it well”. In other words, an application encapsulates some particular feature. If this sounds new to you, maybe you're interested in this talk.
controller
application.controller
module.Following the Python modules that you can expect to find inside each application:
admin.py
Admin interface support provided by django.contrib.admin.api.py
REST API views based on Django REST Framework.models.py
Models of the application (data layer)permissions.py
Permission definitions (see Permissions Application).settings.py
Settings of the application (see Django settings).urls.py
: URLs configuration (see URL dispatcher).views.py
Django viewsactions.py
: Admin actions.filters.py
: model admin list filter.fields.py
Model and Form Fields.forms.py
Django forms.widgets.py
Forms widgets.renderers.py
: REST API renderers (see DRF renderers).serializers.py
REST API serializers (see DRF serializers guide).ifaces.py
Sliver network interface definitions.notifications.py
: pluggable notification system based on server-apps-notifications notification app.tasks.py
: Celery tasks (Celery is an asynchronous task queue/job queue based on distributed message passing).utils.py
Functions that do one repetitive and specific thing.helpers.py
Functions that are part of other functions, in contrast with utils, helpers functions are highly coupled with their parent and do not have context other than that.validators.py
Django validators.tests.py
Tests (see Testing in Django).Apart from the ovbious benefit for others because of being able to reuse our software, writing code with reusability in mind also helps to keep the code structure clean and modular. Keep this in mind:
These are ideal states, be pragmatic above all :)
Well known related design principles:
Some online resources that can be worth reading
We will follow these guidelines:
In general try to write as less code as possible. And remember Don't repeat yourself, Keep it simple! and Repair broken windows!
Be careful choosing class, function and variable names: be descriptive and avoid abbreviations if they aren't clear (characters are almost free :)
Naming convention:
SingularName
verb_name()
(validate_user()
, get_whatever()
, make_something()
)has_something()
(has_permission()
, has_blue_eyes()
) attribute_on
(deleted_on
)is_something
, allow_something
(is_active
, allow_slices
)If your code needs to be commented maybe is because it is too complex, give it a second thought!
Readings that you might find interesting: