@thinhnguyencth1204/nextcli 0.3.0 → 0.4.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.
- package/README.md +6 -2
- package/dist/cli.js +210 -75
- package/package.json +2 -1
- package/templates/next-base/PROJECT_STRUCTURE.md +88 -0
- package/templates/next-base/SETUP.md +86 -0
- package/templates/next-base/bun.lock +1443 -0
- package/templates/next-base/messages/vi/auth.json +18 -4
- package/templates/next-base/next-env.d.ts +3 -1
- package/templates/next-base/prisma/migrations/20260612000000_init/migration.sql +104 -0
- package/templates/next-base/prisma/migrations/migration_lock.toml +3 -0
- package/templates/next-base/prisma/schema.prisma +23 -9
- package/templates/next-base/public/logo.svg +4 -0
- package/templates/next-base/src/app/(auth)/change-password/layout.tsx +21 -0
- package/templates/next-base/src/app/(auth)/change-password/page.tsx +14 -0
- package/templates/next-base/src/app/(auth)/layout.tsx +3 -3
- package/templates/next-base/src/app/(auth)/sign-in/layout.tsx +17 -0
- package/templates/next-base/src/app/(dashboard)/layout.tsx +13 -1
- package/templates/next-base/src/app/api/v1/auth/change-password/route.ts +55 -0
- package/templates/next-base/src/app/api/v1/auth/login/route.ts +15 -5
- package/templates/next-base/src/app/api/v1/auth/me/route.ts +17 -19
- package/templates/next-base/src/app/api/v1/users/[id]/route.ts +104 -0
- package/templates/next-base/src/app/api/v1/users/route.ts +58 -0
- package/templates/next-base/src/app/globals.css +4 -0
- package/templates/next-base/src/app/layout.tsx +7 -3
- package/templates/next-base/src/components/branding/logo.tsx +27 -0
- package/templates/next-base/src/components/layout/private/app-sidebar.tsx +3 -4
- package/templates/next-base/src/components/layout/private/dashboard-layout.tsx +2 -1
- package/templates/next-base/src/config/branding.ts +14 -0
- package/templates/next-base/src/features/auth/components/account-panel.tsx +12 -7
- package/templates/next-base/src/features/auth/components/change-password-form.tsx +82 -0
- package/templates/next-base/src/features/auth/components/sign-in-form.tsx +18 -13
- package/templates/next-base/src/features/auth/validations.ts +7 -1
- package/templates/next-base/src/features/users/services.ts +132 -0
- package/templates/next-base/src/features/users/validations.ts +21 -0
- package/templates/next-base/src/instrumentation.ts +14 -0
- package/templates/next-base/src/lib/auth-client.ts +2 -2
- package/templates/next-base/src/lib/auth.ts +2 -2
- package/templates/next-base/src/lib/bootstrap.ts +96 -0
- package/templates/next-base/src/lib/constants.ts +7 -0
- package/templates/next-base/src/lib/rbac.ts +62 -0
- package/templates/next-base/tsconfig.json +29 -7
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Project structure
|
|
2
|
+
|
|
3
|
+
Generated by NexTCLI. Folders marked **(module)** or **(feature)** appear only when that add-on is enabled.
|
|
4
|
+
|
|
5
|
+
## Root
|
|
6
|
+
|
|
7
|
+
| Path | Purpose |
|
|
8
|
+
| ---------------------- | ------------------------------------------------------------- |
|
|
9
|
+
| `nextcli.json` | Manifest: CLI version, locales, namespaces, modules, features |
|
|
10
|
+
| `SETUP.md` | Env + branding setup (this repo) |
|
|
11
|
+
| `PROJECT_STRUCTURE.md` | Folder map (this file) |
|
|
12
|
+
| `prisma/` | Schema + migrations |
|
|
13
|
+
| `messages/` | i18n JSON per locale/namespace |
|
|
14
|
+
| `public/` | Static assets (`logo.svg`, etc.) |
|
|
15
|
+
|
|
16
|
+
## `src/app/` — App Router
|
|
17
|
+
|
|
18
|
+
| Path | Purpose |
|
|
19
|
+
| -------------------- | ------------------------------------------ |
|
|
20
|
+
| `layout.tsx` | Root layout, metadata from `branding` |
|
|
21
|
+
| `globals.css` | Design tokens (`nextcli:theme` markers) |
|
|
22
|
+
| `(auth)/` | Sign-in, forced password change |
|
|
23
|
+
| `(dashboard)/` | Protected shell (session + password guard) |
|
|
24
|
+
| `api/auth/[...all]/` | Better Auth passthrough (not wrapped) |
|
|
25
|
+
| `api/v1/` | Project API envelope (`ok` / `fail`) |
|
|
26
|
+
| `api/v1/users/` | User CRUD + RBAC **(base)** |
|
|
27
|
+
| `api/v1/example/` | Demo CRUD sample |
|
|
28
|
+
|
|
29
|
+
## `src/config/`
|
|
30
|
+
|
|
31
|
+
| Path | Purpose |
|
|
32
|
+
| ------------- | ------------------------------------ |
|
|
33
|
+
| `branding.ts` | Project name, logo path, description |
|
|
34
|
+
|
|
35
|
+
## `src/lib/` — Shared runtime
|
|
36
|
+
|
|
37
|
+
| Path | Purpose |
|
|
38
|
+
| ---------------------------- | ------------------------------------------------- |
|
|
39
|
+
| `auth.ts` / `auth-client.ts` | Better Auth (username + JWT) |
|
|
40
|
+
| `bootstrap.ts` | Seeds `admin` role/user on startup |
|
|
41
|
+
| `rbac.ts` | Role hierarchy guards |
|
|
42
|
+
| `prisma.ts` | DB client |
|
|
43
|
+
| `api-response.ts` | `/api/v1/*` envelope helpers |
|
|
44
|
+
| `supabase/` | **(module: `supabase`)** client + storage helpers |
|
|
45
|
+
| `resend/` | **(module: `resend`)** email client + send helper |
|
|
46
|
+
|
|
47
|
+
## `src/features/` vs `src/example/`
|
|
48
|
+
|
|
49
|
+
| Path | Purpose |
|
|
50
|
+
| ------------------ | --------------------------------------------------------- |
|
|
51
|
+
| `features/auth/` | Sign-in + change-password UI |
|
|
52
|
+
| `features/users/` | User validations/services for API |
|
|
53
|
+
| `example/` | Starter demo feature (rename for production) |
|
|
54
|
+
| `features/<name>/` | **(feature: `nextcli add feature <name>`)** CRUD scaffold |
|
|
55
|
+
|
|
56
|
+
## `src/components/`
|
|
57
|
+
|
|
58
|
+
| Path | Purpose |
|
|
59
|
+
| ------------------- | --------------------------------- |
|
|
60
|
+
| `branding/logo.tsx` | Logo + project name |
|
|
61
|
+
| `layout/private/` | Dashboard shell (sidebar, header) |
|
|
62
|
+
| `ui/` | shadcn-style primitives |
|
|
63
|
+
|
|
64
|
+
## `src/i18n/`
|
|
65
|
+
|
|
66
|
+
Locale config with `nextcli:locales` / `nextcli:namespaces` markers (patched by `nextcli add language` / `add feature`).
|
|
67
|
+
|
|
68
|
+
## `src/emails/`
|
|
69
|
+
|
|
70
|
+
**(module: `resend`)** React Email templates.
|
|
71
|
+
|
|
72
|
+
## Optional modules (via `nextcli add module`)
|
|
73
|
+
|
|
74
|
+
| Module | Adds |
|
|
75
|
+
| ------------------- | ------------------------------------------------------------------- |
|
|
76
|
+
| `chat` | Chat routes, hooks, Prisma chat models (+ auto `supabase-realtime`) |
|
|
77
|
+
| `supabase` | `src/lib/supabase/*`, Storage upload helpers |
|
|
78
|
+
| `supabase-realtime` | Realtime channel helpers |
|
|
79
|
+
| `seo` | robots/sitemap/JSON-LD helpers |
|
|
80
|
+
| `resend` | `src/lib/resend/*`, `src/emails/*` |
|
|
81
|
+
|
|
82
|
+
Module **env variables** and where to find them: see `SETUP.md` → **Optional module environment** (full catalog; `Enabled modules` line updates when you create/add modules).
|
|
83
|
+
|
|
84
|
+
## Notes
|
|
85
|
+
|
|
86
|
+
- Do not wrap `api/auth/[...all]` responses — Better Auth expects raw format.
|
|
87
|
+
- Review `prisma/schema.prisma` before production migrations (demo `Example` model).
|
|
88
|
+
- Super-admin account `admin` cannot be modified/deleted via user APIs.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Project setup guide
|
|
2
|
+
|
|
3
|
+
Quick reference for env vars and branding after `nextcli create`.
|
|
4
|
+
|
|
5
|
+
## First run (required)
|
|
6
|
+
|
|
7
|
+
1. Start PostgreSQL and set `DATABASE_URL` in `.env`.
|
|
8
|
+
2. `bun run db:migrate` — applies `prisma/migrations` (includes `Role`, `User.username`, `requirePasswordChange`).
|
|
9
|
+
3. `bun run dev` — bootstrap seeds `admin` / `admin` on first start.
|
|
10
|
+
|
|
11
|
+
`postinstall` runs `prisma generate` so TypeScript knows models like `Role` and `requirePasswordChange`. If types look stale, run `bun run db:generate` manually.
|
|
12
|
+
|
|
13
|
+
## Branding (edit in repo, not env)
|
|
14
|
+
|
|
15
|
+
| What | Where |
|
|
16
|
+
| ------------------------------------------ | ------------------------------------------------------------------------- |
|
|
17
|
+
| Display name, slug, description, logo path | `src/config/branding.ts` |
|
|
18
|
+
| Logo file | `public/logo.svg` (or update `logoPath`) |
|
|
19
|
+
| Theme colors (primary, sidebar, …) | `src/app/globals.css` between `nextcli:theme:start` / `nextcli:theme:end` |
|
|
20
|
+
| Sidebar/header labels (i18n) | `messages/<locale>/common.json` → `appName` |
|
|
21
|
+
|
|
22
|
+
## Core environment variables
|
|
23
|
+
|
|
24
|
+
Set in `.env` / `.env.development` (secrets are generated at create time).
|
|
25
|
+
|
|
26
|
+
| Variable | Purpose | Where to get |
|
|
27
|
+
| --------------------- | ---------------------- | -------------------------------------------------------------- |
|
|
28
|
+
| `DATABASE_URL` | PostgreSQL connection | Local Postgres or cloud provider dashboard → connection string |
|
|
29
|
+
| `BETTER_AUTH_SECRET` | Auth signing secret | Auto-generated on create; rotate in production |
|
|
30
|
+
| `BETTER_AUTH_URL` | Server auth base URL | Your app URL (e.g. `http://localhost:3000`) |
|
|
31
|
+
| `NEXT_PUBLIC_APP_URL` | Client-visible app URL | Same as public site URL |
|
|
32
|
+
|
|
33
|
+
### Default admin account
|
|
34
|
+
|
|
35
|
+
On first `dev` / `start`, bootstrap creates role `admin` and user `admin` / `admin` (must change password on first login).
|
|
36
|
+
|
|
37
|
+
## Optional module environment
|
|
38
|
+
|
|
39
|
+
Reference for all optional modules. Matching keys are merged into `.env` when selected at `nextcli create` or via `nextcli add module`.
|
|
40
|
+
|
|
41
|
+
<!-- nextcli:enabled-modules:start -->
|
|
42
|
+
|
|
43
|
+
**Enabled modules:** none
|
|
44
|
+
|
|
45
|
+
<!-- nextcli:enabled-modules:end -->
|
|
46
|
+
|
|
47
|
+
<!-- nextcli:module-env:start -->
|
|
48
|
+
|
|
49
|
+
### Module: Chat module (`chat`)
|
|
50
|
+
|
|
51
|
+
| Variable | Where to get |
|
|
52
|
+
| ------------------------- | ---------------------------------------------------- |
|
|
53
|
+
| `NEXT_PUBLIC_ENABLE_CHAT` | Set `true` when chat module is enabled (auto on add) |
|
|
54
|
+
|
|
55
|
+
Requires `supabase-realtime` (auto-added). Run `db:migrate` after add — chat Prisma models are appended.
|
|
56
|
+
|
|
57
|
+
### Module: Supabase (`supabase`)
|
|
58
|
+
|
|
59
|
+
| Variable | Where to get |
|
|
60
|
+
| ------------------------------------- | ---------------------------------------------------------------------- |
|
|
61
|
+
| `NEXT_PUBLIC_SUPABASE_URL` | Supabase Dashboard → Project Settings → API → Project URL |
|
|
62
|
+
| `NEXT_PUBLIC_SUPABASE_ANON_KEY` | Same page → Project API keys → `anon` `public` |
|
|
63
|
+
| `NEXT_PUBLIC_SUPABASE_STORAGE_BUCKET` | Storage → create bucket → use bucket name (default scaffold: `public`) |
|
|
64
|
+
|
|
65
|
+
### Module: Supabase Realtime (`supabase-realtime`)
|
|
66
|
+
|
|
67
|
+
Uses same Supabase URL/anon key as `supabase` module. Enable Realtime on tables in Supabase Dashboard → Database → Replication.
|
|
68
|
+
|
|
69
|
+
### Module: SEO pack (`seo`)
|
|
70
|
+
|
|
71
|
+
No extra env keys. Edit `src/app/robots.ts`, `sitemap.ts`, and JSON-LD helpers after add.
|
|
72
|
+
|
|
73
|
+
### Module: Resend email (`resend`)
|
|
74
|
+
|
|
75
|
+
| Variable | Where to get |
|
|
76
|
+
| ------------------- | ------------------------------------------------------------------ |
|
|
77
|
+
| `RESEND_API_KEY` | resend.com → API Keys → Create |
|
|
78
|
+
| `RESEND_FROM_EMAIL` | resend.com → Domains → verify domain → use `Name <you@domain.com>` |
|
|
79
|
+
|
|
80
|
+
<!-- nextcli:module-env:end -->
|
|
81
|
+
|
|
82
|
+
## After adding modules
|
|
83
|
+
|
|
84
|
+
1. Fill new env keys in `.env` and `.env.example`.
|
|
85
|
+
2. Run `bun run db:migrate` when a module adds Prisma models.
|
|
86
|
+
3. See `PROJECT_STRUCTURE.md` for folders introduced by each module.
|