Skip to content

Commit 3a9e8c0

Browse files
authored
Merge pull request #53 from ruiqi7/docs/readme
Update readme
2 parents f236fa9 + b5f084a commit 3a9e8c0

File tree

10 files changed

+85
-58
lines changed

10 files changed

+85
-58
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@
44

55
We will be using Docker to set up PeerPrep. Install Docker [here](https://docs.docker.com/get-started/get-docker).
66

7-
Follow the instructions in the [backend directory](./backend/) first before proceeding.
7+
Follow the instructions in [here](./backend/README.md) first before proceeding.
8+
9+
1. Build all the services (without using cache).
10+
11+
```
12+
docker-compose build --no-cache
13+
```
14+
15+
2. Run all the services (in detached mode).
16+
17+
```
18+
docker-compose up -d
19+
```
20+
21+
To stop all the services, use the following command:
822

9-
Run:
1023
```
11-
docker-compose up --build
24+
docker-compose down
1225
```
1326

1427
## Useful links
1528

1629
- User Service: http://localhost:3001
1730
- Question Service: http://localhost:3000
18-
- Frontend: http://localhost:5173
31+
- Frontend: http://localhost:5173

backend/README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# PeerPrep Backend
22

3-
> Set-up either a local or cloud MongoDB first, before proceeding to each microservice for more instructions.
3+
> Before proceeding to each microservice for more instructions:
4+
5+
1. Set-up either a local or cloud MongoDB.
6+
7+
2. Set-up Firebase.
48

59
## Setting-up local MongoDB (only if you are using Docker)
610

711
1. In the `backend` directory, create a copy of the `.env.sample` file and name it `.env`.
812

913
2. To set up credentials for the MongoDB database, update `MONGO_INITDB_ROOT_USERNAME`, `MONGO_INITDB_ROOT_PASSWORD` of the `.env` file.
1014

11-
3. Your local Mongo URI will be `mongodb://<MONGO_INITDB_ROOT_USERNAME>:<MONGO_INITDB_ROOT_PASSWORD>@mongo:27017/`. Take note of it as we will be using in the `.env` file in the various microservices later on.
15+
3. Your local Mongo URI will be `mongodb://<MONGO_INITDB_ROOT_USERNAME>:<MONGO_INITDB_ROOT_PASSWORD>@mongo:27017/`. Take note of it as we will be using in the `.env` files in the various microservices later on.
1216

13-
5. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081.
17+
4. You can view the MongoDB collections locally using Mongo Express. To set up Mongo Express, update `ME_CONFIG_BASICAUTH_USERNAME` and `ME_CONFIG_BASICAUTH_PASSWORD`. The username and password will be the login credentials when you access Mongo Express at http://localhost:8081.
1418

1519
## Setting-up cloud MongoDB (in production)
1620

@@ -49,7 +53,6 @@
4953

5054
![alt text](./GuideAssets/Selection4.png)
5155

52-
5356
![alt text](./GuideAssets/Security.png)
5457

5558
7. Next, click on `Add my Current IP Address`. This will whitelist your IP address and allow you to connect to the MongoDB Database.
@@ -61,28 +64,63 @@
6164
9. [Optional] Whitelisting All IP's
6265

6366
1. Select `Network Access` from the left side pane on Dashboard.
64-
![alt text](./GuideAssets/SidePane.png)
67+
68+
![alt text](./GuideAssets/SidePane.png)
6569

6670
2. Click on the `Add IP Address` Button
67-
![alt text](./GuideAssets/AddIPAddress.png)
71+
72+
![alt text](./GuideAssets/AddIPAddress.png)
6873

6974
3. Select the `ALLOW ACCESS FROM ANYWHERE` Button and Click `Confirm`
70-
![alt text](./GuideAssets/IPWhitelisting.png)
75+
76+
![alt text](./GuideAssets/IPWhitelisting.png)
7177

7278
4. Now, any IP Address can access this Database.
7379

7480
10. After setting up, go to the Database Deployment Page. You would see a list of the Databases you have set up. Select `Connect` on the cluster you just created earlier.
7581

76-
![alt text](GuideAssets/ConnectCluster.png)
82+
![alt text](GuideAssets/ConnectCluster.png)
7783

7884
11. Select the `Drivers` option.
7985

80-
![alt text](GuideAssets/DriverSelection.png)
86+
![alt text](GuideAssets/DriverSelection.png)
8187

8288
12. Select `Node.js` in the `Driver` pull-down menu, and copy the connection string.
8389

8490
Notice, you may see `<password>` in this connection string. We will be replacing this with the admin account password that we created earlier on when setting up the Shared Cluster.
8591

8692
![alt text](GuideAssets/ConnectionString.png)
8793

88-
13. Your cloud Mongo URI will be the string you copied earlier. Take note of it as we will be using in the `.env` file in the various microservices later on.
94+
13. Your cloud Mongo URI will be the string you copied earlier. Take note of it as we will be using in the `.env` files in the various microservices later on.
95+
96+
## Setting-up Firebase
97+
98+
1. Go to https://console.firebase.google.com/u/0/.
99+
100+
2. Create a project and choose a project name. Navigate to `Storage` and click on it to activate it.
101+
102+
3. Select `Start in production mode` and your preferred cloud storage region.
103+
104+
4. After Storage is created, go to `Rules` section and set rule to:
105+
106+
```
107+
rules_version = '2';
108+
service firebase.storage {
109+
match /b/{bucket}/o {
110+
match /{allPaths=**} {
111+
allow read: if true;
112+
allow write: if request.auth != null;
113+
}
114+
}
115+
}
116+
```
117+
118+
This rule ensures that only verified users can upload images while ensuring that URLs of images are public. Remember to click `Publish` to save changes.
119+
120+
5. Go to `Settings`, `Project settings`, `Service accounts` and click `Generate new private key`. This will download a `.json` file, which will contain your credentials.
121+
122+
6. You will need to update the following variables in the `.env` files of the various microservices later on.
123+
- `FIREBASE_PROJECT_ID` is the value of `project_id` found in the downloaded json file.
124+
- `FIREBASE_PRIVATE_KEY` is the value of `private_key` found in the downloaded json file.
125+
- `FIREBASE_CLIENT_EMAIL` is the value of `client_email` found in the downloaded json file.
126+
- `FIREBASE_STORAGE_BUCKET` is the folder path of the Storage. It should look something like `gs://<appname>.appspot.com`.

backend/question-service/.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NODE_ENV=development
22

33
MONGO_CLOUD_URI=<MONGO_CLOUD_URI>
4-
MONGO_LOCAL_URI=mongodb://root:example@mongo:27017/
4+
MONGO_LOCAL_URI=<MONGO_LOCAL_URI>
55

66
FIREBASE_PROJECT_ID=<FIREBASE_PROJECT_ID>
77
FIREBASE_PRIVATE_KEY=<FIREBASE_PRIVATE_KEY>

backend/question-service/README.md

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
11
# Question Service
22

3-
> If you have not set-up either a local or cloud MongoDB, go [here](../) first before proceding.
4-
5-
## Setting-up Firebase
6-
7-
1. Go to https://console.firebase.google.com/u/0/.
8-
9-
2. Create a project and choose a project name. Navigate to `Storage` and click on it to activate it.
10-
11-
3. Select `Start in production mode` and your preferred cloud storage region.
12-
13-
4. After Storage is created, go to `Rules` section and set rule to:
14-
15-
```
16-
rules_version = '2';
17-
service firebase.storage {
18-
match /b/{bucket}/o {
19-
match /{allPaths=**} {
20-
allow read: if true;
21-
allow write: if request.auth != null;
22-
}
23-
}
24-
}
25-
```
26-
27-
This rule ensures that only verified users can upload images while ensuring that URLs of images are public. Remember to click `Publish` to save changes.
28-
29-
5. Go to `Settings`, `Project settings`, `Service accounts` and click `Generate new private key`. This will download a `.json` file, which will contain your credentials.
3+
> If you have not set-up either a local or cloud MongoDB, as well as Firebase, visit [this](../README.md) before proceeding.
304
315
## Setting-up Question Service
326

337
1. In the `question-service` directory, create a copy of the `.env.sample` file and name it `.env`.
348

35-
2. Update `MONGO_CLOUD_URI`, `MONGO_LOCAL_URI`, `FIREBASE_PROJECT_ID`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_STORAGE_BUCKET`.
36-
- `FIREBASE_PROJECT_ID` is the value of `project_id` found in the downloaded json file.
37-
- `FIREBASE_PRIVATE_KEY` is the value of `private_key` found in the downloaded json file.
38-
- `FIREBASE_CLIENT_EMAIL` is the value of `client_email` found in the downloaded json file.
39-
- `FIREBASE_STORAGE_BUCKET` is the folder path of the Storage. It should look something like `gs://<appname>.appspot.com`.
9+
2. To connect to your cloud MongoDB instead of your local MongoDB, set the `NODE_ENV` to `production` instead of `development`.
10+
11+
3. Update `MONGO_CLOUD_URI`, `MONGO_LOCAL_URI`, `FIREBASE_PROJECT_ID`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_STORAGE_BUCKET`.
4012

4113
## Running Question Service without Docker
4214

@@ -53,10 +25,8 @@
5325
1. With Docker
5426

5527
- Run `docker ps` to get a list of the Docker containers on your machine.
56-
5728
- Retrieve the `CONTAINER_ID` of `peerprep/question-service`.
58-
59-
- Run `docker exec -it <CONTAINER_ID> npm run seed`.
29+
- Run `docker exec -it <CONTAINER_ID> npm run seed`.
6030

6131
2. Without Docker
6232

backend/question-service/config/db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const connectDB = async () => {
1515
}
1616

1717
await mongoose.connect(mongoDBUri);
18-
console.log("MongoDB connected");
1918
} catch (error) {
2019
console.error(error);
2120
process.exit(1);

backend/question-service/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const PORT = process.env.PORT || 3000;
66
if (process.env.NODE_ENV !== "test") {
77
connectDB()
88
.then(() => {
9-
console.log("MongoDB connected");
9+
console.log("MongoDB Connected!");
1010

1111
app.listen(PORT, () => {
12-
console.log(`Server running on port ${PORT}`);
12+
console.log(
13+
`Question service server listening on http://localhost:${PORT}`,
14+
);
1315
});
1416
})
1517
.catch((err) => {

backend/user-service/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
coverage
12
node_modules
23
tests
34
.env*

backend/user-service/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# User Service Guide
22

3-
> If you have not set-up either a local or cloud MongoDB, as well as Firebase, go [here](../) first before proceding.
3+
> If you have not set-up either a local or cloud MongoDB, as well as Firebase, visit [this](../README.md) before proceeding.
44
5-
## Setting-up
5+
## Setting-up User Service
66

77
1. In the `user-service` directory, create a copy of the `.env.sample` file and name it `.env`.
88

9-
2. Update `MONGO_CLOUD_URI`, `MONGO_LOCAL_URI`, `FIREBASE_PROJECT_ID`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_STORAGE_BUCKET`, `JWT_SECRET`.
9+
2. To connect to your cloud MongoDB instead of your local MongoDB, set the `NODE_ENV` to `production` instead of `development`.
1010

11-
3. A default admin account (`email: [email protected]` and `password: Admin@123`) wil be created. If you wish to change the default credentials, update them in `.env`. Alternatively, you can also edit your credentials and user profile after you have created the default account.
11+
3. Update `MONGO_CLOUD_URI`, `MONGO_LOCAL_URI`, `FIREBASE_PROJECT_ID`, `FIREBASE_PRIVATE_KEY`, `FIREBASE_CLIENT_EMAIL`, `FIREBASE_STORAGE_BUCKET`, `JWT_SECRET`.
12+
13+
4. A default admin account (`email: [email protected]` and `password: Admin@123`) wil be created. If you wish to change the default credentials, update them in `.env`. Alternatively, you can also edit your credentials and user profile after you have created the default account.
1214

1315
## Running User Service without Docker
1416

frontend/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
coverage
12
node_modules
3+
*.md

frontend/src/contexts/AuthContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const AuthProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
5656
});
5757
} else {
5858
setUser(null);
59-
setLoading(false);
59+
setTimeout(() => setLoading(false), 500);
6060
}
6161
}, []);
6262

0 commit comments

Comments
 (0)