Skip to content

Commit

Permalink
python/layout, general/architecture: Add lessons learned from Credere
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Nov 23, 2023
1 parent df86492 commit 4754227
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/general/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ When using :doc:`../python/django`, the workers are written as Django `managemen
In other words, **nothing is a microservice**, where a `microservice <https://en.wikipedia.org/wiki/Microservices>`__ means a sub-service that is developed and deployed *independently* of others, as part of a service.

Instead, we achieve loose coupling and proper encapsulation by other means: dividing program logic by UI responsibility (e.g. :ref:`model-template-view`); organizing a set of features into an `application <https://docs.djangoproject.com/en/4.2/ref/applications/#projects-and-applications>`__, when using Django; and otherwise organizing code carefully.

.. _fat-models:

Fat models
----------

If a function performs `CRUD operations <https://en.wikipedia.org/wiki/Create,_read,_update_and_delete>`__ and accepts only a database session and instance values as arguments, add this function as a method on the model's class.
16 changes: 16 additions & 0 deletions docs/python/layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ Static files

- Don't mix static files with Python files in the same directory.

Module files
------------

- Use a single module for all models.
- If a module defines names that are imported by only one other module, merge the modules unless:

- The module is a convention of a framework (for example, the files created by the `startapp <https://docs.djangoproject.com/en/4.2/intro/tutorial01/#creating-the-polls-app>`__ command in Django).
- There is a divide in terms of responsibility (for example, model and view).

- Don't split a module only to reduce its length.

.. seealso::

- :ref:`fat-models`
- `FastAPI documentation <https://sqlmodel.tiangolo.com/tutorial/code-structure/#single-module-for-models>`__

Filename conventions
--------------------

Expand Down

0 comments on commit 4754227

Please sign in to comment.