Skip to main content

Local Development Environment

This document describes how to set up a complete development environment (Server, Client, Mobile) on your personal computer.

Prerequisites​

Infrastructure Setup​

We use Docker Compose to run the core services (MongoDB, Redis, Mosquitto).

  1. In the project root directory, run:
    docker-compose up -d
    This command will start the following services:
    • MongoDB: port 27017
    • Redis: port 6380
    • Mosquitto (MQTT): port 1883 (standard) and 9001 (WebSockets)
    • Nginx & Grafana: (optional, for monitoring)

Environment Variables Setup (.env)​

Create .env files according to the templates in the various directories:

Server NestJS (server-nest/.env)​

DATABASE_URL=mongodb://root:MONGO_ROOT_PASSWORD@localhost:27017/bt-management?authSource=admin
REDIS_URL=redis://:REDIS_PASSWORD@localhost:6380
JWT_SECRET=YOUR_SECRET_KEY
MQTT_BROKER_URL=mqtt://localhost:1883

Client (client/.env)​

REACT_APP_API_URL=http://localhost:5000/api

Mobile (GabaiSmart/.env)​

EXPO_PUBLIC_API_URL=http://192.168.1.X:5000  # Your local machine IP address
EXPO_PUBLIC_SOCKET_URL=ws://192.168.1.X:5000

Running the Projects​

1. Server (NestJS)​

cd server-nest
npm install
npx prisma generate # Generate Prisma Client
npm run start:dev # Run in Watch mode

The server will be available at: http://localhost:5000 API documentation (Swagger): http://localhost:5000/api/docs

2. Client (React)​

cd client
npm install
npm start

The application will open at: http://localhost:3000

3. Mobile (GabaiSmart React Native)​

cd GabaiSmart
npm install
npm run android # Run on emulator or connected device

Useful Commands​

  • Prisma Studio: View and manage the DB in a graphical interface.
    cd server-nest && npx prisma studio
  • Type Check: Type checking across the entire project.
    npm run typecheck:all

Workflows and Procedures​

  • Commit Checklist: Before pushing code, ensure you've run typecheck and there are no linter errors.
  • DTOs: Always use nestjs-zod for creating DTOs.
  • Migrations: MongoDB doesn't have classic SQL migrations, but you should run db push if you significantly change the schema sometimes (although Prisma-Mongo is flexible).
  • Multi-Tenancy: Never manually add where: { userId } in regular controllers. The Middleware does this automatically.