|
| 1 | +# Kubelab Collections Structure |
| 2 | + |
| 3 | +This document describes the PocketBase collections used in Kubelab. |
| 4 | + |
| 5 | +## Collections Overview |
| 6 | + |
| 7 | +All collections are created programmatically in `pkg/collections/collections.go` on application bootstrap. No manual migration files are needed. |
| 8 | + |
| 9 | +### 1. **users** (Auth Collection) |
| 10 | +The main user authentication collection. |
| 11 | + |
| 12 | +**Custom Fields:** |
| 13 | +- `role` (text, required) - User role: "user" or "admin" |
| 14 | +- `plan` (text) - Associated plan ID |
| 15 | +- `company` (text) - Company name |
| 16 | +- `workshop` (boolean) - Workshop participant flag |
| 17 | + |
| 18 | +**Access Rules:** |
| 19 | +- List/View: Authenticated users only |
| 20 | +- Update/Delete: Own record or admin |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +### 2. **labs** |
| 25 | +Lab courses that contain multiple exercises. |
| 26 | + |
| 27 | +**Fields:** |
| 28 | +- `name` (text, required) - Lab name |
| 29 | +- `description` (editor) - Lab description |
| 30 | +- `icon` (text) - Icon identifier |
| 31 | +- `order` (number) - Display order |
| 32 | +- `active` (boolean) - Active status |
| 33 | +- `difficulty` (text) - Difficulty level |
| 34 | + |
| 35 | +**Access Rules:** |
| 36 | +- List/View: Authenticated users |
| 37 | +- Create/Update/Delete: Admins only |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +### 3. **exercises** |
| 42 | +Individual exercises within labs. |
| 43 | + |
| 44 | +**Fields:** |
| 45 | +- `name` (text, required) - Exercise name |
| 46 | +- `description` (editor) - Exercise description |
| 47 | +- `lab` (relation, required) - Parent lab |
| 48 | +- `bootstrap` (URL) - Bootstrap script URL |
| 49 | +- `check` (URL) - Validation script URL |
| 50 | +- `order` (number) - Display order |
| 51 | +- `maxScore` (number) - Maximum achievable score |
| 52 | +- `active` (boolean) - Active status |
| 53 | + |
| 54 | +**Access Rules:** |
| 55 | +- List/View: Authenticated users |
| 56 | +- Create/Update/Delete: Admins only |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +### 4. **lab_sessions** |
| 61 | +User progress for labs (manages vcluster lifecycle). |
| 62 | + |
| 63 | +**Fields:** |
| 64 | +- `user` (relation, required) - User ID |
| 65 | +- `lab` (relation, required) - Lab ID |
| 66 | +- `clusterRunning` (boolean) - vcluster status |
| 67 | +- `lastClusterStart` (date) - Last start timestamp |
| 68 | +- `lastClusterStop` (date) - Last stop timestamp |
| 69 | + |
| 70 | +**Access Rules:** |
| 71 | +- List/View: Own records or admin |
| 72 | +- Create: Authenticated users |
| 73 | +- Update/Delete: Own records or admin |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### 5. **exercise_sessions** |
| 78 | +User progress for individual exercises. |
| 79 | + |
| 80 | +**Fields:** |
| 81 | +- `user` (relation, required) - User ID |
| 82 | +- `exercise` (relation, required) - Exercise ID |
| 83 | +- `agentRunning` (boolean) - Agent deployment status |
| 84 | +- `score` (number) - Current score |
| 85 | +- `lastAgentStart` (date) - Last start timestamp |
| 86 | +- `lastAgentStop` (date) - Last stop timestamp |
| 87 | +- `solved` (boolean) - Completion status |
| 88 | +- `solvedAt` (date) - Completion timestamp |
| 89 | + |
| 90 | +**Access Rules:** |
| 91 | +- List/View: Own records or admin |
| 92 | +- Create: Authenticated users |
| 93 | +- Update/Delete: Own records or admin |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +### 6. **exercise_session_logs** |
| 98 | +Logs for exercise session events. |
| 99 | + |
| 100 | +**Fields:** |
| 101 | +- `user` (relation, required) - User ID |
| 102 | +- `exercise_session` (relation, required) - Exercise session ID |
| 103 | +- `message` (text, required) - Log message |
| 104 | +- `type` (text, required) - Log type/severity |
| 105 | + |
| 106 | +**Access Rules:** |
| 107 | +- List/View: Own records or admin |
| 108 | +- Create: Authenticated users |
| 109 | +- Delete: Admins only (no updates) |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +### 7. **hooks** |
| 114 | +Configurable event hooks for automation. |
| 115 | + |
| 116 | +**Fields:** |
| 117 | +- `table` (text, required) - Target collection |
| 118 | +- `event` (text, required) - Event type (insert/update/delete) |
| 119 | +- `actionType` (text, required) - Action to perform |
| 120 | +- `actionMeta` (text) - Additional action metadata |
| 121 | +- `disabled` (boolean) - Enable/disable hook |
| 122 | + |
| 123 | +**Access Rules:** |
| 124 | +- All operations: Admins only |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +### 8. **plans** |
| 129 | +Subscription/pricing plans. |
| 130 | + |
| 131 | +**Fields:** |
| 132 | +- `name` (text, required) - Plan name |
| 133 | +- `description` (text) - Plan description |
| 134 | +- `price` (number) - Plan price |
| 135 | +- `active` (boolean) - Active status |
| 136 | + |
| 137 | +**Access Rules:** |
| 138 | +- List/View: Authenticated users |
| 139 | +- Create/Update/Delete: Admins only |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +### 9. **features** |
| 144 | +Features associated with plans. |
| 145 | + |
| 146 | +**Fields:** |
| 147 | +- `name` (text, required) - Feature name |
| 148 | +- `plan` (relation) - Associated plan |
| 149 | + |
| 150 | +**Access Rules:** |
| 151 | +- List/View: Authenticated users |
| 152 | +- Create/Update/Delete: Admins only |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +### 10. **faqs** |
| 157 | +Frequently asked questions. |
| 158 | + |
| 159 | +**Fields:** |
| 160 | +- `question` (text, required) - Question text |
| 161 | +- `answer` (text, required) - Answer text |
| 162 | +- `order` (number) - Display order |
| 163 | + |
| 164 | +**Access Rules:** |
| 165 | +- List/View: Public (no auth required) |
| 166 | +- Create/Update/Delete: Admins only |
| 167 | + |
| 168 | +--- |
| 169 | + |
| 170 | +### 11. **companies** |
| 171 | +Company logos for landing page. |
| 172 | + |
| 173 | +**Fields:** |
| 174 | +- `name` (text, required) - Company name |
| 175 | +- `logo` (file, max 5MB) - Company logo image |
| 176 | +- `order` (number) - Display order |
| 177 | + |
| 178 | +**Access Rules:** |
| 179 | +- List/View: Public (no auth required) |
| 180 | +- Create/Update/Delete: Admins only |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +### 12. **notifications** |
| 185 | +User notifications. |
| 186 | + |
| 187 | +**Fields:** |
| 188 | +- `user` (relation, required) - User ID |
| 189 | +- `message` (text, required) - Notification message |
| 190 | +- `type` (text, required) - Notification type |
| 191 | +- `read` (boolean) - Read status |
| 192 | + |
| 193 | +**Access Rules:** |
| 194 | +- List/View: Own records or admin |
| 195 | +- Create: Authenticated users |
| 196 | +- Update/Delete: Own records or admin |
| 197 | + |
| 198 | +--- |
| 199 | + |
| 200 | +## Initialization |
| 201 | + |
| 202 | +Collections are automatically created on application bootstrap via `collections.InitializeCollections()` in `main.go`. If a collection already exists, it's skipped - no data is lost. |
| 203 | + |
| 204 | +## First Run Setup |
| 205 | + |
| 206 | +1. Start the backend: `npm run dev:backend` (from kubelab-ui directory) |
| 207 | +2. Open the admin dashboard: http://localhost:8090/_/ |
| 208 | +3. Create your first admin account |
| 209 | +4. Collections will be automatically created on first bootstrap |
| 210 | + |
| 211 | +## Notes |
| 212 | + |
| 213 | +- Old JS migrations in `pb_migrations_old/` are kept for reference but not used |
| 214 | +- All schema changes should now be done in `pkg/collections/collections.go` |
| 215 | +- For production, you may want to add collection schema versioning |
| 216 | + |
0 commit comments