nexu-app 2.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 (106) hide show
  1. package/README.md +149 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +1192 -0
  4. package/package.json +43 -0
  5. package/templates/default/.changeset/config.json +11 -0
  6. package/templates/default/.eslintignore +16 -0
  7. package/templates/default/.eslintrc.js +67 -0
  8. package/templates/default/.github/actions/build/action.yml +35 -0
  9. package/templates/default/.github/actions/quality/action.yml +53 -0
  10. package/templates/default/.github/dependabot.yml +51 -0
  11. package/templates/default/.github/workflows/deploy-dev.yml +83 -0
  12. package/templates/default/.github/workflows/deploy-prod.yml +83 -0
  13. package/templates/default/.github/workflows/deploy-rec.yml +83 -0
  14. package/templates/default/.husky/commit-msg +1 -0
  15. package/templates/default/.husky/pre-commit +1 -0
  16. package/templates/default/.nexu-version +1 -0
  17. package/templates/default/.prettierignore +7 -0
  18. package/templates/default/.prettierrc +19 -0
  19. package/templates/default/.vscode/extensions.json +14 -0
  20. package/templates/default/.vscode/settings.json +36 -0
  21. package/templates/default/apps/gitkeep +0 -0
  22. package/templates/default/commitlint.config.js +26 -0
  23. package/templates/default/docker/docker-compose.dev.yml +49 -0
  24. package/templates/default/docker/docker-compose.prod.yml +64 -0
  25. package/templates/default/docker/docker-compose.yml +6 -0
  26. package/templates/default/docs/architecture.md +452 -0
  27. package/templates/default/docs/cli.md +330 -0
  28. package/templates/default/docs/contributing.md +462 -0
  29. package/templates/default/docs/scripts.md +460 -0
  30. package/templates/default/gitignore +44 -0
  31. package/templates/default/lintstagedrc.cjs +4 -0
  32. package/templates/default/package.json +51 -0
  33. package/templates/default/packages/auth/package.json +61 -0
  34. package/templates/default/packages/auth/src/components/ProtectedRoute.tsx +75 -0
  35. package/templates/default/packages/auth/src/components/SignInForm.tsx +153 -0
  36. package/templates/default/packages/auth/src/components/SignUpForm.tsx +179 -0
  37. package/templates/default/packages/auth/src/components/SocialButtons.tsx +147 -0
  38. package/templates/default/packages/auth/src/components/index.ts +4 -0
  39. package/templates/default/packages/auth/src/hooks/index.ts +4 -0
  40. package/templates/default/packages/auth/src/hooks/useAuth.ts +51 -0
  41. package/templates/default/packages/auth/src/hooks/useRequireAuth.ts +54 -0
  42. package/templates/default/packages/auth/src/hooks/useSession.ts +48 -0
  43. package/templates/default/packages/auth/src/hooks/useUser.ts +48 -0
  44. package/templates/default/packages/auth/src/index.ts +45 -0
  45. package/templates/default/packages/auth/src/next/index.ts +18 -0
  46. package/templates/default/packages/auth/src/next/middleware.ts +183 -0
  47. package/templates/default/packages/auth/src/next/server.ts +219 -0
  48. package/templates/default/packages/auth/src/providers/AuthContext.tsx +435 -0
  49. package/templates/default/packages/auth/src/providers/index.ts +1 -0
  50. package/templates/default/packages/auth/src/types/index.ts +284 -0
  51. package/templates/default/packages/auth/src/utils/api.ts +228 -0
  52. package/templates/default/packages/auth/src/utils/index.ts +3 -0
  53. package/templates/default/packages/auth/src/utils/oauth.ts +230 -0
  54. package/templates/default/packages/auth/src/utils/token.ts +204 -0
  55. package/templates/default/packages/auth/tsconfig.json +14 -0
  56. package/templates/default/packages/auth/tsup.config.ts +18 -0
  57. package/templates/default/packages/cache/package.json +26 -0
  58. package/templates/default/packages/cache/src/index.ts +137 -0
  59. package/templates/default/packages/cache/tsconfig.json +9 -0
  60. package/templates/default/packages/cache/tsup.config.ts +9 -0
  61. package/templates/default/packages/config/eslint/index.js +20 -0
  62. package/templates/default/packages/config/package.json +9 -0
  63. package/templates/default/packages/config/typescript/base.json +26 -0
  64. package/templates/default/packages/constants/package.json +26 -0
  65. package/templates/default/packages/constants/src/index.ts +121 -0
  66. package/templates/default/packages/constants/tsconfig.json +9 -0
  67. package/templates/default/packages/constants/tsup.config.ts +9 -0
  68. package/templates/default/packages/logger/package.json +27 -0
  69. package/templates/default/packages/logger/src/index.ts +197 -0
  70. package/templates/default/packages/logger/tsconfig.json +11 -0
  71. package/templates/default/packages/logger/tsup.config.ts +9 -0
  72. package/templates/default/packages/result/package.json +26 -0
  73. package/templates/default/packages/result/src/index.ts +142 -0
  74. package/templates/default/packages/result/tsconfig.json +9 -0
  75. package/templates/default/packages/result/tsup.config.ts +9 -0
  76. package/templates/default/packages/types/package.json +26 -0
  77. package/templates/default/packages/types/src/index.ts +78 -0
  78. package/templates/default/packages/types/tsconfig.json +9 -0
  79. package/templates/default/packages/types/tsup.config.ts +10 -0
  80. package/templates/default/packages/ui/package.json +38 -0
  81. package/templates/default/packages/ui/src/components/Button.tsx +58 -0
  82. package/templates/default/packages/ui/src/components/Card.tsx +85 -0
  83. package/templates/default/packages/ui/src/components/Input.tsx +45 -0
  84. package/templates/default/packages/ui/src/index.ts +15 -0
  85. package/templates/default/packages/ui/tsconfig.json +11 -0
  86. package/templates/default/packages/ui/tsup.config.ts +11 -0
  87. package/templates/default/packages/utils/package.json +30 -0
  88. package/templates/default/packages/utils/src/index.test.ts +130 -0
  89. package/templates/default/packages/utils/src/index.ts +154 -0
  90. package/templates/default/packages/utils/tsconfig.json +10 -0
  91. package/templates/default/packages/utils/tsup.config.ts +10 -0
  92. package/templates/default/pnpm-workspace.yaml +3 -0
  93. package/templates/default/scripts/audit.mjs +700 -0
  94. package/templates/default/scripts/deploy.mjs +40 -0
  95. package/templates/default/scripts/generate-app.mjs +808 -0
  96. package/templates/default/scripts/lib/package-manager.mjs +186 -0
  97. package/templates/default/scripts/setup.mjs +102 -0
  98. package/templates/default/services/.env.example +16 -0
  99. package/templates/default/services/docker-compose.yml +207 -0
  100. package/templates/default/services/grafana/provisioning/dashboards/dashboards.yml +11 -0
  101. package/templates/default/services/grafana/provisioning/datasources/datasources.yml +9 -0
  102. package/templates/default/services/postgres/init/gitkeep +2 -0
  103. package/templates/default/services/prometheus/prometheus.yml +13 -0
  104. package/templates/default/tsconfig.json +27 -0
  105. package/templates/default/turbo.json +40 -0
  106. package/templates/default/vitest.config.ts +15 -0
