# Monolith API Humand's main API that contains most of the business logic and platform functionalities. ## Description This monolithic service manages the main APIs, including public endpoints, administrative panels, events, and gRPC services. It implements the core business logic and handles communication with the database. ## Local Setup 1. Copy `.env.example` to `.env` and configure the necessary variables 2. Build monolith `pnpm nx run monolith:build` 3. Start the service using one of these methods: ### Start Methods #### Method 1: Integrated Build + Start Run `pnpm nx run monolith:serve` to start the service with hot reload enabled. This method is also available through Docker using the `compose.yml`. #### Method 2: Separate Build + Start Run these commands in parallel in separated terminals: - `pnpm nx run monolith:build:watch` - Once build is ready: `pnpm nx run monolith:start-local` ### Debugging #### Local Debugging (VSCode) Add this configuration to your launch.json: ```json { "type": "node", "request": "attach", "name": "Attach to Node 9229", "port": 9229, "skipFiles": ["/**"] } ``` #### Docker Debugging (VSCode) For debugging in Docker, use this configuration: ```json { "name": "Docker: Attach to Node 9229", "type": "node", "request": "attach", "remoteRoot": "/usr", "localRoot": "${workspaceFolder}", "address": "localhost", "port": 9229, "restart": true, "timeout": 60000, "sourceMaps": true, "outFiles": ["${workspaceFolder}/humand-packages/**/build/**/*.js"], "skipFiles": ["/**"] } ``` ## Main Endpoints The service exposes different types of endpoints: - Public API - Admin panel - Event endpoints - gRPC services ## Available Scripts - **Build the project**: `pnpm nx build monolith` - **Run unit tests**: `pnpm nx test monolith` - **Run integration tests**: `pnpm nx test-integration monolith` - **Run linting**: `pnpm nx lint monolith` ## Setting Up Local Environment with Docker 1. Install Docker. 2. Set the following environment variables: * DB_NAME=humand_dev * DB_USER=humand_user * DB_PASSWORD=humand_password * DB_HOST=db * DB_PORT=5432 3. If it's your first time, you need to load a test db dump into the local db to have data to work with: 1. Run the command `docker compose -f compose.yml up db` in the repo root. 2. Install pg_dump and psql (both are found in the libpq package). 3. Run the command `/path/to/executable/pg_dump --file=/path/to/dump/humand_test_dump.sql --dbname=dbname --username=username --host=host --port=port --no-privileges --disable-triggers`. 4. Enter the test db password. 5. Run the command `/path/to/executable/psql --file=/path/to/dump/humand_test_dump.sql --username=humand_user --host=localhost --port=5432 humand_dev`. 6. Stop the db (ctrl+c). ## gRPC Configuration To use services that utilize the gRPC protocol, you need to set up two things: - Install protobuf to generate libraries. - On MacOS, run the following command: `brew install protobuf` - Set environment variables to access the service: - For the analytics service: `ANALYTICS_SERVICE_ADDRESS` - For the notifications service: `NOTIFICATIONS_SERVICE_ADDRESS` - For the bamboo service: `BAMBOO_SERVICE_ADDRESS` - For the desert eagle service: `DESERT_EAGLE_SERVICE_ADDRESS` - For the cerberus service: `CERBERUS_SERVICE_ADDRESS` - To create the library corresponding to the protobuf file (these files are in the `protos` folder), you can either: * Use the NX target: `pnpm nx run monolith:build-proto` * Or run the script directly: `./build-proto.sh` In the local development environment, these libraries created by running this command are injected into the docker container using the `./api` mount. * If you don't have execution permissions set, use: `chmod +x ./build-proto.sh` * If the command doesn't work, check that you have all libraries installed. `pnpm install`