cyclecad 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/BILLING-IMPLEMENTATION-SUMMARY.md +425 -0
  2. package/BILLING-INDEX.md +293 -0
  3. package/BILLING-INTEGRATION-GUIDE.md +414 -0
  4. package/COLLABORATION-INDEX.md +440 -0
  5. package/COLLABORATION-SYSTEM-SUMMARY.md +548 -0
  6. package/DOCKER-BUILD-MANIFEST.txt +483 -0
  7. package/DOCKER-FILES-REFERENCE.md +440 -0
  8. package/DOCKER-INFRASTRUCTURE.md +475 -0
  9. package/DOCKER-README.md +435 -0
  10. package/Dockerfile +33 -55
  11. package/PWA-FILES-CREATED.txt +350 -0
  12. package/QUICK-START-TESTING.md +126 -0
  13. package/STEP-IMPORT-QUICKSTART.md +347 -0
  14. package/STEP-IMPORT-SYSTEM-SUMMARY.md +502 -0
  15. package/app/css/mobile.css +1074 -0
  16. package/app/icons/generate-icons.js +203 -0
  17. package/app/index.html +93 -0
  18. package/app/js/billing-ui.js +990 -0
  19. package/app/js/brep-kernel.js +933 -981
  20. package/app/js/collab-client.js +750 -0
  21. package/app/js/mobile-nav.js +623 -0
  22. package/app/js/mobile-toolbar.js +476 -0
  23. package/app/js/modules/billing-module.js +724 -0
  24. package/app/js/modules/step-module-enhanced.js +938 -0
  25. package/app/js/offline-manager.js +705 -0
  26. package/app/js/responsive-init.js +360 -0
  27. package/app/js/touch-handler.js +429 -0
  28. package/app/manifest.json +211 -0
  29. package/app/offline.html +508 -0
  30. package/app/sw.js +571 -0
  31. package/app/tests/billing-tests.html +779 -0
  32. package/app/tests/brep-tests.html +980 -0
  33. package/app/tests/collab-tests.html +743 -0
  34. package/app/tests/mobile-tests.html +1299 -0
  35. package/app/tests/pwa-tests.html +1134 -0
  36. package/app/tests/step-tests.html +1042 -0
  37. package/app/tests/test-agent-v3.html +719 -0
  38. package/docker-compose.yml +225 -0
  39. package/docs/BILLING-HELP.json +260 -0
  40. package/docs/BILLING-README.md +639 -0
  41. package/docs/BILLING-TUTORIAL.md +736 -0
  42. package/docs/BREP-HELP.json +326 -0
  43. package/docs/BREP-TUTORIAL.md +802 -0
  44. package/docs/COLLABORATION-HELP.json +228 -0
  45. package/docs/COLLABORATION-TUTORIAL.md +818 -0
  46. package/docs/DOCKER-HELP.json +224 -0
  47. package/docs/DOCKER-TUTORIAL.md +974 -0
  48. package/docs/MOBILE-HELP.json +243 -0
  49. package/docs/MOBILE-RESPONSIVE-README.md +378 -0
  50. package/docs/MOBILE-TUTORIAL.md +747 -0
  51. package/docs/PWA-HELP.json +228 -0
  52. package/docs/PWA-README.md +662 -0
  53. package/docs/PWA-TUTORIAL.md +757 -0
  54. package/docs/STEP-HELP.json +481 -0
  55. package/docs/STEP-IMPORT-TUTORIAL.md +824 -0
  56. package/docs/TESTING-GUIDE.md +528 -0
  57. package/docs/TESTING-HELP.json +182 -0
  58. package/fusion-vs-cyclecad.html +1771 -0
  59. package/nginx.conf +237 -0
  60. package/package.json +1 -1
  61. package/server/Dockerfile.converter +51 -0
  62. package/server/Dockerfile.signaling +28 -0
  63. package/server/billing-server.js +487 -0
  64. package/server/converter-enhanced.py +528 -0
  65. package/server/requirements-converter.txt +29 -0
  66. package/server/signaling-server.js +801 -0
  67. package/tests/docker-tests.sh +389 -0
