nestforge-generator 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.
Files changed (326) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +371 -0
  3. package/README.pt-BR.md +370 -0
  4. package/dist/features/auth-strategy.js +19 -0
  5. package/dist/features/auth-strategy.js.map +1 -0
  6. package/dist/features/database.js +59 -0
  7. package/dist/features/database.js.map +1 -0
  8. package/dist/features/dependencies.js +57 -0
  9. package/dist/features/dependencies.js.map +1 -0
  10. package/dist/features/language.js +172 -0
  11. package/dist/features/language.js.map +1 -0
  12. package/dist/features/markers.js +116 -0
  13. package/dist/features/markers.js.map +1 -0
  14. package/dist/generator.js +120 -0
  15. package/dist/generator.js.map +1 -0
  16. package/dist/index.js +59 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/prompts.js +137 -0
  19. package/dist/prompts.js.map +1 -0
  20. package/package.json +76 -0
  21. package/templates/drizzle/.env.example +45 -0
  22. package/templates/drizzle/.env.test +38 -0
  23. package/templates/drizzle/.github/workflows/ci.yml +119 -0
  24. package/templates/drizzle/ARCHITECTURE.md +227 -0
  25. package/templates/drizzle/ARCHITECTURE.pt-BR.md +225 -0
  26. package/templates/drizzle/CODE_OF_CONDUCT.md +29 -0
  27. package/templates/drizzle/CODE_OF_CONDUCT.pt-BR.md +27 -0
  28. package/templates/drizzle/CONTRIBUTING.md +57 -0
  29. package/templates/drizzle/CONTRIBUTING.pt-BR.md +54 -0
  30. package/templates/drizzle/Dockerfile +43 -0
  31. package/templates/drizzle/LICENSE +21 -0
  32. package/templates/drizzle/README.md +257 -0
  33. package/templates/drizzle/README.pt-BR.md +257 -0
  34. package/templates/drizzle/ROADMAP.md +143 -0
  35. package/templates/drizzle/ROADMAP.pt-BR.md +143 -0
  36. package/templates/drizzle/TESTING.md +136 -0
  37. package/templates/drizzle/TESTING.pt-BR.md +136 -0
  38. package/templates/drizzle/docker-compose.yml +82 -0
  39. package/templates/drizzle/docs/adding-a-module.md +585 -0
  40. package/templates/drizzle/docs/features-markers.md +457 -0
  41. package/templates/drizzle/drizzle.config.ts +49 -0
  42. package/templates/drizzle/nest-cli.json +8 -0
  43. package/templates/drizzle/package.json +96 -0
  44. package/templates/drizzle/src/app.module.ts +72 -0
  45. package/templates/drizzle/src/auth/auth.controller.ts +283 -0
  46. package/templates/drizzle/src/auth/auth.module.ts +81 -0
  47. package/templates/drizzle/src/auth/auth.service.spec.ts +111 -0
  48. package/templates/drizzle/src/auth/auth.service.ts +631 -0
  49. package/templates/drizzle/src/auth/drizzle-session.store.ts +263 -0
  50. package/templates/drizzle/src/auth/dto/forgot-password.dto.ts +9 -0
  51. package/templates/drizzle/src/auth/dto/login.dto.ts +10 -0
  52. package/templates/drizzle/src/auth/dto/refresh-token.dto.ts +9 -0
  53. package/templates/drizzle/src/auth/dto/register.dto.ts +11 -0
  54. package/templates/drizzle/src/auth/dto/reset-password.dto.ts +10 -0
  55. package/templates/drizzle/src/auth/guards/github-auth.guard.ts +10 -0
  56. package/templates/drizzle/src/auth/guards/google-auth.guard.ts +10 -0
  57. package/templates/drizzle/src/auth/guards/jwt-auth.guard.ts +25 -0
  58. package/templates/drizzle/src/auth/guards/session-auth.guard.spec.ts +77 -0
  59. package/templates/drizzle/src/auth/guards/session-auth.guard.ts +37 -0
  60. package/templates/drizzle/src/auth/session.service.spec.ts +74 -0
  61. package/templates/drizzle/src/auth/session.service.ts +96 -0
  62. package/templates/drizzle/src/auth/strategies/github.strategy.ts +41 -0
  63. package/templates/drizzle/src/auth/strategies/google.strategy.ts +43 -0
  64. package/templates/drizzle/src/auth/strategies/jwt.strategy.ts +25 -0
  65. package/templates/drizzle/src/auth/token.service.ts +175 -0
  66. package/templates/drizzle/src/common/constants/permissions.ts +8 -0
  67. package/templates/drizzle/src/common/constants/role-permissions.ts +9 -0
  68. package/templates/drizzle/src/common/constants/role.enum.ts +5 -0
  69. package/templates/drizzle/src/common/decorators/current-user.decorator.ts +8 -0
  70. package/templates/drizzle/src/common/decorators/permissions.decorator.ts +7 -0
  71. package/templates/drizzle/src/common/decorators/public.decorator.ts +4 -0
  72. package/templates/drizzle/src/common/decorators/roles.decorator.ts +6 -0
  73. package/templates/drizzle/src/common/filters/http-exception.filter.ts +34 -0
  74. package/templates/drizzle/src/common/guards/permissions.guard.spec.ts +54 -0
  75. package/templates/drizzle/src/common/guards/permissions.guard.ts +28 -0
  76. package/templates/drizzle/src/common/guards/roles.guard.spec.ts +37 -0
  77. package/templates/drizzle/src/common/guards/roles.guard.ts +24 -0
  78. package/templates/drizzle/src/common/interceptors/logging.interceptor.ts +23 -0
  79. package/templates/drizzle/src/common/middleware/csrf.middleware.spec.ts +97 -0
  80. package/templates/drizzle/src/common/middleware/csrf.middleware.ts +46 -0
  81. package/templates/drizzle/src/common/utils/avatar-storage.util.ts +32 -0
  82. package/templates/drizzle/src/common/utils/hash.util.ts +5 -0
  83. package/templates/drizzle/src/config/env.validation.ts +50 -0
  84. package/templates/drizzle/src/database/database-lifecycle.service.ts +30 -0
  85. package/templates/drizzle/src/database/database.constants.ts +2 -0
  86. package/templates/drizzle/src/database/database.decorators.ts +5 -0
  87. package/templates/drizzle/src/database/database.module.ts +96 -0
  88. package/templates/drizzle/src/database/database.types.ts +28 -0
  89. package/templates/drizzle/src/database/schema/index.ts +11 -0
  90. package/templates/drizzle/src/database/schema/mysql.schema.ts +215 -0
  91. package/templates/drizzle/src/database/schema/postgres.schema.ts +218 -0
  92. package/templates/drizzle/src/database/schema/sqlite.schema.ts +190 -0
  93. package/templates/drizzle/src/database/seed.ts +152 -0
  94. package/templates/drizzle/src/health/health.controller.ts +49 -0
  95. package/templates/drizzle/src/health/health.module.ts +19 -0
  96. package/templates/drizzle/src/health/indicators/drizzle-health.indicator.spec.ts +71 -0
  97. package/templates/drizzle/src/health/indicators/drizzle-health.indicator.ts +52 -0
  98. package/templates/drizzle/src/health/indicators/redis-health.indicator.spec.ts +54 -0
  99. package/templates/drizzle/src/health/indicators/redis-health.indicator.ts +33 -0
  100. package/templates/drizzle/src/mail/mail.module.ts +12 -0
  101. package/templates/drizzle/src/mail/mail.processor.ts +48 -0
  102. package/templates/drizzle/src/mail/mail.service.ts +24 -0
  103. package/templates/drizzle/src/mail/templates/email-templates.ts +28 -0
  104. package/templates/drizzle/src/main.ts +145 -0
  105. package/templates/drizzle/src/metrics/metrics.controller.ts +22 -0
  106. package/templates/drizzle/src/metrics/metrics.interceptor.ts +30 -0
  107. package/templates/drizzle/src/metrics/metrics.module.ts +12 -0
  108. package/templates/drizzle/src/metrics/metrics.service.ts +34 -0
  109. package/templates/drizzle/src/types/express-session.d.ts +13 -0
  110. package/templates/drizzle/src/users/dto/create-user.dto.ts +12 -0
  111. package/templates/drizzle/src/users/dto/find-users-query.dto.ts +12 -0
  112. package/templates/drizzle/src/users/dto/update-user.dto.ts +6 -0
  113. package/templates/drizzle/src/users/entities/user.entity.ts +23 -0
  114. package/templates/drizzle/src/users/users.controller.ts +165 -0
  115. package/templates/drizzle/src/users/users.module.ts +10 -0
  116. package/templates/drizzle/src/users/users.service.spec.ts +301 -0
  117. package/templates/drizzle/src/users/users.service.ts +213 -0
  118. package/templates/drizzle/test/auth.e2e-spec.ts +114 -0
  119. package/templates/drizzle/test/session-auth.e2e-spec.ts +163 -0
  120. package/templates/drizzle/test/users.e2e-spec.ts +212 -0
  121. package/templates/drizzle/test/utils/clean-database.ts +104 -0
  122. package/templates/drizzle/test/utils/e2e-setup.ts +77 -0
  123. package/templates/drizzle/tsconfig.build.json +4 -0
  124. package/templates/drizzle/tsconfig.json +25 -0
  125. package/templates/drizzle/vitest.config.ts +20 -0
  126. package/templates/drizzle/vitest.e2e.config.ts +19 -0
  127. package/templates/prisma/.env.example +44 -0
  128. package/templates/prisma/.env.test +37 -0
  129. package/templates/prisma/.github/workflows/ci.yml +109 -0
  130. package/templates/prisma/ARCHITECTURE.md +70 -0
  131. package/templates/prisma/ARCHITECTURE.pt-BR.md +63 -0
  132. package/templates/prisma/CODE_OF_CONDUCT.md +29 -0
  133. package/templates/prisma/CODE_OF_CONDUCT.pt-BR.md +27 -0
  134. package/templates/prisma/CONTRIBUTING.md +57 -0
  135. package/templates/prisma/CONTRIBUTING.pt-BR.md +54 -0
  136. package/templates/prisma/Dockerfile +33 -0
  137. package/templates/prisma/LICENSE +21 -0
  138. package/templates/prisma/README.md +267 -0
  139. package/templates/prisma/README.pt-BR.md +267 -0
  140. package/templates/prisma/ROADMAP.md +75 -0
  141. package/templates/prisma/ROADMAP.pt-BR.md +65 -0
  142. package/templates/prisma/TESTING.md +123 -0
  143. package/templates/prisma/TESTING.pt-BR.md +123 -0
  144. package/templates/prisma/docker-compose.yml +78 -0
  145. package/templates/prisma/docs/adding-a-module.md +230 -0
  146. package/templates/prisma/docs/features-markers.md +50 -0
  147. package/templates/prisma/nest-cli.json +8 -0
  148. package/templates/prisma/package.json +95 -0
  149. package/templates/prisma/prisma/schema.prisma +105 -0
  150. package/templates/prisma/prisma/seed.ts +46 -0
  151. package/templates/prisma/src/app.module.ts +72 -0
  152. package/templates/prisma/src/auth/auth.controller.ts +283 -0
  153. package/templates/prisma/src/auth/auth.module.ts +59 -0
  154. package/templates/prisma/src/auth/auth.service.spec.ts +53 -0
  155. package/templates/prisma/src/auth/auth.service.ts +224 -0
  156. package/templates/prisma/src/auth/dto/forgot-password.dto.ts +9 -0
  157. package/templates/prisma/src/auth/dto/login.dto.ts +10 -0
  158. package/templates/prisma/src/auth/dto/refresh-token.dto.ts +9 -0
  159. package/templates/prisma/src/auth/dto/register.dto.ts +11 -0
  160. package/templates/prisma/src/auth/dto/reset-password.dto.ts +10 -0
  161. package/templates/prisma/src/auth/guards/github-auth.guard.ts +10 -0
  162. package/templates/prisma/src/auth/guards/google-auth.guard.ts +10 -0
  163. package/templates/prisma/src/auth/guards/jwt-auth.guard.ts +25 -0
  164. package/templates/prisma/src/auth/guards/session-auth.guard.spec.ts +77 -0
  165. package/templates/prisma/src/auth/guards/session-auth.guard.ts +37 -0
  166. package/templates/prisma/src/auth/session.service.spec.ts +74 -0
  167. package/templates/prisma/src/auth/session.service.ts +96 -0
  168. package/templates/prisma/src/auth/strategies/github.strategy.ts +41 -0
  169. package/templates/prisma/src/auth/strategies/google.strategy.ts +43 -0
  170. package/templates/prisma/src/auth/strategies/jwt.strategy.ts +25 -0
  171. package/templates/prisma/src/auth/token.service.ts +84 -0
  172. package/templates/prisma/src/common/constants/permissions.ts +8 -0
  173. package/templates/prisma/src/common/constants/role-permissions.ts +9 -0
  174. package/templates/prisma/src/common/decorators/current-user.decorator.ts +8 -0
  175. package/templates/prisma/src/common/decorators/permissions.decorator.ts +7 -0
  176. package/templates/prisma/src/common/decorators/public.decorator.ts +4 -0
  177. package/templates/prisma/src/common/decorators/roles.decorator.ts +6 -0
  178. package/templates/prisma/src/common/filters/http-exception.filter.ts +34 -0
  179. package/templates/prisma/src/common/guards/permissions.guard.spec.ts +54 -0
  180. package/templates/prisma/src/common/guards/permissions.guard.ts +28 -0
  181. package/templates/prisma/src/common/guards/roles.guard.spec.ts +37 -0
  182. package/templates/prisma/src/common/guards/roles.guard.ts +24 -0
  183. package/templates/prisma/src/common/interceptors/logging.interceptor.ts +23 -0
  184. package/templates/prisma/src/common/middleware/csrf.middleware.spec.ts +97 -0
  185. package/templates/prisma/src/common/middleware/csrf.middleware.ts +46 -0
  186. package/templates/prisma/src/common/utils/avatar-storage.util.ts +32 -0
  187. package/templates/prisma/src/common/utils/hash.util.ts +5 -0
  188. package/templates/prisma/src/config/env.validation.ts +49 -0
  189. package/templates/prisma/src/database/prisma.module.ts +9 -0
  190. package/templates/prisma/src/database/prisma.service.ts +13 -0
  191. package/templates/prisma/src/health/health.controller.ts +49 -0
  192. package/templates/prisma/src/health/health.module.ts +19 -0
  193. package/templates/prisma/src/health/indicators/prisma-health.indicator.spec.ts +22 -0
  194. package/templates/prisma/src/health/indicators/prisma-health.indicator.ts +19 -0
  195. package/templates/prisma/src/health/indicators/redis-health.indicator.spec.ts +54 -0
  196. package/templates/prisma/src/health/indicators/redis-health.indicator.ts +33 -0
  197. package/templates/prisma/src/mail/mail.module.ts +12 -0
  198. package/templates/prisma/src/mail/mail.processor.ts +48 -0
  199. package/templates/prisma/src/mail/mail.service.ts +24 -0
  200. package/templates/prisma/src/mail/templates/email-templates.ts +28 -0
  201. package/templates/prisma/src/main.ts +92 -0
  202. package/templates/prisma/src/metrics/metrics.controller.ts +22 -0
  203. package/templates/prisma/src/metrics/metrics.interceptor.ts +30 -0
  204. package/templates/prisma/src/metrics/metrics.module.ts +12 -0
  205. package/templates/prisma/src/metrics/metrics.service.ts +34 -0
  206. package/templates/prisma/src/types/express-session.d.ts +13 -0
  207. package/templates/prisma/src/users/dto/create-user.dto.ts +12 -0
  208. package/templates/prisma/src/users/dto/find-users-query.dto.ts +12 -0
  209. package/templates/prisma/src/users/dto/update-user.dto.ts +6 -0
  210. package/templates/prisma/src/users/entities/user.entity.ts +20 -0
  211. package/templates/prisma/src/users/users.controller.ts +165 -0
  212. package/templates/prisma/src/users/users.module.ts +10 -0
  213. package/templates/prisma/src/users/users.service.spec.ts +104 -0
  214. package/templates/prisma/src/users/users.service.ts +114 -0
  215. package/templates/prisma/test/auth.e2e-spec.ts +75 -0
  216. package/templates/prisma/test/session-auth.e2e-spec.ts +163 -0
  217. package/templates/prisma/test/users.e2e-spec.ts +106 -0
  218. package/templates/prisma/test/utils/clean-database.ts +14 -0
  219. package/templates/prisma/test/utils/e2e-setup.ts +58 -0
  220. package/templates/prisma/tsconfig.build.json +4 -0
  221. package/templates/prisma/tsconfig.json +25 -0
  222. package/templates/prisma/vitest.config.ts +20 -0
  223. package/templates/prisma/vitest.e2e.config.ts +19 -0
  224. package/templates/typeorm/.env.example +45 -0
  225. package/templates/typeorm/.env.test +38 -0
  226. package/templates/typeorm/.github/workflows/ci.yml +116 -0
  227. package/templates/typeorm/ARCHITECTURE.md +158 -0
  228. package/templates/typeorm/ARCHITECTURE.pt-BR.md +156 -0
  229. package/templates/typeorm/CODE_OF_CONDUCT.md +29 -0
  230. package/templates/typeorm/CODE_OF_CONDUCT.pt-BR.md +27 -0
  231. package/templates/typeorm/CONTRIBUTING.md +57 -0
  232. package/templates/typeorm/CONTRIBUTING.pt-BR.md +54 -0
  233. package/templates/typeorm/Dockerfile +43 -0
  234. package/templates/typeorm/LICENSE +21 -0
  235. package/templates/typeorm/README.md +266 -0
  236. package/templates/typeorm/README.pt-BR.md +266 -0
  237. package/templates/typeorm/ROADMAP.md +79 -0
  238. package/templates/typeorm/ROADMAP.pt-BR.md +67 -0
  239. package/templates/typeorm/TESTING.md +114 -0
  240. package/templates/typeorm/TESTING.pt-BR.md +114 -0
  241. package/templates/typeorm/docker-compose.yml +78 -0
  242. package/templates/typeorm/docs/adding-a-module.md +369 -0
  243. package/templates/typeorm/docs/features-markers.md +50 -0
  244. package/templates/typeorm/nest-cli.json +8 -0
  245. package/templates/typeorm/package.json +98 -0
  246. package/templates/typeorm/src/app.module.ts +72 -0
  247. package/templates/typeorm/src/auth/auth.controller.ts +283 -0
  248. package/templates/typeorm/src/auth/auth.module.ts +86 -0
  249. package/templates/typeorm/src/auth/auth.service.spec.ts +111 -0
  250. package/templates/typeorm/src/auth/auth.service.ts +346 -0
  251. package/templates/typeorm/src/auth/dto/forgot-password.dto.ts +9 -0
  252. package/templates/typeorm/src/auth/dto/login.dto.ts +10 -0
  253. package/templates/typeorm/src/auth/dto/refresh-token.dto.ts +9 -0
  254. package/templates/typeorm/src/auth/dto/register.dto.ts +11 -0
  255. package/templates/typeorm/src/auth/dto/reset-password.dto.ts +10 -0
  256. package/templates/typeorm/src/auth/entities/email-verification-token.entity.ts +69 -0
  257. package/templates/typeorm/src/auth/entities/oauth-account.entity.ts +50 -0
  258. package/templates/typeorm/src/auth/entities/password-reset-token.entity.ts +69 -0
  259. package/templates/typeorm/src/auth/entities/refresh-token.entity.ts +69 -0
  260. package/templates/typeorm/src/auth/entities/session.entity.ts +50 -0
  261. package/templates/typeorm/src/auth/guards/github-auth.guard.ts +10 -0
  262. package/templates/typeorm/src/auth/guards/google-auth.guard.ts +10 -0
  263. package/templates/typeorm/src/auth/guards/jwt-auth.guard.ts +25 -0
  264. package/templates/typeorm/src/auth/guards/session-auth.guard.spec.ts +77 -0
  265. package/templates/typeorm/src/auth/guards/session-auth.guard.ts +37 -0
  266. package/templates/typeorm/src/auth/session.service.spec.ts +74 -0
  267. package/templates/typeorm/src/auth/session.service.ts +96 -0
  268. package/templates/typeorm/src/auth/strategies/github.strategy.ts +41 -0
  269. package/templates/typeorm/src/auth/strategies/google.strategy.ts +43 -0
  270. package/templates/typeorm/src/auth/strategies/jwt.strategy.ts +25 -0
  271. package/templates/typeorm/src/auth/token.service.ts +115 -0
  272. package/templates/typeorm/src/common/constants/permissions.ts +8 -0
  273. package/templates/typeorm/src/common/constants/role-permissions.ts +9 -0
  274. package/templates/typeorm/src/common/constants/role.enum.ts +5 -0
  275. package/templates/typeorm/src/common/decorators/current-user.decorator.ts +8 -0
  276. package/templates/typeorm/src/common/decorators/permissions.decorator.ts +7 -0
  277. package/templates/typeorm/src/common/decorators/public.decorator.ts +4 -0
  278. package/templates/typeorm/src/common/decorators/roles.decorator.ts +6 -0
  279. package/templates/typeorm/src/common/filters/http-exception.filter.ts +34 -0
  280. package/templates/typeorm/src/common/guards/permissions.guard.spec.ts +54 -0
  281. package/templates/typeorm/src/common/guards/permissions.guard.ts +28 -0
  282. package/templates/typeorm/src/common/guards/roles.guard.spec.ts +37 -0
  283. package/templates/typeorm/src/common/guards/roles.guard.ts +24 -0
  284. package/templates/typeorm/src/common/interceptors/logging.interceptor.ts +23 -0
  285. package/templates/typeorm/src/common/middleware/csrf.middleware.spec.ts +97 -0
  286. package/templates/typeorm/src/common/middleware/csrf.middleware.ts +46 -0
  287. package/templates/typeorm/src/common/utils/avatar-storage.util.ts +32 -0
  288. package/templates/typeorm/src/common/utils/hash.util.ts +5 -0
  289. package/templates/typeorm/src/config/env.validation.ts +50 -0
  290. package/templates/typeorm/src/database/data-source.ts +20 -0
  291. package/templates/typeorm/src/database/database.module.ts +39 -0
  292. package/templates/typeorm/src/database/seed.ts +81 -0
  293. package/templates/typeorm/src/database/typeorm-options.ts +49 -0
  294. package/templates/typeorm/src/health/health.controller.ts +49 -0
  295. package/templates/typeorm/src/health/health.module.ts +19 -0
  296. package/templates/typeorm/src/health/indicators/redis-health.indicator.spec.ts +54 -0
  297. package/templates/typeorm/src/health/indicators/redis-health.indicator.ts +33 -0
  298. package/templates/typeorm/src/health/indicators/typeorm-health.indicator.spec.ts +49 -0
  299. package/templates/typeorm/src/health/indicators/typeorm-health.indicator.ts +37 -0
  300. package/templates/typeorm/src/mail/mail.module.ts +12 -0
  301. package/templates/typeorm/src/mail/mail.processor.ts +48 -0
  302. package/templates/typeorm/src/mail/mail.service.ts +24 -0
  303. package/templates/typeorm/src/mail/templates/email-templates.ts +28 -0
  304. package/templates/typeorm/src/main.ts +107 -0
  305. package/templates/typeorm/src/metrics/metrics.controller.ts +22 -0
  306. package/templates/typeorm/src/metrics/metrics.interceptor.ts +30 -0
  307. package/templates/typeorm/src/metrics/metrics.module.ts +12 -0
  308. package/templates/typeorm/src/metrics/metrics.service.ts +34 -0
  309. package/templates/typeorm/src/types/express-session.d.ts +13 -0
  310. package/templates/typeorm/src/users/dto/create-user.dto.ts +12 -0
  311. package/templates/typeorm/src/users/dto/find-users-query.dto.ts +12 -0
  312. package/templates/typeorm/src/users/dto/update-user.dto.ts +6 -0
  313. package/templates/typeorm/src/users/entities/user.entity.ts +113 -0
  314. package/templates/typeorm/src/users/users.controller.ts +165 -0
  315. package/templates/typeorm/src/users/users.module.ts +13 -0
  316. package/templates/typeorm/src/users/users.service.spec.ts +183 -0
  317. package/templates/typeorm/src/users/users.service.ts +124 -0
  318. package/templates/typeorm/test/auth.e2e-spec.ts +111 -0
  319. package/templates/typeorm/test/session-auth.e2e-spec.ts +159 -0
  320. package/templates/typeorm/test/users.e2e-spec.ts +183 -0
  321. package/templates/typeorm/test/utils/clean-database.ts +65 -0
  322. package/templates/typeorm/test/utils/e2e-setup.ts +77 -0
  323. package/templates/typeorm/tsconfig.build.json +4 -0
  324. package/templates/typeorm/tsconfig.json +25 -0
  325. package/templates/typeorm/vitest.config.ts +20 -0
  326. package/templates/typeorm/vitest.e2e.config.ts +19 -0
