# Mainroom - Orchestration Layer

## Purpose

Mainroom orchestrates **soleprint + managed rooms** together (e.g., amar).

Key principle: Connect soleprint to managed apps **without modifying either side**.

## Structure

```
mainroom/
├── amar -> ../cfg/amar    # Symlink to room config
├── soleprint/             # Soleprint Docker config
│   ├── docker-compose.yml
│   ├── docker-compose.nginx.yml
│   └── .env
├── sbwrapper/             # Sidebar wrapper UI
│   ├── config.json        # Room-specific (users, Jira)
│   ├── sidebar.js
│   └── sidebar.css
└── ctrl/                  # Orchestration scripts
    ├── start.sh           # Start all services
    ├── stop.sh
    ├── deploy.sh          # Deploy to AWS
    └── server/            # AWS setup scripts
```

## Usage

### Local Development
```bash
# First, build soleprint
cd spr/
python build.py dev --cfg amar

# Create shared network
docker network create soleprint_network

# Start everything
cd mainroom/ctrl
./start.sh -d              # Detached
./start.sh                 # Foreground (logs)
./start.sh amar            # Only amar
./start.sh soleprint       # Only soleprint
./stop.sh                  # Stop all
```

### Deploy to AWS
```bash
cd mainroom/ctrl
./deploy.sh --dry-run      # Preview
./deploy.sh                # Deploy
```

## Components

### ctrl/ - Orchestration
| Script | Purpose |
|--------|---------|
| start.sh | Start amar + soleprint |
| stop.sh | Stop all |
| deploy.sh | rsync to AWS |
| server/ | AWS setup scripts |

### soleprint/ - Docker Config
Uses `SOLEPRINT_BARE_PATH` to mount gen/ into container.

**Env vars:**
- `SOLEPRINT_BARE_PATH` - Path to gen/
- `DEPLOYMENT_NAME` - Container prefix
- `NETWORK_NAME` - Docker network (soleprint_network)
- `SOLEPRINT_PORT` - Default 12000

### sbwrapper/ - Sidebar Wrapper
Collapsible sidebar overlay for managed apps.

**Features:**
- Quick login (switch test users)
- Jira ticket info
- Environment info
- Keyboard: `Ctrl+Shift+P`

**config.json:**
```json
{
  "room_name": "amar",
  "wrapper": {
    "users": [
      {"id": "admin", "label": "Admin", "username": "admin@test.com", ...}
    ],
    "jira": {"ticket_id": "VET-535"}
  }
}
```

### amar/ - Room Symlink
Points to `../cfg/amar` which contains:
- docker-compose.yml
- .env
- Dockerfile.backend, Dockerfile.frontend
- databrowse/depot/, tester/tests/, monitors/, models/

## How It Works

1. `build.py dev --cfg amar` creates gen/ with room config
2. `mainroom/amar` symlinks to `cfg/amar`
3. `ctrl/start.sh` finds docker-compose.yml in amar/ and soleprint/
4. Both share `soleprint_network` for inter-container communication
5. sbwrapper overlays UI on managed app

## Ports

| Service | Port |
|---------|------|
| Soleprint | 12000 |
| Amar Backend | 8000 |
| Amar Frontend | 3000 |

## Integration with ppl/

Deploy via ppl/ctrl for centralized infrastructure management:
```bash
cd /home/mariano/wdir/ppl/ctrl
./deploy-gen.sh              # Build spr + deploy
./dns.sh add soleprint       # Add DNS record
```

## Server Structure (mcrn.ar)

```
~/mainroom/
├── amar/                  # Amar Docker services
├── soleprint/             # Soleprint Docker services
└── ctrl/                  # Server-side scripts
```

## External Paths

| What | Path |
|------|------|
| Amar Backend | /home/mariano/wdir/ama/amar_django_back |
| Amar Frontend | /home/mariano/wdir/ama/amar_frontend |
| Soleprint gen | /home/mariano/wdir/spr/gen |
| Pipelines | /home/mariano/wdir/ppl |