@@ -0,0 +1,462 @@
1
+ # Guide de contribution
2
+
3
+ Merci de votre intérêt pour contribuer à Nexu ! Ce guide vous aidera à démarrer.
4
+
5
+ ## Prérequis
6
+
7
+ - Node.js 20+
8
+ - pnpm 9+
9
+ - Git
10
+ - Docker (optionnel, pour les services)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ # Cloner le repository
16
+ git clone https://github.com/heccath/nexu.git
17
+ cd nexu
18
+
19
+ # Installer les dépendances
20
+ pnpm install
21
+
22
+ # Build les packages
23
+ pnpm build
24
+ ```
25
+
26
+ ## Workflow de développement
27
+
28
+ ### 1. Créer une branche
29
+
30
+ ```bash
31
+ # Depuis la branche dev
32
+ git checkout dev
33
+ git pull origin dev
34
+ git checkout -b feature/ma-fonctionnalite
35
+ ```
36
+
37
+ ### Conventions de nommage des branches
38
+
39
+ | Préfixe | Usage |
40
+ | ----------- | ----------------------- |
41
+ | `feature/` | Nouvelle fonctionnalité |
42
+ | `fix/` | Correction de bug |
43
+ | `docs/` | Documentation |
44
+ | `refactor/` | Refactorisation |
45
+ | `test/` | Tests |
46
+ | `chore/` | Maintenance |
47
+
48
+ ### 2. Développer
49
+
50
+ ```bash
51
+ # Lancer le mode dev
52
+ pnpm dev
53
+
54
+ # Dans un autre terminal, vérifier le code
55
+ pnpm lint
56
+ pnpm typecheck
57
+ pnpm test
58
+ ```
59
+
60
+ ### 3. Commiter
61
+
62
+ ```bash
63
+ # Ajouter les fichiers
64
+ git add .
65
+
66
+ # Commiter (le message est validé par commitlint)
67
+ git commit -m "feat: add new feature"
68
+ ```
69
+
70
+ ### Conventions de commit
71
+
72
+ Format: `<type>: <description>`
73
+
74
+ | Type | Description |
75
+ | ---------- | ------------------------------------- |
76
+ | `feat` | Nouvelle fonctionnalité |
77
+ | `fix` | Correction de bug |
78
+ | `docs` | Documentation |
79
+ | `style` | Formatage (pas de changement de code) |
80
+ | `refactor` | Refactorisation |
81
+ | `perf` | Amélioration des performances |
82
+ | `test` | Ajout ou modification de tests |
83
+ | `build` | Changements de build ou dépendances |
84
+ | `ci` | Configuration CI |
85
+ | `chore` | Autres changements |
86
+
87
+ **Exemples:**
88
+
89
+ ```bash
90
+ git commit -m "feat: add user authentication"
91
+ git commit -m "fix: resolve login redirect issue"
92
+ git commit -m "docs: update API documentation"
93
+ git commit -m "refactor: simplify error handling"
94
+ ```
95
+
96
+ ### 4. Créer un changeset (si nécessaire)
97
+
98
+ Si vos changements affectent les packages publiés:
99
+
100
+ ```bash
101
+ pnpm changeset
102
+ ```
103
+
104
+ Suivez les instructions pour:
105
+
106
+ 1. Sélectionner les packages affectés
107
+ 2. Choisir le type de version (major, minor, patch)
108
+ 3. Décrire les changements
109
+
110
+ ### 5. Push et Pull Request
111
+
112
+ ```bash
113
+ git push origin feature/ma-fonctionnalite
114
+ ```
115
+
116
+ Créez une Pull Request vers `dev` sur GitHub.
117
+
118
+ ## Structure des Pull Requests
119
+
120
+ ### Titre
121
+
122
+ Utilisez le même format que les commits:
123
+
124
+ ```
125
+ feat: add user authentication
126
+ ```
127
+
128
+ ### Description
129
+
130
+ ```markdown
131
+ ## Description
132
+
133
+ Brève description des changements.
134
+
135
+ ## Changements
136
+
137
+ - Liste des modifications
138
+ - Fichiers ajoutés/modifiés
139
+ - Dépendances ajoutées
140
+
141
+ ## Tests
142
+
143
+ Comment tester les changements:
144
+
145
+ 1. Étape 1
146
+ 2. Étape 2
147
+
148
+ ## Checklist
149
+
150
+ - [ ] Tests ajoutés/mis à jour
151
+ - [ ] Documentation mise à jour
152
+ - [ ] Changeset créé (si applicable)
153
+ - [ ] Lint et typecheck passent
154
+ ```
155
+
156
+ ## Guidelines de code
157
+
158
+ ### TypeScript
159
+
160
+ ```typescript
161
+ // ✅ Bon
162
+ function calculateTotal(items: Item[]): number {
163
+ return items.reduce((sum, item) => sum + item.price, 0);
164
+ }
165
+
166
+ // ❌ Mauvais
167
+ function calculateTotal(items: any): any {
168
+ let sum = 0;
169
+ for (let i = 0; i < items.length; i++) {
170
+ sum += items[i].price;
171
+ }
172
+ return sum;
173
+ }
174
+ ```
175
+
176
+ **Règles:**
177
+
178
+ - Toujours typer les paramètres et retours
179
+ - Éviter `any`, préférer `unknown` si nécessaire
180
+ - Utiliser les types stricts
181
+
182
+ ### Imports
183
+
184
+ ```typescript
185
+ // ✅ Bon - imports organisés
186
+ import { useState, useEffect } from 'react';
187
+
188
+ import { Button } from '@repo/ui';
189
+ import { formatDate } from '@repo/utils';
190
+ import type { User } from '@repo/types';
191
+
192
+ import { UserCard } from './components/UserCard';
193
+ import { useUser } from './hooks/useUser';
194
+
195
+ // ❌ Mauvais - imports désorganisés
196
+ import { UserCard } from './components/UserCard';
197
+ import { useState, useEffect } from 'react';
198
+ import { Button } from '@repo/ui';
199
+ import { useUser } from './hooks/useUser';
200
+ ```
201
+
202
+ **Ordre des imports:**
203
+
204
+ 1. Modules Node.js natifs
205
+ 2. Packages externes (react, etc.)
206
+ 3. Packages du monorepo (@repo/\*)
207
+ 4. Imports relatifs
208
+
209
+ ### Nommage
210
+
211
+ | Type | Convention | Exemple |
212
+ | ---------------- | ---------------- | ----------------- |
213
+ | Variables | camelCase | `userName` |
214
+ | Constantes | UPPER_SNAKE_CASE | `MAX_RETRIES` |
215
+ | Fonctions | camelCase | `getUserById` |
216
+ | Classes | PascalCase | `UserService` |
217
+ | Interfaces/Types | PascalCase | `UserProfile` |
218
+ | Fichiers | kebab-case | `user-service.ts` |
219
+ | Composants React | PascalCase | `UserCard.tsx` |
220
+
221
+ ### Commentaires
222
+
223
+ ```typescript
224
+ // ✅ Bon - explique le "pourquoi"
225
+ // Skip validation for admin users as they have full access
226
+ if (user.role === 'admin') {
227
+ return true;
228
+ }
229
+
230
+ // ❌ Mauvais - explique le "quoi" (évident)
231
+ // Check if user is admin
232
+ if (user.role === 'admin') {
233
+ return true;
234
+ }
235
+ ```
236
+
237
+ ### Error handling
238
+
239
+ ```typescript
240
+ // ✅ Bon - utiliser Result
241
+ import { tryCatchAsync, match } from '@repo/result';
242
+
243
+ const result = await tryCatchAsync(() => fetchUser(id));
244
+ return match(result, {
245
+ ok: user => user,
246
+ err: error => {
247
+ logger.error('Failed to fetch user', { id, error });
248
+ throw new AppError('USER_NOT_FOUND', error.message);
249
+ },
250
+ });
251
+
252
+ // ❌ Mauvais - try/catch générique
253
+ try {
254
+ const user = await fetchUser(id);
255
+ return user;
256
+ } catch (e) {
257
+ console.log('error');
258
+ throw e;
259
+ }
260
+ ```
261
+
262
+ ## Tests
263
+
264
+ ### Écrire des tests
265
+
266
+ ```typescript
267
+ // packages/utils/src/__tests__/string.test.ts
268
+ import { describe, it, expect } from 'vitest';
269
+ import { capitalize, slugify } from '../string';
270
+
271
+ describe('capitalize', () => {
272
+ it('should capitalize first letter', () => {
273
+ expect(capitalize('hello')).toBe('Hello');
274
+ });
275
+
276
+ it('should handle empty string', () => {
277
+ expect(capitalize('')).toBe('');
278
+ });
279
+
280
+ it('should handle already capitalized', () => {
281
+ expect(capitalize('Hello')).toBe('Hello');
282
+ });
283
+ });
284
+
285
+ describe('slugify', () => {
286
+ it('should convert to lowercase kebab-case', () => {
287
+ expect(slugify('Hello World')).toBe('hello-world');
288
+ });
289
+ });
290
+ ```
291
+
292
+ ### Exécuter les tests
293
+
294
+ ```bash
295
+ # Tous les tests
296
+ pnpm test
297
+
298
+ # Tests avec watch
299
+ pnpm test -- --watch
300
+
301
+ # Tests avec coverage
302
+ pnpm test:coverage
303
+
304
+ # Tests d'un package spécifique
305
+ pnpm test --filter=@repo/utils
306
+ ```
307
+
308
+ ## Ajouter un nouveau package
309
+
310
+ ### 1. Créer la structure
311
+
312
+ ```bash
313
+ mkdir -p packages/my-package/src
314
+ cd packages/my-package
315
+ ```
316
+
317
+ ### 2. Créer package.json
318
+
319
+ ```json
320
+ {
321
+ "name": "@repo/my-package",
322
+ "version": "0.0.1",
323
+ "private": true,
324
+ "type": "module",
325
+ "exports": {
326
+ ".": {
327
+ "types": "./dist/index.d.ts",
328
+ "import": "./dist/index.js"
329
+ }
330
+ },
331
+ "scripts": {
332
+ "build": "tsup",
333
+ "dev": "tsup --watch",
334
+ "lint": "eslint src/",
335
+ "typecheck": "tsc --noEmit",
336
+ "test": "vitest run",
337
+ "test:watch": "vitest"
338
+ },
339
+ "devDependencies": {
340
+ "@repo/typescript-config": "workspace:*",
341
+ "tsup": "^8.0.0",
342
+ "typescript": "^5.4.0",
343
+ "vitest": "^2.0.0"
344
+ }
345
+ }
346
+ ```
347
+
348
+ ### 3. Créer tsconfig.json
349
+
350
+ ```json
351
+ {
352
+ "extends": "@repo/typescript-config/base.json",
353
+ "compilerOptions": {
354
+ "outDir": "dist",
355
+ "rootDir": "src"
356
+ },
357
+ "include": ["src/**/*"],
358
+ "exclude": ["node_modules", "dist"]
359
+ }
360
+ ```
361
+
362
+ ### 4. Créer tsup.config.ts
363
+
364
+ ```typescript
365
+ import { defineConfig } from 'tsup';
366
+
367
+ export default defineConfig({
368
+ entry: ['src/index.ts'],
369
+ format: ['esm'],
370
+ dts: true,
371
+ clean: true,
372
+ sourcemap: true,
373
+ });
374
+ ```
375
+
376
+ ### 5. Créer le code source
377
+
378
+ ```typescript
379
+ // src/index.ts
380
+ export function myFunction(): string {
381
+ return 'Hello from my-package!';
382
+ }
383
+ ```
384
+
385
+ ### 6. Installer les dépendances
386
+
387
+ ```bash
388
+ cd ../..
389
+ pnpm install
390
+ ```
391
+
392
+ ## Ajouter une nouvelle app
393
+
394
+ Utilisez le script de génération:
395
+
396
+ ```bash
397
+ pnpm generate:app my-app next 3000
398
+ ```
399
+
400
+ Ou manuellement:
401
+
402
+ 1. Créer le dossier dans `apps/`
403
+ 2. Ajouter `package.json` avec `name: "@repo/my-app"`
404
+ 3. Créer la configuration Docker
405
+ 4. Mettre à jour `docker/docker-compose.yml`
406
+
407
+ ## Debugging
408
+
409
+ ### VS Code
410
+
411
+ Configuration recommandée `.vscode/launch.json`:
412
+
413
+ ```json
414
+ {
415
+ "version": "0.2.0",
416
+ "configurations": [
417
+ {
418
+ "name": "Debug Package",
419
+ "type": "node",
420
+ "request": "launch",
421
+ "program": "${workspaceFolder}/packages/${input:package}/src/index.ts",
422
+ "runtimeArgs": ["-r", "tsx/cjs"],
423
+ "console": "integratedTerminal"
424
+ }
425
+ ],
426
+ "inputs": [
427
+ {
428
+ "id": "package",
429
+ "type": "promptString",
430
+ "description": "Package name"
431
+ }
432
+ ]
433
+ }
434
+ ```
435
+
436
+ ### Logs
437
+
438
+ ```typescript
439
+ import { logger } from '@repo/logger';
440
+
441
+ // En développement
442
+ logger.debug('Debug info', { data });
443
+
444
+ // Activer les logs debug
445
+ LOG_LEVEL=debug pnpm dev
446
+ ```
447
+
448
+ ## Ressources
449
+
450
+ - [Turborepo Documentation](https://turbo.build/repo/docs)
451
+ - [pnpm Workspaces](https://pnpm.io/workspaces)
452
+ - [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/)
453
+ - [Conventional Commits](https://www.conventionalcommits.org/)
454
+ - [Changesets](https://github.com/changesets/changesets)
455
+
456
+ ## Questions ?
457
+
458
+ Si vous avez des questions, n'hésitez pas à:
459
+
460
+ 1. Ouvrir une issue sur GitHub
461
+ 2. Demander dans les discussions
462
+ 3. Contacter les mainteneurs