Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django project architecture

As my Django projects are bigger and bigger I am facing issues regarding architecture. Before starting to code, I spend a lot of time to find a nice architecture for my project: how I split my project in apps, which apps are dependent on other apps and so on. To be clear, by architecture I don't mean project layout.

I have done my research and I haven't found yet a ressource showcasing some methods to find the best architecture for a given Django project. Outside web development, UML seems to be the way to go.

My questions are:

1) Why is there almost no discussion about those topics on the internet ? Am I missing something and totally wrong in my approach ?

2) Can UML be used to work on Django project architecture ?

3) Is there a common way to tackle this issue with Django ?

like image 449
Ali Baba Avatar asked Sep 25 '16 12:09

Ali Baba


People also ask

What is the root of a Django project?

Django root directory is the default app which Django provides you. It contains the files which will be used in maintaining the whole project. The name of Django root directory is the same as the project name you mentioned in django-admin startproject [projectname].

How does a Django project work?

Starting a Django project allows you to build your application's entire data model in Python without needing to use SQL. Using an object-relational mapper (ORM), Django converts traditional database structure into Python classes to make it easier to work within a fully Python environment.

What is the flow of Django project?

You can cache output of your specified views as per your need , or cache those views which are difficult to produce , or you can even cache the entire site . So this was the workflow of Django , i.e how these components interact with each other and makes Django a powerful Web Development Framework.


3 Answers

Before starting to code, I spend a lot of time to find a nice architecture for my project: how I split my project in apps, which apps are dependent on other apps and so on.

I think you're overthinking this. Your project architecture can (& probably should) evolve as you go. You can start with 1 big app and then split it when the appropriate structure becomes obvious to you.

1) Why is there almost no discussion about those topics on the internet ? Am I missing something and totally wrong in my approach ?

Because the short answer is "it's up to you" or "it depends on your project". This will help you: Django: best practice for splitting up project into apps

2) Can UML be used to work on Django project architecture ?

I don't see why not.

3) Is there a common way to tackle this issue with Django ?

There are several ways, consider dividing your apps around:

  • Responsabilities (1 app to do 1 thing)
  • Reusability (an app could be ported with no to limited changes to another project)
  • Ease of use (another dev can guess where a model / view should be)
like image 59
François Constant Avatar answered Oct 01 '22 22:10

François Constant


If you would like to have some guidance on how to create a UML design for a web application, you may like my white paper "Technical design in UML for AngularJS applications". It focuses on Angular apps, but most of it applies to web apps in general.

like image 26
www.admiraalit.nl Avatar answered Oct 01 '22 23:10

www.admiraalit.nl


After gathering more information I came accross an interesting architecture (I have found the idea on reddit but could not retrieve the url).

Your whole code should be sperated into independent apps (separation of concern) and you need to define 2 "project wide" apps (site and utils):

  • the site app can depend on any other app.
  • the utils app does not depend on other apps but other apps can depend on it.
  • the independent apps can only depend on utils.
like image 33
Ali Baba Avatar answered Oct 01 '22 22:10

Ali Baba