@thinhnguyencth1204/nextcli 0.6.1 → 0.8.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 (122) hide show
  1. package/README.md +68 -47
  2. package/dist/cli.js +1002 -753
  3. package/package.json +6 -2
  4. package/templates/{next-base/src/lib/axios-instance.ts → features/api/src/lib/api/axios.ts} +7 -2
  5. package/templates/{next-base/src/lib/api-response.ts → features/api/src/lib/api/response.ts} +1 -5
  6. package/templates/{next-base → features/auth}/src/app/(auth)/change-password/layout.tsx +1 -1
  7. package/templates/{next-base → features/auth}/src/app/(auth)/sign-in/layout.tsx +1 -1
  8. package/templates/{next-base → features/auth}/src/app/api/v1/auth/change-password/route.ts +3 -3
  9. package/templates/{next-base → features/auth}/src/app/api/v1/auth/login/route.ts +3 -3
  10. package/templates/{next-base → features/auth}/src/app/api/v1/auth/logout/route.ts +2 -2
  11. package/templates/{next-base → features/auth}/src/app/api/v1/auth/me/route.ts +2 -2
  12. package/templates/{next-base → features/auth}/src/app/api/v1/auth/refresh/route.ts +2 -2
  13. package/templates/{next-base → features/auth}/src/app/api/v1/users/[id]/route.ts +3 -3
  14. package/templates/{next-base → features/auth}/src/app/api/v1/users/route.ts +3 -3
  15. package/templates/{next-base → features/auth}/src/features/auth/components/account-panel.tsx +1 -1
  16. package/templates/{next-base → features/auth}/src/features/auth/components/change-password-form.tsx +1 -1
  17. package/templates/{next-base → features/auth}/src/features/auth/components/sign-in-form.tsx +2 -2
  18. package/templates/{next-base → features/auth}/src/features/users/services.ts +1 -1
  19. package/templates/{next-base → features/auth}/src/instrumentation.ts +1 -1
  20. package/templates/{next-base/src/lib → features/auth/src/lib/auth}/bootstrap.ts +2 -3
  21. package/templates/features/auth/src/lib/auth/index.ts +1 -0
  22. package/templates/{next-base/src/lib → features/auth/src/lib/auth}/rbac.ts +2 -5
  23. package/templates/{next-base/src/lib/auth.ts → features/auth/src/lib/auth/server.ts} +2 -1
  24. package/templates/{next-base → features/auth}/src/lib/constants.ts +3 -0
  25. package/templates/features/chat/src/app/api/v1/chat/route.ts +1 -1
  26. package/templates/features/chat/src/features/chat/api/use-chat-history.ts +1 -1
  27. package/templates/features/chat/src/features/chat/api/use-send-message.ts +1 -1
  28. package/templates/{next-base → features/dashboard}/src/app/(dashboard)/layout.tsx +1 -1
  29. package/templates/features/dashboard/src/app/page.tsx +5 -0
  30. package/templates/{next-base → features/dashboard}/src/components/layout/private/nav-user.tsx +1 -1
  31. package/templates/{next-base → features/database}/prisma/schema.prisma +0 -12
  32. package/templates/{next-base → features/database}/prisma.config.ts +2 -2
  33. package/templates/features/database/src/lib/prisma.ts +23 -0
  34. package/templates/{next-base → features/example}/src/app/api/v1/example/route.ts +2 -2
  35. package/templates/{next-base → features/example}/src/example/api/use-example.ts +1 -1
  36. package/templates/{next-base → features/example}/src/example/api/use-mutations.ts +1 -1
  37. package/templates/{next-base → features/example}/src/example/services.ts +1 -1
  38. package/templates/features/i18n/next.config.ts +17 -0
  39. package/templates/features/i18n/src/app/layout.tsx +42 -0
  40. package/templates/features/supabase/src/lib/supabase/rich-text-image-sync.ts +28 -0
  41. package/templates/next-base/.env +0 -14
  42. package/templates/next-base/.env.development +0 -14
  43. package/templates/next-base/.env.example +0 -14
  44. package/templates/next-base/PROJECT_STRUCTURE.md +43 -54
  45. package/templates/next-base/SETUP.md +12 -60
  46. package/templates/next-base/bun.lock +59 -397
  47. package/templates/next-base/next-env.d.ts +1 -1
  48. package/templates/next-base/next.config.ts +1 -4
  49. package/templates/next-base/nextcli.json +3 -3
  50. package/templates/next-base/package.json +6 -21
  51. package/templates/next-base/src/app/blog-demo/page.tsx +9 -0
  52. package/templates/next-base/src/app/globals.css +57 -0
  53. package/templates/next-base/src/app/layout.tsx +6 -14
  54. package/templates/next-base/src/app/page.tsx +25 -2
  55. package/templates/next-base/src/components/rich-text/adapters/textarea-field.tsx +50 -0
  56. package/templates/next-base/src/components/rich-text/client-only.tsx +23 -0
  57. package/templates/next-base/src/components/rich-text/editor-field.tsx +62 -0
  58. package/templates/next-base/src/components/rich-text/examples/blog-rich-text-demo.tsx +218 -0
  59. package/templates/next-base/src/components/rich-text/index.ts +11 -0
  60. package/templates/next-base/src/components/rich-text/lexical/extension.ts +37 -0
  61. package/templates/next-base/src/components/rich-text/lexical/nodes/image-node.tsx +187 -0
  62. package/templates/next-base/src/components/rich-text/lexical/plugins/image-plugin.tsx +40 -0
  63. package/templates/next-base/src/components/rich-text/lexical/plugins/initial-state-plugin.tsx +26 -0
  64. package/templates/next-base/src/components/rich-text/lexical/plugins/on-change-plugin.tsx +26 -0
  65. package/templates/next-base/src/components/rich-text/lexical/plugins/toolbar-plugin.tsx +190 -0
  66. package/templates/next-base/src/components/rich-text/lexical/rich-text-editor.tsx +121 -0
  67. package/templates/next-base/src/components/rich-text/lexical/theme.ts +18 -0
  68. package/templates/next-base/src/components/rich-text/rich-text-renderer.tsx +72 -0
  69. package/templates/next-base/src/components/rich-text/types.ts +60 -0
  70. package/templates/next-base/src/hooks/index.ts +1 -1
  71. package/templates/next-base/src/lib/rich-text/default-image-removal.ts +10 -0
  72. package/templates/next-base/src/lib/rich-text/image-urls.ts +41 -0
  73. package/templates/next-base/src/lib/rich-text/index.ts +12 -0
  74. package/templates/next-base/src/lib/rich-text/supabase-url.ts +67 -0
  75. package/templates/next-base/src/lib/rich-text/sync-removed-images.ts +48 -0
  76. package/templates/next-base/src/types/index.ts +0 -2
  77. package/templates/next-base/tsconfig.tsbuildinfo +1 -0
  78. package/templates/next-base/prisma/migrations/20260612000000_init/migration.sql +0 -104
  79. package/templates/next-base/prisma/migrations/migration_lock.toml +0 -3
  80. package/templates/next-base/src/app/(auth)/.gitkeep +0 -1
  81. /package/templates/{next-base → features/api}/src/components/providers/query-provider.tsx +0 -0
  82. /package/templates/{next-base/src/lib → features/api/src/lib/api}/token-store.ts +0 -0
  83. /package/templates/{next-base → features/auth}/messages/vi/auth.json +0 -0
  84. /package/templates/{next-base/prisma/migrations → features/auth/src/app/(auth)}/.gitkeep +0 -0
  85. /package/templates/{next-base → features/auth}/src/app/(auth)/change-password/page.tsx +0 -0
  86. /package/templates/{next-base → features/auth}/src/app/(auth)/layout.tsx +0 -0
  87. /package/templates/{next-base → features/auth}/src/app/(auth)/sign-in/page.tsx +0 -0
  88. /package/templates/{next-base → features/auth}/src/app/api/auth/[...all]/route.ts +0 -0
  89. /package/templates/{next-base → features/auth}/src/features/auth/validations.ts +0 -0
  90. /package/templates/{next-base → features/auth}/src/features/users/validations.ts +0 -0
  91. /package/templates/{next-base/src/lib/auth-client.ts → features/auth/src/lib/auth/client.ts} +0 -0
  92. /package/templates/{next-base/src/lib/auth-cookies.ts → features/auth/src/lib/auth/cookies.ts} +0 -0
  93. /package/templates/{next-base → features/dashboard}/src/app/(dashboard)/account/page.tsx +0 -0
  94. /package/templates/{next-base → features/dashboard}/src/app/(dashboard)/dashboard/page.tsx +0 -0
  95. /package/templates/{next-base → features/dashboard}/src/components/layout/private/app-sidebar.tsx +0 -0
  96. /package/templates/{next-base → features/dashboard}/src/components/layout/private/dashboard-layout.tsx +0 -0
  97. /package/templates/{next-base → features/dashboard}/src/components/layout/private/nav-sidebar.tsx +0 -0
  98. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table-column-header.tsx +0 -0
  99. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table-filter-list.tsx +0 -0
  100. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table-pagination.tsx +0 -0
  101. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table-skeleton.tsx +0 -0
  102. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table-toolbar.tsx +0 -0
  103. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table-view-options.tsx +0 -0
  104. /package/templates/{next-base → features/dashboard}/src/components/ui/data-table/data-table.tsx +0 -0
  105. /package/templates/{next-base → features/dashboard}/src/components/ui/sidebar.tsx +0 -0
  106. /package/templates/{next-base → features/dashboard}/src/data/sidebar-modules.ts +0 -0
  107. /package/templates/{next-base → features/dashboard}/src/hooks/table/use-data-table.ts +0 -0
  108. /package/templates/{next-base → features/dashboard}/src/hooks/use-mobile.ts +0 -0
  109. /package/templates/{next-base → features/dashboard}/src/types/data-table.ts +0 -0
  110. /package/templates/{next-base/src/lib → features/database/src/lib/db}/prisma.ts +0 -0
  111. /package/templates/{next-base → features/example}/messages/vi/example.json +0 -0
  112. /package/templates/{next-base → features/example}/src/app/(dashboard)/example/page.tsx +0 -0
  113. /package/templates/{next-base → features/example}/src/example/components/example-table.tsx +0 -0
  114. /package/templates/{next-base → features/example}/src/example/validations.ts +0 -0
  115. /package/templates/{next-base → features/i18n}/messages/vi/common.json +0 -0
  116. /package/templates/{next-base → features/i18n}/src/components/layout/private/locale-switcher.tsx +0 -0
  117. /package/templates/{next-base → features/i18n}/src/i18n/config.ts +0 -0
  118. /package/templates/{next-base → features/i18n}/src/i18n/namespaces.ts +0 -0
  119. /package/templates/{next-base → features/i18n}/src/i18n/request.ts +0 -0
  120. /package/templates/{next-base → features/supabase}/src/lib/supabase/client.ts +0 -0
  121. /package/templates/{next-base → features/supabase}/src/lib/supabase/storage-config.ts +0 -0
  122. /package/templates/{next-base → features/supabase}/src/lib/supabase/storage.ts +0 -0
