📌 The goal of this exercise is to create a simple browser-based chat application using .NET. This application should allow several users to talk in a chatroom and also to get stock quotes from an API using a specific command.
- ✔ Allow registered users to log in and talk with other users in a chatroom.
- ✔ Allow users to post messages as commands into the chatroom with the following format /stock=stock_code
- ✔ Create a decoupled bot that will call an API using the stock_code as a parameter (https://stooq.com/q/l/?s=aapl.us&f=sd2t2ohlcv&h&e=csv, here aapl.us is the stock_code).
- ✔ The bot should parse the received CSV file and then it should send a message back into the chatroom using a message broker like RabbitMQ. The message will be a stock quote using the following format: “APPL.US quote is $93.42 per share”. The post owner will be the bot.
- ✔ Have the chat messages ordered by their timestamps and show only the last 50 messages.
- ✔ Unit test the functionality you prefer.
- ✔ Have more than one chatroom.
- ✔ Use .NET identity for users authentication.
- ✔ Handle messages that are not understood or any exceptions raised within the bot.
⚠️ Build an installer. => I used docker-compose to build and run the application, i'm not sure if that counts
- ✔ We will open 2 browser windows and log in with 2 different users to test the functionalities.
- ✔ The stock command won’t be saved on the database as a post.
- ✔ The project is totally focused on the backend; please have the frontend as simple as you can.
- ✔ Keep confidential information secure.
- ✔ Pay attention if your chat is consuming too many resources.
- ✔ Keep your code versioned with Git locally.
- ✔ Feel free to use small helper libraries.
Images showing how the application works:
🛠 These are all the technologies and patterns used to develop this application
- C# .NET 6.0 Web API
- AspNetCore SignalR 6.0
- AspNetCore Identity 6.0
- RabbitMQ
- MediatR
- FluentValidation
- AutoMapper
- MassTransit
- Refit
- Polly
- Xunit
- FluentAssertions
- Moq
Patterns and Techniques:
- TDD (Test Driven Development)
- DDD (Domain Driven Design)
- CQRS (Command Query Responsibility Segregation)
- Middlewares: Error, Request and Response
- Dependency Injection
- Repository Pattern
- Unit of Work Pattern
- Domain Notification
- Domain Message
The project solution was based on DDD (Domain Driven Design) concept.
Below is the workflow diagram of the solution used: Explaining: The users connect to the web application, which will interact to the web API. A channel will be opened with the client using SignalR, and the Web API will use SQLServer as database. A decoupled bot worker was created to communicate with the Stock API, and send messages to the rabbitMQ queue.
I recommend following the option 01, so you wont need to install and run all the other tools needed for the project to work.
Option 01: Run in Containers To run the local application in containers, you will need to download and install the following:
Option 02: Outside Containers If you want to run the project outside containers, you must also have the following:
To execute the project, follow the steps below:
- When executing the page for two or more users, you need to open the browser as incognito mode, because the token session is stored on local storage of your browser.
- If for any reason you receive error sending message to RabbitMQ, it is because the port couldnt be opened or is in use. To solve the problem go on docker-compose on 'rabbitmq-service', change port number and run the commands again.
Option 01: Run in Containers
- Run Docker Desktop.
- Open the command prompt (cmd), navigate inside the project "\src" folder, and type: "docker-compose build" to build the containers (this is only necessary the first time).
- Type "docker-compose up -d" to start the application containers.
- Now you can view the application:
- To run the Web Application, navigate to http://localhost:8080
- To view the Web Api Swagger documentation, navigate to http://localhost:8082/swagger
to stop the execution of the containers, type "docker-compose down"
Option 02: Outside Containers
- Run SQLServer(port 1435) and RabbitMQ (port 15673).
- Open the command prompt (cmd), navigate inside the project "\src" folder, and type: "run.bat"
- This script will run the projects and open the browsers.