This project is a sales dashboard for Lennar, a leading homebuilder in the US. It is designed to provide a comprehensive view of sales data, enabling users to track performance, identify trends, and make data-driven decisions. The dashboard is built with Node.js, and uses a Snowflake database for data storage.
The project is divided into two main parts: the backend and the frontend. The backend is responsible for fetching, processing, and serving data from the Snowflake database. The frontend is a web application that presents the data in a user-friendly format.
node18.x- It's recommended to use nvm for this.
Install with
brew install nvmand then runnvm usein the root directory of this repo.
- It's recommended to use nvm for this.
Install with
npm8.x- If you used
nvm, this should be set up for you after runningnvm use.
- If you used
git
Follow these steps to set up the backend:
- Clone the repository using
git clone. - Navigate to the server directory and copy the example environment file to a new
.envfile:cd server && cp .env.example .env. - Update the environment variables in
.envwith your Snowflake credentials. - Install the necessary dependencies with
npm i. - Build the project with
npm run build. - Fetch the cache data from Snowflake with
npm run start-cron:now. - Start the backend server with
npm start.
Follow these steps to set up the frontend:
- In the root folder, copy the example environment file to a new
.envfile:cp .env.example .env. - Update the environment variables in
.envas necessary. - Install the necessary dependencies with
npm i. - Start the local development server with
npm start.
- Connect the servers using the credentials provided by DSS Team.
-
Dev Server:
ssh {username}@10.252.15.19 -
Prod Server:
ssh {username}@10.76.137.10Note:
- The repository is cloned in
/opt/node/projectsfolder. - DNS Certificates are located in
/opt/node/projects/cert_files. - We use hosting service - Nginx and pm2 for Node.js Process Manager
- The repository is cloned in
-
To update the project, navigate to the project folder and pull the latest changes (you can skip this step if only restarting processes is required).
cd /opt/node/projects/corp_hub git pull -
If you need to rebuild server bundles (you can skip this step if only restarting processes is needed):
cd server npm run build cd .. npm run build
-
To restart all registered pm2 processes, run:
pm2 resurrect
We have two main processes running in the background: one for the Rest API and one for CronJob.
- CronJob
To handle the high-volume data load in each connection request to Snowflake, we've implemented a cache that stores JSON files in ./server/dist/cache. This cache fetches data every 30 minutes, starting at every 00 and 30 minutes.
- Rest APIs
The Rest API serves data to the frontend through the API. KPI data is retrieved from the cached JSON file stored by the CronJob.
GET /api/cohorts: Fetch the list of divisions.GET /api/metrics: Retrieve tooltips for KPI labels.GET /api/data: Get analytics data from the cached JSON file.
The frontend is developed using Create-React-App, and we use Mapbox as a third-party service.
Important Notes:
- Ensure the API base URL is correctly configured in the .env file.
- The Backend API process should already be running.
- Configure the Mapbox access token in the .env file. You can obtain free Mapbox access tokens by signing up at Mapbox Studio. Free-tier tokens are sufficient for development; avoid using free-tier keys in production.