nodejs-quickstart-structure 1.17.0 → 1.18.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/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.18.0] - 2026-03-25
9
+
10
+ ### Added
11
+ - **Enterprise-Grade Security Hardening**: Integrated **Snyk (SCA)** and **SonarQube (SAST)** into the project scaffolding, providing "Big Tech" industry-standard security analysis out of the box.
12
+ - **Automated Security Workflows**: Pre-configured CI/CD stages for security scanning across GitHub Actions, GitLab CI, and Jenkins.
13
+ - **Pre-commit Security Gates**: Integrated **Husky** and **lint-staged** to automatically enforce code quality and security standards locally before every commit.
14
+ - **Security Standard Enforcement**: Added a standardized `SECURITY.md` policy and automated quality gates to ensure code resilience.
15
+ - **Comprehensive Security Guide**: Created a new documentation guide detailing the setup and operational workflows for the enterprise security features.
16
+
17
+ ### Changed
18
+ - **Matrix Expansion**: Updated the CLI to support over **1,680+ project combinations** by adding a conditional security hardening layer across all CI/CD providers.
19
+
20
+ ### Fixed
21
+ - **Docker Node Version**: Updated Docker node version to 22.22.2-trixie-slim
22
+
8
23
  ## [1.17.0] - 2026-03-23
9
24
 
10
25
  ### Added
