create-charcole 2.0.4 → 2.2.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 (100) hide show
  1. package/CHANGELOG.md +290 -14
  2. package/README.md +258 -312
  3. package/bin/index.js +392 -55
  4. package/bin/lib/pkgManager.js +8 -25
  5. package/bin/lib/templateHandler.js +5 -42
  6. package/create-charcole-2.1.0.tgz +0 -0
  7. package/package.json +2 -2
  8. package/packages/swagger/BACKWARD_COMPATIBILITY.md +145 -0
  9. package/packages/swagger/CHANGELOG.md +404 -0
  10. package/packages/swagger/README.md +578 -0
  11. package/packages/swagger/charcole-swagger-1.0.0.tgz +0 -0
  12. package/packages/swagger/package-lock.json +1715 -0
  13. package/packages/swagger/package.json +44 -0
  14. package/packages/swagger/src/helpers.js +427 -0
  15. package/packages/swagger/src/index.d.ts +126 -0
  16. package/packages/swagger/src/index.js +12 -0
  17. package/packages/swagger/src/setup.js +100 -0
  18. package/template/js/.env.example +8 -0
  19. package/template/js/README.md +128 -5
  20. package/template/js/basePackage.json +11 -13
  21. package/template/js/src/app.js +8 -2
  22. package/template/js/src/config/swagger.config.js +15 -0
  23. package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
  24. package/template/js/src/modules/auth/auth.constants.js +3 -0
  25. package/template/js/src/modules/auth/auth.controller.js +29 -0
  26. package/template/js/src/modules/auth/auth.middlewares.js +19 -0
  27. package/template/js/src/modules/auth/auth.routes.js +131 -0
  28. package/template/js/src/modules/auth/auth.schemas.js +60 -0
  29. package/template/js/src/modules/auth/auth.service.js +67 -0
  30. package/template/js/src/modules/auth/package.json +6 -0
  31. package/template/js/src/modules/health/controller.js +104 -3
  32. package/template/js/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
  33. package/template/js/src/modules/swagger/package.json +5 -0
  34. package/template/js/src/repositories/user.repo.js +19 -0
  35. package/template/js/src/routes/index.js +25 -0
  36. package/template/js/src/routes/protected.js +57 -0
  37. package/template/ts/.env.example +8 -0
  38. package/template/ts/README.md +128 -5
  39. package/template/ts/basePackage.json +19 -15
  40. package/template/ts/build.js +46 -0
  41. package/template/ts/src/app.ts +12 -7
  42. package/template/ts/src/config/swagger.config.ts +30 -0
  43. package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
  44. package/template/ts/src/middlewares/errorHandler.ts +15 -23
  45. package/template/ts/src/middlewares/requestLogger.ts +1 -1
  46. package/template/ts/src/middlewares/validateRequest.ts +1 -1
  47. package/template/ts/src/modules/auth/auth.constants.ts +6 -0
  48. package/template/ts/src/modules/auth/auth.controller.ts +32 -0
  49. package/template/ts/src/modules/auth/auth.middlewares.ts +46 -0
  50. package/template/ts/src/modules/auth/auth.routes.ts +52 -0
  51. package/template/ts/src/modules/auth/auth.schemas.ts +73 -0
  52. package/template/ts/src/modules/auth/auth.service.ts +106 -0
  53. package/template/ts/src/modules/auth/package.json +10 -0
  54. package/template/ts/src/modules/health/controller.ts +61 -45
  55. package/template/ts/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
  56. package/template/ts/src/modules/swagger/package.json +5 -0
  57. package/template/ts/src/repositories/user.repo.ts +33 -0
  58. package/template/ts/src/routes/index.ts +24 -0
  59. package/template/ts/src/routes/protected.ts +46 -0
  60. package/template/ts/src/server.ts +3 -4
  61. package/template/ts/src/utils/logger.ts +1 -1
  62. package/template/ts/tsconfig.json +14 -7
  63. package/tmpclaude-1049-cwd +1 -0
  64. package/tmpclaude-3e37-cwd +1 -0
  65. package/tmpclaude-4d73-cwd +1 -0
  66. package/tmpclaude-8a8e-cwd +1 -0
  67. package/template/js/ARCHITECTURE_DIAGRAMS.md +0 -283
  68. package/template/js/CHECKLIST.md +0 -279
  69. package/template/js/COMPLETE.md +0 -405
  70. package/template/js/ERROR_HANDLING.md +0 -393
  71. package/template/js/IMPLEMENTATION.md +0 -368
  72. package/template/js/IMPLEMENTATION_COMPLETE.md +0 -363
  73. package/template/js/INDEX.md +0 -290
  74. package/template/js/QUICK_REFERENCE.md +0 -270
  75. package/template/js/package.json +0 -28
  76. package/template/js/src/routes.js +0 -17
  77. package/template/js/test-api.js +0 -100
  78. package/template/ts/ARCHITECTURE_DIAGRAMS.md +0 -283
  79. package/template/ts/CHECKLIST.md +0 -279
  80. package/template/ts/COMPLETE.md +0 -405
  81. package/template/ts/ERROR_HANDLING.md +0 -393
  82. package/template/ts/IMPLEMENTATION.md +0 -368
  83. package/template/ts/IMPLEMENTATION_COMPLETE.md +0 -363
  84. package/template/ts/INDEX.md +0 -290
  85. package/template/ts/QUICK_REFERENCE.md +0 -270
  86. package/template/ts/package.json +0 -32
  87. package/template/ts/src/app.js +0 -75
  88. package/template/ts/src/config/constants.js +0 -20
  89. package/template/ts/src/config/env.js +0 -26
  90. package/template/ts/src/middlewares/errorHandler.js +0 -180
  91. package/template/ts/src/middlewares/requestLogger.js +0 -33
  92. package/template/ts/src/middlewares/validateRequest.js +0 -42
  93. package/template/ts/src/modules/health/controller.js +0 -50
  94. package/template/ts/src/routes.js +0 -17
  95. package/template/ts/src/routes.ts +0 -16
  96. package/template/ts/src/server.js +0 -38
  97. package/template/ts/src/utils/AppError.js +0 -182
  98. package/template/ts/src/utils/logger.js +0 -73
  99. package/template/ts/src/utils/response.js +0 -51
  100. package/template/ts/test-api.js +0 -100
