Skip to content

ELEVATE-Project/user

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0e825a0 · Mar 19, 2024
Jan 5, 2023
Jan 10, 2024
Jan 25, 2024
Jan 10, 2024
Mar 19, 2024
Jan 9, 2023
Nov 28, 2023
May 24, 2022
May 24, 2022
Aug 25, 2022
Jan 24, 2024
Sep 20, 2023
Jan 12, 2023
Nov 25, 2022
Nov 14, 2022

Repository files navigation

User Service

CircleCI Duplicated Lines (%) Coverage Vulnerabilities Prettier Docs Docs

GitHub package.json version (subfolder of monorepo) License

CircleCI insights

CircleCI

dev

CircleCI GitHub package.json version (subfolder of monorepo)

CircleCI


The Mentoring building block enables effective mentoring interactions between mentors and mentees. The capability aims to create a transparent eco-system to learn, connect, solve, and share within communities.MentorED is an open source mentoring application that facilitates peer learning and professional development by creating a community of mentors and mentees.

Setup Options

Elevate user services can be setup in local using two methods:

Dockerized service with local dependencies(Intermediate)

Expectation: Run single docker containerized service with existing local (in host) or remote dependencies.

Local Dependencies Steps

  1. Update dependency (Mongo v4.1.4, Kafka etc) IP addresses in .env with "host.docker.internal".

    Eg:

     #MongoDb Connectivity Url
     MONGODB_URL = mongodb://host.docker.internal:27017/elevate-mentoring
    
     #Kafka Host Server URL
     KAFKA_URL = host.docker.external:9092
    
  2. Find host.docker.internal IP address and added it to mongod.conf file in host.

    Eg: If host.docker.internal is 172.17.0.1, mongod.conf:

    # network interfaces
    net:
        port: 27017
        bindIp: "127.0.0.1,172.17.0.1"
    

    Note: Steps to find host.docker.internal IP address & location of mongod.conf is operating system specific. Refer this for more information.

  3. Build the docker image.

    /ELEVATE/user$ docker build -t elevate/user:1.0 .
    
  4. Run the docker container.

    • For Mac & Windows with docker v18.03+:

      $ docker run --name user elevate/user:1.0
      
    • For Linux:

      $ docker run --name user --add-host=host.docker.internal:host-gateway elevate/user:1.0`
      

      Refer this for more information.

Remote Dependencies Steps

  1. Update dependency (Mongo v4.1.4, Kafka etc) Ip addresses in .env with respective remote server IPs.

    Eg:

     #MongoDb Connectivity Url
     MONGODB_URL = mongodb://10.1.2.34:27017/elevate-mentoring
    
     #Kafka Host Server URL
     KAFKA_URL = 11.2.3.45:9092
    
  2. Add Bind IP to mongod.conf in host:

    Follow instructions given here.

    Note: Instructions might differ based on MongoDB version and operating system.

  3. Build the docker image.

    /ELEVATE/user$ docker build -t elevate/user:1.0 .
    
  4. Run the docker container.

    $ docker run --name user elevate/user:1.0
    
Local Service with local dependencies(Hardest)

Expectation: Run single service with existing local dependencies in host (Non-Docker Implementation).

Steps

  1. Install required tools & dependencies

    Install any IDE (eg: VScode)

    Install Nodejs: https://nodejs.org/en/download/

    Install MongoDB: https://docs.mongodb.com/manual/installation/

    Install Robo-3T: ​​ https://robomongo.org/

  2. Clone the User service repository.

    git clone https://github.com/ELEVATE-Project/user.git
    
  3. Add .env file to the project directory

    Create a .env file in src directory of the project and copy these environment variables into it.

    #User Service Config
    
    # Port on which service runs
    APPLICATION_PORT = 3000
    
    # Service environment
    APPLICATION_ENV = development
    
    # Database connectivity url
    MONGODB_URL = mongodb://localhost:27017/db-name
    
    # Token secret to generate access token
    ACCESS_TOKEN_SECRET = 'access-token-secret'
    
    # Token secret to generate refresh token
    REFRESH_TOKEN_SECRET = 'refresh-token-secret'
    
    # Kafka hosted server url
    KAFKA_URL = localhost:9092
    
    # Kafka group to which consumer belongs
    KAFKA_GROUP_ID = userservice
    
    # Kafka topic to consume data from
    KAFKA_TOPIC = 'topic'
    
    # Kafka topic to push notification data
    NOTIFICATION_KAFKA_TOPIC = notificationtopic
    
    # Any one of three features available for cloud storage
    CLOUD_STORAGE = 'GCP/AWS/AZURE'
    
    # Gcp json config file path
    GCP_PATH = 'gcp.json'
    
    # Gcp bucket name which stores files
    DEFAULT_GCP_BUCKET_NAME = 'gcp-bucket-storage-name'
    
    # Gcp project id
    GCP_PROJECT_ID = 'project-id'
    
    # Aws access key id
    AWS_ACCESS_KEY_ID = 'aws-access-key-id'
    
    # Aws secret access key
    AWS_SECRET_ACCESS_KEY = 'aws-secret-access-key'
    
    # Aws region where bucket will be located
    AWS_BUCKET_REGION = 'ap-south-1'
    
    # Aws end point
    AWS_BUCKET_ENDPOINT = 's3.ap-south-1.amazonaws.com'
    
    # Aws bucket name which stores files
    DEFAULT_AWS_BUCKET_NAME = 'aws-bucket-storage-name'
    
    # Azure storage account name
    AZURE_ACCOUNT_NAME = 'account-name'
    
    # Azure storage account key
    AZURE_ACCOUNT_KEY = 'azure-account-key'
    
    # Azure storage container which stores files
    DEFAULT_AZURE_CONTAINER_NAME = 'azure-container-storage-name'
    
    # Internal access token for communicationcation between services via network call
    INTERNAL_ACCESS_TOKEN = 'internal-access-token'
    
    # JWT Access Token expiry In Days
    ACCESS_TOKEN_EXPIRY = '1'
    
    # JWT Refresh Token expiry In Days
    REFRESH_TOKEN_EXPIRY = '183'
    
    # Redis Host connectivity url
    REDIS_HOST = 'redis://localhost:6379'
    
    # Otp expiration time for forgetpassword or registration process
    OTP_EXP_TIME = 86400
    
    # Enable email based otp verification for registration process
    ENABLE_EMAIL_OTP_VERIFICATION = true
    
    # Api doc url
    API_DOC_URL = '/api-doc'
    
  4. Start MongoDB locally

    Based on your host operating system and method used, start MongoDB.

  5. Install Npm packages

    ELEVATE/user/src$ npm install
    
  6. Start User server

    ELEVATE/user/src$ npm start
    

Tech stack

  • Node - 16.0.0
  • Kafka - 3.1.0
  • Jest - 28.1.1
  • MongoDB - 4.1.4
  • Redis - 7.0.0

Migrations Commands

Check migrations

npm run elevate-migrations s

Create migrations

npm run elevate-migrations create categoryEntity #Where categoryEntity is the file name.
20220726145008-categoryEntity.js

We have followed the following structure for migration files to reduce code duplication.

let categories = [
	{
		value: 'sqaa',
		label: 'SQAA',
		image: 'entity/SQAA.jpg',
	},
	{
		value: 'communication',
		label: 'Communication',
		image: 'entity/Communication.png',
	},
    ...
]
var moment = require('moment')

module.exports = {
	async up(db) {
		global.migrationMsg = 'Uploaded categories entity'
		let entityData = []
		categories.forEach(async function (category) {
			category['status'] = 'ACTIVE'
			category['deleted'] = false
			category['type'] = 'categories'
			category['updatedAt'] = moment().format()
			category['createdAt'] = moment().format()
			category['createdBy'] = 'SYSTEM'
			category['updatedBy'] = 'SYSTEM'
			entityData.push(category)
		})
		await db.collection('entities').insertMany(entityData)
	},

	async down(db) {
		db.collection('entities').deleteMany({
			value: { $in: categories.map((category) => category.value) },
		})
	},
}

Run migrations

npm run elevate-migrations up

Down migrations

npm run elevate-migrations down

To know more about migrations refer project Wiki

Run tests

Integration tests

npm run test:integration

To know more about integration tests and their implementation refer to the project Wiki.

Unit tests

npm test

Used in

This project was built to be used with Mentoring Service.

Notification service repo can be found here.

The frontend/mobile application repo.

You can learn more about the full implementation of MentorEd here .

Team


Open Source Dependencies

Several open source dependencies that have aided user service development:

NodeJS MongoDB Apache Kafka Redis Jest Git