# Bigscreen Cloud Development Setup

This guide explains how to run the full stack development environment for Bigscreen Cloud.

## Prerequisites

- Node.js (v18+ recommended)
- Yarn package manager
- Redis server running locally
- PostgreSQL database (for admin_api)

## Installation

First, install all dependencies:

```bash
yarn run install-dev-deps
```

This will install dependencies in both the root and the webapps directory.

## Development Mode

To start all services in development mode with file watching and hot reload:

```bash
yarn dev
```

This starts all 7 services concurrently:

1. **admin-api** - Admin API server (`apps/admin_api/admin_api.ts`)
2. **api** - Main API server (`apps/api/api.ts`) 
3. **cloud-api** - Cloud API server (`cloud/cloud_api/cloud_api.ts`)
4. **cloud-worker** - Cloud worker service (`cloud/cloud_worker/cloud_worker.ts`)
5. **ws-server** - WebSocket server (`cloud/ws_server/ws_server.ts`)
6. **arda-server** - Arda web application (`webapps/arda/arda.js`)
7. **arda-webpack** - Webpack build watcher (`webapps/arda/`)

Each service will:
- Automatically restart when relevant files change
- Watch shared dependencies (lib, auth, api modules)
- Use different colors in the console output for easy identification
- Include TypeScript compilation and path resolution

## Individual Services

You can also start services individually:

```bash
# Start individual services in development mode (with file watching)
yarn dev:admin-api
yarn dev:api
yarn dev:cloud-api
yarn dev:cloud-worker
yarn dev:ws-server
yarn dev:arda-server
yarn dev:arda-webpack

# Start individual services once (no file watching)
yarn start:admin-api
yarn start:api
yarn start:cloud-api
yarn start:cloud-worker
yarn start:ws-server
yarn start:arda
yarn webpack:arda
```

## File Watching

The development setup watches for changes in:

- **TypeScript services**: Watch their own directories plus shared modules (`lib/src`, `auth/src`, `api/src`, `cloud/src`)
- **Arda server**: Watches `webapps/arda/` (JavaScript files)
- **Arda webpack**: Watches and rebuilds frontend assets automatically

## Configuration Files

- `nodemon.*.json` - Individual nodemon configurations for each service
- `webapps/arda/webpack.config.js` - Webpack configuration with watch mode enabled

## Ports

The services typically run on these ports (check the actual service files for current configurations):

- Admin API: Usually port 3010
- Main API: Usually port 3009  
- Cloud API: Check cloud_api.ts
- WebSocket Server: Check ws_server.ts
- Arda Web App: Check arda.js

## Logs

Each service is prefixed with a colored label in the console output:
- `admin-api` (red)
- `api` (green)  
- `cloud-api` (blue)
- `cloud-worker` (yellow)
- `ws-server` (magenta)
- `arda-server` (cyan)
- `arda-webpack` (white)

## Troubleshooting

1. **Port conflicts**: Check if the required ports are available
2. **Redis connection**: Ensure Redis is running on localhost:6379
3. **Database issues**: Ensure PostgreSQL is running and accessible
4. **Dependencies**: Run `yarn install-dev-deps` if packages are missing
5. **TypeScript errors**: Run `yarn build` to check for compilation issues

## Environment Variables

Make sure you have the necessary `.env` files in place:
- Root `.env` for shared configuration
- Individual service `.env` files as needed

Note: `.env` files are ignored by git for security reasons.