package/CHANGELOG.md CHANGED
@@ -1,25 +1,301 @@
1
1
  # Changelog
2
2
 
3
+ All notable changes to Charcole will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.2.0] – 2026-02-06
9
+
10
+ ### 🎉 Major Release: Auto-Generated Swagger Documentation
11
+
12
+ #### ✨ **New Features**
13
+
14
+ - **🎯 @charcoles/swagger Package** – Effortless API documentation with automatic Zod-to-OpenAPI conversion
15
+ - **📚 Zero Schema Duplication** – Define schemas once in Zod, auto-generate OpenAPI specs
16
+ - **🎁 Built-in Response Templates** – Common responses (Success, ValidationError, Unauthorized, Forbidden, NotFound, InternalError) included
17
+ - **🔄 Always in Sync** – Impossible for documentation to drift from validation schemas
18
+ - **📦 Optional Module** – Include/exclude Swagger during project creation
19
+ - **🌍 Framework Agnostic** – Works with any Express.js project via `npm install @charcoles/swagger`
20
+
21
+ #### 🚀 **Swagger Features**
22
+
23
+ - **Automatic Schema Conversion**: Zod schemas automatically converted to OpenAPI JSON Schema
24
+ - **Response Templates**: 6 common response schemas included by default
25
+ - **Helper Functions**: Export utilities for advanced usage (`convertZodToOpenAPI`, `registerSchemas`, etc.)
26
+ - **Full TypeScript Support**: Complete type definitions for all functions
27
+ - **JavaScript Support**: Works perfectly with JavaScript projects too
28
+ - **100% Backward Compatible**: Old JSDoc approach still works
29
+
30
+ #### 📊 **Impact**
31
+
32
+ - **60-80% less documentation** per endpoint
33
+ - **0% schema duplication** (Zod → OpenAPI automatic)
34
+ - **Impossible to get out of sync** (single source of truth)
35
+ - **76 lines → 20 lines** for typical endpoint documentation
36
+
37
+ #### 📁 **New Files**
38
+
39
+ - `packages/swagger/src/helpers.js` - All helper utilities
40
+ - `packages/swagger/src/setup.js` - Enhanced setup with schema registration
41
+ - `packages/swagger/README.md` - Comprehensive package documentation
42
+ - `packages/swagger/CHANGELOG.md` - Package changelog
43
+ - `packages/swagger/BACKWARD_COMPATIBILITY.md` - Migration guide
44
+ - `template/*/src/lib/swagger/SWAGGER_GUIDE.md` - Complete usage guide
45
+
46
+ #### 🔧 **Technical Improvements**
47
+
48
+ - **Fixed Zod-to-OpenAPI conversion**: Properly handles internal `$ref` with `definitions`
49
+ - **Schema extraction**: Automatically extracts body schemas from nested Zod objects
50
+ - **Clean OpenAPI output**: Removes `$schema` and `definitions` for clean components
51
+
52
+ #### 📝 **Documentation Updates**
53
+
54
+ - All templates updated to demonstrate new approach
55
+ - Comprehensive guide in `SWAGGER_GUIDE.md`
56
+ - README with before/after comparisons
57
+ - Full API reference documentation
58
+
59
+ #### 🔐 **Auth Integration**
60
+
61
+ - Auth schemas (registerSchema, loginSchema) auto-documented when Swagger enabled
62
+ - Protected routes automatically show security requirements in Swagger UI
63
+ - Zero additional work for auth documentation
64
+
65
+ #### 🎯 **Developer Experience**
66
+
67
+ Before:
68
+
69
+ ```typescript
70
+ // Define Zod schema (6 lines)
71
+ // Manually duplicate in Swagger (76 lines!)
72
+ // Update both when changes happen
73
+ ```
74
+
75
+ After:
76
+
77
+ ```typescript
78
+ // Define Zod schema (6 lines)
79
+ // Register once in config (1 line)
80
+ // Reference everywhere with $ref (1 line)
81
+ // Done! Auto-synced forever!
82
+ ```
83
+
84
+ ### 🚦 **Migration Notes from v2.1**
85
+
86
+ - Existing v2.1 projects remain fully compatible
87
+ - No breaking changes to any core features
88
+ - New projects get optional Swagger module
89
+ - Swagger is opt-in for existing codebases
90
+ - Old JSDoc approach still works (100% backward compatible)
91
+
92
+ ### ✅ **Known Issues**
93
+
94
+ - None reported
95
+
96
+ ---
97
+
98
+ ## [2.1.0] – 2026-01-29
99
+
100
+ ### 🎉 Major Release: Repository Pattern & JWT Authentication
101
+
102
+ #### ✨ **New Features**
103
+
104
+ - **🎯 Revolutionary Repository Pattern** – Database abstraction layer for clean separation between business logic and data access
105
+ - **🔐 Optional JWT Authentication Module** – Complete auth system with register, login, logout, and protected routes
106
+ - **🧪 In-Memory Repository Implementation** – Test APIs instantly without database setup
107
+ - **🏗️ Repository Interfaces** – `BaseRepository` and `InMemoryRepository` for easy database switching
108
+ - **💻 Command-line project name support** – Create projects via `npx create-charcole@latest my-project`
109
+ - **📝 Enhanced TypeScript support** – Improved type definitions and compilation
110
+
111
+ #### 🚀 **New Architecture**
112
+
113
+ - **Database Abstraction Layer**: Switch between MongoDB, PostgreSQL, MySQL, etc., by changing one file
114
+ - **Modular Auth System**:
115
+ - Full user authentication (register/login/logout)
116
+ - JWT token generation and validation
117
+ - Password hashing with bcrypt
118
+ - Protected route middleware
119
+ - In-memory user repository for testing
120
+ - **Improved CLI**:
121
+ - Accept project name as command-line argument
122
+ - Better dependency merging for optional modules
123
+ - Cleaner project generation flow
124
+
125
+ #### 🔧 **Technical Improvements**
126
+
127
+ - **Fixed Module Copying**: Auth module properly excluded when user selects "No"
128
+ - **Fixed Package.json Merging**: Dependencies correctly merged into single package.json
129
+ - **Fixed TypeScript Compilation**: Clean builds with proper type definitions
130
+ - **Improved Path Resolution**: Better template directory structure handling
131
+
132
+ #### 📁 **Project Structure Updates**
133
+
134
+ - Added `src/modules/auth/` directory with complete auth system
135
+ - Modules now located in `src/modules/` instead of template root
136
+ - Cleaner dependency management with proper merging
137
+ - Enhanced CLI user experience with better flow control
138
+
139
+ #### 📦 **New Dependencies** (when auth selected)
140
+
141
+ - `jsonwebtoken@^9.0.0` for JWT authentication
142
+ - `bcryptjs@^2.4.3` for password hashing
143
+ - Type definitions for both libraries
144
+
145
+ #### 🎯 **Repository Pattern Benefits**
146
+
147
+ - ✅ Test without database setup
148
+ - ✅ Easy database migration
149
+ - ✅ Clean separation of concerns
150
+ - ✅ Better unit testing capabilities
151
+
152
+ #### 🔐 **Auth Module Structure**
153
+
154
+ ```
155
+ auth/
156
+ ├── auth.controller.js
157
+ ├── auth.middleware.js
158
+ ├── auth.constants.js
159
+ ├── auth.schemas.js
160
+
161
+ ```
162
+
163
+ ### 🚦 **Migration Notes from v2.0**
164
+
165
+ - Existing v2.0 projects remain compatible
166
+ - No breaking changes to core error handling or validation
167
+ - New projects get optional auth module
168
+ - Repository pattern is opt-in for existing codebases
169
+
170
+ ### ✅ **Known Issues**
171
+
172
+ - None reported
173
+
174
+ ---
175
+
3
176
  ## [2.0.0] – 2026-01-24
