Skip to content

Commit f85a63b

Browse files
limcaaarlsamuelim01KhoonSun47
authored
Add Collab Page (#52)
* Wrap delete questions in single API call * Add new POST `questions/delete` endpoint * Update question service README * Update frontend to use new endpoint * Ensure question table is responsive to fit smaller viewports * Fix question README * Fix comments * Update return type of getQuestionByID * Revert "Update return type of getQuestionByID" This reverts commit cb11b5a. * Update return type of getQuestionByID * Set up layout for question box and editor * Add codemirror * Update layout styling * Update chip colours to match difficulty * Update question-box to fetch question through API call * Update to set cursor position * Fix styling issue Previously, the content of the question-box gets cut off when the panel is resized to a very small size * Add confirm dialog box for submit and forfeit buttons * Added Collaboration Services Features * Remove controller and add client1 and client2 to test websocket * Able to update database * Integrate collab service * Containerize collaboration service and enhance structure - Added a README.md to document the collaboration service. - Added a Dockerfile and docker-compose configuration to containerize the collaboration service. - Moved project files into appropriate directories for better structure and organization. - Updated helper.ts with improvements and new helper methods. - Refactored code to use the helper methods in helper.ts for consistency and reusability. - Removed unused tests.html file (will develop a new testing approach for HTML files in the future). * Added MongoDB URI configuration for Collaboration Service database - Updated .env.sample to include MONGO_URI for MongoDB Atlas. - Modified mongodbservice.ts to use MONGO_URI for database connection. - Updated docker-compose.yml to pass MONGO_URI as an environment variable for the collaboration service. * Updated README.md for improved clarity and documentation - Clarified MongoDB URI usage and environment variable setup. - Improved explanation of collaboration service setup and configuration. * Fix formatting issues * Fix button placement * Add code formatter * Add icons to buttons * Randomise user's color in codemirror * Fix formatting issues * Update MongoDB Atlas URI, config.json, and file organization - Updated MongoDB Atlas URI in .env to ensure proper connection. - Modified config.json to compile JavaScript files in addition to TypeScript. - Refactored naming and file locations of helper.ts and utility.js. * Update configurations on MongoDB - changing URI * Adding new files and changing file structure * Add Read from Question to Create Room, Update Question Service URL and Axios call - Updated `QUESTION_SERVICE_URL` in the `.env` file to use `question` as the service hostname (matching the Docker service name). - Refactored `createRoomWithQuestion` in `roomController` to correctly append `/questions/search` to the base URL. - Ensured the correct retrieval of question data using Axios, resolving the `ENOTFOUND` error in the Docker environment. * Initialize ydocs and create room collections - Updated MongoDB service to initialize ydocs. - Modified MongoDB service to create room collections using room_id. - Enhanced API to retrieve room details by user_id (have not tested yet) * Update message production and add logging - Updated producer to send messages to the collab-created queue. - Added logging to track message production and consumption in the queue. * Separate WebSocket and HTTP services into different ports and update room retrieval API - Configured WebSocket service to run on port 8084 (collaboration) and HTTP API service on port 8087 (rooms). - Updated API to retrieve a list of room IDs based on the user ID instead of full room details. - Modified Docker Compose file to reflect the new service port structure for collaboration and room services. - Added logging for room consumer initialisation to ensure proper service startup. * Update ESLint configurations for collaboration and refactor code * Enhance collaboration microservice with improved error handling and new APIs - Updated methods to properly handle success and error messages - Refined try-catch implementations - Added room_status field for room creation (true for on, false for off) - Updated API to retrieve only active room IDs (status: true) - Created new API to close rooms (sets status to false and removes Yjs documents from DB) * Update README.md * Add collaboration-db to Docker Compose and update MongoDB URIs - Added collaboration-db service to Docker Compose YAML - Updated mongoURI in question service - Updated mongoURI in collaboration service - Modified environment sample files in root and collaboration service * Add package.json and package-lock.json * Update broker.ts, consumer.ts in both collab and matching - broker.ts: Update the getChannel - consumer.ts in collab: Add channel.nack(msg) - consumer.ts in matching: Add debug message * Fix collab package.json * Fix collab service running the wrong file in development mode * Fix env variables * Choose environment DB URI instead of defaulting to cloud if available * Add broker env variable for match * Handle COLLAB_CREATED status Ensure COLLAB_CREATED status triggers success UI. URL redirection has not been handled. * Add API call * Add URL redirection from matching to collab * Update question retrieval * Update yjs roomId to match the passed roomId * Add guard for collab page * Fix roomId retrieval issue * Fix styling issue caused by nav bar * Add 2s delay on match found * Fix linting * Tidy up codes * Add API to update user isForfeit status - Implement new API for updating the isForfeit status of users in a room. - Modify existing APIs to align with the isForfeit status functionality. - Update README.md for both root and collaboration services to reflect changes. * Update room closing functionality and documentation - Modified `compose.yml` and environment sample files. - Updated `README.md` to include details on room closure. - Enhanced room close functionality to return success if the room is already closed. * Add functionality to submit button * Update websocket initialisation - Include param, which contains userId, when initialising * Update collab guard * Fix bug - roomId initialisation was not done on init, which caused the roomId to be undefined when initialising websocket * Add forfeit functionality * Fix bug - The user who accepted first would get stuck and not retrieve COLLAB_CREATED status as the polling was unsubscribed prematurely * Fix error - Uninitialised question was causing error in console logs as the question title is being retrieved before it's even initialised * - Update README.md - Change posiiton of initRoomId * Enhance environment configuration and collaboration service - Updated environment sample files for both root and collaboration services. - Added collaboration guard in `websocketservice.ts` to improve security. - Revised `README.md` to include new details and instructions. * Added collaboration guard in `websocketservice.ts` to improve security. * Fix eslint at websocketservice.ts * Fix linting * Add citation for utility.js in Collaboration Service * Collab: Centralize env variables * Fix linting * Remove packages The collaboration service has many unused packages. Let's remove them * Adjust Dockerfile * Minor Fix Based On Comments: - .env.sample: Remove the port numbers - compose.yml: Remove the ports to not exposed it, and remove the env as well - README.md: Change the collaboration and room service to under Port 8084 - default.conf: Change the collaboration-api to be 8084 - config.ts: Change to one PORT instead of two PORTS - index.ts: Change to one PORT instead of two PORTS - README.md in Collaboration Service: Update the documentation to use one port only - consumer.ts in Match Service: Remove the debug code * Fix bugs * Update submit logic Submit now keep tracks the number of user connected to the session. If the other user is not connected (log out or forfeit), only 1 user is required for the submission to go through. * Minor Fix Based On Comments: - README.md: Update port from 8087 to 8084Z - roomController.ts: Update the helper methods - webSocketService.ts: Update the helper methods - helper.ts: Seperate the helper methods for HTTPS and WebSocket * Update forfeit warning message Forfeit warning message now depends on the number of remaining users that have access to the session. * Minor Fix Based On Comments: - broker.ts: Adapt the broker.ts from Match Service - consumer.ts: Update consumer.ts with new broker.ts - producer.ts: Update producer.ts with new broker.ts * Minor Fixes Based On Comments: - types.ts: Contains interface for User and Room - mongodbService.ts: Update method for new types - roomController.ts: Update method for new types and remove any * Minor Fixes Based On Comments: - types.ts: Contains interface for User and Room - mongodbService.ts: Update method for new types - roomController.ts: Update method for new types and remove any * Update submit Submit will now show a warning message if the user attempts to submit while the other user is disconnected * Minor Additional Details Based On Comments (Added a new queue to handle error if the room is not created) - queues.ts: A new queue called COLLAB_CREATE_FAILED (if room is not created successfully) - consumer.ts: Update method to handle if room is not created successfully * Add notification on forfeit Previously, when user2 forfeits, user1 is not notified. Now, user1 will be able to tell if user2 forfeits * Major Fix Based On Comments (Using JWT Token) - compose.yml: Added JWT Token to Collaboration Service - .env.sample: Added JWT Token to Collaboration Service - package.json: Added jsonwebtoken and mongoose - README.md: Updated the API Calls to include JWT, and added details on handling room not created for Queue - app.ts: Added verifyAccessToken - config.ts: Added JWT Token to Collaboration Service - roomController.ts: Change from retrieving user_id to use JWT Token to retrieve the user_id instead - types.ts: Change room_id from string to Object_id - express.d.ts: Declare Request User - jwt.ts: Added JWT functionality - request.ts: Added types for Request User - roomRoutes.ts: Update routes - mongodbService.ts: Update method based on types.ts * Testing Fix * Change path from /start to /collab * Remove prettier-standalone library * Fix Issues On The WebSocketService.ts * Fix using ESLINT * Remove params from editor.component.ts * Fixed Based On Comments: - compose.dev.yml: Add port 8084 - compose.yml: Remove port 8084 - api.config.ts: Change to api gateway - editor.component.ts: Change the websocketurl - default.conf: Add the proxy - package.json: Add --files to solves issue on dev - index.ts: Edit the file sequence * Minor Fix On Collaboration Service: - Use Linting to fix - webSocketService.ts: Add new checks - editor.component.ts: Parse userid in the params * Fix linting * Update api calls to match new endpoint * Remove the duplicate createYJSDocument method * Fix unexpected end of array error This error seems to be due to YJS attempting to read strings sent by the collab service. Let's keep the websocket channel purely for YJS-related changes. * Remove wscat * Adjust Collab to use only 8084 * Simplify websocket path routing * Match: Nuke update route * Question: Consume MatchFoundEvent and produce QuestionFoundEvent, MatchFailedEvent * Collab: Consume QuestionFoundEvent instead * Frontend: Obtain question from collab * Match: Consume MatchFailedEvent * Frontend: Delay first match request status poll The finding match component could poll the status of the previous match request before the matchId updating to the new match request. Let's create a delay before the first poll to prevent this.` * Ensure question awaits broker * Use accessToken for websockets * Fix minor logger typos * Collab: Protect routes Ensure that a user cannot query for rooms not belonging to them * Ensure all services restart --------- Co-authored-by: Samuel Lim <[email protected]> Co-authored-by: KhoonSun47 <[email protected]> Co-authored-by: Yek Khoon Sun <[email protected]>
1 parent ee93410 commit f85a63b

File tree

94 files changed

+8995
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+8995
-225
lines changed

.env.sample

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This is a sample environment configuration file.
2-
# Copy this file to .env and replace the placeholder values with your own.
3-
41
# Question Service
52
QUESTION_DB_CLOUD_URI=<FILL-THIS-IN>
63
QUESTION_DB_LOCAL_URI=mongodb://question-db:27017/question
@@ -19,10 +16,22 @@ MATCH_DB_LOCAL_URI=mongodb://match-db:27017/match
1916
MATCH_DB_USERNAME=user
2017
MATCH_DB_PASSWORD=password
2118

19+
# Room Service
20+
COLLAB_DB_CLOUD_URI=mongodb+srv://<username>:<password>@cluster0.h5ukw.mongodb.net/collaboration-service?retryWrites=true&w=majority&appName=Cluster0
21+
COLLAB_DB_LOCAL_URI=mongodb://collaboration-db:27017/collaboration-service
22+
23+
# Collaboration Service (Yjs Documents)
24+
YJS_DB_CLOUD_URI=mongodb+srv://<username>:<password>@cluster0.h5ukw.mongodb.net/yjs-documents?retryWrites=true&w=majority&appName=Cluster0
25+
YJS_DB_LOCAL_URI=mongodb://collaboration-db:27017/yjs-documents
26+
27+
# Will use cloud MongoDB Atlas database
28+
ENV=PROD
29+
2230
# Broker
2331
BROKER_URL=amqp://broker:5672
2432

2533
# Secret for creating JWT signature
2634
JWT_SECRET=you-can-replace-this-with-your-own-secret
2735

28-
NODE_ENV=development
36+
# Node environment
37+
NODE_ENV=development

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
service: [frontend, services/question, services/user, services/match]
26+
service: [frontend, services/question, services/user, services/match, services/collaboration]
2727
steps:
2828
- uses: actions/checkout@v4
2929
- name: Use Node.js

README.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/bzPrOe11)
2+
23
# CS3219 Project (PeerPrep) - AY2425S1
4+
35
## Group: G03
46

