Skip to content

Commit

Permalink
Merge pull request #65 from techstartucalgary/feature/migrating-micro…
Browse files Browse the repository at this point in the history
…services

feat: Migrating from monolith to microservices
  • Loading branch information
Axeloooo authored Feb 24, 2024
2 parents 850b0ca + 98492dd commit b9a80f4
Show file tree
Hide file tree
Showing 73 changed files with 17,153 additions and 1,229 deletions.
54 changes: 42 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: cd backend && npm install
- name: Install dependencies in feed-service
run: cd backend && cd feed-service && npm install

- name: Lint
run: cd backend && npm run lint
- name: Lint feed-service
run: cd backend && cd feed-service && npm run lint

- name: Install dependencies in product-service
run: cd backend && cd product-service && npm install

- name: Lint product-service
run: cd backend && cd product-service && npm run lint

- name: Install dependencies in scanner-service
run: cd backend && cd scanner-service && npm install

- name: Lint scanner-service
run: cd backend && cd scanner-service && npm run lint

build:
runs-on: ubuntu-latest
Expand All @@ -27,11 +39,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: cd backend && npm install
- name: Install dependencies in feed-service
run: cd backend && cd feed-service && npm install

- name: Build feed-service
run: cd backend && cd feed-service && npm run build

- name: Build
run: cd backend && npm run build
- name: Install dependencies in product-service
run: cd backend && cd product-service && npm install

- name: Build product-service
run: cd backend && cd product-service && npm run build

- name: Install dependencies in scanner-service
run: cd backend && cd scanner-service && npm install

- name: Build scanner-service
run: cd backend && cd scanner-service && npm run build

test:
runs-on: ubuntu-latest
Expand All @@ -40,8 +64,14 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: cd backend && npm install
- name: Install dependencies in product-service
run: cd backend && cd product-service && npm install

- name: Test product-service
run: cd backend && cd product-service && npm test

- name: Install dependencies in scanner-service
run: cd backend && cd scanner-service && npm install