4
177
 
5
- ### Added
178
+ ### 🎉 **Major Release: TypeScript & JavaScript Support**
179
+
180
+ #### ✨ **New Features**
181
+
182
+ - **Full TypeScript project template support** – Production-ready TypeScript setup
183
+ - **Language selection at CLI runtime** – Choose between JavaScript or TypeScript during project creation
184
+ - **Improved project scaffolding structure** – Better organized template files
185
+ - **Enhanced developer experience** – Streamlined production setup process
186
+
187
+ #### 🔧 **Technical Improvements**
188
+
189
+ - **Improved template resolution logic** – More reliable project generation
190
+ - **Enhanced CLI output** – Better onboarding messages and instructions
191
+ - **Fixed template path resolution** – Resolved issues from previous versions
192
+ - **Fixed local CLI linking** – Improved development workflow
193
+
194
+ #### 📝 **Release Notes**
195
+
196
+ - This release focuses on stability and language parity
197
+ - Authentication and database modules intentionally excluded (added in v2.1)
198
+ - Foundation for future modular expansion
199
+
200
+ ---
201
+
202
+ ## [1.0.0] – 2025-12-15
203
+
204
+ ### 🎉 **Initial Release**
205
+
206
+ #### ✨ **Core Features**
207
+
208
+ - **Production-grade Express API boilerplate**
209
+ - **Centralized error handling system** – All errors flow through single handler
210
+ - **Error classification** – Operational vs programmer errors distinguished
211
+ - **Zod validation integration** – Type-safe schema validation with automatic error formatting
212
+ - **Structured logging** – Color-coded logs with context and stack traces
213
+ - **Consistent JSON responses** – Standardized format across all endpoints
214
+ - **Async error handling** – Promise rejection leaks prevented with asyncHandler
215
+ - **Graceful shutdown** – Proper cleanup on SIGTERM/SIGINT
216
+ - **Request logging** – Method, path, status, duration, IP automatically tracked
217
+
218
+ #### 🛡️ **Error Handling System**
219
+
220
+ - **AppError class hierarchy** – Specialized error types (ValidationError, NotFoundError, etc.)
221
+ - **Global error middleware** – Catches all unhandled errors
222
+ - **Production-safe responses** – Internal details hidden in production
223
+ - **Context-rich errors** – Debug information included in development
224
+
225
+ #### 📦 **Key Dependencies**
226
+
227
+ - Express.js web framework
228
+ - Zod for validation
229
+ - Structured logging system
230
+ - CORS middleware
231
+ - dotenv for environment variables
232
+
233
+ #### 🎯 **Design Philosophy**
234
+
235
+ - Never leak internal errors to clients in production
236
+ - Always classify errors (operational vs programmer)
237
+ - Consistent response format for all endpoints
238
+ - Type-safe validation with helpful error messages
239
+ - Easy to extend and maintain
240
+
241
+ ---
242
+
243
+ ## Versioning Scheme
244
+
245
+ Charcole follows [Semantic Versioning 2.0.0](https://semver.org/):
246
+
247
+ - **MAJOR** version for incompatible API changes
248
+ - **MINOR** version for new functionality (backwards compatible)
249
+ - **PATCH** version for bug fixes (backwards compatible)
250
+
251
+ ## Release Notes Policy
252
+
253
+ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
254
+
255
+ ---
256
+
257
+ ## How to Update the Changelog
258
+
259
+ When creating a new release:
260
+
261
+ 1. Add a new `## [X.Y.Z]` header at the top of the file
262
+ 2. Use descriptive headings for each section
263
+ 3. Include migration notes if there are breaking changes
264
+ 4. Add emojis for visual clarity (optional but recommended)
265
+ 5. Update the "Unreleased" section if using one
266
+ 6. Include links to issues/PRs when relevant
267
+
268
+ ## Template for Future Releases
269
+
270
+ ```markdown
271
+ ## [X.Y.Z] – YYYY-MM-DD
272
+
273
+ ### ✨ Added
274
+
275
+ - New features or functionality
276
+
277
+ ### 🔧 Changed
278
+
279
+ - Changes to existing functionality
280
+
281
+ ### 🐛 Fixed
282
+
283
+ - Bug fixes
284
+
285
+ ### 🗑️ Removed
6
286
 
7
- - Full TypeScript project template support
8
- - Language selection (JavaScript / TypeScript) at CLI runtime
9
- - Improved project scaffolding structure
10
- - Better developer experience for production setups
287
+ - Features removed or deprecated
11
288
 
12
- ### Changed
289
+ ### 🚦 Migration Notes
13
290
 
14
- - Internal template resolution logic
15
- - CLI output and onboarding messages
291
+ - Instructions for upgrading from previous versions
16
292
 
17
- ### Fixed
293
+ ### ✅ Known Issues
18
294
 
19
- - Incorrect template path resolution in previous versions
20
- - Local CLI linking issues during development
295
+ - Any known bugs or limitations in this release
296
+ ```
21
297
 
22
- ### Notes
298
+ ---
23
299
 
24
- - This release focuses on stability and language parity.
25
- - Authentication and database modules are intentionally not included yet.
300
+ **Maintained by:** The Charcole Team
301
+ **Last Updated:** 2026-01-29