@l4yercak3/cli 1.0.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 (61) hide show
  1. package/.claude/settings.local.json +18 -0
  2. package/.cursor/rules.md +203 -0
  3. package/.eslintrc.js +31 -0
  4. package/README.md +227 -0
  5. package/bin/cli.js +61 -0
  6. package/docs/ADDING_NEW_PROJECT_TYPE.md +156 -0
  7. package/docs/ARCHITECTURE_RELATIONSHIPS.md +411 -0
  8. package/docs/CLI_AUTHENTICATION.md +214 -0
  9. package/docs/DETECTOR_ARCHITECTURE.md +326 -0
  10. package/docs/DEVELOPMENT.md +194 -0
  11. package/docs/IMPLEMENTATION_PHASES.md +468 -0
  12. package/docs/OAUTH_CLARIFICATION.md +258 -0
  13. package/docs/OAUTH_SETUP_GUIDE_TEMPLATE.md +211 -0
  14. package/docs/PHASE_0_PROGRESS.md +120 -0
  15. package/docs/PHASE_1_COMPLETE.md +366 -0
  16. package/docs/PHASE_SUMMARY.md +149 -0
  17. package/docs/PLAN.md +511 -0
  18. package/docs/README.md +56 -0
  19. package/docs/STRIPE_INTEGRATION.md +447 -0
  20. package/docs/SUMMARY.md +230 -0
  21. package/docs/UPDATED_PLAN.md +447 -0
  22. package/package.json +53 -0
  23. package/src/api/backend-client.js +148 -0
  24. package/src/commands/login.js +146 -0
  25. package/src/commands/logout.js +24 -0
  26. package/src/commands/spread.js +364 -0
  27. package/src/commands/status.js +62 -0
  28. package/src/config/config-manager.js +205 -0
  29. package/src/detectors/api-client-detector.js +85 -0
  30. package/src/detectors/base-detector.js +77 -0
  31. package/src/detectors/github-detector.js +74 -0
  32. package/src/detectors/index.js +80 -0
  33. package/src/detectors/nextjs-detector.js +139 -0
  34. package/src/detectors/oauth-detector.js +122 -0
  35. package/src/detectors/registry.js +97 -0
  36. package/src/generators/api-client-generator.js +197 -0
  37. package/src/generators/env-generator.js +162 -0
  38. package/src/generators/gitignore-generator.js +92 -0
  39. package/src/generators/index.js +50 -0
  40. package/src/generators/nextauth-generator.js +242 -0
  41. package/src/generators/oauth-guide-generator.js +277 -0
  42. package/src/logo.js +116 -0
  43. package/tests/api-client-detector.test.js +214 -0
  44. package/tests/api-client-generator.test.js +169 -0
  45. package/tests/backend-client.test.js +361 -0
  46. package/tests/base-detector.test.js +101 -0
  47. package/tests/commands/login.test.js +98 -0
  48. package/tests/commands/logout.test.js +70 -0
  49. package/tests/commands/status.test.js +167 -0
  50. package/tests/config-manager.test.js +313 -0
  51. package/tests/detector-index.test.js +209 -0
  52. package/tests/detector-registry.test.js +93 -0
  53. package/tests/env-generator.test.js +278 -0
  54. package/tests/generators-index.test.js +215 -0
  55. package/tests/github-detector.test.js +145 -0
  56. package/tests/gitignore-generator.test.js +109 -0
  57. package/tests/logo.test.js +96 -0
  58. package/tests/nextauth-generator.test.js +231 -0
  59. package/tests/nextjs-detector.test.js +235 -0
  60. package/tests/oauth-detector.test.js +264 -0
  61. package/tests/oauth-guide-generator.test.js +273 -0
