File size: 4,764 Bytes
38b4eff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# NeuralAI Service Architecture

## Podman Quadlet → Zo Service Mapping

| Podman Concept | Zo Equivalent | NeuralAI Implementation |
|----------------|---------------|------------------------|
| `.container` files | `register_user_service()` | 3 registered services |
| systemd `Requires=` | Service startup order | model→webui dependency |
| systemd `After=` | Service health checks | tools→webui dependency |
| NFS volumes | `/home/workspace/NeuralAI/` | Built-in persistent storage |
| `Restart=always` | Zo supervisor | Auto-restart on crash |
| `.network` files | `localhost` networking | Services talk via HTTP |

## Service Definitions (like Quadlets)

### neuralai-model.service (port 7001)
```ini
# Equivalent to: neuralai-model.container
[Service]
Entrypoint=python3 /home/workspace/Projects/NeuralAI/services/model_service.py
Port=7001
Restart=always
Environment=MODEL_PATH=/home/workspace/Projects/NeuralAI/checkpoints/v2_model

[Unit]
Description=NeuralAI Model Inference Service
# Model must be ready before webui
Before=neuralai-webui.service
```

### neuralai-tools.service (port 7002)
```ini
# Equivalent to: neuralai-tools.container
[Service]
Entrypoint=python3 /home/workspace/Projects/NeuralAI/services/tools_service.py
Port=7002
Restart=always
Volume=/home/workspace/NeuralAI:/data:rw

[Unit]
Description=NeuralAI Tools Service (sandbox, storage)
# Tools must be ready before webui
Before=neuralai-webui.service
```

### neuralai-webui.service (port 5000)
```ini
# Equivalent to: neuralai-webui.container
[Service]
Entrypoint=python3 /home/workspace/Projects/NeuralAI/services/webui_service.py
Port=5000
Public=true
Restart=always

[Unit]
Description=NeuralAI Web Interface
Requires=neuralai-model.service
Requires=neuralai-tools.service
After=neuralai-model.service
After=neuralai-tools.service
```

## Dependency Graph

```
                    ┌─────────────────┐
                    │  neuralai-model │ :7001
                    │  (inference)    │
                    └────────┬────────┘

                             │ Requires

┌─────────────────┐    ┌─────────────────┐
│  neuralai-tools │───▶│  neuralai-webui │ :5000 (public)
│  (sandbox)      │    │  (router)       │
└─────────────────┘    └─────────────────┘
       :7002                   │

                       Public URL:
                       https://neuralai-webui-deandrewharris.zocomputer.io
```

## Storage (like NFS volume)

```
/home/workspace/NeuralAI/
├── images/          # Generated images (shared)
├── documents/       # User documents for RAG (shared)
├── conversations/   # Chat history (shared)
├── models/          # Model checkpoints (shared)
└── cache/           # Temporary files (shared)
```

All services mount `/home/workspace/NeuralAI/` - like an NFS volume shared across containers.

## Management Commands

### Like systemctl for Podman:
```bash
# Check status
systemctl --user status neuralai-*.service
# In Zo:
service_doctor("neuralai-model")

# Restart a service
systemctl --user restart neuralai-model.service
# In Zo:
update_user_service(service_id)

# View logs
journalctl --user -u neuralai-model.service
# In Zo:
cat /dev/shm/neuralai-model.log
```

### Start/Stop All:
```bash
# Podman quadlet style
./services/start_all.sh    # Starts in dependency order
./services/stop_all.sh     # Stops in reverse order
./services/status.sh       # Shows all service states
```

## Restart Behavior

| Failure Scenario | What Happens |
|------------------|--------------|
| Model OOM crash | Only model service restarts, webui stays up |
| Tools timeout | Only tools service restarts |
| WebUI crash | Only webui restarts, model stays loaded |
| Model unhealthy | Webui returns 503, auto-recovery in progress |

## Benefits (Same as Your Podman Setup)

1. **Isolation**: Each service in its own process
2. **Independence**: Failures don't cascade
3. **Dependencies**: Proper startup ordering
4. **Shared storage**: All services access same `/NeuralAI/`
5. **Declarative**: Service configs are simple Python files
6. **Auto-restart**: Supervisor handles recovery
7. **Observability**: Separate logs per service

## Current Status

```
✅ neuralai-model  (7001) - Ready, model loaded
✅ neuralai-tools  (7002) - Ready, sandbox active
✅ neuralai-webui  (5000) - Ready, public URL live
```

Public: https://neuralai-webui-deandrewharris.zocomputer.io