package/README.md CHANGED
@@ -1,135 +1,144 @@
1
- # Node.js Quickstart Generator
2
-
3
- [![npm version](https://img.shields.io/npm/v/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
4
- [![npm total downloads](https://img.shields.io/npm/dt/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
5
- [![npm monthly downloads](https://img.shields.io/npm/dm/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
6
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=flat-square)](https://opensource.org/licenses/ISC)
7
-
8
- A powerful CLI tool to scaffold production-ready Node.js microservices with built-in best practices, allowing you to choose between **MVC** or **Clean Architecture**, **JavaScript** or **TypeScript**, and your preferred database.
9
-
10
- ![Demo](docs/demo.gif)
11
-
12
- ## Features
13
-
14
- - **Interactive CLI**: Easy-to-use prompts to configure your project.
15
- - **Multiple Architectures**: Supports both **MVC** (Model-View-Controller) and **Clean Architecture**.
16
- - **Language Support**: Choose between **JavaScript** and **TypeScript**.
17
- - **Database Integration**: Pre-configured setup for **MySQL**, **PostgreSQL**, or **MongoDB**.
18
- - **Communication Flow**: Scaffold APIs using **REST**, **GraphQL** (with Apollo Server), or **Kafka** (event-driven).
19
- - **Caching Layer**: Choose between **Redis** or built-in **Memory Cache** for data caching.
20
- - **Centralized Error Handling**: Every project ships with a global error handler, custom error classes and structured JSON error responses — consistent across REST & GraphQL.
21
- - **Dockerized**: Automatically generates `docker-compose.yml` for DB, Kafka, and Redis.
22
- - **Database Migrations/Schemas**: Integrated **Flyway** for SQL migrations or **Mongoose** schemas for MongoDB.
23
- - **Professional Standards**: Generated projects come with highly professional, industry-standard tooling.
24
-
25
- ## 🌟 Why developers love this?
26
-
27
- - **Community Trusted**: Over **3,000+** projects bootstrapped within the first month.
28
- - **Actively Maintained**: Constant updates and optimizations (30+ versions released) based on real-world developer feedback.
29
- - **Resilience First**: Unlike basic boilerplates, our generated code focuses on infrastructure stability (Retry logic, Health checks, and Graceful shutdowns).
30
-
31
- ## 🏆 Professional Standards (New)
32
-
33
- We don't just generate boilerplate; we generate **production-ready** foundations. Every project includes:
34
-
35
- - **🔍 Code Quality**: Pre-configured `Eslint` and `Prettier` for consistent coding standards.
36
- - **🛡️ Security**: Built-in `Helmet`, `HPP`, `CORS`, and Rate-Limiting middleware.
37
- - **🚨 Error Handling**: Centralized global error middleware with custom error classes and structured JSON responses. GraphQL uses Apollo's `formatError` hook; REST uses Express error middleware.
38
- - **🧪 Testing Excellence**: Integrated `Jest` and `Supertest`. Every generated project maintains **>80% Unit Test coverage** for controllers, services, and resolvers out of the box.
39
- - **🔄 CI/CD Integration**: Pre-configured workflows for **GitHub Actions**, **Jenkins**, and **GitLab CI**.
40
- - **⚓ Git Hooks**: `Husky` and `Lint-Staged` to ensure no bad code is ever committed.
41
- - **🤝 Reliability**: Health Checks (`/health`) with deep database pings, Infrastructure Retry Logic (handling Docker startup delays), and Graceful Shutdown workflows.
42
- - **🐳 DevOps**: Highly optimized **Multi-Stage Dockerfile** for small, secure production images.
43
- - **🚀 Deployment**: Ship confidently with an integrated **PM2 Ecosystem Configuration** for zero-downtime reloads and robust process management.
44
-
45
- ## 🧩 480+ Project Combinations
46
-
47
- The CLI supports a massive number of configurations to fit your exact needs:
48
-
49
- - **240 Core Combinations**:
50
- - **MVC Architecture**: 180 variants (Languages × View Engines × Databases × Communication Patterns × Caching)
51
- - **Clean Architecture**: 60 variants (Languages × Databases × Communication Patterns × Caching)
52
- - **480 Total Scenarios**:
53
- - Every combination can be generated with or without (**GitHub Actions CI/CD** / **Jenkins** or **GitLab CI**), tripling the possibilities.
54
- - Every single one of these 480 scenarios is verified to be compatible with our 80% Coverage Threshold policy.
55
-
56
- For a detailed list of all supported cases, check out [docs/generateCase.md](docs/generateCase.md).
57
-
58
- ## Installation
59
-
60
- You can install the tool globally directly from npm:
61
-
62
- ```bash
63
- npm install -g nodejs-quickstart-structure
64
- ```
65
-
66
- ## Usage
67
-
68
- Once installed, simply run the following command in any directory where you want to create a new project:
69
-
70
- ```bash
71
- nodejs-quickstart init
72
- ```
73
-
74
- ## Quick Start (Recommended)
75
-
76
- You can run the generator directly without installing it globally:
77
-
78
- ```bash
79
- npx nodejs-quickstart-structure@latest init
80
- ```
81
-
82
- ### Configuration Options
83
-
84
- The CLI will guide you through the following steps:
85
-
86
- 1. **Project Name**: The name of the folder to create.
87
- 2. **Language**: `JavaScript` or `TypeScript`.
88
- 3. **Architecture**: `MVC` or `Clean Architecture`.
89
- 4. **Database**: `MySQL`, `PostgreSQL`, or `MongoDB`.
90
- 5. **Database Name**: The name of the initial database.
91
- 6. **Communication**: `REST APIs` (default), `GraphQL`, or `Kafka`.
92
- 7. **Caching**: `None`, `Redis`, or `Memory Cache`.
93
- 8. **CI/CD**: `GitHub Actions`, `Jenkins`, `GitLab CI` or `None`.
94
-
95
- ## Generated Project Structure
96
-
97
- The generated project will include:
98
-
99
- - `src/`: Source code (controllers, routes, services/use-cases).
100
- - `src/errors/`: Custom error classes — `ApiError`, `NotFoundError`, `BadRequestError`.
101
- - `flyway/sql/`: SQL migration scripts (if SQL database selected).
102
- - `docker-compose.yml`: Services configuration for DB, Flyway, and Kafka.
103
- - `package.json`: Dependencies and scripts (`start`, `dev`, `build`).
104
- - `tsconfig.json`: (If TypeScript is selected) Type checking configuration.
105
-
106
- ### Getting Started with the Generated App
107
-
108
- ```bash
109
- cd <your-project-name>
110
-
111
- # Start infrastructure (DB, etc.)
112
- npm install
113
-
114
- docker-compose up
115
- ```
116
-
117
- ## ❤️ Support the Project
118
-
119
- We just hit **3,000 downloads**! If this tool helped you save hours of setup time, please consider:
120
- - Giving us a ⭐ on [GitHub](https://github.com/paudang/nodejs-quickstart-structure) to help others find it.
121
- - Following the [Medium Article](https://medium.com/@paudang/nodejs-quickstart-generator-93c276d60e0b) for deep-dive tutorials.
122
-
123
- ## License
124
-
125
- ISC
126
-
127
- ## 🚀 Roadmap & Upcoming Features
128
-
129
- We are constantly working to improve `nodejs-quickstart-structure` and make it the most robust boilerplate generator for Node.js.
130
-
131
- You can track our current progress, see what features are being worked on, and vote for your favorites on our public Trello board:
132
-
133
- 👉 **[View our Public Roadmap on Trello](https://trello.com/b/TPTo8ylF/nodejs-quickstart-structure-product)**
134
-
135
- If you have a feature request or want to contribute, feel free to check the board and open an issue or pull request!
1
+ # Node.js Quickstart Generator
2
+
3
+ [![npm version](https://img.shields.io/npm/v/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
4
+ [![npm total downloads](https://img.shields.io/npm/dt/nodejs-quickstart-structure?style=flat-square&color=emerald&label=Downloads)](https://www.npmjs.com/package/nodejs-quickstart-structure)
5
+ [![npm monthly downloads](https://img.shields.io/npm/dm/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
6
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=flat-square)](https://opensource.org/licenses/ISC)
7
+
8
+ A powerful CLI tool to scaffold production-ready Node.js microservices with built-in best practices, allowing you to choose between **MVC** or **Clean Architecture**, **JavaScript** or **TypeScript**, and your preferred database.
9
+
10
+ ![Demo](docs/demo.gif)
11
+
12
+ ---
13
+
14
+ ## 📌 Table of Contents
15
+
16
+ - [🚀 Quick Start](#-quick-start)
17
+ - [✨ Key Features](#-key-features)
18
+ - [🛡️ Professional Standards](#-professional-standards)
19
+ - [🧩 1,680+ Project Combinations](#-1680-project-combinations)
20
+ - [⚙️ Configuration Options](#-configuration-options)
21
+ - [🏗️ Generated Project Structure](#-generated-project-structure)
22
+ - [📖 Documentation](#-documentation)
23
+ - [🗺️ Roadmap & Support](#️-roadmap--support)
24
+
25
+ ---
26
+
27
+ ## 🚀 Quick Start
28
+
29
+ Generate your professional Node.js project in seconds without installing anything globally:
30
+
31
+ ```bash
32
+ npx nodejs-quickstart-structure@latest init
33
+ ```
34
+
35
+ ### Installation (Optional)
36
+
37
+ If you prefer to install it globally:
38
+
39
+ ```bash
40
+ npm install -g nodejs-quickstart-structure
41
+ # Then run:
42
+ nodejs-quickstart init
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Key Features
48
+
49
+ - **Interactive CLI**: Smooth, guided configuration process.
50
+ - **Multiple Architectures**: Supports both **MVC** and **Clean Architecture**.
51
+ - **Modern Languages**: Choice of **JavaScript** or **TypeScript**.
52
+ - **Database Ready**: Pre-configured for **MySQL**, **PostgreSQL**, or **MongoDB**.
53
+ - **Communication Patterns**: Supports **REST**, **GraphQL** (Apollo), and **Kafka** (Event-driven).
54
+ - **Multi-layer Caching**: Integrated **Redis** or built-in **Memory Cache**.
55
+ - **AI-Native Optimized**: specifically designed for **Cursor** and AI agents, including built-in `.cursorrules` and Agent Skill prompts. 🚀
56
+
57
+ ---
58
+
59
+ ## 🛡️ Professional Standards
60
+
61
+ We don't just generate boilerplate; we generate **production-ready** foundations. Every project includes:
62
+
63
+ - **🔍 Code Quality**: Pre-configured `Eslint` and `Prettier`.
64
+ - **🛡️ Enterprise Security**: Integrated **Snyk (SCA)**, **SonarCloud (SAST)**, `Helmet`, `HPP`, and Rate-Limiting.
65
+ - **🚨 Robust Error Handling**: Centralized global error middleware with custom error classes (`ApiError`, `NotFoundError`, etc.) — consistent across REST & GraphQL.
66
+ - **🧪 Testing Excellence**: Integrated `Jest` and `Supertest` with **>80% Unit Test coverage** out of the box.
67
+ - **🔄 DevOps & CI/CD**: Optimized **Multi-Stage Dockerfiles**, health checks, infrastructure retry logic, and workflows for **GitHub Actions**, **Jenkins**, and **GitLab CI**.
68
+ - **🚀 Scalable Deployment**: Integrated **PM2 Ecosystem** config for zero-downtime reloads.
69
+
70
+ ---
71
+
72
+ ## 🧩 1,680+ Project Combinations
73
+
74
+ The CLI supports a massive number of configurations to fit your exact needs:
75
+
76
+ - **240 Core Combinations**:
77
+ - **MVC Architecture**: 180 variants (Languages × View Engines × Databases × Communication Patterns × Caching)
78
+ - **Clean Architecture**: 60 variants (Languages × Databases × Communication Patterns × Caching)
79
+ - **1,680+ Total Scenarios**:
80
+ - Every combination can be generated across 3 CI/CD providers.
81
+ - Optional **Enterprise-Grade Security Hardening** doubles the scenarios.
82
+ - Every single scenario is verified to be compatible with our **80% Coverage Threshold** policy.
83
+
84
+ ---
85
+
86
+ ## ⚙️ Configuration Options
87
+
88
+ The CLI will guide you through:
89
+ 1. **Project Name**
90
+ 2. **Language**: `JavaScript` | `TypeScript`
91
+ 3. **Architecture**: `MVC` | `Clean Architecture`
92
+ 4. **View Engine**: (MVC only) `None` | `EJS` | `Pug`
93
+ 5. **Database**: `MySQL` | `PostgreSQL` | `MongoDB`
94
+ 6. **Communication**: `REST` | `GraphQL` | `Kafka`
95
+ 7. **Caching**: `None` | `Redis` | `Memory Cache`
96
+ 8. **CI/CD**: `GitHub Actions` | `Jenkins` | `GitLab CI`
97
+ 9. **Security**: (Optional) Snyk & SonarCloud Hardening
98
+
99
+ ---
100
+
101
+ ## 🏗️ Generated Project Structure
102
+
103
+ A typical generated project (TypeScript + Clean Architecture) looks like this:
104
+
105
+ ```text
106
+ .
107
+ ├── src/
108
+ │ ├── application/ # Use cases & Business logic
109
+ │ ├── domain/ # Entities & Repository interfaces
110
+ │ ├── infrastructure/ # DB, External services, Repositories
111
+ │ ├── interfaces/ # Controllers, Routes, GraphQL, Kafka
112
+ │ ├── errors/ # Custom Error Classes
113
+ │ └── index.ts # Entry point
114
+ ├── flyway/sql/ # SQL migrations (if applicable)
115
+ ├── docker-compose.yml # Infrastructure services
116
+ ├── package.json # Scripts and dependencies
117
+ ├── tsconfig.json # TypeScript config
118
+ └── .cursorrules # AI assistance rules
119
+ ```
120
+
121
+ ---
122
+
123
+ ## 📖 Documentation
124
+
125
+ For full guides, architecture deep-dives, and feature references, visit our **[Official Documentation Site](https://paudang.github.io/nodejs-quickstart-structure/)**.
126
+
127
+ ---
128
+
129
+ ## ❤️ Support & 🗺️ Roadmap
130
+
131
+ ### Support the Project
132
+ We just hit **3,000+ downloads**! If this tool helped you, please:
133
+ - Give us a on [GitHub](https://github.com/paudang/nodejs-quickstart-structure).
134
+ - Read our [Medium Article](https://medium.com/@paudang/nodejs-quickstart-generator-93c276d60e0b) for tutorials.
135
+
136
+ ### Roadmap
137
+ Track our progress and vote for features on our public board:
138
+ 👉 **[View our Public Roadmap on Trello](https://trello.com/b/TPTo8ylF/nodejs-quickstart-structure-product)**
139
+
140
+ ---
141
+
142
+ ## License
143
+
144
+ ISC
package/bin/index.js CHANGED
@@ -29,7 +29,8 @@ program
29
29
  .option('-d, --database <database>', 'Database (MySQL, PostgreSQL)')
30
30
  .option('--db-name <name>', 'Database name')
31
31
  .option('-c, --communication <communication>', 'Communication (REST APIs, GraphQL, Kafka)')
32
- .option('--ci-provider <provider>', 'CI/CD Provider (None, GitHub Actions, Jenkins)')
32
+ .option('--ci-provider <provider>', 'CI/CD Provider (None, GitHub Actions, Jenkins, GitLab CI)')
33
+ .option('--include-security', 'Include Enterprise Security Hardening')
33
34
  .option('--caching <type>', 'Caching Layer (None/Redis)')
34
35
  .action(async (options) => {
35
36
  // Fix for Commander camelCase conversion
@@ -83,6 +84,7 @@ program
83
84
  process.exit(1);
84
85
  }
85
86
  });
87
+
86
88
  program.parse(process.argv);
87
89
 
88
90
  if (!process.argv.slice(2).length) {
package/lib/generator.js CHANGED
@@ -16,9 +16,10 @@ export const generateProject = async (config) => {
16
16
  viewEngine: 'None',
17
17
  caching: 'None',
18
18
  dbName: 'demo',
19
- ciProvider: 'None',
19
+ ciProvider: 'GitHub Actions',
20
20
  communication: 'REST APIs',
21
21
  database: 'None',
22
+ includeSecurity: false,
22
23
  ...config
23
24
  };
24
25
 
@@ -112,7 +113,7 @@ export const generateProject = async (config) => {
112
113
  ----------------------------------------------------
113
114
  ✅ Linting & Formatting: Eslint + Prettier configured
114
115
  ✅ Git Hooks: Husky + Lint-Staged ready
115
- ✅ Security: Helmet, CORS, Rate-Limiting added
116
+ ✅ Security: Helmet, CORS, Rate-Limiting added${config.includeSecurity ? '\n ✅ Enterprise Security: Snyk (SCA) & SonarCloud (SAST) integration' : ''}
116
117
  ✅ Testing: Jest setup for Unit/Integration tests
117
118
  ✅ Docker: Production-ready multi-stage build
118
119
  ${config.ciProvider !== 'None' ? `✅ CI/CD: ${config.ciProvider} Workflow ready` : '❌ CI/CD: Skipped (User preferred)'}
@@ -52,6 +52,20 @@ export const renderProfessionalConfig = async (templatesDir, targetDir, config)
52
52
  const jestE2eTemplate = await fs.readFile(path.join(templatesDir, 'common', 'jest.e2e.config.js.ejs'), 'utf-8');
53
53
  const jestE2eContent = ejs.render(jestE2eTemplate, { ...config });
54
54
  await fs.writeFile(path.join(targetDir, 'jest.e2e.config.js'), jestE2eContent);
55
+
56
+ // 1. Setup Husky pre-commit (Always for Professional Standard)
57
+ const huskyDir = path.join(targetDir, '.husky');
58
+ await fs.ensureDir(huskyDir);
59
+ await fs.copy(path.join(templatesDir, 'common', '_husky', 'pre-commit'), path.join(huskyDir, 'pre-commit'));
60
+
61
+ // 2. Enterprise Security Hardening (Optional)
62
+ if (config.includeSecurity) {
63
+ await fs.copy(path.join(templatesDir, 'common', 'SECURITY.md'), path.join(targetDir, 'SECURITY.md'));
64
+
65
+ const sonarTemplate = await fs.readFile(path.join(templatesDir, 'common', 'sonar-project.properties.ejs'), 'utf-8');
66
+ const sonarContent = ejs.render(sonarTemplate, { ...config });
67
+ await fs.writeFile(path.join(targetDir, 'sonar-project.properties'), sonarContent);
68
+ }
55
69
  };
56
70
 
57
71
  export const renderAiNativeFiles = async (templatesDir, targetDir, config) => {
@@ -80,10 +94,20 @@ export const renderAiNativeFiles = async (templatesDir, targetDir, config) => {
80
94
  };
81
95
 
82
96
  export const setupCiCd = async (templatesDir, targetDir, config) => {
83
- const { ciProvider } = config;
97
+ const { ciProvider, includeSecurity } = config;
84
98
  if (ciProvider === 'GitHub Actions') {
85
- await fs.ensureDir(path.join(targetDir, '.github/workflows'));
86
- await fs.copy(path.join(templatesDir, 'common', '_github/workflows/ci.yml'), path.join(targetDir, '.github/workflows/ci.yml'));
99
+ const workflowsDir = path.join(targetDir, '.github/workflows');
100
+ await fs.ensureDir(workflowsDir);
101
+
102
+ const ciTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/ci.yml.ejs'), 'utf-8');
103
+ const ciContent = ejs.render(ciTemplate, { ...config });
104
+ await fs.writeFile(path.join(workflowsDir, 'ci.yml'), ciContent);
105
+
106
+ if (includeSecurity) {
107
+ const securityTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/security.yml.ejs'), 'utf-8');
108
+ const securityContent = ejs.render(securityTemplate, { ...config });
109
+ await fs.writeFile(path.join(workflowsDir, 'security.yml'), securityContent);
110
+ }
87
111
  } else if (ciProvider === 'Jenkins') {
88
112
  const jenkinsTemplate = await fs.readFile(path.join(templatesDir, 'common', 'Jenkinsfile.ejs'), 'utf-8');
89
113
  const jenkinsContent = ejs.render(jenkinsTemplate, { ...config });
package/lib/prompts.js CHANGED
@@ -77,9 +77,24 @@ export const getProjectDetails = async (options = {}) => {
77
77
  choices: ['None', 'GitHub Actions', 'Jenkins', 'GitLab CI'],
78
78
  default: 'None',
79
79
  when: !options.ciProvider
80
+ },
81
+ {
82
+ type: 'select',
83
+ name: 'includeSecurity',
84
+ message: 'Include Enterprise Security Hardening (Big Tech Standard: Snyk, SonarQube)?',
85
+ choices: ['No', 'Yes'],
86
+ default: "No",
87
+ when: (answers) => !options.includeSecurity && (options.ciProvider || answers.ciProvider) !== 'None'
80
88
  }
81
89
  ];
82
90
 
83
91
  const answers = await inquirer.prompt(questions);
84
- return { ...options, ...answers };
92
+ const result = { ...options, ...answers };
93
+
94
+ // Normalize includeSecurity to boolean if it's a string from the select prompt
95
+ if (typeof result.includeSecurity === 'string') {
96
+ result.includeSecurity = result.includeSecurity === 'Yes';
97
+ }
98
+
99
+ return result;
85
100
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-quickstart-structure",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "type": "module",
5
5
  "description": "The ultimate nodejs quickstart structure CLI to scaffold Node.js microservices with MVC or Clean Architecture",
6
6
  "main": "bin/index.js",
@@ -12,7 +12,12 @@
12
12
  "test:e2e": "npm run test:e2e:windows",
13
13
  "test:e2e:windows": "node scripts/validate-windows.js",
14
14
  "test:e2e:linux": "node scripts/validate-linux.js",
15
- "test:verify:mongo": "node scripts/verify-migration.js"
15
+ "test:verify:mongo": "node scripts/verify-migration.js",
16
+ "docs:dev": "vitepress dev docs",
17
+ "docs:build": "vitepress build docs",
18
+ "docs:preview": "vitepress preview docs",
19
+ "security:check": "npm audit && npm run snyk:test",
20
+ "snyk:test": "snyk test"
16
21
  },
17
22
  "keywords": [
18
23
  "nodejs",
@@ -45,6 +50,13 @@
45
50
  "fs-extra": "^11.3.0",
46
51
  "inquirer": "^13.3.2"
47
52
  },
53
+ "overrides": {
54
+ "esbuild": "^0.25.0"
55
+ },
56
+ "devDependencies": {
57
+ "snyk": "^1.1303.2",
58
+ "vitepress": "^1.0.0-rc.45"
59
+ },
48
60
  "files": [
49
61
  "bin",
50
62
  "lib",
@@ -1,3 +1,4 @@
1
+ import { env } from '@/config/env';
1
2
  import express from 'express';
2
3
  import cors from 'cors';
3
4
  import helmet from 'helmet';
@@ -23,8 +24,6 @@ import { typeDefs, resolvers } from '@/interfaces/graphql';
23
24
  import { gqlContext, MyContext } from '@/interfaces/graphql/context';
24
25
  <%_ } -%>
25
26
 
26
- import { env } from '@/config/env';
27
-
28
27
  const app = express();
29
28
  const port = env.PORT;
30
29
 
@@ -4,6 +4,10 @@ variables:
4
4
  stages:
5
5
  - lint
6
6
  - test
7
+ <% if (includeSecurity) { %>
8
+ - security
9
+ - quality
10
+ <% } %>
7
11
  - build
8
12
 
9
13
  cache:
@@ -12,19 +16,19 @@ cache:
12
16
 
13
17
  install_dependencies:
14
18
  stage: .pre
15
- image: node:22-alpine
19
+ image: node:22-slim
16
20
  script:
17
21
  - npm ci
18
22
 
19
23
  lint_code:
20
24
  stage: lint
21
- image: node:22-alpine
25
+ image: node:22-slim
22
26
  script:
23
27
  - npm run lint
24
28
 
25
29
  run_unit_tests:
26
30
  stage: test
27
- image: node:22-alpine
31
+ image: node:22-slim
28
32
  script:
29
33
  - npm run test:coverage
30
34
 
@@ -37,7 +41,44 @@ run_e2e_tests:
37
41
  - apk add --no-cache nodejs npm docker-compose
38
42
  - npm ci
39
43
  - npm run test:e2e
44
+ <% if (includeSecurity) { %>
45
+ snyk_scan:
46
+ stage: security
47
+ image: node:22-alpine
48
+ script:
49
+ - npm ci
50
+ - npm run snyk:test
51
+ only:
52
+ - main
40
53
 
54
+ snyk_container_scan:
55
+ stage: security
56
+ image: docker:20.10.16
57
+ services:
58
+ - docker:20.10.16-dind
59
+ script:
60
+ - apk add --no-cache nodejs npm
61
+ - npm install -g snyk
62
+ - docker build -t <%= projectName %>:latest .
63
+ - snyk container test <%= projectName %>:latest --file=Dockerfile --severity-threshold=high --skip-unused-projects
64
+
65
+ sonarqube_check:
66
+ stage: quality
67
+ image:
68
+ name: sonarsource/sonar-scanner-cli:latest
69
+ entrypoint: [""]
70
+ variables:
71
+ SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
72
+ GIT_DEPTH: "0"
73
+ cache:
74
+ key: "${CI_JOB_NAME}"
75
+ paths:
76
+ - .sonar/cache
77
+ script:
78
+ - sonar-scanner
79
+ only:
80
+ - main
81
+ <% } %>
41
82
  build_app:
42
83
  stage: build
43
84
  image: node:22-alpine
@@ -1,7 +1,12 @@
1
1
  # ==========================================
2
2
  # Stage 1: Builder
3
3
  # ==========================================
4
- FROM node:22-alpine AS builder
4
+ FROM node:22.22.2-trixie-slim AS builder
5
+
6
+ # Upgrade OS packages to fix upstream vulnerabilities (Snyk-detected)
7
+ RUN apt-get update && apt-get upgrade -y && \
8
+ apt-get install -y --no-install-recommends ca-certificates && \
9
+ rm -rf /var/lib/apt/lists/*
5
10
 
6
11
  WORKDIR /app
7
12
  ENV NPM_CONFIG_UPDATE_NOTIFIER=false
@@ -20,7 +25,12 @@ COPY . .
20
25
  # ==========================================
21
26
  # Stage 2: Production
22
27
  # ==========================================
23
- FROM node:22-alpine AS production
28
+ FROM node:22.22.2-trixie-slim AS production
29
+
30
+ # Upgrade OS packages to fix upstream vulnerabilities (Snyk-detected)
31
+ RUN apt-get update && apt-get upgrade -y && \
32
+ apt-get install -y --no-install-recommends ca-certificates && \
33
+ rm -rf /var/lib/apt/lists/*
24
34
 
25
35
  WORKDIR /app
26
36
 
@@ -31,29 +31,34 @@ pipeline {
31
31
  }
32
32
  }
33
33
 
34
- // stage('Build') {
35
- // steps {
36
- // sh 'npm run build'
37
- // }
38
- // }
39
-
40
- // stage('SonarQube Analysis') {
41
- // environment {
42
- // scannerHome = tool 'SonarScanner'
43
- // }
44
- // steps {
45
- // withSonarQubeEnv('SonarQube') {
46
- // sh "${scannerHome}/bin/sonar-scanner"
47
- // }
48
- // }
49
- // }
34
+ <% if (includeSecurity) { %>
35
+ stage('SonarQube Analysis') {
36
+ environment {
37
+ scannerHome = tool 'SonarScanner'
38
+ }
39
+ steps {
40
+ withSonarQubeEnv('SonarQube') {
41
+ sh "${scannerHome}/bin/sonar-scanner"
42
+ }
43
+ }
44
+ }
50
45
 
51
- // stage('Security Scan') {
52
- // steps {
53
- // sh 'npm audit --audit-level=high'
54
- // }
55
- // }
46
+ stage('Security Scan') {
47
+ steps {
48
+ sh 'npm audit --audit-level=high'
49
+ sh 'npm run snyk:test'
50
+ }
51
+ }
56
52
 
53
+ stage('Snyk Container Scan') {
54
+ steps {
55
+ script {
56
+ sh 'docker build -t <%= projectName %>:latest .'
57
+ sh 'snyk container test <%= projectName %>:latest --file=Dockerfile --severity-threshold=high --skip-unused-projects'
58
+ }
59
+ }
60
+ }
61
+ <% } %>
57
62
  // stage('Docker Build & Push') {
58
63
  // steps {
59
64
  // script {
@@ -3,6 +3,10 @@
3
3
  ![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)
4
4
  ![License](https://img.shields.io/badge/License-ISC-blue.svg)
5
5
  <% if (language === 'TypeScript') { %>![TypeScript](https://img.shields.io/badge/Language-TypeScript-blue.svg)<% } else { %>![JavaScript](https://img.shields.io/badge/Language-JavaScript-yellow.svg)<% } %>
6
+ <% if (includeSecurity) { %>
7
+ [![Snyk Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/yourusername/<%= projectName %>?style=flat-square)](https://snyk.io/)
8
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=<%= projectName %>&metric=alert_status)](https://sonarcloud.io/)
9
+ <% } %>
6
10
 
7
11
  A production-ready Node.js microservice generated with **<%= architecture %>** and **<%= database %>**.
8
12
  This project comes pre-configured with industry-standard tooling for **Code Quality**, **Testing**, and **Security**.
@@ -15,6 +19,7 @@ This project comes pre-configured with industry-standard tooling for **Code Qual
15
19
  - **Quality**: Eslint, Prettier, Husky, Lint-Staged.
16
20
  - **Testing**: Jest (Unit & Integration).
17
21
  - **DevOps**: Multi-stage Docker build, CI/CD ready.
22
+ <% if (includeSecurity) { %>- **Enterprise Security**: Snyk SCA, SonarCloud SAST.<% } %>
18
23
 
19
24
  ## 🔄 CI/CD Pipeline
20
25
  <%_ if (ciProvider === 'GitHub Actions') { -%>
@@ -49,19 +54,20 @@ CI/CD is not currently configured, but the project is ready for integration.
49
54
 
50
55
  ### 2. Quick Start
51
56
  ```bash
52
- # Initialize Git (Required for Husky)
57
+ # Initialize Git (Mandatory for Husky hooks)
53
58
  git init
54
59
 
55
60
  # Install dependencies
56
61
  npm install
57
62
 
58
- # Setup Git Hooks (Husky)
59
- npm run prepare
63
+ # Troubleshooting Husky (if skip git init)
64
+ # npx husky install
60
65
 
61
66
  # Start Infrastructure (DB, etc.)
62
67
  docker-compose up -d
63
68
 
64
69
  # Run Development Server
70
+ docker-compose up -d<% if (database !== 'None') { %> db<% } %><% if (caching === 'Redis') { %> redis<% } %><% if (communication === 'Kafka') { %> kafka<% } %>
65
71
  npm run dev
66
72
  ```
67
73
 
@@ -241,8 +247,12 @@ docker-compose down
241
247
  - **CORS**: Configured for cross-origin requests.
242
248
  - **Rate Limiting**: Protects against DDoS / Brute-force.
243
249
  - **HPP**: Prevents HTTP Parameter Pollution attacks.
244
-
245
-
250
+ <% if (includeSecurity) { %>
251
+ ### 🛡️ Enterprise Hardening (Big Tech Standard)
252
+ - **Snyk SCA**: Automated dependency vulnerability scanning.
253
+ - **SonarCloud**: Deep static analysis for code quality and security hotspots.
254
+ - **Security Policy**: Standard `SECURITY.md` for vulnerability reporting.
255
+ <% } %>
246
256
  ## 🤖 AI-Native Development
247
257
 
248
258
  This project is "AI-Ready" out of the box. We have pre-configured industry-leading AI context files to bridge the gap between "Generated Code" and "AI-Assisted Development."
@@ -0,0 +1,20 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Only the latest `main` branch is supported for security updates.
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 1.0.x | :white_check_mark: |
10
+ | < 1.0 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ We take the security of this project seriously. If you believe you have found a security vulnerability, please report it following these steps:
15
+
16
+ 1. **Do not open a public issue.**
17
+ 2. Send an email to the project maintainers (see `package.json`).
18
+ 3. Provide a detailed description of the vulnerability, including steps to reproduce.
19
+
20
+ We will acknowledge your report within 48 hours and work on a fix as soon as possible.
@@ -14,17 +14,13 @@ jobs:
14
14
 
15
15
  runs-on: ubuntu-latest
16
16
 
17
- strategy:
18
- matrix:
19
- node-version: [20.x, 22.x]
20
-
21
17
  steps:
22
18
  - uses: actions/checkout@v4
23
19
 
24
- - name: Use Node.js ${{ matrix.node-version }}
20
+ - name: Use Node.js 22.x
25
21
  uses: actions/setup-node@v4
26
22
  with:
27
- node-version: ${{ matrix.node-version }}
23
+ node-version: 22.x
28
24
  cache: 'npm'
29
25
 
30
26
  - name: Install Dependencies
@@ -41,3 +37,10 @@ jobs:
41
37
 
42
38
  - name: Build
43
39
  run: npm run build --if-present
40
+ <% if (includeSecurity) { %>
41
+ - name: SonarQube Scan
42
+ uses: SonarSource/sonarqube-scan-action@master
43
+ env:
44
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
45
+ SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
46
+ <% } %>
@@ -0,0 +1,36 @@
1
+ name: Enterprise Security Scan
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+ schedule:
9
+ - cron: '0 0 * * 1' # Weekly scan
10
+
11
+ jobs:
12
+ node-security:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Run Snyk to check for vulnerabilities
18
+ uses: snyk/actions/node@master
19
+ env:
20
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
21
+ with:
22
+ args: --severity-threshold=high
23
+
24
+ container-security:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ - name: Build Docker image
29
+ run: docker build -t <%= projectName %>:latest .
30
+ - name: Run Snyk to check Docker image for vulnerabilities
31
+ uses: snyk/actions/docker@master
32
+ env:
33
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
34
+ with:
35
+ image: <%= projectName %>:latest
36
+ args: --file=Dockerfile --severity-threshold=high --skip-unused-projects
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
@@ -99,7 +99,7 @@ services:
99
99
  - mongodb_data:/data/db
100
100
 
101
101
  mongo-migrate:
102
- image: node:22-alpine
102
+ image: node:22-slim
103
103
  working_dir: /app
104
104
  volumes:
105
105
  - .:/app
@@ -1,8 +1,9 @@
1
1
  const { Kafka } = require('kafkajs');
2
+ const { env } = require('./env');
2
3
 
3
4
  const kafka = new Kafka({
4
5
  clientId: 'nodejs-service',
5
- brokers: [process.env.KAFKA_BROKER || 'localhost:9092']
6
+ brokers: [env.KAFKA_BROKER]
6
7
  });
7
8
 
8
9
  module.exports = { kafka };
@@ -9,6 +9,12 @@ jest.mock('kafkajs', () => {
9
9
  };
10
10
  });
11
11
 
12
+ jest.mock('<% if (architecture === "MVC") { %>@/config/env<% } else { %>@/infrastructure/config/env<% } %>', () => ({
13
+ env: {
14
+ KAFKA_BROKER: 'localhost:9092'
15
+ }
16
+ }));
17
+
12
18
  describe('Kafka Configuration', () => {
13
19
  beforeEach(() => {
14
20
  jest.clearAllMocks();
@@ -9,6 +9,12 @@ jest.mock('kafkajs', () => {
9
9
  };
10
10
  });
11
11
 
12
+ jest.mock('@/config/env', () => ({
13
+ env: {
14
+ KAFKA_BROKER: 'localhost:9092'
15
+ }
16
+ }));
17
+
12
18
  describe('Kafka Configuration', () => {
13
19
  beforeEach(() => {
14
20
  jest.clearAllMocks();
@@ -1,6 +1,7 @@
1
1
  import { Kafka } from 'kafkajs';
2
+ import { env } from '@/config/env';
2
3
 
3
4
  export const kafka = new Kafka({
4
5
  clientId: 'nodejs-service',
5
- brokers: [process.env.KAFKA_BROKER || 'localhost:9092']
6
+ brokers: [env.KAFKA_BROKER]
6
7
  });
@@ -11,14 +11,16 @@
11
11
  "lint": "eslint .",
12
12
  "lint:fix": "eslint . --fix",
13
13
  "format": "prettier --write .",
14
- "prepare": "node -e \"try { require('child_process').execSync('husky install'); } catch (e) { console.log('Not a git repository, skipping husky install'); }\"",
14
+ "prepare": "node -e \"if (require('fs').existsSync('.git')) { try { require('child_process').execSync('husky install', { stdio: 'inherit' }); } catch (e) { console.error('Husky installation failed:', e.message); } }\"",
15
15
  <% if (database === 'MongoDB') { %> "migrate": "migrate-mongo up",
16
16
  <% } -%>
17
17
  "test": "jest",
18
18
  "test:watch": "jest --watch",
19
19
  "test:coverage": "jest --coverage",
20
20
  "test:e2e:run": "jest --config ./jest.e2e.config.js --passWithNoTests",
21
- "test:e2e": "node scripts/run-e2e.js"
21
+ "test:e2e": "node scripts/run-e2e.js"<% if (includeSecurity) { %>,
22
+ "security:check": "npm audit && npm run snyk:test",
23
+ "snyk:test": "snyk test"<% } %>
22
24
  },
23
25
  "dependencies": {
24
26
  "express": "^4.18.2",
@@ -82,7 +84,8 @@
82
84
  "eslint-plugin-import-x": "^4.6.1",
83
85
  "eslint-import-resolver-typescript": "^3.7.0",
84
86
  "husky": "^8.0.3",
85
- "lint-staged": "^15.4.3"<% if (language === 'TypeScript') { %>,
87
+ "lint-staged": "^15.4.3",
88
+ "snyk": "^1.1295.0"<% if (language === 'TypeScript') { %>,
86
89
  "typescript-eslint": "^8.24.1",<%_ if (communication === 'REST APIs' || communication === 'Kafka') { %>
87
90
  "@types/swagger-ui-express": "^4.1.6",
88
91
  "@types/yamljs": "^0.2.34",<%_ } %>
@@ -0,0 +1,27 @@
1
+ # SonarCloud/SonarQube Project Configuration
2
+ # See https://docs.sonarqube.org/latest/analysis/analysis-parameters/
3
+
4
+ sonar.projectKey=your-org-key_<%= projectName %>
5
+ sonar.projectName=<%= projectName %>
6
+ sonar.organization=your-org-key
7
+ sonar.projectVersion=1.0.0
8
+
9
+ # Path to the source directories
10
+ sonar.sources=src
11
+ # Path to the test directories
12
+ sonar.tests=tests
13
+
14
+ # Language specific settings
15
+ sonar.javascript.environments=node
16
+ sonar.typescript.tsconfigPath=tsconfig.json
17
+ sonar.javascript.lcov.reportPaths=coverage/lcov.info
18
+
19
+ # Exclusions
20
+ sonar.exclusions=node_modules/**, dist/**, coverage/**, tests/**
21
+
22
+ # Quality Gates
23
+ sonar.qualitygate.wait=true
24
+ sonar.qualitygate.timeout=300
25
+
26
+ # Security Hotspots
27
+ sonar.security.reportPaths=snyk-report.json
@@ -1,3 +1,4 @@
1
+ const { env } = require('./config/env');
1
2
  const express = require('express');
2
3
  const cors = require('cors');
3
4
  <%_ if (communication === 'REST APIs' || communication === 'Kafka') { -%>const apiRoutes = require('./routes/api');<%_ } %>
@@ -16,7 +17,6 @@ const { gqlContext } = require('./graphql/context');
16
17
  const swaggerUi = require('swagger-ui-express');
17
18
  const swaggerSpecs = require('./config/swagger');
18
19
  <%_ } -%>
19
- const { env } = require('./config/env');
20
20
  const setupGracefulShutdown = require('./utils/gracefulShutdown');
21
21
 
22
22
  const app = express();