@lastbrain/app 0.1.8 → 0.1.9

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 (39) hide show
  1. package/dist/scripts/init-app.js +0 -2
  2. package/package.json +3 -2
  3. package/src/app-shell/(admin)/layout.tsx +13 -0
  4. package/src/app-shell/(auth)/layout.tsx +13 -0
  5. package/src/app-shell/(public)/page.tsx +11 -0
  6. package/src/app-shell/layout.tsx +5 -0
  7. package/src/app-shell/not-found.tsx +28 -0
  8. package/src/auth/authHelpers.ts +24 -0
  9. package/src/auth/useAuthSession.ts +54 -0
  10. package/src/cli.ts +96 -0
  11. package/src/index.ts +21 -0
  12. package/src/layouts/AdminLayout.tsx +7 -0
  13. package/src/layouts/AppProviders.tsx +61 -0
  14. package/src/layouts/AuthLayout.tsx +7 -0
  15. package/src/layouts/PublicLayout.tsx +7 -0
  16. package/src/layouts/RootLayout.tsx +27 -0
  17. package/src/modules/module-loader.ts +14 -0
  18. package/src/scripts/README.md +262 -0
  19. package/src/scripts/db-init.ts +338 -0
  20. package/src/scripts/db-migrations-sync.ts +86 -0
  21. package/src/scripts/dev-sync.ts +218 -0
  22. package/src/scripts/init-app.ts +1077 -0
  23. package/src/scripts/module-add.ts +242 -0
  24. package/src/scripts/module-build.ts +502 -0
  25. package/src/scripts/module-create.ts +809 -0
  26. package/src/scripts/module-list.ts +37 -0
  27. package/src/scripts/module-remove.ts +367 -0
  28. package/src/scripts/readme-build.ts +60 -0
  29. package/src/styles.css +3 -0
  30. package/src/templates/AuthGuidePage.tsx +68 -0
  31. package/src/templates/DefaultDoc.tsx +462 -0
  32. package/src/templates/DocPage.tsx +381 -0
  33. package/src/templates/DocsPageWithModules.tsx +22 -0
  34. package/src/templates/MigrationsGuidePage.tsx +61 -0
  35. package/src/templates/ModuleGuidePage.tsx +71 -0
  36. package/src/templates/SimpleDocPage.tsx +587 -0
  37. package/src/templates/SimpleHomePage.tsx +385 -0
  38. package/src/templates/env.example/.env.example +6 -0
  39. package/src/templates/migrations/20201010100000_app_base.sql +228 -0