package/README.md CHANGED
@@ -17,7 +17,7 @@ node dist/cli.js --help
17
17
 
18
18
  ## Command: create
19
19
 
20
- Create a new project from the base template:
20
+ Create a new project from the minimal base template:
21
21
 
22
22
  ```bash
23
23
  node dist/cli.js create
@@ -27,18 +27,49 @@ This command is fully interactive:
27
27
 
28
28
  - enter project name
29
29
  - select package manager in CLI UI (`npm`, `pnpm`, `yarn`, `bun`)
30
- - multi-select optional modules (`chat`, `supabase-realtime`, `seo`, `email`)
30
+ - multi-select optional modules (see module list below)
31
31
  - confirm install step
32
32
  - normalizes project directory name into a safe project slug for generated `package.json` and env placeholders
33
33
  - ships `SETUP.md` and `PROJECT_STRUCTURE.md` in the generated project root
34
34
 
35
- ## Core auth in base template
35
+ **Default output is minimal:** Next.js shell, branding, theme, UI primitives, and Lexical rich text adapters only. Database, auth, dashboard, and other stacks are added only when selected.
36
36
 
37
- Generated projects now include:
37
+ ## Rich text (base)
38
+
39
+ All generated projects include Lexical rich text building blocks:
40
+
41
+ - `EditorField` — swappable `textarea` or `lexical` adapter for forms
42
+ - `RichTextRenderer` — read-only playback of Lexical JSON from API data
43
+ - Toolbar: bold/italic/underline, emoji picker, image URL insertion
44
+ - Demo page: `/blog-demo`
45
+
46
+ Lexical content is stored as JSON (`SerializedEditorState`). With the `supabase` module, removed Supabase-managed image URLs trigger storage cleanup via `syncRemovedSupabaseRichTextImages`.
47
+
48
+ Available during `create` and `add module`:
49
+
50
+ | Module | Adds |
51
+ | ------------------- | ------------------------------------------------------------- |
52
+ | `database` | Prisma schema, client, `DATABASE_URL`, db scripts |
53
+ | `supabase` | Supabase browser client + Storage helpers |
54
+ | `auth` | Better Auth, sign-in pages, user APIs, bootstrap admin |
55
+ | `api` | Axios client, API envelope helpers, React Query provider |
56
+ | `i18n` | next-intl config, messages, locale switcher (auto-adds `api`) |
57
+ | `dashboard` | Protected dashboard shell, sidebar, data-table UI |
58
+ | `example` | Starter CRUD demo + `Example` Prisma model |
59
+ | `chat` | Chat routes, hooks, Prisma chat models (+ auto deps) |
60
+ | `supabase-realtime` | Realtime channel helpers (+ auto `supabase`) |
61
+ | `seo` | robots/sitemap/JSON-LD helpers |
62
+ | `email` | Email helper + React Email templates (SMTP or Resend) |
63
+
64
+ Module dependencies are auto-added (e.g. `auth` → `database`, `dashboard` → `auth` + `api` + `i18n`, `chat` → `database` + `supabase-realtime` + `supabase`).
65
+
66
+ ## Auth module (`auth`)
67
+
68
+ When selected, generated projects include:
38
69
 
39
70
  - Better Auth + Prisma adapter with JWT + username plugins
40
71
  - username/password sign-in (`/sign-in`) and forced password change (`/change-password`)
41
- - default bootstrap user `admin` / `admin` (must change password on first login)
72
+ - default bootstrap user `admin` / `admin1234` (must change password on first login)
42
73
  - hierarchical RBAC (`Role.level`) and user CRUD under `/api/v1/users`
43
74
  - account sample page (`/account`)
44
75
  - auth API wrappers:
@@ -48,7 +79,7 @@ Generated projects now include:
48
79
  - `GET /api/v1/auth/me`
49
80
  - `POST /api/v1/auth/change-password`
50
81
 
51
- Axios setup is split:
82
+ Axios setup (`api` module):
52
83
 
53
84
  - `publicApi`: public calls
54
85
  - `protectedApi`: bearer token calls with 401 refresh queue + retry
@@ -63,18 +94,18 @@ Project-owned routes under `/api/v1/*` use a unified envelope:
63
94
  - Error:
64
95
  - `{ success: false, error: { code, message, details? }, timestamp, requestId? }`
65
96
 
66
- This is powered by `src/lib/api-response.ts` in generated apps.
97
+ This is powered by `src/lib/api/response.ts` when the `api` module is enabled.
67
98
  The Better Auth passthrough route `/api/auth/[...all]` remains unwrapped.
68
99
 
69
100
  ## Command: add feature
70
101
 
71
- Run inside a generated project root:
102
+ Run inside a generated project root (requires `database` and `api` for full CRUD wiring):
72
103
 
73
104
  ```bash
74
105
  node ../dist/cli.js add feature orders
75
106
  ```
76
107
 
77
- `add feature` now always creates:
108
+ `add feature` creates:
78
109
 
79
110
  - `src/features/<feature>/api/use-<feature>.ts`
80
111
  - `src/features/<feature>/components/`
@@ -92,27 +123,20 @@ node ../dist/cli.js add module
92
123
 
93
124
  Module copy is non-destructive: existing files are kept and reported as skipped conflicts.
94
125
 
95
- Interactive multiselect shows available module catalog:
96
-
97
- - `chat`
98
- - `supabase-realtime`
99
- - `seo`
100
- - `email`
101
-
102
126
  Non-interactive example:
103
127
 
104
128
  ```bash
105
- node ../dist/cli.js add module --module seo --module supabase-realtime --yes
129
+ node ../dist/cli.js add module --module database --module auth --module dashboard --yes
106
130
  ```
107
131
 
108
- `supabase` is no longer an optional module; Supabase client, Storage helpers, and Supabase Postgres env placeholders are part of the base template.
109
- `resend` is now handled by the `email` module (legacy `--module resend` maps to `email` with provider `resend`).
132
+ `--module supabase` installs the Supabase client + Storage module.
133
+ `resend` is handled by the `email` module (legacy `--module resend` maps to `email` with provider `resend`).
110
134
 
111
135
  When `email` is selected, CLI asks for provider (`resend` or `smtp`) and only merges env keys/dependencies for that provider.
112
136
 
113
137
  ## Command: add auth-provider
114
138
 
115
- Enable social auth providers after project creation (not created by default):
139
+ Enable social auth providers after the `auth` module is installed:
116
140
 
117
141
  ```bash
118
142
  node ../dist/cli.js add auth-provider
@@ -131,13 +155,13 @@ node ../dist/cli.js add auth-provider --provider google --provider facebook --ye
131
155
 
132
156
  This command:
133
157
 
134
- - updates `src/lib/auth.ts` provider block
158
+ - updates `src/lib/auth/server.ts` provider block
135
159
  - merges provider env keys into `.env`, `.env.example`, and `.env.development`
136
160
  - runs Better Auth schema generation helper (with install prompt if CLI is missing in interactive mode)
137
161
 
138
162
  ## Command: migrate
139
163
 
140
- Run Prisma migration script automatically from project root:
164
+ Run Prisma migration script automatically from project root (requires `database` module):
141
165
 
142
166
  ```bash
143
167
  node ../dist/cli.js migrate
@@ -148,37 +172,35 @@ Optional flags:
148
172
  - `--name <migration-name>`: set migration name manually
149
173
  - `--skip-generate`: pass through to `prisma migrate dev --skip-generate`
150
174
 
151
- Example:
152
-
153
- ```bash
154
- node ../dist/cli.js migrate --name init_auth --skip-generate
155
- ```
175
+ ## Generated stack (when modules selected)
156
176
 
157
- ## Generated stack
158
-
159
- - Next.js App Router + TypeScript
160
- - Better Auth + Prisma adapter
161
- - Supabase as the default Postgres/Storage stack
162
- - Prisma ORM (`prisma/schema.prisma`, `prisma/migrations`)
163
- - Axios fetch wrapper
164
- - TanStack React Query
165
- - TanStack React Table
166
- - TanStack React Form (dependency included for form workflows)
167
- - shadcn-style shared UI folder
168
- - Zod validation
169
- - i18n base with `next-intl`
170
- - Sonner notifications
171
- - date-fns utility library
172
- - Optional modules: chat, supabase-realtime, seo, email
177
+ - Next.js App Router + TypeScript (base)
178
+ - Better Auth + Prisma (`database` + `auth`)
179
+ - Supabase client + Storage (`supabase`)
180
+ - Axios + React Query (`api`)
181
+ - next-intl (`i18n`)
182
+ - Dashboard shell + TanStack Table (`dashboard`)
183
+ - shadcn-style shared UI folder (base)
184
+ - Zod validation (base)
185
+ - Sonner notifications (base)
186
+ - Lexical rich text editor + renderer (base)
187
+ - Optional: chat, supabase-realtime, seo, email
173
188
 
174
189
  ## Template structure
175
190
 
176
- Base template lives in:
191
+ Minimal base template:
177
192
 
178
193
  - `templates/next-base`
179
194
 
180
195
  Optional module templates:
181
196
 
197
+ - `templates/features/database`
198
+ - `templates/features/supabase`
199
+ - `templates/features/auth`
200
+ - `templates/features/api`
201
+ - `templates/features/i18n`
202
+ - `templates/features/dashboard`
203
+ - `templates/features/example`
182
204
  - `templates/features/chat`
183
205
  - `templates/features/supabase-realtime`
184
206
  - `templates/features/seo`
@@ -189,10 +211,9 @@ Optional module templates:
189
211
  Chatbox Prisma entities are appended only when you add the `chat` module
190
212
  (during `create` or via `add module --module chat`).
191
213
 
192
- When chat is selected, NexTCLI auto-adds `supabase-realtime` if missing.
214
+ When chat is selected, NexTCLI auto-adds `database`, `supabase-realtime`, and `supabase` when missing.
193
215
 
194
- The generated chat schema is provider-agnostic so you can plug in Supabase Realtime,
195
- WebSocket, Pusher, or any transport later without redesigning data:
216
+ The generated chat schema is provider-agnostic:
196
217
 
197
218
  - `ChatConversation`
198
219
  - `ChatParticipant`