- name: Test
run: cd backend && npm test
- name: Test scanner-service
run: cd backend && cd scanner-service && npm test
165 changes: 140 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
- [🏃 Quick start](#-quick-start)
- [🛠️ Installation](#️-installation)
- [🧪 Testing](#-testing)
- [🚧 Development Environment](#-development-environment)
- [🌟 Frontend Documentation](#-frontend-documentation)
- [🏃 Quickstart](#-quickstart-1)
- [🛠️ Setup and Installation](#%EF%B8%8F-setup-and-installation)
Expand Down Expand Up @@ -66,13 +65,13 @@ All the code is located in the `backend/src` directory. The backend is written u
1. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

```bash
git clone [email protected]:techstartucalgary/fashion.git
git [email protected]:techstartucalgary/rethread.git
```

2. `cd` into the `fashion` directory.
2. `cd` into the `rethread` directory.

```bash
cd fashion
cd rethread
```

3. `cd` into the `backend` directory.
Expand All @@ -81,6 +80,78 @@ cd fashion
cd backend
```

4. `cd` into the microservice you want to work on. For example, if you want to work on the `product-service` microservice, run the following command.

```bash
cd product-service
```

5. Run `npm install` to install all the dependencies.

```bash
npm install
```

6. Run `docker compose -f docker-compose.dev.yml up` to start the database.

```bash
docker compose -f docker-compose.dev.yml up
```

7. Run `docker ps` to check if the database is running.

```bash
docker ps
```

8. If you see the database running then copy the `CONTAINER ID` of the database.

9. Run `docker exec -it <CONTAINER ID> bash` to enter the database.

```bash
docker exec -it <CONTAINER ID> bash
```

10. Run `mysql -u root -p` to enter the MySQL shell and enter the password as "root".

```bash
mysql -u root -p
```

11. Run `CREATE DATABASE product;` to create the database (So far the product and feed microservices need a database).

```bash
CREATE DATABASE product;

#or

CREATE DATABASE feed;
```

12. Run `exit` to exit the MySQL shell.

```bash
exit
```

13. Run `exit` to exit the docker container.

```bash
exit
```

14. Run `npx prisma migrate dev --name init` to create the database schema.

```bash
npx prisma migrate dev --name init
```

15. Run `npm run dev` to start the server.

```bash
npm run dev
```

### 🛠️ Installation

1. Make sure you have `Node.js` and `NPM` installed on your machine. Click [here](https://nodejs.org/en/) to download and install Node.js. Make sure you install the LTS version. NPM is installed automatically when you install Node.js.
Expand Down Expand Up @@ -113,44 +184,60 @@ git -v

### 🧪 Testing

All the tests are located in the `backend/test` directory. The tests suites are written using [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/).
All the tests are located in the `backend/test` directory. The tests suites are written using [Jest](https://jestjs.io/).

1. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

```bash
git clone [email protected]:techstartucalgary/fashion.git
git clone [email protected]:techstartucalgary/rethread.git
```

2. `cd` into the `backend` directory.
2. `cd` into the `rethread` directory.

```bash
cd rethread
```

3. `cd` into the `backend` directory.

```bash
cd backend
```

3. Run `npm install` to install all the dependencies.
4. `cd` into the microservice you want to test. For example, if you want to test the `product-service` microservice, run the following command.

```bash
cd product-service
```

5. Run `npm install` to install all the dependencies.

```bash
npm install
```

4. Run `npm run test` to start the server.
6. Run `npm test` to run the tests.

```bash
npm run test
npm test
```

### 🚧 Development Environment
7. If you see all the tests passing then you are good to go.

### 🚦 Linting

All the code is linted using [ESLint](https://eslint.org/). The configuration file is located in the `backend/.eslintrc.config.json` file.

1. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

```bash
git clone [email protected]:techstartucalgary/fashion.git
git clone [email protected]:techstartucalgary/rethread.git
```

2. `cd` into the `fashion` directory.
2. `cd` into the `rethread` directory.

```bash
cd fashion
cd rethread
```

3. `cd` into the `backend` directory.
Expand All @@ -165,26 +252,46 @@ cd backend
npm install
```

5. Run `npx prisma init` to initialize the database.
5. Run `npm run lint` to lint the code.

```bash
npm run lint
```

6. If you see no errors then you are good to go.

### 💅 Prettier

All the code is formatted using [Prettier](https://prettier.io/). The configuration file is located in the `backend/.prettierrc` file.

1. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

```bash
git clone [email protected]:techstartucalgary/rethread.git
```

2. `cd` into the `rethread` directory.

```bash
npx prisma init
cd rethread
```

3. `cd` into the `backend` directory.

```bash
cd backend
```

6. Update your `prisma/schema.prisma` file within the `backend` folder to use the `mysql` provider and set the relation mode type to `prisma`.
4. Run `npm install` to install all the dependencies.

```prisma
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
```bash
npm install
```

7. Once you are ready to push your schema to PlanetScale, run `prisma db push` against your PlanetScale database to update the schema in your database.
5. Run `npm run format` to format the code.

```bash
npx prisma db push
npm run format
```

# 🌟 Frontend Documentation
Expand All @@ -199,6 +306,10 @@ The frontend is crafted for iOS platforms, utilizing Swift and SwiftUI. The code
git clone [email protected]:techstartucalgary/fashion.git
```

```
```

2. **Navigate to the Frontend Directory**:

```bash
Expand Down Expand Up @@ -251,3 +362,7 @@ The frontend is crafted for iOS platforms, utilizing Swift and SwiftUI. The code
- **SwiftUI Tutorials**: Explore [SwiftUI Tutorials](https://developer.apple.com/tutorials/swiftui) for hands-on learning.

- **Apple Developer Forums**: Utilize [Apple Developer Forums](https://developer.apple.com/forums/) for community support.

```
```
22 changes: 0 additions & 22 deletions backend/.eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
# Keep environment variables out of version control
.env
dist
coverage
coverage
migrations
21 changes: 21 additions & 0 deletions backend/api-gateway/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events {
}

http {

server {
listen 80;

location /api/v1/product/ {
proxy_pass http://product-service:3000;
}

location /api/v1/feed/ {
proxy_pass http://feed-service:3001;
}

location /api/v1/scanner/ {
proxy_pass http://scanner-service:3002;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ version: "3"
services:
mysql:
image: mysql
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: rethread
ports:
- "3306:3306"
volumes:
Expand Down
Loading

0 comments on commit b9a80f4

Please sign in to comment.