diff --git a/README.md b/README.md index 9c14d55..4fb92b4 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,17 @@ # Decentralised Skilling and Education Protocol: Trainings and Courses - This doc underlines the architectural implementational details of reference **Beckn Provider Platform (BPP)** implementation for the **Courses and Training** track complaint to **DSEP spec v1.0.0.** ### Deployment and Network Registration Details -which is onboarded on the `Beckn Gateway` and `Beckn Gateway Registry` under the `Courses and Trainings` category. +The reference BPP implemented in this repository is onboarded on the `Beckn Gateway` and `Beckn Gateway Registry` under the `Courses and Trainings` category. - [**BPP Deployed URL**](https://bpp.dsep.samagra.io) - [**BAP Deployed URL**](https://bap.dsep.samagra.io) - **BPP Network Participant Id**: bpp.dsep.samagra.io - [Network Participant Information on Beckn Registry](https://registry.becknprotocol.io/network_participants/index/network_participants/show/430) - -## Tech Stack +## Tech Stack **Programming Language**: TypeScript **Framework**: NestJS @@ -22,10 +20,11 @@ which is onboarded on the `Beckn Gateway` and `Beckn Gateway Registry` under the ## Project Organisation -This reference implementation contains all three network participants, i.e. **Beckn Provider Platform**, **Beckn Gateway**, **Beckn Provider Platform**, organised as a **NestJS Monorepo**. +This reference implementation contains all three network participants, i.e. **Beckn Provider Platform**, **Beckn Gateway**, **Beckn Provider Platform**, organised as a **NestJS Monorepo**. ### Directory structure -``` + +```bash . ├── apps │   ├── bap @@ -51,6 +50,7 @@ The `apps` directory contains the actual apps for each network participant `apps/bap` and `apps/bg` contains the code for a sample `Beckn Application Platform` and `Beckn Gateway` respectively for testing the `Beckn Provider Platform`. More details about each network participant and their implementation can be found their following directories here as: + - [Beckn Application Platform (BAP)](https://github.com/Samagra-Development/dsep/blob/master/apps/bap/README.md) - [Beckn Gateway(BG)](https://github.com/Samagra-Development/dsep/blob/master/apps/bg/README.md) - [Beckn Provider Platform (BPP)](https://github.com/Samagra-Development/dsep/blob/master/apps/bpp/README.md) @@ -59,12 +59,13 @@ More details about each network participant and their implementation can be foun ![Block Diagram](./docs/Arch.png) +## Features & User workflow + The reference app is a **Course Discovery Platform** that talks in **Decentralised Skilling and Education Protocol** and curates courses from various providers like, **Swayam Portal**, **MIT OCW**, **Udemy**, etc., right now only swayam is onboarded as a provider, other platforms can be easily onboarded onto the BPP. The `/search` request is forwarded to the `Beckn Gateway` with the domain of `dsep:courses` so that reaches our reference `BPP`. The `BPP` then forwards the `search` request to the `Swayam Provider Wrapper` which translates the `Beckn` compliant search request into a search query compatible to be forwarded to the `Swayam Portal` and fetches the result from there. The fetched results are then again converted in `Beckn /on_search` compliant response and forwarded to the `BPP`, which then calls the `/on_back` endpoint on the `bap_uri` present in the search requests's `context`. The sample `BAP` implementation for the demonstration of end to end flow right now, forwards the request to the `client proxy` which determines which client the request belongs to based on the `message_id` and `transaction_id` in the context of the `on_search` request and forwards the response to the concerned client. The `client` and `client proxy` are connected together via a websocket connection using `redis` and `socket.io` to create a `publish-subscribe` model to support the **asynchronous nature** of `Beckn APIs`. (To learn more about the Beckn APIs and their structure refer the [official Beckn Protocol Website](https://https://becknprotocol.io/)) - ### Supported Methods **/search:** This method/endpoint allows for searching of courses and training via a direct DSEP complaint request to the BPP using the context.domain as `dsep:courses` @@ -80,39 +81,53 @@ The `client` and `client proxy` are connected together via a websocket connectio Follow the following steps to setup the monorepo locally on your system. 1. Clone the repository + ```bash git clone https://github.com/Samagra-Development/dsep ``` + 2. Navigate into the directory where you have cloned the repository - ```bash - cd /path/to/cloned/repository - ``` + +```bash +cd /path/to/cloned/repository +``` + 3. Install the required dependencies using the package manager of your choice (yarn preferred). + ```bash yarn install ``` + 4. Create a `.env` file similar to the `.env,sample` file and populate it with required credentials 5. [Install Docker](https://docs.docker.com/engine/install/), [Install Docker Compose](https://docs.docker.com/compose/install/linux/), and run + ```bash docker compose up ``` + 6. Navigate to your hasura UI which will be started after running the command in `Step 5` and create a table named `dsep_courses`. 7. Run the services for the required network participant using the following commands + ```bash yarn start # replace with a single name # for example: yarn start bpp will start the BPP ``` + Or start all of them together using ```bash yarn start:all # this will start all the services - ``` +``` ## Deployment + 1. [Install Docker](https://docs.docker.com/engine/install/), [Install Docker Compose](https://docs.docker.com/compose/install/linux/), and run + ```bash docker compose up ``` + 2. PM2 Based Deployment + ```bash yarn build pm2 start dist/apps/bpp/main.js --name beckn-bpp @@ -121,17 +136,21 @@ Or start all of them together using ``` ## Related Repositories + - [Mock Provider (Swayam)](https://github.com/Samagra-Development/swayam-wrapper) - [BAP Client Proxy](https://github.com/Samagra-Development/dsep-ui/tree/master/apps/client-proxy) - Acts as a service connecting Client and Proxy - [BAP Client](https://github.com/Samagra-Development/dsep-ui) - A course search page ## Adding Services to Beckn Registry + Follow [this guide](https://github.com/sanjay95/BECKN-Integration-to-Gateway/blob/main/README.md) to onboard yourself on the Beckn Registry. ## Resources to know more about DSEP and Beckn + - [Beckn Official Website](https://becknprotocol.io) - [Core DSEP Specification](https://github.com/beckn/protocol-server/blob/v2/schemas/core.yaml) ## Stay in touch + - Author: [Yash Mittal](https://github.com/techsavvyash) - Mentor on the project: [Chakshu Gautam](https://github.com/ChakshuGautam) diff --git a/apps/bpp/src/confirm/confirm.service.ts b/apps/bpp/src/confirm/confirm.service.ts index e7322fc..9940962 100644 --- a/apps/bpp/src/confirm/confirm.service.ts +++ b/apps/bpp/src/confirm/confirm.service.ts @@ -54,7 +54,7 @@ export class ConfirmService { return await lastValueFrom( this.httpService.post( - confirmResponse.context.bap_uri + '/on_select', + confirmResponse.context.bap_uri + 'on_confirm', confirmResponse, requestOptions, ), diff --git a/apps/bpp/src/init/init.service.ts b/apps/bpp/src/init/init.service.ts index 03bff56..160c30f 100644 --- a/apps/bpp/src/init/init.service.ts +++ b/apps/bpp/src/init/init.service.ts @@ -48,7 +48,7 @@ export class InitService { return await lastValueFrom( this.httpService.post( - initResponse.context.bap_uri + '/on_init', + initResponse.context.bap_uri + 'on_init', initResponse, requestOptions, ), diff --git a/apps/bpp/src/search/search.service.ts b/apps/bpp/src/search/search.service.ts index 216fb67..8b174fc 100644 --- a/apps/bpp/src/search/search.service.ts +++ b/apps/bpp/src/search/search.service.ts @@ -45,7 +45,7 @@ export class SearchService { console.log('calling request forwarder'); await lastValueFrom( this.httpService.post( - searchDto.context.bap_uri + '/on_search', + searchDto.context.bap_uri + 'on_search', searchResponse, requestOptions, ), diff --git a/apps/bpp/src/select/select.service.ts b/apps/bpp/src/select/select.service.ts index 3c87ab2..424611a 100644 --- a/apps/bpp/src/select/select.service.ts +++ b/apps/bpp/src/select/select.service.ts @@ -47,7 +47,7 @@ export class SelectService { return await lastValueFrom( this.httpService.post( - selectResponse.context.bap_uri + '/on_select', + selectResponse.context.bap_uri + 'on_select', selectResponse, requestOptions, ), diff --git a/yarn.lock b/yarn.lock index d3c7285..e317aba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1881,6 +1881,21 @@ concat-stream@^1.5.2: readable-stream "^2.2.2" typedarray "^0.0.6" +concurrently@^7.4.0: + version "7.6.0" + resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-7.6.0.tgz#531a6f5f30cf616f355a4afb8f8fcb2bba65a49a" + integrity sha512-BKtRgvcJGeZ4XttiDiNcFiRlxoAeZOseqUvyYRUp/Vtd+9p1ULmeoSqGsDA+2ivdeDFpqrJvGvmI+StKfKl5hw== + dependencies: + chalk "^4.1.0" + date-fns "^2.29.1" + lodash "^4.17.21" + rxjs "^7.0.0" + shell-quote "^1.7.3" + spawn-command "^0.0.2-1" + supports-color "^8.1.0" + tree-kill "^1.2.2" + yargs "^17.3.1" + consola@^2.15.0: version "2.15.3" resolved "https://registry.yarnpkg.com/consola/-/consola-2.15.3.tgz#2e11f98d6a4be71ff72e0bdf07bd23e12cb61550" @@ -1963,6 +1978,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" +date-fns@^2.29.1: + version "2.29.3" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8" + integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA== + debug@2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -4150,6 +4170,13 @@ rxjs@6.6.7, rxjs@^6.6.0: dependencies: tslib "^1.9.0" +rxjs@^7.0.0: + version "7.8.0" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.0.tgz#90a938862a82888ff4c7359811a595e14e1e09a4" + integrity sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg== + dependencies: + tslib "^2.1.0" + rxjs@^7.2.0, rxjs@^7.5.5: version "7.5.7" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.7.tgz#2ec0d57fdc89ece220d2e702730ae8f1e49def39" @@ -4246,6 +4273,11 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +shell-quote@^1.7.3: + version "1.8.0" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.0.tgz#20d078d0eaf71d54f43bd2ba14a1b5b9bfa5c8ba" + integrity sha512-QHsz8GgQIGKlRi24yFc6a6lN69Idnx634w49ay6+jA5yFh7a1UY+4Rp6HPx/L/1zcEDPEij8cIsiqR6bQsE5VQ== + shelljs@0.8.5: version "0.8.5" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c" @@ -4335,6 +4367,11 @@ sourcemap-codec@^1.4.8: resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== +spawn-command@^0.0.2-1: + version "0.0.2-1" + resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0" + integrity sha512-n98l9E2RMSJ9ON1AKisHzz7V42VDiBQGY6PB1BwRglz99wpVsSuGzQ+jOi6lFXBGVTCrRpltvjm+/XA+tpeJrg== + sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -4453,7 +4490,7 @@ supports-color@^7.0.0, supports-color@^7.1.0: dependencies: has-flag "^4.0.0" -supports-color@^8.0.0: +supports-color@^8.0.0, supports-color@^8.1.0: version "8.1.1" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== @@ -4570,7 +4607,7 @@ tr46@~0.0.3: resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== -tree-kill@1.2.2: +tree-kill@1.2.2, tree-kill@^1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc" integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==