@@ -0,0 +1,266 @@
1
+ # NestForge
2
+
3
+ [English](README.md) | **Português**
4
+
5
+ > Production-ready NestJS starter with TypeORM, Authentication, Docker, Testing, CI/CD and Clean Architecture.
6
+
7
+ [![CI](https://github.com/jeiel2013/nestforge/actions/workflows/ci.yml/badge.svg)](https://github.com/jeiel2013/nestforge/actions/workflows/ci.yml)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
9
+ [![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](https://nodejs.org)
10
+ [![NestJS](https://img.shields.io/badge/NestJS-11-red)](https://nestjs.com)
11
+
12
+ NestForge é um boilerplate de NestJS pensado para acelerar o início de projetos backend sérios, com autenticação completa, arquitetura limpa, segurança e observabilidade já configuradas. A ideia é você clonar, rodar `docker compose up` e já ter uma API pronta para evoluir.
13
+
14
+ ## ✨ Features
15
+
16
+ - 🔐 **Autenticação configurável** — JWT com access/refresh token, Session/Cookies persistida no TypeORM, OAuth-only ou nenhuma autenticação
17
+ - 🌐 **OAuth** — Google e GitHub, integrado à estratégia de token ou sessão escolhida
18
+ - 👥 **RBAC** — Roles (Admin, Manager, User) e Permissions granulares
19
+ - 🛡️ **Segurança** — Helmet, CORS, Rate Limiting, validação e serialização com Zod
20
+ - 🗄️ **Banco de dados** — TypeORM com PostgreSQL, MySQL ou SQLite
21
+ - 📨 **E-mails** — filas com BullMQ + Redis, testado localmente com Mailpit
22
+ - 📄 **Documentação automática** — Swagger
23
+ - 🪵 **Logs estruturados** — Pino
24
+ - ✅ **Testes** — unitários e de integração com Vitest
25
+ - 🐳 **Docker** — ambiente completo com um comando
26
+ - ⚙️ **CI/CD** — GitHub Actions (build, lint, test)
27
+
28
+ ## 🧱 Stack
29
+
30
+ | Camada | Tecnologia |
31
+ |---|---|
32
+ | Framework | NestJS + TypeScript |
33
+ | ORM | TypeORM |
34
+ | Banco | PostgreSQL, MySQL ou SQLite |
35
+ | Cache / Filas | Redis + BullMQ |
36
+ | Autenticação | JWT, Session/Cookies ou OAuth com Passport |
37
+ | Validação | Zod + nestjs-zod (schemas viram DTO + Swagger automaticamente) |
38
+ | Docs | Swagger |
39
+ | E-mail (dev) | Mailpit |
40
+ | Testes | Vitest |
41
+ | CI | GitHub Actions |
42
+
43
+ ## 📁 Estrutura de pastas
44
+
45
+ ```
46
+ src/
47
+
48
+ ├── auth/ # login, sessões/tokens, OAuth, guards e strategies
49
+ ├── users/ # CRUD de usuários
50
+ ├── common/ # decorators, filters, guards, interceptors, pipes, utils
51
+ ├── config/ # configuração tipada e validada (env)
52
+ ├── database/ # DataSource, configuração, migrations e seed
53
+ ├── modules/ # módulos de domínio adicionais
54
+ ├── shared/ # código compartilhado entre módulos
55
+ ├── jobs/ # filas e workers (BullMQ)
56
+ ├── mail/ # templates e envio de e-mail
57
+ └── main.ts
58
+ ```
59
+
60
+ ## 🚀 Começando
61
+
62
+ ### Pré-requisitos
63
+
64
+ - Node.js 20+
65
+ - Docker e Docker Compose
66
+
67
+ ### Rodando com Docker (recomendado)
68
+
69
+ ```bash
70
+ git clone https://github.com/jeiel2013/nestforge.git
71
+ cd nestforge
72
+ cp .env.example .env
73
+ docker compose up
74
+ ```
75
+
76
+ Isso sobe: API, PostgreSQL, Redis e Mailpit (interface de e-mail em `http://localhost:8025`).
77
+
78
+ ### Rodando localmente
79
+
80
+ ```bash
81
+ npm install
82
+ cp .env.example .env
83
+ npm run migration:generate -- src/database/migrations/InitialSchema
84
+ npm run migration:run
85
+ npm run seed
86
+ npm run start:dev
87
+ ```
88
+
89
+ A documentação Swagger fica disponível em `http://localhost:3000/docs`.
90
+
91
+ ## 🔑 Roles & Permissions
92
+
93
+ | Role | Descrição |
94
+ |---|---|
95
+ | `ADMIN` | acesso total ao sistema |
96
+ | `MANAGER` | gerencia usuários e relatórios |
97
+ | `USER` | acesso padrão |
98
+
99
+ Permissions são granulares (`user:create`, `user:delete`, `report:read`, etc) e combinadas com roles via decorators (`@Roles()`, `@Permissions()`).
100
+
101
+ ## 🗺️ Roadmap
102
+
103
+ - [x] Autenticação por JWT
104
+ - [x] Autenticação por Session/Cookies
105
+ - [x] OAuth Google/GitHub
106
+ - [x] Estratégia OAuth-only
107
+ - [x] Geração sem autenticação
108
+ - [x] Refresh Token
109
+ - [x] Docker
110
+ - [x] CI (build, lint, test)
111
+ - [x] OAuth (Google/GitHub)
112
+ - [x] Upload de arquivos
113
+ - [x] Filas (BullMQ)
114
+ - [x] E-mails transacionais
115
+ - [x] RBAC completo (permissions granulares)
116
+ - [x] Testes de integração completos
117
+ - [x] Documentação completa (Swagger + guia de arquitetura)
118
+
119
+ Veja o [ROADMAP.pt-BR.md](ROADMAP.pt-BR.md) detalhado.
120
+
121
+ ### Configurando o login social (OAuth)
122
+
123
+ Para habilitar login via Google e GitHub, crie um OAuth App em cada provedor e preencha no `.env`:
124
+
125
+ ```bash
126
+ APP_URL=http://localhost:3000
127
+
128
+ GOOGLE_CLIENT_ID=
129
+ GOOGLE_CLIENT_SECRET=
130
+
131
+ GITHUB_CLIENT_ID=
132
+ GITHUB_CLIENT_SECRET=
133
+ ```
134
+
135
+ - **Google**: crie as credenciais no [Google Cloud Console](https://console.cloud.google.com/apis/credentials) e configure a URL de callback como `{APP_URL}/auth/google/callback`.
136
+ - **GitHub**: crie um OAuth App em `Settings > Developer settings > OAuth Apps` e configure a mesma URL de callback, trocando para `{APP_URL}/auth/github/callback`.
137
+
138
+ Depois é só acessar `GET /auth/google` ou `GET /auth/github`. No callback, a API emite access/refresh tokens ou estabelece uma sessão por cookie, conforme a estratégia escolhida. Se for o primeiro acesso, uma conta é criada e vinculada ao provedor.
139
+
140
+ ### Autenticação por Session/Cookies
141
+
142
+ Quando o projeto é gerado com Session/Cookies, cadastro e login criam uma sessão persistida no banco por `connect-typeorm`. O identificador é enviado no cookie `nestforge.sid`, configurado com `httpOnly`, `sameSite=lax` e `secure` em produção.
143
+
144
+ Configure no `.env`:
145
+
146
+ ```bash
147
+ SESSION_SECRET=use-um-segredo-com-pelo-menos-32-caracteres
148
+ SESSION_MAX_AGE=604800000
149
+ ```
150
+
151
+ ### Recuperação de senha e verificação de e-mail
152
+
153
+ Todo cadastro (`POST /auth/register`) já dispara um e-mail de verificação automaticamente. Os e-mails são enfileirados com BullMQ/Redis e processados por um worker que envia via SMTP — em desenvolvimento, tudo cai no Mailpit (`http://localhost:8025`), então nada sai pra internet de verdade.
154
+
155
+ | Rota | O que faz |
156
+ |---|---|
157
+ | `POST /auth/forgot-password` | Recebe um `email` e enfileira o envio do link de redefinição (resposta sempre genérica, não revela se o e-mail existe) |
158
+ | `POST /auth/reset-password` | Recebe `token` + `password` e troca a senha; também revoga os refresh tokens ativos do usuário |
159
+ | `GET /auth/verify-email?token=...` | Confirma o e-mail a partir do link recebido |
160
+
161
+ Os tokens de reset e verificação expiram em 1 hora e 24 horas, respectivamente, e são de uso único.
162
+
163
+ ## 🔑 Roles & Permissions
164
+
165
+ | Role | Descrição |
166
+ |---|---|
167
+ | `ADMIN` | acesso total ao sistema |
168
+ | `MANAGER` | gerencia usuários e relatórios |
169
+ | `USER` | acesso padrão |
170
+
171
+ Cada role tem um conjunto fixo de permissões, mapeado em `src/common/constants/role-permissions.ts`:
172
+
173
+ | Permission | ADMIN | MANAGER | USER |
174
+ |---|:---:|:---:|:---:|
175
+ | `user:create` | ✅ | ❌ | ❌ |
176
+ | `user:read` | ✅ | ✅ | ✅ |
177
+ | `user:update` | ✅ | ✅ | ❌ |
178
+ | `user:delete` | ✅ | ❌ | ❌ |
179
+ | `report:read` | ✅ | ✅ | ❌ |
180
+
181
+ Nas rotas, use `@Permissions(Permission.UserCreate)` para exigir uma permissão específica, ou `@Roles(Role.ADMIN)` quando o controle por cargo já for suficiente. Os dois guards (`RolesGuard` e `PermissionsGuard`) rodam globalmente e só bloqueiam a rota se ela tiver o decorator correspondente.
182
+
183
+ ## 👥 Usuários: paginação, filtros e avatar
184
+
185
+ `GET /users` aceita query params pra paginar e filtrar a listagem:
186
+
187
+ ```bash
188
+ GET /users?page=2&limit=20&search=jeiel&role=ADMIN
189
+ ```
190
+
191
+ | Parâmetro | Descrição |
192
+ |---|---|
193
+ | `page` | página atual (padrão: 1) |
194
+ | `limit` | itens por página, até 100 (padrão: 10) |
195
+ | `search` | busca por nome ou e-mail (case-insensitive) |
196
+ | `role` | filtra por `ADMIN`, `MANAGER` ou `USER` |
197
+
198
+ A resposta vem no formato `{ data, meta: { total, page, limit, totalPages } }`.
199
+
200
+ Pra trocar o avatar do usuário autenticado:
201
+
202
+ ```bash
203
+ curl -X POST http://localhost:3000/users/me/avatar \
204
+ -H "Authorization: Bearer <accessToken>" \
205
+ -F "file=@/caminho/da/foto.png"
206
+ ```
207
+
208
+ Aceita PNG, JPEG e WEBP até 2MB; o arquivo fica salvo em `./uploads/avatars` e é servido em `/uploads/avatars/<arquivo>`.
209
+
210
+ ## 🛡️ Segurança: serialização e CSRF
211
+
212
+ Toda validação de entrada (`body`, `query`) usa **Zod** via [`nestjs-zod`](https://github.com/BenLorantfy/nestjs-zod): cada DTO é um `z.object({...})` transformado em classe com `createZodDto(schema)`, validado globalmente pelo `ZodValidationPipe`. O `patchNestJsSwagger()` no bootstrap ensina o Swagger a ler esses schemas automaticamente — não precisa duplicar validação (Zod) e documentação (`@ApiProperty`) como no `class-validator`. Os schemas exportados (ex.: `createUserSchema`) também podem ser reaproveitados/combinados (como o `updateUserSchema`, que é só um `createUserSchema.partial()`).
213
+
214
+ - 🪵 **Observabilidade** — logs estruturados com Pino, health checks (`/health`) e métricas Prometheus (`/metrics`)
215
+
216
+ O seed cria três contas de teste, uma por role:
217
+
218
+ | E-mail | Senha | Role |
219
+ |---|---|---|
220
+ | `admin@nestforge.dev` | `admin123` | ADMIN |
221
+ | `manager@nestforge.dev` | `manager123` | MANAGER |
222
+ | `user@nestforge.dev` | `user1234` | USER |
223
+
224
+ ## 📈 Observabilidade
225
+
226
+ `GET /health` retorna o status agregado da API — banco (TypeORM), Redis, memória (heap/RSS) e espaço em disco — usando `@nestjs/terminus`. Cada verificação aparece individualmente na resposta, então dá pra saber exatamente o que caiu.
227
+
228
+ `GET /metrics` expõe métricas no formato do Prometheus (via `prom-client`): as métricas padrão de Node.js (CPU, memória, event loop) mais `http_request_duration_seconds` (histograma) e `http_requests_total` (contador), ambas com labels de `method`, `route` e `status_code`. Basta apontar um scrape job do Prometheus pra essa rota.
229
+
230
+ ## 🧪 Testes
231
+
232
+ ```bash
233
+ npm run test # unitários
234
+ npm run test:e2e # integração (e2e)
235
+ npm run test:cov # cobertura
236
+ ```
237
+
238
+ Os testes e2e (`test/*.e2e-spec.ts`) sobem a aplicação real (Nest + TypeORM + Redis) e batem nos endpoints com `supertest`, usando um banco isolado (`.env.test`, banco `nestforge_test` — nunca o de desenvolvimento). Antes de rodar pela primeira vez:
239
+
240
+ ```bash
241
+ createdb nestforge_test # ou: psql -U nestforge -c "CREATE DATABASE nestforge_test;"
242
+ docker compose up -d postgres redis
243
+ npm run test:e2e
244
+ ```
245
+
246
+ O script `pretest:e2e` já aplica as migrations nesse banco automaticamente antes de cada rodada. Cada teste limpa as tabelas antes de rodar (`test/utils/clean-database.ts`), então não precisa zerar nada manualmente entre execuções. Hoje cobrem o fluxo de autenticação completo (registro, login, refresh, logout, e-mail duplicado, credenciais inválidas) e o CRUD de usuários com RBAC (ADMIN consegue tudo, USER lê mas não cria, `/users/me`, acesso sem token).
247
+
248
+ Os testes unitários (`src/**/*.spec.ts`) rodam isolados, com os repositories do TypeORM e o `ioredis` mockados (`vi.fn()` / `vi.mock()`) — não precisam de banco nem Redis de verdade. Hoje cobrem: `AuthService` (registro/login), `UsersService` (CRUD completo + paginação + confirmação de que o `passwordHash` não vaza na serialização via `instanceToPlain`), `RolesGuard`, `PermissionsGuard` e os indicadores de saúde (`TypeOrmHealthIndicator`, `RedisHealthIndicator`).
249
+
250
+ ## 📚 Documentação adicional
251
+
252
+ - [ARCHITECTURE.pt-BR.md](ARCHITECTURE.pt-BR.md) — como o projeto é organizado e por que certas decisões de design foram tomadas (Zod vs. class-validator, permissions em código vs. banco, BullMQ, etc.)
253
+ - [TESTING.pt-BR.md](TESTING.pt-BR.md) — como validar migrations, build, testes unitários e testes E2E
254
+ - [docs/adding-a-module.md](docs/adding-a-module.md) — passo a passo pra adicionar um recurso novo seguindo as convenções do projeto
255
+
256
+ ## 🤝 Contribuindo
257
+
258
+ Contribuições são bem-vindas! Veja o [CONTRIBUTING.pt-BR.md](CONTRIBUTING.pt-BR.md) para o guia completo.
259
+
260
+ ## 📄 Licença
261
+
262
+ Este projeto está sob a licença MIT — veja [LICENSE](LICENSE).
263
+
264
+ ---
265
+
266
+ Feito por [Jeiel Alves](https://github.com/jeiel2013) · [jeieldev.com.br](https://jeieldev.com.br)
@@ -0,0 +1,79 @@
1
+ # Roadmap
2
+
3
+ **English** | [Português](ROADMAP.pt-BR.md)
4
+
5
+ This roadmap makes it clear what is ready and where contributions are possible. PRs for any open item are very welcome — open an issue first for large changes so the approach can be aligned.
6
+
7
+ ## Authentication
8
+
9
+ - [x] Login
10
+ - [x] Registration
11
+ - [x] Logout
12
+ - [x] Refresh Token
13
+ - [x] Forgot Password
14
+ - [x] Reset Password
15
+ - [x] Email Verification
16
+ - [x] Google OAuth
17
+ - [x] GitHub OAuth
18
+
19
+ ## Users
20
+
21
+ - [x] Basic CRUD
22
+ - [x] Pagination and advanced filters
23
+ - [x] Avatar upload
24
+
25
+ ## RBAC
26
+
27
+ - [x] Roles (Admin, Manager, User)
28
+ - [x] Granular permissions (`user:create`, `report:read`, etc.)
29
+ - [x] Guard combining roles + permissions
30
+
31
+ ## Security
32
+
33
+ - [x] Helmet
34
+ - [x] CORS
35
+ - [x] Rate Limit
36
+ - [x] Validation (Zod + nestjs-zod, integrated with Swagger through `createZodDto`)
37
+ - [x] Serialization (output interceptor)
38
+ - [x] CSRF (when required)
39
+
40
+ ## Database
41
+
42
+ - [x] TypeORM
43
+ - [x] PostgreSQL
44
+ - [x] MySQL
45
+ - [x] SQLite
46
+ - [x] Migrations
47
+ - [x] Seed with users for the default roles
48
+
49
+ ## Infrastructure
50
+
51
+ - [x] Docker / docker-compose (API, Postgres, Redis, Mailpit)
52
+ - [x] GitHub Actions CI (build, lint, test)
53
+ - [ ] Automated deployment (Railway/Fly.io example)
54
+
55
+ ## Observability
56
+
57
+ - [x] Structured logging with Pino
58
+ - [x] Health checks (`/health`)
59
+ - [x] Metrics (optional Prometheus)
60
+
61
+ ## Jobs & Email
62
+
63
+ - [x] BullMQ queue
64
+ - [x] Transactional email delivery (Mailpit in development)
65
+ - [x] Email templates
66
+
67
+ ## Tests
68
+
69
+ - [x] Unit test structure (Vitest)
70
+ - [x] Integration tests (auth + users)
71
+
72
+ ## Documentation
73
+
74
+ - [x] Initial README
75
+ - [x] Complete Swagger with request/response examples
76
+ - [x] Architecture guide (ADR / design decisions)
77
+ - [x] “How to add a new module” guide
78
+
79
+ ---
@@ -0,0 +1,67 @@
1
+ # Roadmap
2
+
3
+ [English](ROADMAP.md) | **Português**
4
+
5
+ Este roadmap existe para deixar claro o que já está pronto e onde dá pra contribuir. PRs para qualquer item em aberto são muito bem-vindos — abra uma issue antes se for algo grande, pra alinharmos a abordagem.
6
+
7
+ ## Autenticação
8
+ - [x] Login
9
+ - [x] Cadastro
10
+ - [x] Logout
11
+ - [x] Refresh Token
12
+ - [x] Forgot Password
13
+ - [x] Reset Password
14
+ - [x] Email Verification
15
+ - [x] OAuth Google
16
+ - [x] OAuth GitHub
17
+
18
+ ## Usuários
19
+ - [x] CRUD básico
20
+ - [x] Paginação e filtros avançados
21
+ - [x] Upload de avatar
22
+
23
+ ## RBAC
24
+ - [x] Roles (Admin, Manager, User)
25
+ - [x] Permissions granulares (`user:create`, `report:read`, etc)
26
+ - [x] Guard combinando roles + permissions
27
+
28
+ ## Segurança
29
+ - [x] Helmet
30
+ - [x] CORS
31
+ - [x] Rate Limit
32
+ - [x] Validação (Zod + nestjs-zod, integrado ao Swagger via `createZodDto`)
33
+ - [x] Serialização (interceptor de output)
34
+ - [x] CSRF (quando necessário)
35
+
36
+ ## Banco de dados
37
+ - [x] TypeORM
38
+ - [x] PostgreSQL
39
+ - [x] MySQL
40
+ - [x] SQLite
41
+ - [x] Migrations
42
+ - [x] Seed com usuários para as roles padrão
43
+
44
+ ## Infra
45
+ - [x] Docker / docker-compose (API, Postgres, Redis, Mailpit)
46
+ - [x] GitHub Actions CI (build, lint, test)
47
+ - [ ] Deploy automatizado (exemplo com Railway/Fly.io)
48
+
49
+ ## Observabilidade
50
+ - [x] Logs estruturados com Pino
51
+ - [x] Health checks (`/health`)
52
+ - [x] Métricas (Prometheus opcional)
53
+
54
+ ## Jobs & E-mail
55
+ - [x] Fila com BullMQ
56
+ - [x] Envio de e-mail transacional (Mailpit em dev)
57
+ - [x] Templates de e-mail
58
+
59
+ ## Testes
60
+ - [x] Estrutura de testes unitários (Vitest)
61
+ - [x] Testes de integração (auth + users)
62
+
63
+ ## Documentação
64
+ - [x] README inicial
65
+ - [x] Swagger completo com exemplos de request/response
66
+ - [x] Guia de arquitetura (ADR / decisões de design)
67
+ - [x] Guia "como adicionar um novo módulo"
@@ -0,0 +1,114 @@
1
+ # Testing the TypeORM template
2
+
3
+ **English** | [Português](TESTING.pt-BR.md)
4
+
5
+ This guide validates a project generated from the NestForge TypeORM template.
6
+
7
+ ## Prerequisites
8
+
9
+ * Node.js 20 or later
10
+ * npm 10 or later
11
+ * Docker when testing PostgreSQL, MySQL, Redis, or Mailpit
12
+
13
+ SQLite can be tested without Docker. Make sure the installed `better-sqlite3` version supports your Node version.
14
+
15
+ ## Prepare the environment
16
+
17
+ ```bash
18
+ npm install
19
+ cp .env.example .env
20
+ cp .env.example .env.test
21
+ ```
22
+
23
+ Use different databases in `.env` and `.env.test`.
24
+
25
+ ## Generate and apply a migration
26
+
27
+ ```bash
28
+ npm run migration:generate -- src/database/migrations/InitialSchema
29
+ npm run migration:run
30
+ ```
31
+
32
+ Run the seed when the generated project includes password authentication:
33
+
34
+ ```bash
35
+ npm run seed
36
+ ```
37
+
38
+ ## Static validation
39
+
40
+ ```bash
41
+ npm run build
42
+ npm run lint
43
+ ```
44
+
45
+ ## Unit tests
46
+
47
+ ```bash
48
+ npm test
49
+ ```
50
+
51
+ For coverage:
52
+
53
+ ```bash
54
+ npm run test:cov
55
+ ```
56
+
57
+ Unit tests mock TypeORM repositories and Redis, so they do not require real services.
58
+
59
+ ## E2E tests
60
+
61
+ ```bash
62
+ npm run test:e2e
63
+ ```
64
+
65
+ The `pretest:e2e` script applies migrations using `.env.test` before the suite starts.
66
+
67
+ Depending on the generated authentication strategy, the suite may cover JWT, Session/Cookies, CSRF, user CRUD, RBAC, and permissions.
68
+
69
+ ## Database-specific checks
70
+
71
+ ### PostgreSQL
72
+
73
+ ```bash
74
+ docker compose up -d postgres
75
+ npm run migration:run
76
+ ```
77
+
78
+ ### MySQL
79
+
80
+ ```bash
81
+ docker compose up -d mysql
82
+ npm run migration:run
83
+ ```
84
+
85
+ ### SQLite
86
+
87
+ Set the database configuration to SQLite and run:
88
+
89
+ ```bash
90
+ npm run migration:generate -- src/database/migrations/InitialSchema
91
+ npm run migration:run
92
+ npm run build
93
+ npm test
94
+ npm run test:e2e
95
+ ```
96
+
97
+ Check the native driver when necessary:
98
+
99
+ ```bash
100
+ npm ls better-sqlite3
101
+ ```
102
+
103
+ ## Final checklist
104
+
105
+ * [ ] Dependencies install successfully
106
+ * [ ] The correct database driver is installed
107
+ * [ ] Migration is generated and reviewed
108
+ * [ ] Migrations are applied
109
+ * [ ] Seed runs when applicable
110
+ * [ ] Build passes
111
+ * [ ] Lint passes
112
+ * [ ] Unit tests pass
113
+ * [ ] E2E tests pass
114
+ * [ ] `.env.test` uses an isolated database
@@ -0,0 +1,114 @@
1
+ # Testando o template TypeORM
2
+
3
+ [English](TESTING.md) | **Português**
4
+
5
+ Este guia valida um projeto gerado a partir do template TypeORM do NestForge.
6
+
7
+ ## Pré-requisitos
8
+
9
+ * Node.js 20 ou superior
10
+ * npm 10 ou superior
11
+ * Docker para testar PostgreSQL, MySQL, Redis ou Mailpit
12
+
13
+ SQLite pode ser testado sem Docker. Confirme que a versão instalada do `better-sqlite3` oferece suporte à sua versão do Node.
14
+
15
+ ## Preparar o ambiente
16
+
17
+ ```bash
18
+ npm install
19
+ cp .env.example .env
20
+ cp .env.example .env.test
21
+ ```
22
+
23
+ Use bancos diferentes em `.env` e `.env.test`.
24
+
25
+ ## Gerar e aplicar uma migration
26
+
27
+ ```bash
28
+ npm run migration:generate -- src/database/migrations/InitialSchema
29
+ npm run migration:run
30
+ ```
31
+
32
+ Execute o seed quando o projeto gerado incluir autenticação por senha:
33
+
34
+ ```bash
35
+ npm run seed
36
+ ```
37
+
38
+ ## Validação estática
39
+
40
+ ```bash
41
+ npm run build
42
+ npm run lint
43
+ ```
44
+
45
+ ## Testes unitários
46
+
47
+ ```bash
48
+ npm test
49
+ ```
50
+
51
+ Para cobertura:
52
+
53
+ ```bash
54
+ npm run test:cov
55
+ ```
56
+
57
+ Os testes unitários simulam os repositories do TypeORM e o Redis, portanto não exigem serviços reais.
58
+
59
+ ## Testes E2E
60
+
61
+ ```bash
62
+ npm run test:e2e
63
+ ```
64
+
65
+ O script `pretest:e2e` aplica as migrations usando `.env.test` antes do início da suíte.
66
+
67
+ Dependendo da estratégia de autenticação gerada, a suíte pode cobrir JWT, Session/Cookies, CSRF, CRUD de usuários, RBAC e permissions.
68
+
69
+ ## Verificações específicas por banco
70
+
71
+ ### PostgreSQL
72
+
73
+ ```bash
74
+ docker compose up -d postgres
75
+ npm run migration:run
76
+ ```
77
+
78
+ ### MySQL
79
+
80
+ ```bash
81
+ docker compose up -d mysql
82
+ npm run migration:run
83
+ ```
84
+
85
+ ### SQLite
86
+
87
+ Defina a configuração do banco como SQLite e execute:
88
+
89
+ ```bash
90
+ npm run migration:generate -- src/database/migrations/InitialSchema
91
+ npm run migration:run
92
+ npm run build
93
+ npm test
94
+ npm run test:e2e
95
+ ```
96
+
97
+ Confira o driver nativo quando necessário:
98
+
99
+ ```bash
100
+ npm ls better-sqlite3
101
+ ```
102
+
103
+ ## Checklist final
104
+
105
+ * [ ] As dependências são instaladas corretamente
106
+ * [ ] O driver correto do banco está instalado
107
+ * [ ] A migration é gerada e revisada
108
+ * [ ] As migrations são aplicadas
109
+ * [ ] O seed executa quando aplicável
110
+ * [ ] O build passa
111
+ * [ ] O lint passa
112
+ * [ ] Os testes unitários passam
113
+ * [ ] Os testes E2E passam
114
+ * [ ] `.env.test` usa um banco isolado