Skip to content

suhailvs/django-whatsapp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hits

demo

A small functional person-to-person message center application built using Django. It has a REST API and uses WebSockets to notify clients of new messages and avoid polling.

Architecture

  • When a user logs in, the frontend downloads the user list and opens a Websocket connection to the server (notifications channel).
  • When a user selects another user to chat, the frontend downloads the latest 15 messages (see settings) they've exchanged.
  • When a user sends a message, the frontend sends a POST to the REST API, then Django saves the message and notifies the users involved using the Websocket connection (sends the new message ID).
  • When the frontend receives a new message notification (with the message ID), it performs a GET query to the API to download the received message.

Scaling

Requests

"Because Channels takes Django into a multi-process model, you no longer run everything in one process along with a WSGI server (of course, you’re still free to do that if you don’t want to use Channels). Instead, you run one or more interface servers, and one or more worker servers, connected by that channel layer you configured earlier."

In this case, I'm using the In-Memory channel system, but could be changed to the Redis backend to improve performance and spawn multiple workers in a distributed environment.

Please take a look at the link below for more information: https://channels.readthedocs.io/en/latest/introduction.html

Assumptions

Because of time constraints this project lacks of:

  • User Selector Pagination
  • Good Test Coverage
  • Better Comments / Documentation Strings
  • Frontend Tests
  • Modern Frontend Framework (like React)
  • Frontend Package (automatic lintin, building and minification)
  • Proper UX / UI design (looks plain bootstrap)

Running the Project Locally

  1. First, clone the repository to your local machine:
git clone https://github.com/suhailvs/django-whatsapp
cd django-whatsapp
  1. Ideally, create a virtualenv and install the projects dependencies:
python3 -m venv env
source env/bin/activate
  1. Install requirements
pip install -r requirements.txt
  1. Init database and runserver
./manage.py migrate
./manage.py runserver
  1. Optional: Install and Start Redis Server
sudo add-apt-repository ppa:redislabs/redis
sudo apt-get update
sudo apt-get install redis
redis-server

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 35.2%
  • Python 30.4%
  • HTML 24.2%
  • CSS 10.2%