File size: 9,231 Bytes
02eac4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
---
title: LeRobot Arena Transport Server
emoji: πŸ€–
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
dockerfile_path: services/transport-server/Dockerfile
suggested_hardware: cpu-upgrade
suggested_storage: small
short_description: Real-time robotics control 
tags:
  - robotics
  - control
  - websocket
  - fastapi
  - svelte
  - real-time
  - video-streaming
  - transport-server
pinned: true
fullWidth: true
---

# πŸ€– LeRobot Arena Transport Server with UI

A complete Docker deployment of the LeRobot Arena Transport Server with integrated web UI. This combines the FastAPI backend with a SvelteKit frontend in a single container, inspired by the [LeRobot Arena Hugging Face Space](https://huggingface.co/spaces/blanchon/LeRobot-Arena).

## πŸš€ Quick Start with Docker

The easiest way to run the complete LeRobot Arena Transport Server is using Docker, which sets up both the frontend and backend automatically.

### Prerequisites

- [Docker](https://www.docker.com/get-started) installed on your system
- [Docker Compose](https://docs.docker.com/compose/install/) (usually included with Docker Desktop)

### Step-by-Step Instructions

1. **Navigate to the transport server directory**
   ```bash
   cd services/transport-server
   ```

2. **Build the Docker image**
   ```bash
   docker build -t lerobot-arena-transport .
   ```

3. **Run the container**
   ```bash
   docker run -p 7860:7860 -e SERVE_FRONTEND=true lerobot-arena-transport
   ```

4. **Access the application**
   - **Frontend**: http://localhost:7860
   - **Backend API**: http://localhost:7860/api
   - **API Documentation**: http://localhost:7860/api/docs

5. **Stop the container**
   ```bash
   # Find the container ID
   docker ps
   
   # Stop the container
   docker stop <container_id>
   ```

### Alternative Build & Run Options

**One-liner build and run:**
```bash
docker build -t lerobot-arena-transport . && docker run -p 7860:7860 -e SERVE_FRONTEND=true lerobot-arena-transport
```

**Run with custom environment variables:**
```bash
docker run -p 8080:7860 \
  -e SERVE_FRONTEND=true \
  -e PORT=7860 \
  -e HOST=0.0.0.0 \
  lerobot-arena-transport
```

**Run with volume mounts for logs:**
```bash
docker run -p 7860:7860 \
  -e SERVE_FRONTEND=true \
  -v $(pwd)/logs:/home/user/app/logs \
  lerobot-arena-transport
```

## πŸ› οΈ Development Setup

For local development with hot-reload capabilities:

### Backend Development

```bash
# Navigate to server directory
cd server

# Install Python dependencies (using uv)
uv sync

# Start the backend server only
python api.py
```

### Frontend Development

```bash
# Navigate to demo directory
cd demo

# Install dependencies
bun install

# Start the development server
bun run dev
```

### Client Library Development

```bash
# Navigate to client library
cd client/js

# Install dependencies
bun install

# Build the client library
bun run build
```

## πŸ“‹ Project Structure

```
services/transport-server/
β”œβ”€β”€ server/                     # Python FastAPI backend
β”‚   β”œβ”€β”€ src/                   # Source code
β”‚   β”œβ”€β”€ api.py                 # Main API application
β”‚   β”œβ”€β”€ launch_with_ui.py      # Combined launcher
β”‚   └── pyproject.toml         # Python dependencies
β”œβ”€β”€ demo/                      # SvelteKit frontend
β”‚   β”œβ”€β”€ src/                   # Frontend source code
β”‚   β”œβ”€β”€ package.json           # Node.js dependencies
β”‚   └── svelte.config.js       # SvelteKit configuration
β”œβ”€β”€ client/js/                 # TypeScript client library
β”‚   β”œβ”€β”€ src/                   # Client library source
β”‚   └── package.json           # Client dependencies
β”œβ”€β”€ Dockerfile                 # Docker configuration
β”œβ”€β”€ docker-compose.yml         # Docker Compose setup
└── README.md                  # This file
```

## 🐳 Docker Information

The Docker setup includes:

- **Multi-stage build**: Optimized for production using Bun and uv
- **Client library build**: Builds the TypeScript client first
- **Frontend build**: Compiles SvelteKit app to static files
- **Backend integration**: FastAPI serves both API and static files
- **Port mapping**: Single port 7860 for both frontend and API
- **User permissions**: Properly configured for Hugging Face Spaces
- **Environment variables**: Configurable via environment

### Environment Variables

- `SERVE_FRONTEND=true`: Enable frontend serving (default: false)
- `PORT=7860`: Port to run the server on (default: 7860)
- `HOST=0.0.0.0`: Host to bind to (default: 0.0.0.0)

## 🌐 What's Included

### Backend Features
- **Real-time Robot Control**: WebSocket-based communication
- **Video Streaming**: WebRTC video streaming capabilities
- **REST API**: Complete robotics control API
- **Room Management**: Create and manage robot control sessions
- **Health Monitoring**: Built-in health checks and logging

### Frontend Features
- **Dashboard**: Server status and room overview
- **Robot Control**: 6-DOF robot arm control interface
- **Real-time Monitoring**: Live joint state visualization
- **Workspace Management**: Isolated environments for different sessions
- **Modern UI**: Responsive design with Tailwind CSS

### Architecture
- **Frontend**: Svelte 5, TypeScript, Tailwind CSS
- **Backend**: FastAPI, Python 3.12, uvicorn
- **Client Library**: TypeScript with WebSocket support
- **Build System**: Bun for frontend, uv for Python
- **Container**: Multi-stage Docker build

## πŸ”§ API Endpoints

### Health Check
- `GET /health` - Server health status
- `GET /api/health` - API health status

### Robotics API
- `GET /api/robotics/rooms` - List active rooms
- `POST /api/robotics/rooms` - Create new room
- `DELETE /api/robotics/rooms/{room_id}` - Delete room
- `WebSocket /api/robotics/ws/{room_id}` - Real-time control

### Video API
- `GET /api/video/rooms` - List video rooms
- `WebSocket /api/video/ws/{room_id}` - Video streaming

## πŸ§ͺ Testing the Setup

Run the included test script to verify everything works:

```bash
./test-docker.sh
```

This script will build the image, start a container, test all endpoints, and clean up automatically.

## 🚨 Troubleshooting

### Port Conflicts
If port 7860 is already in use:

```bash
# Check what's using the port
lsof -i :7860

# Use different port
docker run -p 8080:7860 -e SERVE_FRONTEND=true lerobot-arena-transport
```

### Container Issues

```bash
# View logs
docker logs <container_id>

# Rebuild without cache
docker build --no-cache -t lerobot-arena-transport .

# Run with verbose logging
docker run -p 7860:7860 -e SERVE_FRONTEND=true -e LOG_LEVEL=debug lerobot-arena-transport
```

### Development Issues

```bash
# Clear node modules and reinstall (for local development)
cd demo
rm -rf node_modules
bun install

# Clear SvelteKit cache
rm -rf .svelte-kit
bun run dev

# Re-link client library (if needed for local development)
cd ../client/js
bun link
cd ../../demo
bun link lerobot-arena-client
```

### Client Library Issues

```bash
# Rebuild client library
cd client/js
bun run clean
bun run build
```

## πŸš€ Hugging Face Spaces Deployment

This project is configured for deployment on Hugging Face Spaces:

1. **Fork** this repository to your GitHub account
2. **Create a new Space** on Hugging Face Spaces
3. **Connect** your GitHub repository
4. **Select Docker SDK** (should be auto-detected)
5. **Set the Dockerfile path** to `services/transport-server/Dockerfile`
6. **Deploy**

The Space will automatically build and run both the frontend and backend.

### Hugging Face Spaces Configuration

Add this to your Space's README.md frontmatter:

```yaml
---
title: LeRobot Arena Transport Server
emoji: πŸ€–
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
dockerfile_path: services/transport-server/Dockerfile
suggested_hardware: cpu-upgrade
suggested_storage: small
short_description: Real-time robotics control and video streaming
tags:
  - robotics
  - control
  - websocket
  - fastapi
  - svelte
pinned: true
fullWidth: true
---
```

## 🎯 Use Cases

### Development & Testing
- **API Development**: Test robotics control APIs
- **Frontend Development**: Develop robotics UIs
- **Integration Testing**: Test real-time communication

### Production Deployment
- **Robot Control**: Remote robot operation
- **Multi-user**: Multiple operators on same robot
- **Monitoring**: Real-time robot state monitoring

### Education & Demos
- **Learning**: Robotics programming education
- **Demonstrations**: Showcase robotics capabilities
- **Prototyping**: Rapid robotics application development

## 🀝 Contributing

1. **Fork** the repository
2. **Create feature branch** (`git checkout -b feature/amazing-feature`)
3. **Make changes** and add tests
4. **Test with Docker** (`./test-docker.sh`)
5. **Commit changes** (`git commit -m 'Add amazing feature'`)
6. **Push to branch** (`git push origin feature/amazing-feature`)
7. **Open Pull Request**

## πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

---

**Built with ❀️ for the robotics community** πŸ€–

For more information, visit the [main LeRobot Arena project](https://github.com/lerobot-arena/lerobot-arena).