RecNet-Api
Recnet-api is a backend API service for Recnet (opens in a new tab). Powered by Node.js and NestJS (opens in a new tab), it offers scalable solutions for paper recommendation, news feed system and academic social media network.
Requirements
- node >= 18
- PostgreSQL 16
Documentation
Local Development
Installation
pnpm install
Prepare environment variable
- Copy from sample file
cp apps/recnet-api/.env.sample apps/recnet-api/.env
- Modify environment variable
- Source the .env file
source apps/recnet-api/.env
Set up a local DB
- Use docker to create a PostgreSQL container.
# create and start
docker create --name recnet-postgres -p 5432:5432 -e POSTGRES_PASSWORD=admin postgres:16.2
docker start recnet-postgres
# stop and remove
docker stop recnet-postgres
docker rm recnet-postgres
- Dump the remote database to local
# if you don't have Postgres CLI, install libpq, postgresql first
brew install libpq # macOS
brew install postgresql@16 # macOS
# copy from sample file and modify the .env.dbdump.local
cp apps/recnet-api/scripts/.env.dbdump.sample apps/recnet-api/scripts/.env.dbdump.local
# dump the remote database to local
nx db:dump recnet-api
- Run Prisma Studio to see database at
localhost:5555
.
nx prisma:studio recnet-api
Run the server
nx serve recnet-api
DB Migration
How to generate migration files?
- Prepare a local database. Same as here.
- Modify
apps/recnet-api/prisma/prisma.schema
- Run migration script. The migration script will create a directory under
apps/recnet-api/prisma/migrations
withmigration.sql
anddown.sql
.
nx prisma:migrate recnet-api {migration_name}
How does the migration script been deployed to dev or production environment?
If the environment variable DB_MIGRATE=true
, the migration will be deployed when the server is up. It is executed by prisma.connection.provider.ts
.
Environment and Deployment
We currently maintain two environment - dev and prod. All of the services are deployed to AWS Elastic Beanstalk.
API host
- dev: https://dev-api.recnet.io/ (opens in a new tab)
- prod: https://api.recnet.io/ (opens in a new tab)
Deployment
We utilize AWS CodePipeline to build up the CI/CD for the services. Whenever the designated branch updates, the pipeline will deploy the code on that branch to the corresponding environment.
- dev branch: recnet-api-dev
- prod branch: master