@@ -0,0 +1,587 @@
1
+ // Documentation page with navigation
2
+ "use client";
3
+ import React, { useState } from "react";
4
+ import {
5
+ Card,
6
+ CardBody,
7
+ CardHeader,
8
+ Snippet,
9
+ Listbox,
10
+ ListboxItem,
11
+ } from "@lastbrain/ui";
12
+
13
+ export function SimpleDocPage() {
14
+ const [selectedSection, setSelectedSection] = useState<string>("intro");
15
+
16
+ const scrollToSection = (sectionId: string) => {
17
+ setSelectedSection(sectionId);
18
+ const element = document.getElementById(sectionId);
19
+ if (element) {
20
+ const yOffset = -80;
21
+ const y =
22
+ element.getBoundingClientRect().top + window.pageYOffset + yOffset;
23
+ window.scrollTo({ top: y, behavior: "smooth" });
24
+ }
25
+ };
26
+
27
+ return (
28
+ <div className="pt-32 container mx-auto px-4 py-8">
29
+ <div className="flex gap-8">
30
+ {/* Navigation sidebar */}
31
+ <aside className="w-64 shrink-0 sticky top-4 self-start">
32
+ <Card>
33
+ <CardHeader className="pb-2">
34
+ <h2 className="text-xl font-semibold">Navigation</h2>
35
+ </CardHeader>
36
+ <CardBody>
37
+ <Listbox
38
+ aria-label="Documentation sections"
39
+ selectionMode="single"
40
+ selectedKeys={[selectedSection]}
41
+ onSelectionChange={(keys) => {
42
+ const key = Array.from(keys)[0] as string;
43
+ if (key) scrollToSection(key);
44
+ }}
45
+ >
46
+ <ListboxItem key="intro">Introduction</ListboxItem>
47
+ <ListboxItem key="quickstart">Démarrage Rapide</ListboxItem>
48
+ <ListboxItem key="modules">Modules</ListboxItem>
49
+ <ListboxItem key="database">Base de Données</ListboxItem>
50
+ <ListboxItem key="development">Développement</ListboxItem>
51
+ <ListboxItem key="routes">Routes Protégées</ListboxItem>
52
+ <ListboxItem key="admin">Compte Admin</ListboxItem>
53
+ <ListboxItem key="cli">Commandes CLI</ListboxItem>
54
+ <ListboxItem key="workflow">Workflow</ListboxItem>
55
+ </Listbox>
56
+ </CardBody>
57
+ </Card>
58
+ </aside>
59
+
60
+ {/* Main content */}
61
+ <main className="flex-1 space-y-8">
62
+ {/* Introduction */}
63
+ <section id="intro">
64
+ <h1 className="text-4xl font-bold mb-4 bg-linear-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
65
+ Documentation LastBrain
66
+ </h1>
67
+ <p className="text-xl text-slate-600 dark:text-slate-400 mb-6">
68
+ Framework modulaire pour créer rapidement des applications Next.js
69
+ avec système de modules, authentification et base de données.
70
+ </p>
71
+ <Card>
72
+ <CardBody>
73
+ <ul className="space-y-2 text-slate-700 dark:text-slate-300">
74
+ <li>
75
+ ✅ <strong>CLI intégré</strong> - Créez et gérez vos
76
+ applications en ligne de commande
77
+ </li>
78
+ <li>
79
+ ✅ <strong>Système de modules</strong> - Architecture
80
+ modulaire extensible
81
+ </li>
82
+ <li>
83
+ ✅ <strong>HeroUI</strong> - 58 composants UI modernes et
84
+ accessibles
85
+ </li>
86
+ <li>
87
+ ✅ <strong>TypeScript</strong> - Typage strict pour une
88
+ meilleure DX
89
+ </li>
90
+ <li>
91
+ ✅ <strong>Supabase</strong> - Base de données et
92
+ authentification intégrées
93
+ </li>
94
+ <li>
95
+ ✅ <strong>Hot reload</strong> - Développement avec
96
+ rechargement automatique
97
+ </li>
98
+ <li>
99
+ ✅ <strong>Migrations</strong> - Gestion UP/DOWN des
100
+ migrations SQL
101
+ </li>
102
+ </ul>
103
+ </CardBody>
104
+ </Card>
105
+ </section>
106
+
107
+ {/* Démarrage rapide */}
108
+ <section id="quickstart">
109
+ <Card>
110
+ <CardHeader className="pb-0">
111
+ <h2 className="text-3xl font-semibold">🚀 Démarrage Rapide</h2>
112
+ </CardHeader>
113
+ <CardBody className="pt-4 space-y-4">
114
+ <div>
115
+ <h3 className="text-xl font-semibold mb-2">
116
+ 1. Installation
117
+ </h3>
118
+ <div className="flex flex-col gap-2">
119
+ <Snippet symbol="" color="default" size="sm">
120
+ pnpm install
121
+ </Snippet>
122
+ <Snippet symbol="" color="default" size="sm">
123
+ pnpm build
124
+ </Snippet>
125
+ </div>
126
+ </div>
127
+ <div>
128
+ <h3 className="text-xl font-semibold mb-2">
129
+ 2. Créer une application
130
+ </h3>
131
+ <Snippet symbol="" color="default" size="sm">
132
+ <span>pnpm create-app apps/my-app --heroui</span>
133
+ </Snippet>
134
+ </div>
135
+ <div>
136
+ <h3 className="text-xl font-semibold mb-2">3. Démarrer</h3>
137
+ <div className="flex flex-col gap-2">
138
+ <Snippet symbol="" color="default" size="sm">
139
+ cd apps/my-app
140
+ </Snippet>
141
+ <Snippet symbol="" color="default" size="sm">
142
+ pnpm install
143
+ </Snippet>
144
+ <Snippet symbol="" color="default" size="sm">
145
+ pnpm db:init
146
+ </Snippet>
147
+ <Snippet symbol="" color="default" size="sm">
148
+ pnpm build:modules
149
+ </Snippet>
150
+ <Snippet symbol="" color="default" size="sm">
151
+ pnpm dev
152
+ </Snippet>
153
+ </div>
154
+ <p className="text-sm text-slate-600 dark:text-slate-400 mt-2">
155
+ Votre application est maintenant disponible sur{" "}
156
+ <code className="px-2 py-1 bg-slate-100 dark:bg-slate-800 rounded">
157
+ http://localhost:3000
158
+ </code>
159
+ </p>
160
+ </div>
161
+ </CardBody>
162
+ </Card>
163
+ </section>
164
+
165
+ {/* Modules */}
166
+ <section id="modules">
167
+ <Card>
168
+ <CardHeader className="pb-0">
169
+ <h2 className="text-3xl font-semibold">
170
+ 📦 Modules Disponibles
171
+ </h2>
172
+ </CardHeader>
173
+ <CardBody className="pt-4 space-y-4">
174
+ <div>
175
+ <h3 className="text-xl font-semibold mb-2">module-auth</h3>
176
+ <p className="text-slate-600 dark:text-slate-400 mb-3">
177
+ Authentification complète avec gestion des profils
178
+ utilisateur, adresses et notifications.
179
+ </p>
180
+ <Snippet symbol="" color="default" size="sm">
181
+ <span>pnpm lastbrain add-module auth</span>
182
+ </Snippet>
183
+ </div>
184
+ <div>
185
+ <h3 className="text-xl font-semibold mb-2">module-ai</h3>
186
+ <p className="text-slate-600 dark:text-slate-400 mb-3">
187
+ Génération IA (texte et images) avec système de tokens et
188
+ gestion des coûts.
189
+ </p>
190
+ <Snippet symbol="" color="default" size="sm">
191
+ <span>pnpm lastbrain add-module ai</span>
192
+ </Snippet>
193
+ </div>
194
+ <div>
195
+ <h3 className="text-xl font-semibold mb-2">
196
+ Lister les modules
197
+ </h3>
198
+ <Snippet symbol="" color="default" size="sm">
199
+ <span>pnpm lastbrain list-modules</span>
200
+ </Snippet>
201
+ </div>
202
+ <div>
203
+ <h3 className="text-xl font-semibold mb-2">
204
+ Supprimer un module
205
+ </h3>
206
+ <Snippet symbol="" color="default" size="sm">
207
+ <span>pnpm lastbrain remove-module auth</span>
208
+ </Snippet>
209
+ </div>
210
+ </CardBody>
211
+ </Card>
212
+ </section>
213
+
214
+ {/* Base de données */}
215
+ <section id="database">
216
+ <Card>
217
+ <CardHeader className="pb-0">
218
+ <h2 className="text-3xl font-semibold">🗄️ Base de Données</h2>
219
+ </CardHeader>
220
+ <CardBody className="pt-4 space-y-4">
221
+ <div>
222
+ <h3 className="text-xl font-semibold mb-2">
223
+ Initialiser Supabase
224
+ </h3>
225
+ <Snippet symbol="" color="default" size="sm">
226
+ <span>pnpm db:init</span>
227
+ </Snippet>
228
+ </div>
229
+ <div>
230
+ <h3 className="text-xl font-semibold mb-2">
231
+ Démarrer Supabase local
232
+ </h3>
233
+ <Snippet symbol="" color="default" size="sm">
234
+ <span>supabase start</span>
235
+ </Snippet>
236
+ </div>
237
+ <div>
238
+ <h3 className="text-xl font-semibold mb-2">
239
+ Appliquer les migrations
240
+ </h3>
241
+ <Snippet symbol="" color="default" size="sm">
242
+ <span>supabase migration up</span>
243
+ </Snippet>
244
+ </div>
245
+ <div>
246
+ <h3 className="text-xl font-semibold mb-2">
247
+ Synchroniser les migrations des modules
248
+ </h3>
249
+ <Snippet symbol="" color="default" size="sm">
250
+ <span>pnpm db:migrations:sync</span>
251
+ </Snippet>
252
+ </div>
253
+ <div>
254
+ <h3 className="text-xl font-semibold mb-2">
255
+ Accéder au Studio Supabase
256
+ </h3>
257
+ <p className="text-slate-600 dark:text-slate-400 mb-2">
258
+ Une fois Supabase démarré, accédez au Studio sur{" "}
259
+ <code className="px-2 py-1 bg-slate-100 dark:bg-slate-800 rounded">
260
+ http://localhost:54323
261
+ </code>
262
+ </p>
263
+ </div>
264
+ </CardBody>
265
+ </Card>
266
+ </section>
267
+
268
+ {/* Développement */}
269
+ <section id="development">
270
+ <Card>
271
+ <CardHeader className="pb-0">
272
+ <h2 className="text-3xl font-semibold">🚀 Développement</h2>
273
+ </CardHeader>
274
+ <CardBody className="pt-4 space-y-4">
275
+ <div>
276
+ <h3 className="text-xl font-semibold mb-2">
277
+ Lancer le serveur de développement
278
+ </h3>
279
+ <Snippet symbol="" color="default" size="sm">
280
+ <span>pnpm dev</span>
281
+ </Snippet>
282
+ </div>
283
+ <div>
284
+ <h3 className="text-xl font-semibold mb-2">
285
+ Générer les routes des modules
286
+ </h3>
287
+ <p className="text-slate-600 dark:text-slate-400 mb-2">
288
+ À exécuter après avoir ajouté ou modifié des modules
289
+ </p>
290
+ <Snippet symbol="" color="default" size="sm">
291
+ <span>pnpm build:modules</span>
292
+ </Snippet>
293
+ </div>
294
+ <div>
295
+ <h3 className="text-xl font-semibold mb-2">
296
+ Build de production
297
+ </h3>
298
+ <Snippet symbol="" color="default" size="sm">
299
+ <span>pnpm build</span>
300
+ </Snippet>
301
+ </div>
302
+ <div>
303
+ <h3 className="text-xl font-semibold mb-2">
304
+ Développer un module
305
+ </h3>
306
+ <div className="flex flex-col gap-2">
307
+ <Snippet symbol="" color="default" size="sm">
308
+ cd packages/module-auth
309
+ </Snippet>
310
+ <Snippet symbol="" color="default" size="sm">
311
+ pnpm dev
312
+ </Snippet>
313
+ </div>
314
+ </div>
315
+ </CardBody>
316
+ </Card>
317
+ </section>
318
+
319
+ {/* Routes protégées */}
320
+ <section id="routes">
321
+ <Card>
322
+ <CardHeader className="pb-0">
323
+ <h2 className="text-3xl font-semibold">📝 Routes Protégées</h2>
324
+ </CardHeader>
325
+ <CardBody className="pt-4">
326
+ <p className="text-slate-600 dark:text-slate-400 mb-4">
327
+ Le middleware protège automatiquement vos routes selon ces
328
+ règles :
329
+ </p>
330
+ <div className="space-y-2">
331
+ <div className="p-3 bg-slate-50 dark:bg-slate-900 rounded">
332
+ <code className="text-blue-600 dark:text-blue-400">
333
+ /auth/*
334
+ </code>
335
+ <span className="ml-2">→ Authentification requise</span>
336
+ </div>
337
+ <div className="p-3 bg-slate-50 dark:bg-slate-900 rounded">
338
+ <code className="text-purple-600 dark:text-purple-400">
339
+ /admin/*
340
+ </code>
341
+ <span className="ml-2">→ Superadmin uniquement</span>
342
+ </div>
343
+ <div className="p-3 bg-slate-50 dark:bg-slate-900 rounded">
344
+ <code className="text-green-600 dark:text-green-400">
345
+ /docs/*
346
+ </code>
347
+ <span className="ml-2">→ Accès public</span>
348
+ </div>
349
+ </div>
350
+ <p className="text-sm text-slate-600 dark:text-slate-400 mt-4">
351
+ Le middleware se trouve dans{" "}
352
+ <code className="px-2 py-1 bg-slate-100 dark:bg-slate-800 rounded">
353
+ middleware.ts
354
+ </code>
355
+ </p>
356
+ </CardBody>
357
+ </Card>
358
+ </section>
359
+
360
+ {/* Compte Admin */}
361
+ <section id="admin">
362
+ <Card>
363
+ <CardHeader className="pb-0">
364
+ <h2 className="text-3xl font-semibold">
365
+ 👤 Créer un Compte Administrateur
366
+ </h2>
367
+ </CardHeader>
368
+ <CardBody className="pt-4 space-y-4">
369
+ <ol className="list-decimal list-inside space-y-4">
370
+ <li className="text-lg">
371
+ <strong>Créer un compte</strong>
372
+ <p className="text-slate-600 dark:text-slate-400 ml-6 mb-2">
373
+ Allez sur{" "}
374
+ <code className="px-2 py-1 bg-slate-100 dark:bg-slate-800 rounded">
375
+ /signup
376
+ </code>{" "}
377
+ et créez votre compte
378
+ </p>
379
+ </li>
380
+ <li className="text-lg">
381
+ <strong>Promouvoir en administrateur</strong>
382
+ <p className="text-slate-600 dark:text-slate-400 ml-6 mb-2">
383
+ Exécutez cette requête SQL dans le Studio Supabase ou via
384
+ psql :
385
+ </p>
386
+ <div className="ml-6">
387
+ <Snippet symbol="" color="default" size="sm">
388
+ <span>{`update auth.users`}</span>
389
+ <span>{`
390
+ set raw_app_meta_data = jsonb_set(`}</span>
391
+ <span>{`
392
+ coalesce(raw_app_meta_data, '{}'::jsonb),`}</span>
393
+ <span>{`
394
+ '{roles}',`}</span>
395
+ <span>{`
396
+ '["admin"]'::jsonb`}</span>
397
+ <span>{`
398
+ )`}</span>
399
+ <span>{`
400
+ where email = 'votre@email.com';`}</span>
401
+ </Snippet>
402
+ </div>
403
+ </li>
404
+ <li className="text-lg">
405
+ <strong>Accéder à l'interface admin</strong>
406
+ <p className="text-slate-600 dark:text-slate-400 ml-6">
407
+ Vous pouvez maintenant accéder à{" "}
408
+ <code className="px-2 py-1 bg-slate-100 dark:bg-slate-800 rounded">
409
+ /admin
410
+ </code>
411
+ </p>
412
+ </li>
413
+ </ol>
414
+ </CardBody>
415
+ </Card>
416
+ </section>
417
+
418
+ {/* CLI */}
419
+ <section id="cli">
420
+ <Card>
421
+ <CardHeader className="pb-0">
422
+ <h2 className="text-3xl font-semibold">🔧 Commandes CLI</h2>
423
+ </CardHeader>
424
+ <CardBody className="pt-4 space-y-4">
425
+ <div>
426
+ <h3 className="text-xl font-semibold mb-2">
427
+ Créer une application
428
+ </h3>
429
+ <Snippet symbol="" color="default" size="sm">
430
+ <span>pnpm create-app apps/my-app --heroui</span>
431
+ </Snippet>
432
+ </div>
433
+ <div>
434
+ <h3 className="text-xl font-semibold mb-2">
435
+ Ajouter un module
436
+ </h3>
437
+ <Snippet symbol="" color="default" size="sm">
438
+ <span>pnpm lastbrain add-module [nom]</span>
439
+ </Snippet>
440
+ </div>
441
+ <div>
442
+ <h3 className="text-xl font-semibold mb-2">
443
+ Supprimer un module
444
+ </h3>
445
+ <Snippet symbol="" color="default" size="sm">
446
+ <span>pnpm lastbrain remove-module [nom]</span>
447
+ </Snippet>
448
+ </div>
449
+ <div>
450
+ <h3 className="text-xl font-semibold mb-2">
451
+ Lister les modules
452
+ </h3>
453
+ <Snippet symbol="" color="default" size="sm">
454
+ <span>pnpm lastbrain list-modules</span>
455
+ </Snippet>
456
+ </div>
457
+ <div>
458
+ <h3 className="text-xl font-semibold mb-2">
459
+ Créer un module
460
+ </h3>
461
+ <Snippet symbol="" color="default" size="sm">
462
+ <span>pnpm lastbrain create-module my-module</span>
463
+ </Snippet>
464
+ </div>
465
+ </CardBody>
466
+ </Card>
467
+ </section>
468
+
469
+ {/* Workflow */}
470
+ <section id="workflow">
471
+ <Card>
472
+ <CardHeader className="pb-0">
473
+ <h2 className="text-3xl font-semibold">
474
+ ⚡ Workflow de Développement
475
+ </h2>
476
+ </CardHeader>
477
+ <CardBody className="pt-4 space-y-4">
478
+ <div>
479
+ <h3 className="text-xl font-semibold mb-2">
480
+ 1. Modifier un module
481
+ </h3>
482
+ <p className="text-slate-600 dark:text-slate-400 mb-2">
483
+ Éditez les fichiers dans{" "}
484
+ <code className="px-2 py-1 bg-slate-100 dark:bg-slate-800 rounded">
485
+ packages/module-*/src
486
+ </code>
487
+ </p>
488
+ </div>
489
+ <div>
490
+ <h3 className="text-xl font-semibold mb-2">
491
+ 2. Compiler le module
492
+ </h3>
493
+ <div className="flex flex-col gap-2">
494
+ <Snippet symbol="" color="default" size="sm">
495
+ cd packages/module-auth
496
+ </Snippet>
497
+ <Snippet symbol="" color="default" size="sm">
498
+ pnpm build
499
+ </Snippet>
500
+ </div>
501
+ </div>
502
+ <div>
503
+ <h3 className="text-xl font-semibold mb-2">
504
+ 3. Régénérer les pages
505
+ </h3>
506
+ <div className="flex flex-col gap-2">
507
+ <Snippet symbol="" color="default" size="sm">
508
+ cd apps/my-app
509
+ </Snippet>
510
+ <Snippet symbol="" color="default" size="sm">
511
+ pnpm build:modules
512
+ </Snippet>
513
+ </div>
514
+ </div>
515
+ <div>
516
+ <h3 className="text-xl font-semibold mb-2">
517
+ 4. Appliquer les migrations
518
+ </h3>
519
+ <Snippet symbol="" color="default" size="sm">
520
+ <span>supabase migration up</span>
521
+ </Snippet>
522
+ </div>
523
+ <div>
524
+ <h3 className="text-xl font-semibold mb-2">5. Tester</h3>
525
+ <Snippet symbol="" color="default" size="sm">
526
+ <span>pnpm dev</span>
527
+ </Snippet>
528
+ </div>
529
+ </CardBody>
530
+ </Card>
531
+ </section>
532
+
533
+ {/* Resources supplémentaires */}
534
+ <section id="resources">
535
+ <Card className="bg-linear-to-r from-blue-50 to-purple-50 dark:from-blue-950/30 dark:to-purple-950/30 border-blue-200 dark:border-blue-800">
536
+ <CardHeader className="pb-0">
537
+ <h2 className="text-3xl font-semibold">
538
+ 📚 Resources Supplémentaires
539
+ </h2>
540
+ </CardHeader>
541
+ <CardBody className="pt-4">
542
+ <ul className="space-y-2">
543
+ <li>
544
+ 📖{" "}
545
+ <a
546
+ href="/docs/CLI.md"
547
+ className="text-blue-600 dark:text-blue-400 hover:underline"
548
+ >
549
+ Documentation CLI complète
550
+ </a>
551
+ </li>
552
+ <li>
553
+ 🔧{" "}
554
+ <a
555
+ href="/docs/MODULES.md"
556
+ className="text-blue-600 dark:text-blue-400 hover:underline"
557
+ >
558
+ Guide de création de modules
559
+ </a>
560
+ </li>
561
+ <li>
562
+ 🗄️{" "}
563
+ <a
564
+ href="/docs/MIGRATIONS.md"
565
+ className="text-blue-600 dark:text-blue-400 hover:underline"
566
+ >
567
+ Système de migrations
568
+ </a>
569
+ </li>
570
+ <li>
571
+ 🏗️{" "}
572
+ <a
573
+ href="/docs/MONOREPO_CLI_USAGE.md"
574
+ className="text-blue-600 dark:text-blue-400 hover:underline"
575
+ >
576
+ Architecture du monorepo
577
+ </a>
578
+ </li>
579
+ </ul>
580
+ </CardBody>
581
+ </Card>
582
+ </section>
583
+ </main>
584
+ </div>
585
+ </div>
586
+ );
587
+ }