create-fullstack-boilerplate 1.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 (71) hide show
  1. package/README.md +390 -0
  2. package/index.js +78 -0
  3. package/lib/addDB.js +77 -0
  4. package/lib/addRoute.js +264 -0
  5. package/lib/copyProject.js +25 -0
  6. package/lib/dataTypes.js +79 -0
  7. package/lib/installDeps.js +11 -0
  8. package/lib/prompts.js +289 -0
  9. package/lib/setupExtraDB.js +172 -0
  10. package/lib/setupMainDB.js +9 -0
  11. package/lib/testDBConnection.js +31 -0
  12. package/lib/utils.js +39 -0
  13. package/package.json +45 -0
  14. package/template/Backend/.env +7 -0
  15. package/template/Backend/DB/DBInit.js +28 -0
  16. package/template/Backend/DB/dbConfigs.js +4 -0
  17. package/template/Backend/Models/index.js +54 -0
  18. package/template/Backend/README.md +535 -0
  19. package/template/Backend/middleware/authMiddleware.js +19 -0
  20. package/template/Backend/package-lock.json +2997 -0
  21. package/template/Backend/package.json +32 -0
  22. package/template/Backend/routes/authRoutes.js +15 -0
  23. package/template/Backend/routes/dashboardRoutes.js +13 -0
  24. package/template/Backend/routes/index.js +15 -0
  25. package/template/Backend/routes/settingsRoutes.js +9 -0
  26. package/template/Backend/server.js +70 -0
  27. package/template/Backend/services/authService.js +68 -0
  28. package/template/Backend/services/cryptoService.js +14 -0
  29. package/template/Backend/services/dashboardService.js +39 -0
  30. package/template/Backend/services/settingsService.js +43 -0
  31. package/template/Frontend/.env +3 -0
  32. package/template/Frontend/README.md +576 -0
  33. package/template/Frontend/eslint.config.js +29 -0
  34. package/template/Frontend/index.html +13 -0
  35. package/template/Frontend/package-lock.json +3690 -0
  36. package/template/Frontend/package.json +39 -0
  37. package/template/Frontend/public/PMDLogo.png +0 -0
  38. package/template/Frontend/public/pp.jpg +0 -0
  39. package/template/Frontend/public/tabicon.png +0 -0
  40. package/template/Frontend/src/App.jsx +71 -0
  41. package/template/Frontend/src/assets/fonts/ArticulatCFDemiBold/font.woff +0 -0
  42. package/template/Frontend/src/assets/fonts/ArticulatCFDemiBold/font.woff2 +0 -0
  43. package/template/Frontend/src/assets/fonts/ArticulatCFNormal/font.woff +0 -0
  44. package/template/Frontend/src/assets/fonts/ArticulatCFNormal/font.woff2 +0 -0
  45. package/template/Frontend/src/assets/fonts/ArticulatCFRegular/font.woff +0 -0
  46. package/template/Frontend/src/assets/fonts/ArticulatCFRegular/font.woff2 +0 -0
  47. package/template/Frontend/src/assets/fonts/MixtaProRegularItalic/font.woff +0 -0
  48. package/template/Frontend/src/assets/fonts/MixtaProRegularItalic/font.woff2 +0 -0
  49. package/template/Frontend/src/assets/fonts/fonts_sohne/OTF/S/303/266hneMono-Buch.otf +0 -0
  50. package/template/Frontend/src/assets/fonts/fonts_sohne/OTF/S/303/266hneMono-Leicht.otf +0 -0
  51. package/template/Frontend/src/assets/fonts/fonts_sohne/WOFF2/soehne-mono-buch.woff2 +0 -0
  52. package/template/Frontend/src/assets/fonts/fonts_sohne/WOFF2/soehne-mono-leicht.woff2 +0 -0
  53. package/template/Frontend/src/components/Layout.jsx +61 -0
  54. package/template/Frontend/src/components/Loader.jsx +19 -0
  55. package/template/Frontend/src/components/ProtectedRoute.jsx +19 -0
  56. package/template/Frontend/src/components/Sidebar.jsx +286 -0
  57. package/template/Frontend/src/components/ThemeToggle.jsx +30 -0
  58. package/template/Frontend/src/config/axiosClient.js +46 -0
  59. package/template/Frontend/src/config/encryption.js +11 -0
  60. package/template/Frontend/src/config/routes.js +65 -0
  61. package/template/Frontend/src/contexts/AuthContext.jsx +144 -0
  62. package/template/Frontend/src/contexts/ThemeContext.jsx +69 -0
  63. package/template/Frontend/src/index.css +88 -0
  64. package/template/Frontend/src/main.jsx +11 -0
  65. package/template/Frontend/src/pages/Dashboard.jsx +137 -0
  66. package/template/Frontend/src/pages/Login.jsx +195 -0
  67. package/template/Frontend/src/pages/NotFound.jsx +70 -0
  68. package/template/Frontend/src/pages/Settings.jsx +69 -0
  69. package/template/Frontend/tailwind.config.js +90 -0
  70. package/template/Frontend/vite.config.js +37 -0
  71. package/template/Readme.md +0 -0