5-
### Note:
6-
- You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice.
7-
- In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the development/deployment **AND** add your mentor to the individual repositories as a collaborator.
8-
- The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements.
7+
### Note:
8+
9+
- You can choose to develop individual microservices within separate folders within this repository **OR** use
10+
individual repositories (all public) for each microservice.
11+
- In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the
12+
development/deployment **AND** add your mentor to the individual repositories as a collaborator.
13+
- The teaching team should be given access to the repositories as we may require viewing the history of the repository
14+
in case of any disputes or disagreements.
915

1016
## Pre-requisites
1117

1218
1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
1319
2. Clone the GitHub repository
20+
1421
```
1522
git clone https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g03.git
1623
```
@@ -19,7 +26,7 @@ git clone https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g03.git
1926

2027
**Step 1: Copy Environment Configuration File**
2128

22-
To get started, copy the contents of `.env.sample` into a new `.env` file located at the root level of the project.
29+
To get started, copy the contents of `.env.sample` into a new `.env` file located at the root level of the project.
2330

2431
**Step 2: Build the Docker containers**
2532

@@ -37,25 +44,26 @@ Once the build is complete, you can start the Docker containers.
3744
docker compose -f compose.yml up -d
3845
```
3946

40-
After spinning up the services, you may access the frontend client at `127.0.0.1:4200`. Specifically, you can navigate to the Question SPA at `127.0.0.1:4200/questions` and the login page at `127.0.0.1/account`.
47+
After spinning up the services, you may access the frontend client at `127.0.0.1:4200`. Specifically, you can navigate
48+
to the Question SPA at `127.0.0.1:4200/questions` and the login page at `127.0.0.1/account`.
4149

42-
If you would like to spin up the services in development mode, you may use the following command. This enables hot reloading and exposes the ports for all microservices.
50+
If you would like to spin up the services in development mode, you may use the following command. This enables hot
51+
reloading and exposes the ports for all microservices.
4352

4453
```bash
4554
docker compose -f compose.yml -f compose.dev.yml up -d
4655
```
4756

48-
| Service | Port |
49-
|-----------------------|------|
50-
| Frontend | 4200 |
51-
| API Gateway | 8080 |
52-
| Question Service | 8081 |
53-
| User Service | 8082 |
54-
| Match Service | 8083 |
55-
| Collaboration Service | 8084 |
56-
| Chat Service | 8085 |
57-
| History Service | 8086 |
58-
57+
| Service | Port |
58+
|------------------------------|------|
59+
| Frontend | 4200 |
60+
| API Gateway | 8080 |
61+
| Question Service | 8081 |
62+
| User Service | 8082 |
63+
| Match Service | 8083 |
64+
| Collaboration & Room Service | 8084 |
65+
| Chat Service | 8085 |
66+
| History Service | 8086 |
5967

6068
**Step 4: Stop the Docker containers**
6169

@@ -65,4 +73,6 @@ Once you are done, stop and remove the containers using:
6573
docker compose down -v
6674
```
6775