package/docs/PLAN.md ADDED
@@ -0,0 +1,511 @@
1
+ # 🍰 L4YERCAK3 CLI Tool - Strategic Plan
2
+
3
+ ## Executive Summary
4
+
5
+ This document outlines the strategic plan for the **Icing on the L4yercak3** CLI tool - a universal adapter that connects any frontend application to the L4YERCAK3 backend API platform.
6
+
7
+ ### Vision
8
+
9
+ Enable developers to quickly connect their Next.js applications (or any frontend) to the L4YERCAK3 backend API with minimal configuration, automating the setup of:
10
+ - API client configuration
11
+ - OAuth authentication
12
+ - Environment variables
13
+ - Type definitions
14
+ - Integration patterns
15
+
16
+ ---
17
+
18
+ ## Current State Analysis
19
+
20
+ ### What We Have
21
+
22
+ #### 1. **Backend Platform (vc83-com)**
23
+ - ✅ Full-featured Convex backend with ontology system
24
+ - ✅ CRM integration (contacts, organizations)
25
+ - ✅ OAuth authentication endpoints
26
+ - ✅ Project management backend
27
+ - ✅ Invoicing system backend
28
+ - ✅ API endpoints for core features
29
+ - ✅ Publishing ontology (`convex/publishingOntology.ts`) - manages published pages, deployment configs, env vars
30
+
31
+ #### 2. **Example Frontend Applications**
32
+
33
+ **A. L4YERCAK3 Landing Page** (`l4yercak3-landing`)
34
+ - ✅ CRM integration via `backend-client.ts`
35
+ - ✅ Uses environment variables: `BACKEND_CRM_URL`, `BACKEND_CRM_API_KEY`
36
+ - ✅ Contact creation patterns established
37
+ - ✅ Newsletter, application, appointment integrations
38
+
39
+ **B. Freelancer Client Portal** (`freelancer-client-portal`)
40
+ - ✅ NextAuth.js OAuth setup (Google/Microsoft)
41
+ - ✅ API client with Bearer token auth
42
+ - ✅ Uses environment variables: `NEXT_PUBLIC_BACKEND_API_URL`, `BACKEND_API_URL`
43
+ - ✅ Typed API functions for projects, invoices, messages
44
+ - ✅ Protected routes with middleware
45
+
46
+ #### 3. **CLI Tool (Current State)**
47
+ - ✅ Basic structure with logo display
48
+ - ✅ Package configured for npm publishing
49
+ - ✅ Commands scaffolded (`spread`, `--help`, `--version`)
50
+ - ❌ No actual functionality yet
51
+
52
+ ---
53
+
54
+ ## Strategic Approach
55
+
56
+ ### Option A: CLI Tool as Primary Integration Method (Recommended)
57
+
58
+ **Why CLI Tool?**
59
+ 1. **Universal Adapter**: Works with any Next.js project, not just boilerplates
60
+ 2. **Developer Experience**: One command to set up entire integration
61
+ 3. **Flexibility**: Can adapt to different project structures
62
+ 4. **Discoverability**: Easy to find and use via npm
63
+ 5. **Version Control**: Can update integration patterns over time
64
+
65
+ **How It Works:**
66
+ ```bash
67
+ # In any Next.js project
68
+ npx @l4yercak3/cli spread
69
+
70
+ # Interactive setup:
71
+ # 1. Detect project type (Next.js, Vite, etc.)
72
+ # 2. Ask for backend API URL
73
+ # 3. Generate API key (or use existing)
74
+ # 4. Set up OAuth (if needed)
75
+ # 5. Generate API client files
76
+ # 6. Create environment variable templates
77
+ # 7. Add type definitions
78
+ # 8. Configure NextAuth.js (if Next.js)
79
+ ```
80
+
81
+ ### Option B: Deployment Ontology (Secondary/Complementary)
82
+
83
+ **When to Use:**
84
+ - Automated deployments from backend
85
+ - CI/CD pipeline integration
86
+ - Multi-project management
87
+ - Backend-initiated setups
88
+
89
+ **Relationship:**
90
+ - CLI tool = Developer-initiated integration
91
+ - Deployment ontology = Backend-initiated/automated integration
92
+ - Both can coexist and complement each other
93
+
94
+ ---
95
+
96
+ ## CLI Tool Feature Roadmap
97
+
98
+ ### Phase 1: Core Integration (MVP) 🎯
99
+
100
+ #### 1.1 Project Detection
101
+ - [ ] Detect Next.js projects (check for `next.config.*`, `package.json`)
102
+ - [ ] Detect project structure (App Router vs Pages Router)
103
+ - [ ] Detect existing API client patterns
104
+ - [ ] Detect existing OAuth setup
105
+
106
+ #### 1.2 Configuration Wizard
107
+ - [ ] Interactive prompts for:
108
+ - Backend API URL
109
+ - API key (generate or use existing)
110
+ - OAuth providers (Google, Microsoft)
111
+ - Features to enable (CRM, Projects, Invoices, etc.)
112
+ - [ ] Save configuration to `.l4yercak3/config.json`
113
+
114
+ #### 1.3 File Generation
115
+ - [ ] Generate `lib/api-client.ts` (or adapt existing)
116
+ - [ ] Generate `.env.local.example` with required variables
117
+ - [ ] Generate TypeScript types from backend schema
118
+ - [ ] Generate NextAuth.js configuration (if Next.js)
119
+ - [ ] Generate API integration examples
120
+
121
+ #### 1.4 Environment Setup
122
+ - [ ] Create `.env.local` from template
123
+ - [ ] Add `.env.local` to `.gitignore` (if not present)
124
+ - [ ] Validate environment variables
125
+
126
+ ### Phase 2: Advanced Features 🚀
127
+
128
+ #### 2.1 API Key Management
129
+ - [ ] Generate API keys via backend API
130
+ - [ ] Store API keys securely (local keychain)
131
+ - [ ] Rotate API keys
132
+ - [ ] List active API keys
133
+
134
+ #### 2.2 OAuth Setup Automation
135
+ - [ ] Guide through OAuth app registration
136
+ - [ ] Generate OAuth callback URLs
137
+ - [ ] Validate OAuth configuration
138
+ - [ ] Test OAuth flow
139
+
140
+ #### 2.3 Code Generation
141
+ - [ ] Generate CRUD operations for resources
142
+ - [ ] Generate React hooks for API calls
143
+ - [ ] Generate form components with validation
144
+ - [ ] Generate TypeScript types from API schema
145
+
146
+ #### 2.4 Integration Testing
147
+ - [ ] Test API connectivity
148
+ - [ ] Test OAuth flow
149
+ - [ ] Validate API responses
150
+ - [ ] Generate integration test templates
151
+
152
+ ### Phase 3: Developer Experience ✨
153
+
154
+ #### 3.1 Project Templates
155
+ - [ ] `l4yercak3 spread --template landing-page`
156
+ - [ ] `l4yercak3 spread --template client-portal`
157
+ - [ ] `l4yercak3 spread --template e-commerce`
158
+ - [ ] Custom template support
159
+
160
+ #### 3.2 Documentation Generation
161
+ - [ ] Generate API documentation from backend
162
+ - [ ] Create integration guides
163
+ - [ ] Generate code examples
164
+ - [ ] Create troubleshooting guides
165
+
166
+ #### 3.3 Update Management
167
+ - [ ] Check for CLI updates
168
+ - [ ] Update integration patterns
169
+ - [ ] Migrate old integrations to new patterns
170
+ - [ ] Version compatibility checking
171
+
172
+ ---
173
+
174
+ ## Technical Architecture
175
+
176
+ ### CLI Tool Structure
177
+
178
+ ```
179
+ l4yercak3-cli/
180
+ ├── bin/
181
+ │ └── cli.js # Entry point
182
+ ├── src/
183
+ │ ├── commands/
184
+ │ │ ├── spread.js # Main integration command
185
+ │ │ ├── init.js # Initialize new project
186
+ │ │ ├── login.js # Authenticate with backend
187
+ │ │ ├── generate.js # Generate code/templates
188
+ │ │ └── test.js # Test integration
189
+ │ ├── generators/
190
+ │ │ ├── api-client.js # Generate API client
191
+ │ │ ├── oauth.js # Generate OAuth config
192
+ │ │ ├── env.js # Generate env files
193
+ │ │ └── types.js # Generate TypeScript types
194
+ │ ├── detectors/
195
+ │ │ ├── project-type.js # Detect project type
196
+ │ │ └── existing-setup.js # Detect existing integrations
197
+ │ ├── config/
198
+ │ │ └── manager.js # Config file management
199
+ │ ├── api/
200
+ │ │ └── backend-client.js # Backend API client for CLI
201
+ │ └── utils/
202
+ │ ├── prompts.js # Interactive prompts
203
+ │ └── file-operations.js
204
+ ├── templates/
205
+ │ ├── nextjs/
206
+ │ │ ├── api-client.ts
207
+ │ │ ├── nextauth.ts
208
+ │ │ └── env.example
209
+ │ └── types/
210
+ │ └── api.ts
211
+ └── package.json
212
+ ```
213
+
214
+ ### Integration Patterns
215
+
216
+ #### Pattern 1: API Client Generation
217
+
218
+ **Input:**
219
+ - Backend API URL
220
+ - API key
221
+ - Selected features (CRM, Projects, Invoices)
222
+
223
+ **Output:**
224
+ ```typescript
225
+ // lib/api-client.ts
226
+ export class L4yercak3Client {
227
+ constructor(private apiKey: string, private baseUrl: string) {}
228
+
229
+ // CRM methods
230
+ async createContact(data: CreateContactRequest) { ... }
231
+ async getContacts(filters?: ContactFilters) { ... }
232
+
233
+ // Project methods
234
+ async createProject(data: CreateProjectRequest) { ... }
235
+ async getProjects(filters?: ProjectFilters) { ... }
236
+
237
+ // Invoice methods
238
+ async createInvoice(data: CreateInvoiceRequest) { ... }
239
+ async getInvoices(filters?: InvoiceFilters) { ... }
240
+ }
241
+ ```
242
+
243
+ #### Pattern 2: OAuth Setup
244
+
245
+ **Input:**
246
+ - OAuth providers (Google, Microsoft)
247
+ - Project URL
248
+
249
+ **Output:**
250
+ - NextAuth.js configuration
251
+ - OAuth provider setup guide
252
+ - Environment variables
253
+
254
+ #### Pattern 3: Environment Variables
255
+
256
+ **Generated `.env.local.example`:**
257
+ ```bash
258
+ # L4YERCAK3 Backend API
259
+ NEXT_PUBLIC_BACKEND_API_URL=https://your-backend.convex.site
260
+ BACKEND_API_URL=https://your-backend.convex.site
261
+ BACKEND_CRM_URL=https://your-backend.convex.site
262
+ BACKEND_CRM_API_KEY=your-api-key-here
263
+
264
+ # NextAuth.js (if OAuth enabled)
265
+ NEXTAUTH_URL=http://localhost:3000
266
+ NEXTAUTH_SECRET=your-secret-here
267
+
268
+ # Google OAuth (if enabled)
269
+ GOOGLE_CLIENT_ID=your-client-id
270
+ GOOGLE_CLIENT_SECRET=your-client-secret
271
+
272
+ # Microsoft OAuth (if enabled)
273
+ AZURE_CLIENT_ID=your-client-id
274
+ AZURE_CLIENT_SECRET=your-client-secret
275
+ AZURE_TENANT_ID=your-tenant-id
276
+ ```
277
+
278
+ ---
279
+
280
+ ## Integration Workflow
281
+
282
+ ### Developer Journey
283
+
284
+ ```
285
+ 1. Developer starts new Next.js project
286
+
287
+ 2. Runs: npx @l4yercak3/cli spread
288
+
289
+ 3. CLI detects project type
290
+
291
+ 4. Interactive setup:
292
+ - Backend API URL
293
+ - API key (generate or provide)
294
+ - Features to enable
295
+ - OAuth providers
296
+
297
+ 5. CLI generates:
298
+ - API client code
299
+ - Environment files
300
+ - Type definitions
301
+ - OAuth configuration
302
+
303
+ 6. Developer fills in OAuth credentials
304
+
305
+ 7. Developer runs: npm run dev
306
+
307
+ 8. Integration complete! 🎉
308
+ ```
309
+
310
+ ### Example Commands
311
+
312
+ ```bash
313
+ # Initialize integration
314
+ npx @l4yercak3/cli spread
315
+
316
+ # Initialize with template
317
+ npx @l4yercak3/cli spread --template client-portal
318
+
319
+ # Generate API key
320
+ npx @l4yercak3/cli generate api-key
321
+
322
+ # Test integration
323
+ npx @l4yercak3/cli test
324
+
325
+ # Update integration patterns
326
+ npx @l4yercak3/cli update
327
+
328
+ # Show integration status
329
+ npx @l4yercak3/cli status
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Comparison: CLI vs Deployment Ontology
335
+
336
+ ### CLI Tool Advantages
337
+ - ✅ Works with any project structure
338
+ - ✅ Developer-initiated (on-demand)
339
+ - ✅ Can adapt to existing codebases
340
+ - ✅ Version controlled via npm
341
+ - ✅ Easy to discover and use
342
+ - ✅ Can work offline (after initial setup)
343
+
344
+ ### Deployment Ontology Advantages
345
+ - ✅ Backend-initiated (automated)
346
+ - ✅ Can manage multiple projects
347
+ - ✅ CI/CD integration
348
+ - ✅ Centralized configuration
349
+ - ✅ Deployment tracking
350
+
351
+ ### Recommendation
352
+
353
+ **Use CLI Tool as Primary Method:**
354
+ - Better developer experience
355
+ - More flexible
356
+ - Easier to adopt
357
+ - Works with existing projects
358
+
359
+ **Use Deployment Ontology as Secondary:**
360
+ - For automated deployments
361
+ - For multi-project management
362
+ - For backend-initiated setups
363
+ - For CI/CD pipelines
364
+
365
+ **Both can coexist:**
366
+ - CLI for initial setup
367
+ - Deployment ontology for ongoing management
368
+ - CLI can read from deployment ontology config
369
+
370
+ ---
371
+
372
+ ## Implementation Phases
373
+
374
+ ### Phase 1: Foundation (Week 1-2)
375
+ - [ ] Set up CLI command structure
376
+ - [ ] Implement project detection
377
+ - [ ] Create configuration wizard
378
+ - [ ] Generate basic API client template
379
+ - [ ] Generate environment file templates
380
+
381
+ ### Phase 2: Core Features (Week 3-4)
382
+ - [ ] Implement API key generation
383
+ - [ ] Add OAuth setup automation
384
+ - [ ] Generate TypeScript types
385
+ - [ ] Create NextAuth.js templates
386
+ - [ ] Add integration testing
387
+
388
+ ### Phase 3: Polish (Week 5-6)
389
+ - [ ] Add project templates
390
+ - [ ] Improve error handling
391
+ - [ ] Add update mechanism
392
+ - [ ] Create documentation
393
+ - [ ] Publish to npm
394
+
395
+ ---
396
+
397
+ ## Success Metrics
398
+
399
+ ### Adoption Metrics
400
+ - Number of projects using CLI tool
401
+ - Time to integrate (before vs after)
402
+ - Developer satisfaction scores
403
+
404
+ ### Technical Metrics
405
+ - Integration success rate
406
+ - API call success rate
407
+ - Error rates
408
+ - Support requests
409
+
410
+ ---
411
+
412
+ ## Next Steps
413
+
414
+ 1. **Immediate (This Week)**
415
+ - [ ] Set up development standards (linting, type checking)
416
+ - [ ] Create `.cursor` configuration
417
+ - [ ] Review deployment ontology in backend
418
+ - [ ] Design CLI command structure
419
+
420
+ 2. **Short-term (Next 2 Weeks)**
421
+ - [ ] Implement project detection
422
+ - [ ] Create configuration wizard
423
+ - [ ] Generate API client templates
424
+ - [ ] Test with example projects
425
+
426
+ 3. **Medium-term (Next Month)**
427
+ - [ ] Add OAuth automation
428
+ - [ ] Generate TypeScript types
429
+ - [ ] Create project templates
430
+ - [ ] Publish to npm
431
+
432
+ ---
433
+
434
+ ## Questions Resolved ✅
435
+
436
+ ### 1. **Backend API Key Generation** ✅ RESOLVED
437
+ **Answer:** Not yet implemented, but can be added!
438
+ - Currently: API keys are generated when user creates their account for the first time
439
+ - **Action Required:** Create backend API endpoint for CLI to generate API keys
440
+ - **Implementation:** Add endpoint like `POST /api/v1/api-keys/generate` that creates a new API key for the organization
441
+
442
+ ### 2. **OAuth App Registration** ✅ RESOLVED
443
+ **Answer:** Automate as much as possible - one-click is the goal!
444
+ - **Strategy:** Automate everything we can, only ask for user input when absolutely necessary
445
+ - **Business Value:** The closer to one-click, the more we can charge for it
446
+ - **Implementation Approach:**
447
+ - Use OAuth provider APIs to create apps programmatically where possible
448
+ - Guide through manual steps only when APIs don't support automation
449
+ - Pre-fill all possible fields automatically
450
+ - Generate callback URLs automatically
451
+
452
+ ### 3. **Backend Schema Access for TypeScript Types** ❓ NEEDS CLARIFICATION
453
+ **Question:** How should the CLI generate TypeScript type definitions for API responses?
454
+
455
+ **Context:** When generating the API client, we want to provide proper TypeScript types so developers get autocomplete and type safety. For example:
456
+ ```typescript
457
+ interface Contact {
458
+ _id: string;
459
+ name: string;
460
+ email: string;
461
+ // ... other fields
462
+ }
463
+ ```
464
+
465
+ **Options to Consider:**
466
+ - **Option A:** Backend provides a schema endpoint (e.g., `/api/v1/schema`) that returns JSON Schema or OpenAPI spec
467
+ - **Option B:** CLI makes sample API calls and infers types from responses (less reliable)
468
+ - **Option C:** Types are manually maintained in CLI based on documented API structure
469
+ - **Option D:** Backend exports TypeScript types that CLI can import/generate from
470
+
471
+ **Recommendation:** Option A (schema endpoint) is best for accuracy and maintainability. If not available, Option C (manual maintenance) is acceptable for MVP.
472
+
473
+ ### 4. **Publishing Ontology** ✅ RESOLVED
474
+ **Location:** `/Users/foundbrand_001/Development/vc83-com/convex/publishingOntology.ts`
475
+
476
+ **What It Does:**
477
+ - Manages published pages with templates/themes
478
+ - Stores deployment information (GitHub repos, Vercel URLs)
479
+ - Manages environment variables for deployments
480
+ - Auto-detects env vars from GitHub repos (`autoDetectEnvVarsFromGithub`)
481
+ - Provides deployment validation and pre-flight checks
482
+
483
+ **How CLI Can Integrate:**
484
+ - **Env Var Detection:** Use `autoDetectEnvVarsFromGithub` to automatically detect required env vars from template repos
485
+ - **Deployment Config:** Read deployment env vars from published pages to pre-fill CLI setup
486
+ - **Template Discovery:** Use published page configs to discover available templates
487
+ - **Integration:** CLI can create/update published page configs when setting up integrations
488
+
489
+ **Key Functions Available:**
490
+ - `autoDetectEnvVarsFromGithub` - Fetches `.env.example` from GitHub and parses env vars
491
+ - `getDeploymentEnvVars` - Retrieves configured env vars for a page
492
+ - `updateDeploymentEnvVars` - Stores env vars for deployment
493
+ - `validateGithubRepo` - Validates GitHub repo exists
494
+ - `checkApiKeyStatus` - Checks if org has API keys
495
+
496
+ ---
497
+
498
+ ## Related Documentation
499
+
500
+ - [CLI README](./README.md)
501
+ - [Backend API Documentation](../freelancer-client-portal/docs/API_STATUS_AND_DOCUMENTATION.md)
502
+ - [OAuth Setup Guide](../freelancer-client-portal/docs/FRONTEND_OAUTH_SETUP.md)
503
+ - [Example: Landing Page Integration](../l4yercak3-landing/src/lib/crm-integration/backend-client.ts)
504
+ - [Example: Client Portal Integration](../freelancer-client-portal/lib/api-client.ts)
505
+
506
+ ---
507
+
508
+ **Last Updated:** 2025-01-14
509
+ **Status:** Planning Phase
510
+ **Next Review:** After Phase 1 completion
511
+
package/docs/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # 🍰 L4YERCAK3 CLI Tool Documentation
2
+
3
+ ## Quick Links
4
+
5
+ - **[Implementation Phases](./IMPLEMENTATION_PHASES.md)** - Complete phase breakdown (Backend vs CLI tasks)
6
+ - **[Architecture & Relationships](./ARCHITECTURE_RELATIONSHIPS.md)** - Organization hierarchy and relationships
7
+ - **[Updated Plan](./UPDATED_PLAN.md)** - Strategic plan with all updates
8
+ - **[Stripe Integration](./STRIPE_INTEGRATION.md)** - Stripe Connect setup guide
9
+ - **[OAuth Clarification](./OAUTH_CLARIFICATION.md)** - OAuth automation details
10
+ - **[Development Guide](./DEVELOPMENT.md)** - Developer workflow and standards
11
+
12
+ ## Key Concepts
13
+
14
+ ### Organization Hierarchy
15
+
16
+ **For Agencies:**
17
+ ```
18
+ Agency Organization → Sub-Organization → CRM Organization → CRM Contacts/Frontend Users
19
+ ```
20
+
21
+ **For Regular Organizations:**
22
+ ```
23
+ Regular Organization → CRM Organization → CRM Contacts/Frontend Users
24
+ ```
25
+
26
+ **Key Distinction:**
27
+ - **CRM Organization** = Customer data (NOT a platform organization)
28
+ - **Sub-Organization** = Platform organization (for agencies, boilerplate built FOR this)
29
+ - Boilerplate is scoped to Sub-Organization (for agencies) or Organization (for regular)
30
+
31
+ ### What the CLI Does
32
+
33
+ 1. **Sets up boilerplate** - Generates code to connect frontend to backend
34
+ 2. **Connects to backend** - Uses organization's API key to make API calls
35
+ 3. **Generates integration code** - API client, authentication, Stripe setup, etc.
36
+
37
+ ### What Backend Provides
38
+
39
+ - Account & organization management
40
+ - API key generation
41
+ - Stripe Connect OAuth flow
42
+ - User authentication (frontend_users → crm_contacts)
43
+ - CRM, Projects, Invoices APIs
44
+
45
+ ## Getting Started
46
+
47
+ See [Implementation Phases](./IMPLEMENTATION_PHASES.md) for:
48
+ - What needs to be built on backend
49
+ - What needs to be built in CLI
50
+ - Dependencies between tasks
51
+ - Timeline and priorities
52
+
53
+ ---
54
+
55
+ **Last Updated:** 2025-01-14
56
+