Backend Application for Friddy Project Assessment
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
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
- User Registeration
- User Login
- Chat Room - Creation
- Chat Room - Joining
- Chat - Remove Item
- Real time chat with sockets
- User Session Logging
- User Interaction Logging
The project was built natively with the following technologies
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
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"
}
}
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"
}
}
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"
}
}
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"
}
}
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.
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){
});
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'}
});
- 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'}
});
- 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'}
});
Client connections to sockets are logged with start time and end time being the main fields of interest.
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.
See the open issues for a list of proposed features (and known issues).
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the GNU-V3 License. See LICENSE
for more information.
Project Link: https://github.com/nwokoyepraise/friddy