Skip to content

Node.js backend application which uses MongoDB as database and which also includes authentication with Passport.js as well as realtime communication using Socket.io

License

Notifications You must be signed in to change notification settings

nwokoyepraise/friddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Friddy

Backend Application for Friddy Project Assessment


Logo

Backend Application for Friddy Project Assessment


Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. API Endpoints
  4. UML Diagrams
  5. Roadmap
  6. Contributing
  7. License
  8. Contact
  9. Acknowledgements

About The Project

This project is a demo backend assessment for Friddy project. It consists of endoints for user registeration and login, real-time chat functionality with socket.io, chat room creation and management, session handling and logging as well as user interaction logging.

Friddy project is linked at here

Services Available on the Demo Backend

  • User Registeration
  • User Login
  • Chat Room - Creation
  • Chat Room - Joining
  • Chat - Remove Item
  • Real time chat with sockets
  • User Session Logging
  • User Interaction Logging

Built With

The project was built natively with the following technologies

Getting Started

To build the project locally, simply clone the github repository. Navigate to root project folder and run the following to install packages:

npm install

After packages have been installed. Proceed to run:

node src/app.js

API Endpoints

User Registeration Endpoint

This endpoint is used to for user registeration

POST /api/user_reg
Host: localhost:3000
Content-Type: application/json

{"email": "string", "username": "string", "password": "string"}

Response:
{
  "status": true,
    "data":
        {
            "user_id": "string",
            "username": "string",
            "email": "string",
            "jwt": "string"
        }
}

User Login Endpoint

Endpoint used of user login

POST /api/user_login
Host: localhost:3000
Content-Type: application/json

{"email": "string", "password": "string"}

Response:
{
  "status": true,
    "data":
        {
            "user_id": "string",
            "username": "string",
            "email": "string",
            "jwt": "string"
        }
}

Chat Room - Creation

This endpoint is used to create rooms which are typically mongodb documents. This returns an id which represents the room ID. This room ID will be used in storing real-time chat linked in respect to the particular room.

Users are automatically added to groups they created.

POST /api/room_chats/create_room
Host: localhost:3000
Content-Type: application/json
Authorization: Bearer Token(JWT)

{"room_name": "string"}

Response:
{
  "status": true,
    "data":
        {
            "room_name": "string",
            "members": "[]",
            "members_count": "string",
            "message_count": "number",
            "timestamp": "string",
            "_id": "string",
            "__v": "number"
        }
}

Chat Room - Joining

For a user to send a message to a chat room, the user has to be a member of the chat room. This endpoint is used to add users to a chat room.

POST /api/room_chats/join_room
Host: localhost:3000
Content-Type: application/json
Authorization: Bearer Token(JWT)

{"room_name": "string"}

Response:
{
  "status": true,
    "data":
        {
            "nessage": "string"
        }
}

Reatime Chat with Sockets

Connection

Realtime chat should be done by the client to https://localhost:3000/chat_room with authorization header containing the user Bearer Token (jwt) in request header. Once connection is done, the user can proceed to emit a message to join room of choice (to get messages in real-time). This message should be sent in the following format:

socket.emit('join_room', 'room_id');

Room id is the ID of the room where the user wants to send the message to. The room_id is also to store the chatin DB.

Sending Messages

To send a message to chat, client should emit messages in the following format:

socket.emit('message', {'room_id': 'room_id', 'message_string': 'message' },  function (ack) {
//ack = acknowledgement from server
        });

There is an event emmision from server if a message was sent unsuccefully with the reason also sent along. Clients can listen the following format to get notified if the chat they sent could not be completed successfully:

socket.on('message_error', function(reason){

});

Listening for Messages

To receive real-time messages in chat room, clients should listen to events in the following format:

socket.on('new_message', function(data){
 //data = {'room_id': 'room_id', 'message_string': 'message', 'sender_id': 'string'}
        });

Additional Events

  1. To make the chat system more interactive, clients can signify when they have started typing by emiting even in the following manner:
socket.emit('typing', 'room_id');

Similarly, clients can listen to know when another has started typing as follows:

socket.on('user_typing', function(data){
 //data = {'status': 'true', 'user_id': 'string'}
        });
  1. When a user stops typing, they can emit as below:
socket.emit('typing_stopped', 'room_id');

Other clients can listen to know when another client has stopped typing as below:

socket.on('user_typing', function(data){
 //data = {'status': 'false', 'user_id': 'string'}
        });

Session Logging

Client connections to sockets are logged with start time and end time being the main fields of interest.

Interaction Logging

USer activity is also logged when user performs activity such as joining/becoming member of chat rooms and Interactions such as sending messages to chat rooms along with timestamps of the events.

UML Diagrams

Class Diagram:

class_diagram drawio

DB Diagram:

db_diagram drawio

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the GNU-V3 License. See LICENSE for more information.

Contact

Project Link: https://github.com/nwokoyepraise/friddy

Acknowledgements

About

Node.js backend application which uses MongoDB as database and which also includes authentication with Passport.js as well as realtime communication using Socket.io

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published