This is the PL Network backend built with Nest, Prisma, and PostgreSQL. The parent project is generated using Nx. Check the docs to learn more.
It is set up in monorepo (soon will be revamped to single microservice pattern) fashion currently hosting directory backend and directory frontend for admin (soon will be revamped).
The actual frontend for directory has been moved here.
The folder structure of this project is organized as follows:
- apps/web-api: Contains the actual backend service
- apps/web-api/prisma: Contains the database schema and migration files
- libs/contracts: Contains the API contracts
Before running this project, ensure the following software is installed on your system:
-
Docker
Docker is essential for containerizing the application, making it easier to manage dependencies and deployments.
Install Docker -
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications, which allows for easier orchestration of containers.
Install Docker Compose -
PostgreSQL
PostgreSQL is the primary database used in this project. Make sure to have it installed and configured, or use the Docker image provided in thedocker-compose.yml
file.
Install PostgreSQL -
Redis
Redis is used for caching, which improves performance and scalability. You can also run Redis as a Docker container if you prefer.
Install Redis -
Node.js
Node.js is the JavaScript runtime for server-side scripting in this project. Ensure that a compatible version is installed.
Install Node.js -
npm (Node Package Manager) and Yarn
npm is included with Node.js and is used for installing dependencies and managing packages.
Learn about npm Install Yarn -
NestJS
NestJS is a framework for building efficient, reliable, and scalable server-side applications. It is the primary framework used in this project.
Learn about NestJS -
Prisma
Prisma is an ORM (Object-Relational Mapper) used for interacting with the database in a type-safe way.
Learn about Prisma -
Zod
Zod is a TypeScript-first schema validation library used for data validation.
Learn about Zod
The application is set to send all the logs to Cloudwatch logs. If you have your own AWS access and secret keys with Cloudwatch permissions, you can configure them in .env
.
If you do not want to log in CloudWatch or do not have the necessary AWS keys, you can set LOG_ENV=local
.
Name | Type | Purpose | Mandatory |
---|---|---|---|
Privy | External | The hybrid auth solution provider for users to login | Yes, for local we have already provided you with a client id, just use that |
AWS Cloudwatch logs | External | To store logs | No |
AWS S3 | External | To store runtime images like profile pictures | Yes (You can skip it for local development but you will not be able to upload profile images) |
AWS SES | External | To send email notifications | Yes, but you can skip in local by disabling email in .env |
PL Auth service | Internal | To manage user auth requests and issue tokens, works in OAuth 2.0 standard | Yes, for local we have provided you with sandbox url |
Google API | External | For location-based services | Yes |
Forestadmin | External | To manage data directly from/to database. The admin panel for the database | No |
Github API Key | External | To get information about projects from Github repo | Yes |
$ yarn install
Install Docker and Docker Compose.
Then run:
$ docker-compose up -d
Once this is done, you will have your Postgres and Redis running through Docker and they will be up and running based on the following configurations:
- Sample values through which Docker will run Postgres and Redis:
DB_HOST_PORT=19432 DB_USER=postgres DB_PASSWORD=postgres DB_NAME=plnetwork_dev DATABASE_URL=postgresql://postgres:postgres@localhost:19432/plnetwork_dev REDIS_HOST=localhost REDIS_PORT=6379
- Create the environment variables file:
# ~/protocol-labs-network cp .env.example .env
ENVIRONMENT=development
-
Generate a Github personal access token:
GITHUB_API_KEY=
-
Make sure it has permission to read and write from the provided S3 bucket (If you do not have aws keys, leave it assuming you will not be uploading any profile images):
AWS_ACCESS_KEY= AWS_SECRET_KEY=
-
Must be a public bucket: (Leave it if you do not have any)
AWS_S3_BUCKET_NAME=
-
Set to false if you do not have aws keys with ses permission
IS_EMAIL_ENABLED=false
$ npx prisma generate --schema=./apps/web-api/prisma/schema.prisma
$ npx prisma db push --schema=./apps/web-api/prisma/schema.prisma
⚠ Keep in mind that running the following command completely wipes the database before inserting any mock data.
ℹ Before running the following command, make sure that your database is in sync with your Prisma schema.
$ yarn nx seed web-api
Go to the parent folder:
$ yarn nx serve web-api
The API documentation is available at the following URL:
Visit this link to explore the API endpoints, parameters, and responses.
$ yarn nx build web-api --configuration=production
$ yarn nx run web-api:test
To ensure code reliability and functionality, we use the Jest framework for writing and running test cases. Jest provides a robust environment for unit and integration testing, helping maintain the quality and stability of the application.
$ yarn nx run web-api:lint
This app is used by admin to approve/reject/edit - members and teams join requests
Set the following environment variables for the back office app:
WEB_API_BASE_URL
- Directory Backend API URL configured above. (for local development, use: http://localhost:, where PORT is the variable configured in .env file from the above steps. Eg. http://localhost:3000, where PORT=3000)ADMIN_LOGIN_USERNAME
- Back Office Application Login Username (Set the username you want to use for logging in to the back office app)ADMIN_LOGIN_PASSWORD
- Back Office Application Login Password (Set the password you want to use for logging in to the back office app)
$ yarn nx serve back-office
Application will be available at http://localhost:4201, port 4201 is set in project.json file in back-office app.
Use the username and password you set in the environment variables above to log in to the back office app.
Refer [here] (./docs/GUIDELINES_COMMIT.md)
Refer
And give a PR to develop branch and our team will review and approve it.