@@ -0,0 +1,172 @@
1
+ const path = require("path");
2
+ const { ensure } = require("./utils");
3
+ const fs = ensure("fs-extra");
4
+
5
+ module.exports = async function setupExtraDB(targetDir, dbConfig) {
6
+ const backendDir = path.join(targetDir, "backend");
7
+ const modelsDir = path.join(backendDir, "Models");
8
+ const dbDir = path.join(backendDir, "DB");
9
+
10
+ // 1. Create folder for this DB's models
11
+ const dbFolderName = dbConfig.dbKey;
12
+ const dbModelsFolder = path.join(modelsDir, dbFolderName);
13
+ await fs.ensureDir(dbModelsFolder);
14
+
15
+ // 2. Create config file for this DB
16
+ const configFileName = `${dbFolderName}.config.js`;
17
+ const configPath = path.join(dbDir, configFileName);
18
+
19
+ const configContent = `module.exports = {
20
+ development: {
21
+ username: process.env.${dbConfig.dbKey}_USER || "${dbConfig.username}",
22
+ password: process.env.${dbConfig.dbKey}_PASSWORD || "${dbConfig.password}",
23
+ database: process.env.${dbConfig.dbKey}_NAME || "${dbConfig.database}",
24
+ host: process.env.${dbConfig.dbKey}_HOST || "${dbConfig.host}",
25
+ port: process.env.${dbConfig.dbKey}_PORT || ${dbConfig.port},
26
+ dialect: "${dbConfig.dialect}"
27
+ },
28
+ test: {
29
+ username: process.env.${dbConfig.dbKey}_USER || "${dbConfig.username}",
30
+ password: process.env.${dbConfig.dbKey}_PASSWORD || "${dbConfig.password}",
31
+ database: process.env.${dbConfig.dbKey}_NAME || "${dbConfig.database}",
32
+ host: process.env.${dbConfig.dbKey}_HOST || "${dbConfig.host}",
33
+ port: process.env.${dbConfig.dbKey}_PORT || ${dbConfig.port},
34
+ dialect: "${dbConfig.dialect}"
35
+ },
36
+ production: {
37
+ username: process.env.${dbConfig.dbKey}_USER,
38
+ password: process.env.${dbConfig.dbKey}_PASSWORD,
39
+ database: process.env.${dbConfig.dbKey}_NAME,
40
+ host: process.env.${dbConfig.dbKey}_HOST,
41
+ port: process.env.${dbConfig.dbKey}_PORT,
42
+ dialect: "${dbConfig.dialect}"
43
+ }
44
+ };
45
+ `;
46
+
47
+ await fs.writeFile(configPath, configContent);
48
+
49
+ // 3. Create a sample model file
50
+ const modelContent = generateModelContent(dbConfig);
51
+ const modelFileName = `${dbConfig.tableName}.js`;
52
+ const modelPath = path.join(dbModelsFolder, modelFileName);
53
+ await fs.writeFile(modelPath, modelContent);
54
+
55
+ // 4. Update dbConfigs.js to register this DB
56
+ const dbConfigsPath = path.join(dbDir, "dbConfigs.js");
57
+ let dbConfigsContent = await fs.readFile(dbConfigsPath, "utf8");
58
+
59
+ const newEntry = ` {
60
+ key: "${dbConfig.dbKey}",
61
+ folder: "${dbConfig.dbKey}",
62
+ configPath: "/../DB/${configFileName}"
63
+ }`;
64
+
65
+ // Insert before the closing bracket
66
+ dbConfigsContent = dbConfigsContent.replace(
67
+ /const dbConfigs = \[\s*\];/,
68
+ `const dbConfigs = [
69
+ ${newEntry}
70
+ ];`
71
+ );
72
+
73
+ // If there are already entries, append
74
+ if (!dbConfigsContent.includes(newEntry) && dbConfigsContent.includes("const dbConfigs = [")) {
75
+ dbConfigsContent = dbConfigsContent.replace(
76
+ /(const dbConfigs = \[[\s\S]*?)(\];)/,
77
+ `$1,
78
+ ${newEntry}
79
+ $2`
80
+ );
81
+ }
82
+
83
+ await fs.writeFile(dbConfigsPath, dbConfigsContent);
84
+
85
+ // 5. Update .env file with DB credentials
86
+ const envPath = path.join(backendDir, ".env");
87
+ let envContent = await fs.readFile(envPath, "utf8");
88
+
89
+ const envVars = `\n# ${dbConfig.dbKey} Database Configuration\n${dbConfig.dbKey}_USER=${dbConfig.username}\n${dbConfig.dbKey}_PASSWORD=${dbConfig.password}\n${dbConfig.dbKey}_NAME=${dbConfig.database}\n${dbConfig.dbKey}_HOST=${dbConfig.host}\n${dbConfig.dbKey}_PORT=${dbConfig.port}\n`;
90
+
91
+ if (!envContent.includes(`${dbConfig.dbKey}_USER`)) {
92
+ envContent += envVars;
93
+ await fs.writeFile(envPath, envContent);
94
+ }
95
+
96
+ console.log(`✅ Database '${dbConfig.dbKey}' configured successfully.`);
97
+ };
98
+
99
+ function generateModelContent(dbConfig) {
100
+ const modelName = dbConfig.tableName.charAt(0).toUpperCase() + dbConfig.tableName.slice(1);
101
+
102
+ // Generate model content based on whether attributes were provided
103
+ if (dbConfig.attributes && dbConfig.attributes.length > 0) {
104
+ const attributesStr = dbConfig.attributes.map(attr => {
105
+ let attrDef = ` ${attr.name}: {\n type: DataTypes.${attr.type}`;
106
+
107
+ if (attr.length) {
108
+ attrDef += `(${attr.length})`;
109
+ }
110
+
111
+ if (attr.primaryKey) {
112
+ attrDef += `,\n primaryKey: true,\n autoIncrement: true`;
113
+ }
114
+
115
+ if (attr.allowNull === false) {
116
+ attrDef += `,\n allowNull: false`;
117
+ }
118
+
119
+ if (attr.unique) {
120
+ attrDef += `,\n unique: true`;
121
+ }
122
+
123
+ if (attr.defaultValue !== undefined) {
124
+ attrDef += `,\n defaultValue: ${JSON.stringify(attr.defaultValue)}`;
125
+ }
126
+
127
+ attrDef += `\n }`;
128
+ return attrDef;
129
+ }).join(',\n');
130
+
131
+ return `'use strict';
132
+ module.exports = (sequelize, DataTypes) => {
133
+ const ${modelName} = sequelize.define('${modelName}', {
134
+ ${attributesStr}
135
+ }, {
136
+ tableName: '${dbConfig.tableName}',
137
+ timestamps: true
138
+ });
139
+
140
+ ${modelName}.associate = function(models) {
141
+ // Define associations here
142
+ // Example: ${modelName}.belongsTo(models.OtherModel, { foreignKey: 'otherId' });
143
+ };
144
+
145
+ return ${modelName};
146
+ };
147
+ `;
148
+ } else {
149
+ // Simple model with just ID
150
+ return `'use strict';
151
+ module.exports = (sequelize, DataTypes) => {
152
+ const ${modelName} = sequelize.define('${modelName}', {
153
+ id: {
154
+ type: DataTypes.INTEGER,
155
+ primaryKey: true,
156
+ autoIncrement: true
157
+ }
158
+ }, {
159
+ tableName: '${dbConfig.tableName}',
160
+ timestamps: true
161
+ });
162
+
163
+ ${modelName}.associate = function(models) {
164
+ // Define associations here
165
+ // Example: ${modelName}.belongsTo(models.OtherModel, { foreignKey: 'otherId' });
166
+ };
167
+
168
+ return ${modelName};
169
+ };
170
+ `;
171
+ }
172
+ }
@@ -0,0 +1,9 @@
1
+ const { replaceInFiles, log } = require("./utils");
2
+
3
+ module.exports = async function setupMainDB(targetDir, dialect) {
4
+ log("Configuring main DB in backend...");
5
+ await replaceInFiles(targetDir, {
6
+ "__DB_DIALECT__": dialect
7
+ });
8
+ console.log("✅ Main DB configured.");
9
+ };
@@ -0,0 +1,31 @@
1
+ const path = require("path");
2
+
3
+ async function testDBConnection(targetDir, dbConfig) {
4
+ const sequelizePath = path.join(targetDir, "backend", "node_modules", "sequelize");
5
+ const { Sequelize } = require(sequelizePath);
6
+
7
+ const sequelize = new Sequelize(
8
+ dbConfig.database,
9
+ dbConfig.username,
10
+ dbConfig.password,
11
+ {
12
+ host: dbConfig.host,
13
+ port: dbConfig.port,
14
+ dialect: dbConfig.dialect,
15
+ logging: false
16
+ }
17
+ );
18
+
19
+ try {
20
+ await sequelize.authenticate();
21
+ console.log(`✅ Connection successful to ${dbConfig.dbKey}`);
22
+ await sequelize.close();
23
+ return true;
24
+ } catch (err) {
25
+ console.log(`❌ Failed to connect to ${dbConfig.dbKey}`);
26
+ console.log("Error:", err.message);
27
+ return false;
28
+ }
29
+ }
30
+
31
+ module.exports = testDBConnection;
package/lib/utils.js ADDED
@@ -0,0 +1,39 @@
1
+ const { execSync } = require("child_process");
2
+
3
+ function ensure(dep) {
4
+ try {
5
+ return require(dep);
6
+ } catch (e) {
7
+ console.log(`📦 Installing missing dependency: ${dep}...`);
8
+ execSync(`npm install ${dep} --silent`, { cwd: __dirname + "/..", stdio: "inherit" });
9
+ return require(dep);
10
+ }
11
+ }
12
+
13
+ function log(step) {
14
+ console.log(`\n➡️ ${step}`);
15
+ }
16
+
17
+ const fs = ensure("fs-extra");
18
+ const path = require("path");
19
+
20
+ async function replaceInFiles(base, replacements) {
21
+ const exts = [".js", ".ts", ".json", ".md", ".env", ".yml"];
22
+ async function walk(dir) {
23
+ for (const item of await fs.readdir(dir)) {
24
+ const fullPath = path.join(dir, item);
25
+ const stat = await fs.stat(fullPath);
26
+ if (stat.isDirectory()) await walk(fullPath);
27
+ else if (exts.includes(path.extname(fullPath))) {
28
+ let data = await fs.readFile(fullPath, "utf8");
29
+ for (const [k, v] of Object.entries(replacements)) {
30
+ data = data.replaceAll(k, v);
31
+ }
32
+ await fs.writeFile(fullPath, data);
33
+ }
34
+ }
35
+ }
36
+ await walk(base);
37
+ }
38
+
39
+ module.exports = { ensure, log, replaceInFiles };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "create-fullstack-boilerplate",
3
+ "version": "1.0.0",
4
+ "description": "A Full Stack Application Comprised of React for Frontend, Express & Sequelize with Node js for Backend to help developers get started on real implementation instead of spending time setting up projects.",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "create-fullstack-boilerplate": "index.js"
8
+ },
9
+ "preferGlobal": false,
10
+ "engines": {
11
+ "node": ">=20"
12
+ },
13
+ "files": [
14
+ "index.js",
15
+ "lib",
16
+ "template"
17
+ ],
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/mhuzaifi0604/react-boilerplate.git"
24
+ },
25
+ "keywords": [
26
+ "fullstack",
27
+ "boilerplate",
28
+ "react",
29
+ "node",
30
+ "js",
31
+ "fullstack",
32
+ "app"
33
+ ],
34
+ "dependencies": {
35
+ "execa": "^5.1.1",
36
+ "fs-extra": "^11.3.2",
37
+ "inquirer": "^8.2.7"
38
+ },
39
+ "author": "Muhammad Huzaifa",
40
+ "license": "ISC",
41
+ "bugs": {
42
+ "url": "https://github.com/mhuzaifi0604/react-boilerplate/issues"
43
+ },
44
+ "homepage": "https://github.com/mhuzaifi0604/react-boilerplate#readme"
45
+ }
@@ -0,0 +1,7 @@
1
+ # Server Configuration
2
+ PORT=5000
3
+ CLIENT_URL=http://localhost:5173
4
+
5
+ # Security Credentials
6
+ JWT_SECRET=PMD_SUP3R_S3CR37_JW7_T0K3N
7
+ PASSWORD_ENCRYPTION_KEY=A35_5YM37R1C_3NCRYP710N_K3Y_PMD
@@ -0,0 +1,28 @@
1
+ const colors = require('colors');
2
+
3
+ const RETRY_DELAY_MS = 3000;
4
+ const MAX_RETRIES = 5;
5
+
6
+ async function initializeDatabaseConnection(sequelize, name = 'Database') {
7
+ let retries = 0;
8
+
9
+ while (retries < MAX_RETRIES) {
10
+ try {
11
+ await sequelize.authenticate();
12
+ console.log(`[✅] - ${name} connection established.`.green);
13
+ await sequelize.sync();
14
+ return true;
15
+ } catch (error) {
16
+ console.error(`\n[!] ${name} connection failed: ${error.message}\n`.red);
17
+ retries++;
18
+ if (retries >= MAX_RETRIES) {
19
+ console.error(`\n[❌] ${name} could not connect after ${MAX_RETRIES} attempts.\n`.bgRed.white);
20
+ throw error;
21
+ }
22
+ console.log(`\n[↻] Retrying ${name} in ${RETRY_DELAY_MS / 1000} seconds...\n`.yellow);
23
+ await new Promise(res => setTimeout(res, RETRY_DELAY_MS));
24
+ }
25
+ }
26
+ }
27
+
28
+ module.exports = { initializeDatabaseConnection };
@@ -0,0 +1,4 @@
1
+ const dbConfigs = [
2
+ ];
3
+
4
+ module.exports = dbConfigs;
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ require('dotenv').config();
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const Sequelize = require('sequelize');
7
+ const dbConfigs = require('../DB/dbConfigs')
8
+ const basename = path.basename(__filename);
9
+ const env = process.env.NODE_ENV || 'development';
10
+
11
+
12
+ const databases = {};
13
+
14
+ for (const { key, folder, configPath } of dbConfigs) {
15
+ const config = require(__dirname + configPath)[env];
16
+ let sequelize;
17
+
18
+ if (config.use_env_variable) {
19
+ sequelize = new Sequelize(process.env[config.use_env_variable], config);
20
+ } else {
21
+ sequelize = new Sequelize(config.database, config.user, config.password, config);
22
+ }
23
+
24
+ const db = {};
25
+
26
+ // Load regular models in CMPA folder (excluding operatorCmpaModel.js)
27
+ fs.readdirSync(path.join(__dirname, folder))
28
+ .filter(file =>
29
+ file.indexOf('.') !== 0 &&
30
+ file.slice(-3) === '.js' &&
31
+ file !== basename &&
32
+ !file.includes('.test.js')
33
+ )
34
+ .forEach(file => {
35
+ const model = require(path.join(__dirname, folder, file))(sequelize, Sequelize.DataTypes);
36
+ db[model.name] = model;
37
+ });
38
+
39
+
40
+ // Setup associations
41
+ Object.keys(db).forEach(modelName => {
42
+ if (db[modelName].associate) {
43
+ db[modelName].associate(db);
44
+ }
45
+ });
46
+
47
+ db.sequelize = sequelize;
48
+ db.Sequelize = Sequelize;
49
+
50
+ // Store under key (e.g., CRM_DB, CMPA_DB, etc.)
51
+ databases[key] = db;
52
+ }
53
+
54
+ module.exports = databases;