@rishishanbhag/create-tstemplate 0.1.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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Rishi Shanbhag
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # create-tstemplate
2
+
3
+ A CLI to scaffold a full-stack TypeScript project with:
4
+
5
+ - **Client**: Vite + React + TypeScript + Tailwind CSS
6
+ - **Server**: Express + TypeScript + MongoDB + JWT Authentication
7
+
8
+ ## Usage
9
+
10
+ ```bash
11
+ npm create tstemplate@latest my-app
12
+ # or
13
+ npx create-tstemplate my-app
14
+ ```
15
+
16
+ This creates a `my-app` folder with:
17
+ ```
18
+ my-app/
19
+ ├── client/ # Vite React frontend
20
+ └── server/ # Express backend with JWT auth
21
+ ```
22
+
23
+ ## Getting Started
24
+
25
+ After scaffolding:
26
+
27
+ ```bash
28
+ cd my-app
29
+
30
+ # Setup server
31
+ cd server
32
+ cp .env.example .env # Configure your MONGODB_URI and JWT_SECRET
33
+ npm install
34
+ npm run dev
35
+
36
+ # Setup client (in another terminal)
37
+ cd client
38
+ npm install
39
+ npm run dev
40
+ ```
41
+
42
+ ## Features
43
+
44
+ ### Server
45
+ - Express.js with TypeScript
46
+ - MongoDB with Mongoose
47
+ - JWT authentication (register/login)
48
+ - Role-based authorization (admin/client)
49
+ - Organized folder structure (controllers, services, middlewares, models)
50
+
51
+ ### Client
52
+ - Vite for fast development
53
+ - React 18 with TypeScript
54
+ - Tailwind CSS for styling
55
+ - ESLint configured
56
+
57
+ ## Environment Variables
58
+
59
+ Server requires:
60
+ - `MONGODB_URI` - MongoDB connection string
61
+ - `JWT_SECRET` - Secret for JWT signing
62
+ - `PORT` - Server port (default: 3000)
63
+
64
+ ## License
65
+
66
+ ISC
package/bin/create.js ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { cp, mkdir, readdir } from "node:fs/promises";
6
+ import { existsSync } from "node:fs";
7
+ import readline from "node:readline/promises";
8
+ import process from "node:process";
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ const templateRoot = path.resolve(__dirname, "..");
12
+ const clientSrc = path.join(templateRoot, "client");
13
+ const serverSrc = path.join(templateRoot, "server");
14
+
15
+ const args = process.argv.slice(2);
16
+ const targetName = args[0] || "ts-template";
17
+ const targetDir = path.resolve(process.cwd(), targetName);
18
+
19
+ const shouldCopy = (src) => {
20
+ const normalized = src.replace(/\\/g, "/");
21
+ if (normalized.includes("/node_modules/")) return false;
22
+ if (normalized.includes("/dist/")) return false;
23
+ if (normalized.includes("/.git/")) return false;
24
+ if (normalized.endsWith("/.env")) return false;
25
+ return true;
26
+ };
27
+
28
+ const isDirEmpty = async (dir) => {
29
+ try {
30
+ const files = await readdir(dir);
31
+ return files.length === 0;
32
+ } catch {
33
+ return true;
34
+ }
35
+ };
36
+
37
+ const promptConfirm = async (message) => {
38
+ const rl = readline.createInterface({
39
+ input: process.stdin,
40
+ output: process.stdout
41
+ });
42
+
43
+ const answer = await rl.question(`${message} (y/N): `);
44
+ rl.close();
45
+ return answer.trim().toLowerCase() === "y";
46
+ };
47
+
48
+ const main = async () => {
49
+ if (existsSync(targetDir)) {
50
+ const empty = await isDirEmpty(targetDir);
51
+ if (!empty) {
52
+ const proceed = await promptConfirm(
53
+ `Target directory "${targetName}" is not empty. Continue?`
54
+ );
55
+ if (!proceed) {
56
+ console.log("Aborted.");
57
+ process.exit(0);
58
+ }
59
+ }
60
+ } else {
61
+ await mkdir(targetDir, { recursive: true });
62
+ }
63
+
64
+ await cp(clientSrc, path.join(targetDir, "client"), {
65
+ recursive: true,
66
+ filter: shouldCopy
67
+ });
68
+
69
+ await cp(serverSrc, path.join(targetDir, "server"), {
70
+ recursive: true,
71
+ filter: shouldCopy
72
+ });
73
+
74
+ console.log(`\n✅ Project created at ${targetDir}`);
75
+ console.log("\nNext steps:");
76
+ console.log(` cd ${targetName}`);
77
+ console.log(" cd client && npm install");
78
+ console.log(" cd ../server && npm install");
79
+ console.log("\nThen start client/server as needed.");
80
+ };
81
+
82
+ main().catch((error) => {
83
+ console.error("Failed to create project:", error);
84
+ process.exit(1);
85
+ });
@@ -0,0 +1,73 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
+
18
+ ```js
19
+ export default defineConfig([
20
+ globalIgnores(['dist']),
21
+ {
22
+ files: ['**/*.{ts,tsx}'],
23
+ extends: [
24
+ // Other configs...
25
+
26
+ // Remove tseslint.configs.recommended and replace with this
27
+ tseslint.configs.recommendedTypeChecked,
28
+ // Alternatively, use this for stricter rules
29
+ tseslint.configs.strictTypeChecked,
30
+ // Optionally, add this for stylistic rules
31
+ tseslint.configs.stylisticTypeChecked,
32
+
33
+ // Other configs...
34
+ ],
35
+ languageOptions: {
36
+ parserOptions: {
37
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
+ tsconfigRootDir: import.meta.dirname,
39
+ },
40
+ // other options...
41
+ },
42
+ },
43
+ ])
44
+ ```
45
+
46
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
+
48
+ ```js
49
+ // eslint.config.js
50
+ import reactX from 'eslint-plugin-react-x'
51
+ import reactDom from 'eslint-plugin-react-dom'
52
+
53
+ export default defineConfig([
54
+ globalIgnores(['dist']),
55
+ {
56
+ files: ['**/*.{ts,tsx}'],
57
+ extends: [
58
+ // Other configs...
59
+ // Enable lint rules for React
60
+ reactX.configs['recommended-typescript'],
61
+ // Enable lint rules for React DOM
62
+ reactDom.configs.recommended,
63
+ ],
64
+ languageOptions: {
65
+ parserOptions: {
66
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
+ tsconfigRootDir: import.meta.dirname,
68
+ },
69
+ // other options...
70
+ },
71
+ },
72
+ ])
73
+ ```
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "new-york",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/index.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "iconLibrary": "lucide",
14
+ "rtl": false,
15
+ "aliases": {
16
+ "components": "@/components",
17
+ "utils": "@/lib/utils",
18
+ "ui": "@/components/ui",
19
+ "lib": "@/lib",
20
+ "hooks": "@/hooks"
21
+ },
22
+ "registries": {}
23
+ }
@@ -0,0 +1,23 @@
1
+ import js from '@eslint/js'
2
+ import globals from 'globals'
3
+ import reactHooks from 'eslint-plugin-react-hooks'
4
+ import reactRefresh from 'eslint-plugin-react-refresh'
5
+ import tseslint from 'typescript-eslint'
6
+ import { defineConfig, globalIgnores } from 'eslint/config'
7
+
8
+ export default defineConfig([
9
+ globalIgnores(['dist']),
10
+ {
11
+ files: ['**/*.{ts,tsx}'],
12
+ extends: [
13
+ js.configs.recommended,
14
+ tseslint.configs.recommended,
15
+ reactHooks.configs.flat.recommended,
16
+ reactRefresh.configs.vite,
17
+ ],
18
+ languageOptions: {
19
+ ecmaVersion: 2020,
20
+ globals: globals.browser,
21
+ },
22
+ },
23
+ ])
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>client</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "client",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc -b && vite build",
9
+ "lint": "eslint .",
10
+ "preview": "vite preview"
11
+ },
12
+ "dependencies": {
13
+ "@tailwindcss/vite": "^4.1.18",
14
+ "class-variance-authority": "^0.7.1",
15
+ "clsx": "^2.1.1",
16
+ "lucide-react": "^0.563.0",
17
+ "radix-ui": "^1.4.3",
18
+ "react": "^19.2.0",
19
+ "react-dom": "^19.2.0",
20
+ "tailwind-merge": "^3.4.0",
21
+ "tailwindcss": "^4.1.18"
22
+ },
23
+ "devDependencies": {
24
+ "@eslint/js": "^9.39.1",
25
+ "@types/node": "^24.10.11",
26
+ "@types/react": "^19.2.5",
27
+ "@types/react-dom": "^19.2.3",
28
+ "@vitejs/plugin-react": "^5.1.1",
29
+ "eslint": "^9.39.1",
30
+ "eslint-plugin-react-hooks": "^7.0.1",
31
+ "eslint-plugin-react-refresh": "^0.4.24",
32
+ "globals": "^16.5.0",
33
+ "shadcn": "^3.8.4",
34
+ "tw-animate-css": "^1.4.0",
35
+ "typescript": "~5.9.3",
36
+ "typescript-eslint": "^8.46.4",
37
+ "vite": "^7.2.4"
38
+ }
39
+ }
@@ -0,0 +1,11 @@
1
+ import { Button } from "@/components/ui/button"
2
+
3
+ function App() {
4
+ return (
5
+ <div className="flex min-h-svh flex-col items-center justify-center">
6
+ <Button>Click me</Button>
7
+ </div>
8
+ )
9
+ }
10
+
11
+ export default App
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
@@ -0,0 +1,64 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { Slot } from "radix-ui"
4
+
5
+ import { cn } from "@/lib/utils"
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
+ destructive:
14
+ "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
15
+ outline:
16
+ "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
17
+ secondary:
18
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19
+ ghost:
20
+ "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
21
+ link: "text-primary underline-offset-4 hover:underline",
22
+ },
23
+ size: {
24
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
25
+ xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
26
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
27
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
28
+ icon: "size-9",
29
+ "icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
30
+ "icon-sm": "size-8",
31
+ "icon-lg": "size-10",
32
+ },
33
+ },
34
+ defaultVariants: {
35
+ variant: "default",
36
+ size: "default",
37
+ },
38
+ }
39
+ )
40
+
41
+ function Button({
42
+ className,
43
+ variant = "default",
44
+ size = "default",
45
+ asChild = false,
46
+ ...props
47
+ }: React.ComponentProps<"button"> &
48
+ VariantProps<typeof buttonVariants> & {
49
+ asChild?: boolean
50
+ }) {
51
+ const Comp = asChild ? Slot.Root : "button"
52
+
53
+ return (
54
+ <Comp
55
+ data-slot="button"
56
+ data-variant={variant}
57
+ data-size={size}
58
+ className={cn(buttonVariants({ variant, size, className }))}
59
+ {...props}
60
+ />
61
+ )
62
+ }
63
+
64
+ export { Button, buttonVariants }
@@ -0,0 +1,124 @@
1
+ @import "tailwindcss";
2
+ @import "tw-animate-css";
3
+ @import "shadcn/tailwind.css";
4
+
5
+ @custom-variant dark (&:is(.dark *));
6
+
7
+ @theme inline {
8
+ --radius-sm: calc(var(--radius) - 4px);
9
+ --radius-md: calc(var(--radius) - 2px);
10
+ --radius-lg: var(--radius);
11
+ --radius-xl: calc(var(--radius) + 4px);
12
+ --radius-2xl: calc(var(--radius) + 8px);
13
+ --radius-3xl: calc(var(--radius) + 12px);
14
+ --radius-4xl: calc(var(--radius) + 16px);
15
+ --color-background: var(--background);
16
+ --color-foreground: var(--foreground);
17
+ --color-card: var(--card);
18
+ --color-card-foreground: var(--card-foreground);
19
+ --color-popover: var(--popover);
20
+ --color-popover-foreground: var(--popover-foreground);
21
+ --color-primary: var(--primary);
22
+ --color-primary-foreground: var(--primary-foreground);
23
+ --color-secondary: var(--secondary);
24
+ --color-secondary-foreground: var(--secondary-foreground);
25
+ --color-muted: var(--muted);
26
+ --color-muted-foreground: var(--muted-foreground);
27
+ --color-accent: var(--accent);
28
+ --color-accent-foreground: var(--accent-foreground);
29
+ --color-destructive: var(--destructive);
30
+ --color-border: var(--border);
31
+ --color-input: var(--input);
32
+ --color-ring: var(--ring);
33
+ --color-chart-1: var(--chart-1);
34
+ --color-chart-2: var(--chart-2);
35
+ --color-chart-3: var(--chart-3);
36
+ --color-chart-4: var(--chart-4);
37
+ --color-chart-5: var(--chart-5);
38
+ --color-sidebar: var(--sidebar);
39
+ --color-sidebar-foreground: var(--sidebar-foreground);
40
+ --color-sidebar-primary: var(--sidebar-primary);
41
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
42
+ --color-sidebar-accent: var(--sidebar-accent);
43
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
44
+ --color-sidebar-border: var(--sidebar-border);
45
+ --color-sidebar-ring: var(--sidebar-ring);
46
+ }
47
+
48
+ :root {
49
+ --radius: 0.625rem;
50
+ --background: oklch(1 0 0);
51
+ --foreground: oklch(0.145 0 0);
52
+ --card: oklch(1 0 0);
53
+ --card-foreground: oklch(0.145 0 0);
54
+ --popover: oklch(1 0 0);
55
+ --popover-foreground: oklch(0.145 0 0);
56
+ --primary: oklch(0.205 0 0);
57
+ --primary-foreground: oklch(0.985 0 0);
58
+ --secondary: oklch(0.97 0 0);
59
+ --secondary-foreground: oklch(0.205 0 0);
60
+ --muted: oklch(0.97 0 0);
61
+ --muted-foreground: oklch(0.556 0 0);
62
+ --accent: oklch(0.97 0 0);
63
+ --accent-foreground: oklch(0.205 0 0);
64
+ --destructive: oklch(0.577 0.245 27.325);
65
+ --border: oklch(0.922 0 0);
66
+ --input: oklch(0.922 0 0);
67
+ --ring: oklch(0.708 0 0);
68
+ --chart-1: oklch(0.646 0.222 41.116);
69
+ --chart-2: oklch(0.6 0.118 184.704);
70
+ --chart-3: oklch(0.398 0.07 227.392);
71
+ --chart-4: oklch(0.828 0.189 84.429);
72
+ --chart-5: oklch(0.769 0.188 70.08);
73
+ --sidebar: oklch(0.985 0 0);
74
+ --sidebar-foreground: oklch(0.145 0 0);
75
+ --sidebar-primary: oklch(0.205 0 0);
76
+ --sidebar-primary-foreground: oklch(0.985 0 0);
77
+ --sidebar-accent: oklch(0.97 0 0);
78
+ --sidebar-accent-foreground: oklch(0.205 0 0);
79
+ --sidebar-border: oklch(0.922 0 0);
80
+ --sidebar-ring: oklch(0.708 0 0);
81
+ }
82
+
83
+ .dark {
84
+ --background: oklch(0.145 0 0);
85
+ --foreground: oklch(0.985 0 0);
86
+ --card: oklch(0.205 0 0);
87
+ --card-foreground: oklch(0.985 0 0);
88
+ --popover: oklch(0.205 0 0);
89
+ --popover-foreground: oklch(0.985 0 0);
90
+ --primary: oklch(0.922 0 0);
91
+ --primary-foreground: oklch(0.205 0 0);
92
+ --secondary: oklch(0.269 0 0);
93
+ --secondary-foreground: oklch(0.985 0 0);
94
+ --muted: oklch(0.269 0 0);
95
+ --muted-foreground: oklch(0.708 0 0);
96
+ --accent: oklch(0.269 0 0);
97
+ --accent-foreground: oklch(0.985 0 0);
98
+ --destructive: oklch(0.704 0.191 22.216);
99
+ --border: oklch(1 0 0 / 10%);
100
+ --input: oklch(1 0 0 / 15%);
101
+ --ring: oklch(0.556 0 0);
102
+ --chart-1: oklch(0.488 0.243 264.376);
103
+ --chart-2: oklch(0.696 0.17 162.48);
104
+ --chart-3: oklch(0.769 0.188 70.08);
105
+ --chart-4: oklch(0.627 0.265 303.9);
106
+ --chart-5: oklch(0.645 0.246 16.439);
107
+ --sidebar: oklch(0.205 0 0);
108
+ --sidebar-foreground: oklch(0.985 0 0);
109
+ --sidebar-primary: oklch(0.488 0.243 264.376);
110
+ --sidebar-primary-foreground: oklch(0.985 0 0);
111
+ --sidebar-accent: oklch(0.269 0 0);
112
+ --sidebar-accent-foreground: oklch(0.985 0 0);
113
+ --sidebar-border: oklch(1 0 0 / 10%);
114
+ --sidebar-ring: oklch(0.556 0 0);
115
+ }
116
+
117
+ @layer base {
118
+ * {
119
+ @apply border-border outline-ring/50;
120
+ }
121
+ body {
122
+ @apply bg-background text-foreground;
123
+ }
124
+ }
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx"
2
+ import { twMerge } from "tailwind-merge"
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs))
6
+ }
@@ -0,0 +1,10 @@
1
+ import { StrictMode } from 'react'
2
+ import { createRoot } from 'react-dom/client'
3
+ import './index.css'
4
+ import App from './App.tsx'
5
+
6
+ createRoot(document.getElementById('root')!).render(
7
+ <StrictMode>
8
+ <App />
9
+ </StrictMode>,
10
+ )
@@ -0,0 +1,35 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
+ "target": "ES2022",
5
+ "useDefineForClassFields": true,
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "module": "ESNext",
8
+ "types": ["vite/client"],
9
+ "skipLibCheck": true,
10
+
11
+ /* Bundler mode */
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "moduleDetection": "force",
16
+ "noEmit": true,
17
+ "jsx": "react-jsx",
18
+
19
+ /* Linting */
20
+ "strict": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
23
+ "erasableSyntaxOnly": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ "noUncheckedSideEffectImports": true,
26
+
27
+ "baseUrl": ".",
28
+ "paths": {
29
+ "@/*": [
30
+ "./src/*"
31
+ ]
32
+ }
33
+ },
34
+ "include": ["src"]
35
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.app.json" },
5
+ { "path": "./tsconfig.node.json" }
6
+ ],
7
+ "compilerOptions": {
8
+ "baseUrl": ".",
9
+ "paths": {
10
+ "@/*": ["./src/*"]
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
+ "target": "ES2023",
5
+ "lib": ["ES2023"],
6
+ "module": "ESNext",
7
+ "types": ["node"],
8
+ "skipLibCheck": true,
9
+
10
+ /* Bundler mode */
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "verbatimModuleSyntax": true,
14
+ "moduleDetection": "force",
15
+ "noEmit": true,
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "erasableSyntaxOnly": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noUncheckedSideEffectImports": true
24
+ },
25
+ "include": ["vite.config.ts"]
26
+ }
@@ -0,0 +1,14 @@
1
+ import path from "path"
2
+ import tailwindcss from '@tailwindcss/vite'
3
+ import react from '@vitejs/plugin-react'
4
+ import { defineConfig } from 'vite'
5
+
6
+ // https://vite.dev/config/
7
+ export default defineConfig({
8
+ plugins: [react(), tailwindcss()],
9
+ resolve: {
10
+ alias: {
11
+ "@": path.resolve(__dirname, "./src"),
12
+ },
13
+ },
14
+ })
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@rishishanbhag/create-tstemplate",
3
+ "version": "0.1.0",
4
+ "description": "CLI to scaffold the tsTemplate client + server project",
5
+ "license": "ISC",
6
+ "author": "rishi",
7
+ "type": "module",
8
+ "bin": {
9
+ "create-tstemplate": "bin/create.js"
10
+ },
11
+ "files": [
12
+ "client",
13
+ "server",
14
+ "bin",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "keywords": [
22
+ "template",
23
+ "cli",
24
+ "vite",
25
+ "express",
26
+ "mongoose",
27
+ "jwt"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }
@@ -0,0 +1,5 @@
1
+ PORT=3000
2
+ MONGODB_URI=mongodb://localhost:27017/auth-db
3
+ JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
4
+ JWT_EXPIRES_IN=7d
5
+ NODE_ENV=development
@@ -0,0 +1,24 @@
1
+ {
2
+ "scripts": {
3
+ "start": "nodemon --watch src --ext ts --exec tsx src/index.ts",
4
+ "start_cron": "node backupCron.js",
5
+ "build": "tsc --build"
6
+ },
7
+ "author": "Rishi ",
8
+ "license": "ISC",
9
+ "dependencies": {
10
+ "cors": "^2.8.5",
11
+ "dotenv": "^16.5.0",
12
+ "express": "^5.1.0",
13
+ "http": "^0.0.1-security",
14
+ "mongoose": "^8.15.0"
15
+ },
16
+ "devDependencies": {
17
+ "@types/cors": "^2.8.18",
18
+ "@types/express": "^5.0.2",
19
+ "@types/node": "^22.15.20",
20
+ "nodemon": "^3.1.10",
21
+ "ts-node": "^10.9.2",
22
+ "typescript": "^5.8.3"
23
+ }
24
+ }
@@ -0,0 +1,36 @@
1
+ import { Request, Response } from "express";
2
+ import UserModel from "../models/User";
3
+
4
+ export const createOrUpdateUser = async (req: Request, res: Response) => {
5
+ const { email, firstName, lastName, role } = req.body;
6
+
7
+ try {
8
+ const user = await UserModel.findOneAndUpdate(
9
+ { email },
10
+ {
11
+ firstName,
12
+ lastName,
13
+ role,
14
+ email,
15
+ },
16
+ { new: true, upsert: true }
17
+ );
18
+ res.json(user);
19
+ } catch (err) {
20
+ console.error("Create/Update user error:", err);
21
+ res.status(400).json({ error: "Failed to create/update user" });
22
+ }
23
+ };
24
+
25
+ export const getCurrentUser = async (req: Request, res: Response) => {
26
+ try {
27
+ const user = await UserModel.findOne({ email: req.body.email });
28
+ if (!user) {
29
+ res.status(404).json({ error: "User not found" });
30
+ }
31
+ res.json(user);
32
+ } catch (err) {
33
+ console.error("Get current user error:", err);
34
+ res.status(400).json({ error: "Failed to get current user" });
35
+ }
36
+ };
@@ -0,0 +1,21 @@
1
+ import mongoose from 'mongoose';
2
+ import dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+
6
+ const MONGODB_URI = process.env.MONGODB_URI;
7
+
8
+ export const connectDatabase = async (): Promise<void> => {
9
+ try {
10
+ if (!MONGODB_URI) {
11
+ throw new Error('MONGODB_URI is not set in the environment');
12
+ }
13
+
14
+ await mongoose.connect(MONGODB_URI);
15
+ console.log('MongoDB connected successfully');
16
+ } catch (error) {
17
+ console.error('MongoDB connection error:', error);
18
+ process.exit(1);
19
+ }
20
+ };
21
+
@@ -0,0 +1,52 @@
1
+ import express from "express";
2
+ import cors from "cors";
3
+ import http from "http";
4
+ import dotenv from "dotenv";
5
+ import userRoutes from "./routes/user.routes";
6
+ import { connectDatabase } from "./database/connection";
7
+
8
+ // Load environment variables
9
+ dotenv.config();
10
+
11
+ const app = express();
12
+ const server = http.createServer(app);
13
+ const port = process.env.PORT;
14
+
15
+ // Add CORS middleware before routes
16
+ app.use(
17
+ cors({
18
+ origin: "http://localhost:5173",
19
+ credentials: true,
20
+ methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
21
+ allowedHeaders: ["Content-Type", "Authorization"],
22
+ })
23
+ );
24
+
25
+ // Add body parser middleware
26
+ app.use(express.json());
27
+
28
+ // Register routes - moved up before starting the server
29
+ app.use("/api", userRoutes);
30
+
31
+ // Handle uncaught exceptions
32
+ process.on("uncaughtException", (err: Error) => {
33
+ console.error("UNCAUGHT EXCEPTION! 💥 Shutting down...");
34
+ console.error(err.name, err.message);
35
+ process.exit(1);
36
+ });
37
+
38
+ // Connect to database, then start the server
39
+ connectDatabase().then(() => {
40
+ server.listen(port, () => {
41
+ console.log(`API is running on port ${port}`);
42
+ });
43
+ });
44
+
45
+ // Handle unhandled promise rejections
46
+ process.on("unhandledRejection", (err: Error) => {
47
+ console.error("Unhandled Rejection! 💥 Shutting down...");
48
+ console.error(err.name, err.message);
49
+ server.close(() => {
50
+ process.exit(1);
51
+ });
52
+ });
@@ -0,0 +1,10 @@
1
+ import { Document } from "mongoose";
2
+
3
+ export interface IUser extends Document {
4
+ firstName: string;
5
+ lastName: string;
6
+ email: string;
7
+ role: "admin" | "user";
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ }
@@ -0,0 +1,21 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+
3
+ export const authCheck = async (
4
+ req: Request,
5
+ res: Response,
6
+ next: NextFunction
7
+ ): Promise<void> => {
8
+ try {
9
+ const { email } = req.body;
10
+ if (!email) {
11
+ res.status(401).json({ error: "Email is required" });
12
+ return;
13
+ }
14
+ next();
15
+ } catch (err) {
16
+ console.error("Auth error:", err);
17
+ res.status(401).json({
18
+ error: "Authentication failed",
19
+ });
20
+ }
21
+ };
@@ -0,0 +1,33 @@
1
+ import { IUser } from "../interfaces/user.interface";
2
+ import mongoose from "mongoose";
3
+
4
+ const UserSchema = new mongoose.Schema<IUser>(
5
+ {
6
+ firstName: {
7
+ type: String,
8
+ trim: true,
9
+ required: true,
10
+ },
11
+ lastName: {
12
+ type: String,
13
+ trim: true,
14
+ required: true,
15
+ },
16
+ email: {
17
+ type: String,
18
+ trim: true,
19
+ lowercase: true,
20
+ unique: true,
21
+ required: true,
22
+ },
23
+ role: {
24
+ type: String,
25
+ enum: ["admin", "user"],
26
+ },
27
+ },
28
+ { timestamps: true }
29
+ );
30
+
31
+ const UserModel = mongoose.model<IUser>("Users", UserSchema);
32
+
33
+ export default UserModel;
@@ -0,0 +1,13 @@
1
+ import express from "express";
2
+ import {
3
+ createOrUpdateUser,
4
+ getCurrentUser,
5
+ } from "../controller/authController";
6
+ import { authCheck } from "../middlewares/authMiddleware";
7
+
8
+ const router = express.Router();
9
+
10
+ router.post("/user", authCheck, createOrUpdateUser);
11
+ router.get("/current-user", authCheck, getCurrentUser);
12
+
13
+ export default router;
@@ -0,0 +1,46 @@
1
+ import { sign, verify } from 'jsonwebtoken';
2
+ import bcrypt from 'bcryptjs';
3
+ import { AuthTokenPayload } from '../src/models/types.js';
4
+
5
+ const JWT_SECRET = process.env.JWT_SECRET || 'your-super-secret-jwt-key';
6
+ const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || '7d';
7
+
8
+ export class AuthService {
9
+ //hashing password
10
+ static async hashPassword(password: string): Promise<string> {
11
+ const salt = await bcrypt.genSalt(10);
12
+ return bcrypt.hash(password, salt);
13
+ }
14
+
15
+ // Comparing plain password with hashed password
16
+ static async comparePassword(
17
+ plainPassword: string,
18
+ hashedPassword: string
19
+ ): Promise<boolean> {
20
+ return bcrypt.compare(plainPassword, hashedPassword);
21
+ }
22
+
23
+ // Generate a JWT token
24
+ static generateToken(payload: AuthTokenPayload): string {
25
+ return sign(payload, JWT_SECRET as string, {
26
+ expiresIn: JWT_EXPIRES_IN
27
+ });
28
+ }
29
+
30
+ // Verify and decode a JWT token
31
+ static verifyToken(token: string): AuthTokenPayload {
32
+ try {
33
+ return verify(token, JWT_SECRET) as AuthTokenPayload;
34
+ } catch (error) {
35
+ throw new Error('Invalid or expired token');
36
+ }
37
+ }
38
+
39
+ // Extract token from Authorization header
40
+ static extractTokenFromHeader(authHeader?: string): string | null {
41
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
42
+ return null;
43
+ }
44
+ return authHeader.substring(7);
45
+ }
46
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "rootDir": "./src",
7
+ "outDir": "./dist",
8
+ "esModuleInterop": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "strict": true,
11
+ "skipLibCheck": true,
12
+ "resolveJsonModule": true,
13
+ "allowSyntheticDefaultImports": true
14
+ },
15
+ "include": ["src/**/*"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }