Looking into Django-React Software Architecture

Mahdia Aliyya
4 min readMay 24, 2021

--

In this article, we will look into the architecture used in SekolahKu, Django-React. Hopefully, this will give you a brief idea of how a Django-React project architecture will look like.

Application architecture used in SekolahKu (source)

Django

Django MVT Architecture

Django use the Model-View-Template (MVT) software design pattern. It is a collection of three essential parts that its name explained itself: Models, Views, and Templates. This architecture intends to allows flexibility, since responsibilities are clearly separated.

Models: This layer works as an interface of your data, that responsible to maintain them. It is the logical data structure behind the entire application and is represented by a database. This is where you define objects and relations between objects.

Views: Used to execute the business logic and interact with a model to carry data and renders a template.

Templates: is a presentation layer which handles User Interface part completely. It consists of static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted (HTML, CSS, Javascript).

Serializers in Django REST

In SekolahKu, React is used to handle the UI — frontend, and Django is used to handle the data — backend. And to connect the two of them, we need REST API. Since we handle the interface using React only, we remove the Template part in Django. And to serve our REST API, we change View part with View from Django REST Framework.

Now it becomes Model-View-Serializer.

Serializer: is part of the Django-REST framework. Its main function is to render the available information into formats (like JSON, XML, etc.) that can be easily accessible and utilised by the frontend.

source

Now we have learned the backend part, let’s see what’s going on in the frontend.

React

React is a JavaScript framework that allows to build web frontends for their REST API backends.

Unlike other UI libraries and frameworks, Reactjs doesn’t enforce an architecture pattern. It is just a view that caters to the user interface.

Components: the central structural unit — something minimal, like a button, label, or text input label or perhaps something more complex, like a registration form, user-profile, etc

State: the data needed to track for making the application work, and determines what displays on the UI of an application.

React + Redux

“Redux is used for the provision of a central or app level state/store. All the data that needs to be shared across features, modules or react-component trees, can be added to the redux store.”

An example of React+Redux architecture

Redux use uni-directional data flow. It doesn’t encourage bi-directional flow to ensure clean data flow architecture and have better control over it.

Reducer: Logic that decides how your data changes exist in pure functions

Centralized store: Holds a state object that denotes the state of the entire app

Action: An application event, which is dispatched to the reducer

View: Displays React Components in the UI

“The biggest thing to know here is that the store is where redux stores the data, the data is mapped to props, where React displays through components. And all that is state.”

Detailed architecture of React+Redux and connections between them (source)

--

--

Mahdia Aliyya
Mahdia Aliyya

Written by Mahdia Aliyya

i'll try my best to write something worthy here

No responses yet