@@ -0,0 +1,414 @@
1
+ # Billing Integration Guide - cycleCAD
2
+
3
+ Quick start guide to integrate Stripe billing into cycleCAD.
4
+
5
+ ## 5-Minute Setup
6
+
7
+ ### Step 1: Stripe Account Setup (5 minutes)
8
+
9
+ 1. Go to [stripe.com](https://stripe.com), create/login account
10
+ 2. Go to Dashboard → Products
11
+ 3. Create product "cycleCAD Pro":
12
+ - Price: €49/month (price_1234_pro_monthly)
13
+ - Price: €468/year (price_1234_pro_yearly)
14
+ 4. Create product "cycleCAD Enterprise":
15
+ - Price: €299/month (price_1234_ent_monthly)
16
+ - Price: €2,868/year (price_1234_ent_yearly)
17
+ 5. Copy API keys from Dashboard → Settings → Developers → API Keys:
18
+ - Publishable key: pk_live_...
19
+ - Secret key: sk_live_...
20
+ 6. Create webhook endpoint:
21
+ - Dashboard → Settings → Webhooks
22
+ - Endpoint URL: `https://yourdomain.com/billing/webhook`
23
+ - Events: subscription.* invoice.payment.*
24
+ - Get signing secret: whsec_...
25
+
26
+ ### Step 2: Environment Setup (2 minutes)
27
+
28
+ Create `.env` file:
29
+
30
+ ```env
31
+ # Stripe
32
+ STRIPE_PUBLIC_KEY=pk_live_51234567890
33
+ STRIPE_SECRET_KEY=sk_live_1234567890
34
+ STRIPE_WEBHOOK_SECRET=whsec_1234567890
35
+
36
+ # App
37
+ APP_URL=https://cyclecad.com
38
+ BILLING_SERVER_URL=https://api.cyclecad.com
39
+
40
+ # Price IDs (from Step 1)
41
+ STRIPE_PRICE_PRO_MONTHLY=price_1234_pro_monthly
42
+ STRIPE_PRICE_PRO_YEARLY=price_1234_pro_yearly
43
+ STRIPE_PRICE_ENTERPRISE_MONTHLY=price_1234_ent_monthly
44
+ STRIPE_PRICE_ENTERPRISE_YEARLY=price_1234_ent_yearly
45
+ ```
46
+
47
+ ### Step 3: Install Files (1 minute)
48
+
49
+ ```bash
50
+ # Copy all billing files to your project
51
+ cp app/js/modules/billing-module.js ~/cyclecad/app/js/modules/
52
+ cp app/js/billing-ui.js ~/cyclecad/app/js/
53
+ cp server/billing-server.js ~/cyclecad/server/
54
+ cp docs/BILLING-* ~/cyclecad/docs/
55
+ cp app/tests/billing-tests.html ~/cyclecad/app/tests/
56
+ ```
57
+
58
+ ### Step 4: Wire Into App (3 minutes)
59
+
60
+ **In `app/index.html` - add before closing `</body>`:**
61
+
62
+ ```html
63
+ <!-- Billing System -->
64
+ <script src="js/modules/billing-module.js"></script>
65
+ <script src="js/billing-ui.js"></script>
66
+ <script>
67
+ // Initialize billing when app is ready
68
+ window.addEventListener('DOMContentLoaded', async () => {
69
+ try {
70
+ await window.BillingModule.init();
71
+ console.log('[Billing] System initialized');
72
+
73
+ // Register billing panel in app
74
+ if (window.cycleCAD?.modules) {
75
+ window.cycleCAD.modules.billing = window.BillingModule;
76
+ }
77
+
78
+ // Add billing panel to settings
79
+ const billingUI = window.BillingModule.getUI();
80
+ // Render billingUI.html wherever you render panels
81
+ } catch (e) {
82
+ console.error('[Billing] Initialization failed:', e);
83
+ }
84
+ });
85
+ </script>
86
+ ```
87
+
88
+ **In `server/app.js` - add billing routes:**
89
+
90
+ ```javascript
91
+ const express = require('express');
92
+ const billingRouter = require('./billing-server');
93
+
94
+ const app = express();
95
+
96
+ // Middleware
97
+ app.use(express.json());
98
+ app.use(express.raw({type: 'application/json'}, {path: '/billing/webhook'}));
99
+
100
+ // Mount billing routes
101
+ app.use('/billing', billingRouter);
102
+
103
+ // Start server
104
+ app.listen(3001, () => {
105
+ console.log('Server running on port 3001 with billing enabled');
106
+ });
107
+ ```
108
+
109
+ ## Usage Examples
110
+
111
+ ### Check Limit Before Operation
112
+
113
+ ```javascript
114
+ // Before allowing user to create project
115
+ const check = window.BillingModule.checkLimit('projects');
116
+
117
+ if (!check.allowed) {
118
+ // Show upgrade prompt
119
+ window.BillingUI.showUpgradeModal('projects', 'Free users can only create 3 projects');
120
+ return;
121
+ }
122
+
123
+ // Allow project creation
124
+ createProject();
125
+ ```
126
+
127
+ ### Track Usage
128
+
129
+ ```javascript
130
+ // When project created
131
+ window.BillingModule.trackUsage('project-created');
132
+
133
+ // When STEP file imported (50 MB)
134
+ window.BillingModule.trackUsage('step-import', 50 * 1024 * 1024);
135
+
136
+ // When storage used (0.5 GB)
137
+ window.BillingModule.trackUsage('storage-added', 0.5);
138
+
139
+ // When AI feature used
140
+ window.BillingModule.trackUsage('ai-request');
141
+ ```
142
+
143
+ ### Gate Premium Features
144
+
145
+ ```javascript
146
+ // Disable CAM for Free users
147
+ function initCAMOperations() {
148
+ if (!window.BillingModule.hasFeature('cam-operations')) {
149
+ // Show lock overlay
150
+ document.getElementById('cam-section').appendChild(
151
+ document.createElement('div')
152
+ ).innerHTML = window.BillingUI.getFeatureGateOverlay('cam-operations');
153
+
154
+ // Disable buttons
155
+ document.querySelectorAll('[data-cam]').forEach(btn => {
156
+ btn.disabled = true;
157
+ btn.onclick = () => {
158
+ window.BillingModule.showUpgradePrompt('cam-operations',
159
+ 'CAM operations are available in Pro plan');
160
+ };
161
+ });
162
+ return;
163
+ }
164
+
165
+ // Enable CAM for Pro/Enterprise
166
+ initCAMUI();
167
+ }
168
+ ```
169
+
170
+ ### Show Pricing Page
171
+
172
+ ```javascript
173
+ // In settings or upgrade page
174
+ const pricingUI = window.BillingUI.showPricingPage();
175
+ document.getElementById('pricing-container').innerHTML = pricingUI.html;
176
+ document.head.appendChild(document.createElement('style')).textContent = pricingUI.styles;
177
+ ```
178
+
179
+ ### Show Trial Banner
180
+
181
+ ```javascript
182
+ // At top of app during trial
183
+ const banner = window.BillingUI.getTrialBanner();
184
+ if (banner) {
185
+ document.body.insertAdjacentHTML('afterbegin', banner);
186
+ }
187
+ ```
188
+
189
+ ## Testing
190
+
191
+ ### Run Test Suite
192
+
193
+ ```bash
194
+ # Open in browser
195
+ open app/tests/billing-tests.html
196
+
197
+ # Or serve via server
198
+ http://localhost:3000/app/tests/billing-tests.html
199
+ ```
200
+
201
+ ### Test Key Flows
202
+
203
+ 1. **Upgrade Flow**
204
+ - Click "Upgrade" → Stripe Checkout → Success page
205
+ - Verify user tier changed to Pro
206
+ - Verify usage limits increased
207
+
208
+ 2. **Limit Enforcement**
209
+ - Create 3 projects on Free tier
210
+ - Try to create 4th → Upgrade modal appears
211
+ - Click "Upgrade to Pro" → Checkout flow
212
+
213
+ 3. **Trial Period**
214
+ - Start new account → Get 14-day trial
215
+ - Verify countdown in banner
216
+ - Verify auto-charge on day 15 (test mode)
217
+
218
+ 4. **Payment Failure**
219
+ - Use test card ending in 0002 (fails payment)
220
+ - Verify grace period started
221
+ - Verify reminder emails sent
222
+ - Update payment → Verify recovery
223
+
224
+ 5. **Offline Mode**
225
+ - Disconnect from internet
226
+ - Verify app still loads with cached data
227
+ - Reconnect → Verify sync with server
228
+
229
+ ## Deployment Checklist
230
+
231
+ ### Before Going Live
232
+
233
+ - [ ] Stripe account created and verified
234
+ - [ ] Products and prices created with correct IDs
235
+ - [ ] API keys set in environment (.env)
236
+ - [ ] Webhook endpoint configured
237
+ - [ ] HTTPS enabled on all billing pages
238
+ - [ ] Billing module wired into app
239
+ - [ ] Server routes mounted
240
+ - [ ] All 38 tests passing
241
+ - [ ] Checkout flow tested end-to-end
242
+ - [ ] Payment method update tested
243
+ - [ ] Cancellation tested
244
+ - [ ] Invoice generation tested
245
+ - [ ] User acceptance testing complete
246
+
247
+ ### After Going Live
248
+
249
+ - [ ] Monitor webhook delivery in Stripe Dashboard
250
+ - [ ] Set up billing alerts (failed payments, disputes)
251
+ - [ ] Track MRR and churn metrics
252
+ - [ ] Monitor test mode vs live mode
253
+ - [ ] Review customer support tickets for billing issues
254
+ - [ ] Monthly reconciliation of invoices
255
+
256
+ ## Common Customizations
257
+
258
+ ### Add More Tiers
259
+
260
+ In `billing-module.js`:
261
+
262
+ ```javascript
263
+ tiers: {
264
+ // ... existing tiers ...
265
+ startup: {
266
+ id: 'startup',
267
+ name: 'Startup',
268
+ price: 99 * 100, // €99/mo
269
+ limits: { /* ... */ },
270
+ features: [ /* ... */ ]
271
+ }
272
+ }
273
+ ```
274
+
275
+ ### Custom Pricing
276
+
277
+ ```javascript
278
+ // Change Pro price to €79/month
279
+ tiers.pro.price = 79 * 100;
280
+
281
+ // Change Enterprise to €499/month
282
+ tiers.enterprise.price = 499 * 100;
283
+ ```
284
+
285
+ ### Add Promo Code
286
+
287
+ ```javascript
288
+ // In applyPromoCode() function
289
+ const promoCodes = {
290
+ 'SUMMER20': 0.20,
291
+ 'NEWUSER25': 0.25,
292
+ 'CORPORATE30': 0.30
293
+ };
294
+ ```
295
+
296
+ ### Change Free Tier Limits
297
+
298
+ ```javascript
299
+ tiers.free.limits = {
300
+ projects: 5, // Was 3
301
+ partsPerProject: 200, // Was 100
302
+ storageGB: 2, // Was 1
303
+ aiRequestsPerDay: 50, // Was 20
304
+ // ...
305
+ };
306
+ ```
307
+
308
+ ### Customize Trial Duration
309
+
310
+ ```javascript
311
+ config.trialDays = 21; // 21-day trial instead of 14
312
+ ```
313
+
314
+ ### Change Grace Period
315
+
316
+ ```javascript
317
+ config.gracePeriodDays = 14; // 14 days instead of 7
318
+ ```
319
+
320
+ ## Architecture
321
+
322
+ ```
323
+ ┌─────────────────────────────────────────────┐
324
+ │ cycleCAD App (Frontend) │
325
+ ├─────────────────────────────────────────────┤
326
+ │ BillingModule (state, logic) │
327
+ │ BillingUI (components, display) │
328
+ │ Stripe.js (Checkout, Portal) │
329
+ └─────────────────────────────────────────────┘
330
+ │ HTTP/HTTPS │
331
+ ┌─────────────────────────────────────────────┐
332
+ │ Billing Server (Node.js/Express) │
333
+ ├─────────────────────────────────────────────┤
334
+ │ /billing/create-checkout │
335
+ │ /billing/create-portal │
336
+ │ /billing/webhook (Stripe events) │
337
+ │ /billing/user (status) │
338
+ │ /billing/usage (tracking) │
339
+ └─────────────────────────────────────────────┘
340
+ │ HTTPS │
341
+ ┌─────────────────────────────────────────────┐
342
+ │ Stripe API │
343
+ ├─────────────────────────────────────────────┤
344
+ │ Checkout Sessions │
345
+ │ Subscriptions │
346
+ │ Customers │
347
+ │ Invoices │
348
+ │ Webhooks │
349
+ └─────────────────────────────────────────────┘
350
+ ```
351
+
352
+ ## Monitoring
353
+
354
+ ### Key Metrics to Track
355
+
356
+ 1. **Conversion**: Free → Pro signups
357
+ 2. **Churn**: Pro → Free (canceled)
358
+ 3. **Expansion**: Free → Enterprise upgrades
359
+ 4. **MRR**: Monthly recurring revenue
360
+ 5. **LTV**: Lifetime value per customer
361
+ 6. **Payment Success**: Invoice payment success rate
362
+ 7. **Trial Conversion**: Trial users who upgrade
363
+
364
+ ### Webhook Monitoring
365
+
366
+ Monitor in Stripe Dashboard:
367
+
368
+ ```
369
+ Developers → Webhooks → Select Endpoint
370
+ → Signed Events → View all events
371
+ ```
372
+
373
+ Look for:
374
+ - Failed deliveries (retry)
375
+ - Unexpected errors (investigate)
376
+ - Timing patterns (optimize)
377
+
378
+ ## Support
379
+
380
+ ### User-Facing Help
381
+
382
+ - Tutorial: `docs/BILLING-TUTORIAL.md` (link in app)
383
+ - Help entries: `docs/BILLING-HELP.json` (searchable)
384
+ - Contact: support@cyclecad.com
385
+
386
+ ### Developer Support
387
+
388
+ - Module documentation: `docs/BILLING-README.md`
389
+ - API reference: See BillingModule section
390
+ - Tests: `app/tests/billing-tests.html`
391
+ - Console logging: Check browser console for `[Billing]` messages
392
+
393
+ ### Stripe Support
394
+
395
+ - Dashboard: https://dashboard.stripe.com
396
+ - Documentation: https://stripe.com/docs
397
+ - API Reference: https://stripe.com/docs/api
398
+
399
+ ## Next Steps
400
+
401
+ 1. ✅ Implement basic billing (this guide)
402
+ 2. ⏭️ Add team billing (Pro feature)
403
+ 3. ⏭️ Add usage-based pricing (overage charges)
404
+ 4. ⏭️ Add affiliate program (referral commissions)
405
+ 5. ⏭️ Add invoice customization (logo, payment terms)
406
+ 6. ⏭️ Add dunning management (failed payment recovery)
407
+
408
+ ## Questions?
409
+
410
+ See `docs/BILLING-README.md` for comprehensive documentation, or contact:
411
+
412
+ - **Dev Issues**: Create GitHub issue or PR
413
+ - **Stripe Issues**: https://support.stripe.com
414
+ - **Billing Questions**: support@cyclecad.com