68-
Note that this will clear any data stored in volumes associated with the containers. If you would like to keep your data, you can run the command without the `-v` flag, which will remove the containers but retain the data in the volumes for future use.
76+
Note that this will clear any data stored in volumes associated with the containers. If you would like to keep your
77+
data, you can run the command without the `-v` flag, which will remove the containers but retain the data in the volumes
78+
for future use.

compose.dev.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ services:
4040
ports:
4141
- 27019:27017
4242

43+
collaboration:
44+
command: npm run dev
45+
ports:
46+
- 8084:8084
47+
volumes:
48+
- /app/node_modules
49+
- ./services/collaboration:/app
50+
4351
broker:
4452
ports:
4553
- 5672:5672
@@ -50,3 +58,4 @@ services:
5058
- /var/run/docker.sock:/var/run/docker.sock
5159
ports:
5260
- 8000:8080
61+
restart: always

compose.yml

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
ports:
99
- 4200:4200
1010
restart: always
11-
11+
1212
gateway:
1313
container_name: gateway
1414
image: nginx:1.27
@@ -20,9 +20,11 @@ services:
2020
- question
2121
- user
2222
- match
23+
- collaboration
2324
networks:
2425
- gateway-network
25-
26+
restart: always
27+
2628
question:
2729
container_name: question
2830
image: question
@@ -34,7 +36,11 @@ services:
3436
DB_LOCAL_URI: ${QUESTION_DB_LOCAL_URI}
3537
DB_USERNAME: ${QUESTION_DB_USERNAME}
3638
DB_PASSWORD: ${QUESTION_DB_PASSWORD}
39+
BROKER_URL: ${BROKER_URL}
3740
JWT_SECRET: ${JWT_SECRET}
41+
depends_on:
42+
broker:
43+
condition: service_healthy
3844
networks:
3945
- gateway-network
4046
- question-db-network
@@ -70,7 +76,7 @@ services:
7076
- gateway-network
7177
- user-db-network
7278
restart: always
73-
79+
7480
user-db:
7581
container_name: user-db
7682
image: mongo:7.0.14
@@ -83,7 +89,7 @@ services:
8389
- user-db-network
8490
command: --quiet
8591
restart: always
86-
92+
8793
match:
8894
container_name: match
8995
image: match
@@ -116,7 +122,7 @@ services:
116122
networks:
117123
- match-db-network
118124
restart: always
119-
125+
120126
broker:
121127
container_name: broker
122128
hostname: broker
@@ -130,11 +136,43 @@ services:
130136
timeout: 30s
131137
retries: 10
132138
start_period: 30s
139+
restart: always
140+
141+
collaboration:
142+
container_name: collaboration
143+
image: collaboration
144+
build:
145+
context: services/collaboration
146+
dockerfile: Dockerfile
147+
environment:
148+
COLLAB_DB_CLOUD_URI: ${COLLAB_DB_CLOUD_URI}
149+
COLLAB_DB_LOCAL_URI: ${COLLAB_DB_LOCAL_URI}
150+
YJS_DB_CLOUD_URI: ${YJS_DB_CLOUD_URI}
151+
YJS_DB_LOCAL_URI: ${YJS_DB_LOCAL_URI}
152+
BROKER_URL: ${BROKER_URL}
153+
JWT_SECRET: ${JWT_SECRET}
154+
depends_on:
155+
broker:
156+
condition: service_healthy
157+
networks:
158+
- gateway-network
159+
- collaboration-db-network
160+
restart: always
161+
162+
collaboration-db:
163+
container_name: collaboration-db
164+
image: mongo:7.0.14
165+
volumes:
166+
- collaboration-db:/data/db
167+
networks:
168+
- collaboration-db-network
169+
restart: always
133170

134171
volumes:
135172
question-db:
136173
user-db:
137174
match-db:
175+
collaboration-db:
138176

139177
networks:
140178
gateway-network:
@@ -145,3 +183,5 @@ networks:
145183
driver: bridge
146184
match-db-network:
147185
driver: bridge
186+
collaboration-db-network:
187+
driver: bridge

0 commit comments

Comments
 (0)