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.
- package/LICENSE +21 -0
- package/README.md +371 -0
- package/README.pt-BR.md +370 -0
- package/dist/features/auth-strategy.js +19 -0
- package/dist/features/auth-strategy.js.map +1 -0
- package/dist/features/database.js +59 -0
- package/dist/features/database.js.map +1 -0
- package/dist/features/dependencies.js +57 -0
- package/dist/features/dependencies.js.map +1 -0
- package/dist/features/language.js +172 -0
- package/dist/features/language.js.map +1 -0
- package/dist/features/markers.js +116 -0
- package/dist/features/markers.js.map +1 -0
- package/dist/generator.js +120 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.js +137 -0
- package/dist/prompts.js.map +1 -0
- package/package.json +76 -0
- package/templates/drizzle/.env.example +45 -0
- package/templates/drizzle/.env.test +38 -0
- package/templates/drizzle/.github/workflows/ci.yml +119 -0
- package/templates/drizzle/ARCHITECTURE.md +227 -0
- package/templates/drizzle/ARCHITECTURE.pt-BR.md +225 -0
- package/templates/drizzle/CODE_OF_CONDUCT.md +29 -0
- package/templates/drizzle/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/drizzle/CONTRIBUTING.md +57 -0
- package/templates/drizzle/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/drizzle/Dockerfile +43 -0
- package/templates/drizzle/LICENSE +21 -0
- package/templates/drizzle/README.md +257 -0
- package/templates/drizzle/README.pt-BR.md +257 -0
- package/templates/drizzle/ROADMAP.md +143 -0
- package/templates/drizzle/ROADMAP.pt-BR.md +143 -0
- package/templates/drizzle/TESTING.md +136 -0
- package/templates/drizzle/TESTING.pt-BR.md +136 -0
- package/templates/drizzle/docker-compose.yml +82 -0
- package/templates/drizzle/docs/adding-a-module.md +585 -0
- package/templates/drizzle/docs/features-markers.md +457 -0
- package/templates/drizzle/drizzle.config.ts +49 -0
- package/templates/drizzle/nest-cli.json +8 -0
- package/templates/drizzle/package.json +96 -0
- package/templates/drizzle/src/app.module.ts +72 -0
- package/templates/drizzle/src/auth/auth.controller.ts +283 -0
- package/templates/drizzle/src/auth/auth.module.ts +81 -0
- package/templates/drizzle/src/auth/auth.service.spec.ts +111 -0
- package/templates/drizzle/src/auth/auth.service.ts +631 -0
- package/templates/drizzle/src/auth/drizzle-session.store.ts +263 -0
- package/templates/drizzle/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/drizzle/src/auth/dto/login.dto.ts +10 -0
- package/templates/drizzle/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/drizzle/src/auth/dto/register.dto.ts +11 -0
- package/templates/drizzle/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/drizzle/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/drizzle/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/drizzle/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/drizzle/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/drizzle/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/drizzle/src/auth/session.service.spec.ts +74 -0
- package/templates/drizzle/src/auth/session.service.ts +96 -0
- package/templates/drizzle/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/drizzle/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/drizzle/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/drizzle/src/auth/token.service.ts +175 -0
- package/templates/drizzle/src/common/constants/permissions.ts +8 -0
- package/templates/drizzle/src/common/constants/role-permissions.ts +9 -0
- package/templates/drizzle/src/common/constants/role.enum.ts +5 -0
- package/templates/drizzle/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/drizzle/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/drizzle/src/common/decorators/public.decorator.ts +4 -0
- package/templates/drizzle/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/drizzle/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/drizzle/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/drizzle/src/common/guards/permissions.guard.ts +28 -0
- package/templates/drizzle/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/drizzle/src/common/guards/roles.guard.ts +24 -0
- package/templates/drizzle/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/drizzle/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/drizzle/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/drizzle/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/drizzle/src/common/utils/hash.util.ts +5 -0
- package/templates/drizzle/src/config/env.validation.ts +50 -0
- package/templates/drizzle/src/database/database-lifecycle.service.ts +30 -0
- package/templates/drizzle/src/database/database.constants.ts +2 -0
- package/templates/drizzle/src/database/database.decorators.ts +5 -0
- package/templates/drizzle/src/database/database.module.ts +96 -0
- package/templates/drizzle/src/database/database.types.ts +28 -0
- package/templates/drizzle/src/database/schema/index.ts +11 -0
- package/templates/drizzle/src/database/schema/mysql.schema.ts +215 -0
- package/templates/drizzle/src/database/schema/postgres.schema.ts +218 -0
- package/templates/drizzle/src/database/schema/sqlite.schema.ts +190 -0
- package/templates/drizzle/src/database/seed.ts +152 -0
- package/templates/drizzle/src/health/health.controller.ts +49 -0
- package/templates/drizzle/src/health/health.module.ts +19 -0
- package/templates/drizzle/src/health/indicators/drizzle-health.indicator.spec.ts +71 -0
- package/templates/drizzle/src/health/indicators/drizzle-health.indicator.ts +52 -0
- package/templates/drizzle/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/drizzle/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/drizzle/src/mail/mail.module.ts +12 -0
- package/templates/drizzle/src/mail/mail.processor.ts +48 -0
- package/templates/drizzle/src/mail/mail.service.ts +24 -0
- package/templates/drizzle/src/mail/templates/email-templates.ts +28 -0
- package/templates/drizzle/src/main.ts +145 -0
- package/templates/drizzle/src/metrics/metrics.controller.ts +22 -0
- package/templates/drizzle/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/drizzle/src/metrics/metrics.module.ts +12 -0
- package/templates/drizzle/src/metrics/metrics.service.ts +34 -0
- package/templates/drizzle/src/types/express-session.d.ts +13 -0
- package/templates/drizzle/src/users/dto/create-user.dto.ts +12 -0
- package/templates/drizzle/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/drizzle/src/users/dto/update-user.dto.ts +6 -0
- package/templates/drizzle/src/users/entities/user.entity.ts +23 -0
- package/templates/drizzle/src/users/users.controller.ts +165 -0
- package/templates/drizzle/src/users/users.module.ts +10 -0
- package/templates/drizzle/src/users/users.service.spec.ts +301 -0
- package/templates/drizzle/src/users/users.service.ts +213 -0
- package/templates/drizzle/test/auth.e2e-spec.ts +114 -0
- package/templates/drizzle/test/session-auth.e2e-spec.ts +163 -0
- package/templates/drizzle/test/users.e2e-spec.ts +212 -0
- package/templates/drizzle/test/utils/clean-database.ts +104 -0
- package/templates/drizzle/test/utils/e2e-setup.ts +77 -0
- package/templates/drizzle/tsconfig.build.json +4 -0
- package/templates/drizzle/tsconfig.json +25 -0
- package/templates/drizzle/vitest.config.ts +20 -0
- package/templates/drizzle/vitest.e2e.config.ts +19 -0
- package/templates/prisma/.env.example +44 -0
- package/templates/prisma/.env.test +37 -0
- package/templates/prisma/.github/workflows/ci.yml +109 -0
- package/templates/prisma/ARCHITECTURE.md +70 -0
- package/templates/prisma/ARCHITECTURE.pt-BR.md +63 -0
- package/templates/prisma/CODE_OF_CONDUCT.md +29 -0
- package/templates/prisma/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/prisma/CONTRIBUTING.md +57 -0
- package/templates/prisma/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/prisma/Dockerfile +33 -0
- package/templates/prisma/LICENSE +21 -0
- package/templates/prisma/README.md +267 -0
- package/templates/prisma/README.pt-BR.md +267 -0
- package/templates/prisma/ROADMAP.md +75 -0
- package/templates/prisma/ROADMAP.pt-BR.md +65 -0
- package/templates/prisma/TESTING.md +123 -0
- package/templates/prisma/TESTING.pt-BR.md +123 -0
- package/templates/prisma/docker-compose.yml +78 -0
- package/templates/prisma/docs/adding-a-module.md +230 -0
- package/templates/prisma/docs/features-markers.md +50 -0
- package/templates/prisma/nest-cli.json +8 -0
- package/templates/prisma/package.json +95 -0
- package/templates/prisma/prisma/schema.prisma +105 -0
- package/templates/prisma/prisma/seed.ts +46 -0
- package/templates/prisma/src/app.module.ts +72 -0
- package/templates/prisma/src/auth/auth.controller.ts +283 -0
- package/templates/prisma/src/auth/auth.module.ts +59 -0
- package/templates/prisma/src/auth/auth.service.spec.ts +53 -0
- package/templates/prisma/src/auth/auth.service.ts +224 -0
- package/templates/prisma/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/prisma/src/auth/dto/login.dto.ts +10 -0
- package/templates/prisma/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/prisma/src/auth/dto/register.dto.ts +11 -0
- package/templates/prisma/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/prisma/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/prisma/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/prisma/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/prisma/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/prisma/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/prisma/src/auth/session.service.spec.ts +74 -0
- package/templates/prisma/src/auth/session.service.ts +96 -0
- package/templates/prisma/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/prisma/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/prisma/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/prisma/src/auth/token.service.ts +84 -0
- package/templates/prisma/src/common/constants/permissions.ts +8 -0
- package/templates/prisma/src/common/constants/role-permissions.ts +9 -0
- package/templates/prisma/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/prisma/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/prisma/src/common/decorators/public.decorator.ts +4 -0
- package/templates/prisma/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/prisma/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/prisma/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/prisma/src/common/guards/permissions.guard.ts +28 -0
- package/templates/prisma/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/prisma/src/common/guards/roles.guard.ts +24 -0
- package/templates/prisma/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/prisma/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/prisma/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/prisma/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/prisma/src/common/utils/hash.util.ts +5 -0
- package/templates/prisma/src/config/env.validation.ts +49 -0
- package/templates/prisma/src/database/prisma.module.ts +9 -0
- package/templates/prisma/src/database/prisma.service.ts +13 -0
- package/templates/prisma/src/health/health.controller.ts +49 -0
- package/templates/prisma/src/health/health.module.ts +19 -0
- package/templates/prisma/src/health/indicators/prisma-health.indicator.spec.ts +22 -0
- package/templates/prisma/src/health/indicators/prisma-health.indicator.ts +19 -0
- package/templates/prisma/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/prisma/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/prisma/src/mail/mail.module.ts +12 -0
- package/templates/prisma/src/mail/mail.processor.ts +48 -0
- package/templates/prisma/src/mail/mail.service.ts +24 -0
- package/templates/prisma/src/mail/templates/email-templates.ts +28 -0
- package/templates/prisma/src/main.ts +92 -0
- package/templates/prisma/src/metrics/metrics.controller.ts +22 -0
- package/templates/prisma/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/prisma/src/metrics/metrics.module.ts +12 -0
- package/templates/prisma/src/metrics/metrics.service.ts +34 -0
- package/templates/prisma/src/types/express-session.d.ts +13 -0
- package/templates/prisma/src/users/dto/create-user.dto.ts +12 -0
- package/templates/prisma/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/prisma/src/users/dto/update-user.dto.ts +6 -0
- package/templates/prisma/src/users/entities/user.entity.ts +20 -0
- package/templates/prisma/src/users/users.controller.ts +165 -0
- package/templates/prisma/src/users/users.module.ts +10 -0
- package/templates/prisma/src/users/users.service.spec.ts +104 -0
- package/templates/prisma/src/users/users.service.ts +114 -0
- package/templates/prisma/test/auth.e2e-spec.ts +75 -0
- package/templates/prisma/test/session-auth.e2e-spec.ts +163 -0
- package/templates/prisma/test/users.e2e-spec.ts +106 -0
- package/templates/prisma/test/utils/clean-database.ts +14 -0
- package/templates/prisma/test/utils/e2e-setup.ts +58 -0
- package/templates/prisma/tsconfig.build.json +4 -0
- package/templates/prisma/tsconfig.json +25 -0
- package/templates/prisma/vitest.config.ts +20 -0
- package/templates/prisma/vitest.e2e.config.ts +19 -0
- package/templates/typeorm/.env.example +45 -0
- package/templates/typeorm/.env.test +38 -0
- package/templates/typeorm/.github/workflows/ci.yml +116 -0
- package/templates/typeorm/ARCHITECTURE.md +158 -0
- package/templates/typeorm/ARCHITECTURE.pt-BR.md +156 -0
- package/templates/typeorm/CODE_OF_CONDUCT.md +29 -0
- package/templates/typeorm/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/typeorm/CONTRIBUTING.md +57 -0
- package/templates/typeorm/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/typeorm/Dockerfile +43 -0
- package/templates/typeorm/LICENSE +21 -0
- package/templates/typeorm/README.md +266 -0
- package/templates/typeorm/README.pt-BR.md +266 -0
- package/templates/typeorm/ROADMAP.md +79 -0
- package/templates/typeorm/ROADMAP.pt-BR.md +67 -0
- package/templates/typeorm/TESTING.md +114 -0
- package/templates/typeorm/TESTING.pt-BR.md +114 -0
- package/templates/typeorm/docker-compose.yml +78 -0
- package/templates/typeorm/docs/adding-a-module.md +369 -0
- package/templates/typeorm/docs/features-markers.md +50 -0
- package/templates/typeorm/nest-cli.json +8 -0
- package/templates/typeorm/package.json +98 -0
- package/templates/typeorm/src/app.module.ts +72 -0
- package/templates/typeorm/src/auth/auth.controller.ts +283 -0
- package/templates/typeorm/src/auth/auth.module.ts +86 -0
- package/templates/typeorm/src/auth/auth.service.spec.ts +111 -0
- package/templates/typeorm/src/auth/auth.service.ts +346 -0
- package/templates/typeorm/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/typeorm/src/auth/dto/login.dto.ts +10 -0
- package/templates/typeorm/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/typeorm/src/auth/dto/register.dto.ts +11 -0
- package/templates/typeorm/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/typeorm/src/auth/entities/email-verification-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/oauth-account.entity.ts +50 -0
- package/templates/typeorm/src/auth/entities/password-reset-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/refresh-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/session.entity.ts +50 -0
- package/templates/typeorm/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/typeorm/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/typeorm/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/typeorm/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/typeorm/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/typeorm/src/auth/session.service.spec.ts +74 -0
- package/templates/typeorm/src/auth/session.service.ts +96 -0
- package/templates/typeorm/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/typeorm/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/typeorm/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/typeorm/src/auth/token.service.ts +115 -0
- package/templates/typeorm/src/common/constants/permissions.ts +8 -0
- package/templates/typeorm/src/common/constants/role-permissions.ts +9 -0
- package/templates/typeorm/src/common/constants/role.enum.ts +5 -0
- package/templates/typeorm/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/typeorm/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/typeorm/src/common/decorators/public.decorator.ts +4 -0
- package/templates/typeorm/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/typeorm/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/typeorm/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/typeorm/src/common/guards/permissions.guard.ts +28 -0
- package/templates/typeorm/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/typeorm/src/common/guards/roles.guard.ts +24 -0
- package/templates/typeorm/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/typeorm/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/typeorm/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/typeorm/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/typeorm/src/common/utils/hash.util.ts +5 -0
- package/templates/typeorm/src/config/env.validation.ts +50 -0
- package/templates/typeorm/src/database/data-source.ts +20 -0
- package/templates/typeorm/src/database/database.module.ts +39 -0
- package/templates/typeorm/src/database/seed.ts +81 -0
- package/templates/typeorm/src/database/typeorm-options.ts +49 -0
- package/templates/typeorm/src/health/health.controller.ts +49 -0
- package/templates/typeorm/src/health/health.module.ts +19 -0
- package/templates/typeorm/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/typeorm/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/typeorm/src/health/indicators/typeorm-health.indicator.spec.ts +49 -0
- package/templates/typeorm/src/health/indicators/typeorm-health.indicator.ts +37 -0
- package/templates/typeorm/src/mail/mail.module.ts +12 -0
- package/templates/typeorm/src/mail/mail.processor.ts +48 -0
- package/templates/typeorm/src/mail/mail.service.ts +24 -0
- package/templates/typeorm/src/mail/templates/email-templates.ts +28 -0
- package/templates/typeorm/src/main.ts +107 -0
- package/templates/typeorm/src/metrics/metrics.controller.ts +22 -0
- package/templates/typeorm/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/typeorm/src/metrics/metrics.module.ts +12 -0
- package/templates/typeorm/src/metrics/metrics.service.ts +34 -0
- package/templates/typeorm/src/types/express-session.d.ts +13 -0
- package/templates/typeorm/src/users/dto/create-user.dto.ts +12 -0
- package/templates/typeorm/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/typeorm/src/users/dto/update-user.dto.ts +6 -0
- package/templates/typeorm/src/users/entities/user.entity.ts +113 -0
- package/templates/typeorm/src/users/users.controller.ts +165 -0
- package/templates/typeorm/src/users/users.module.ts +13 -0
- package/templates/typeorm/src/users/users.service.spec.ts +183 -0
- package/templates/typeorm/src/users/users.service.ts +124 -0
- package/templates/typeorm/test/auth.e2e-spec.ts +111 -0
- package/templates/typeorm/test/session-auth.e2e-spec.ts +159 -0
- package/templates/typeorm/test/users.e2e-spec.ts +183 -0
- package/templates/typeorm/test/utils/clean-database.ts +65 -0
- package/templates/typeorm/test/utils/e2e-setup.ts +77 -0
- package/templates/typeorm/tsconfig.build.json +4 -0
- package/templates/typeorm/tsconfig.json +25 -0
- package/templates/typeorm/vitest.config.ts +20 -0
- package/templates/typeorm/vitest.e2e.config.ts +19 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Arquitetura
|
|
2
|
+
|
|
3
|
+
[English](ARCHITECTURE.md) | **Portuguรชs**
|
|
4
|
+
|
|
5
|
+
Este documento explica como o NestForge com TypeORM estรก organizado e por que certas decisรตes de design foram tomadas.
|
|
6
|
+
|
|
7
|
+
## Visรฃo geral
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
Request โ main.ts (pipes, filters e interceptors globais)
|
|
11
|
+
โ Guards de autenticaรงรฃo e autorizaรงรฃo
|
|
12
|
+
โ Controller (valida DTO e delega)
|
|
13
|
+
โ Service (regra de negรณcio)
|
|
14
|
+
โ Repository do TypeORM
|
|
15
|
+
โ PostgreSQL, MySQL ou SQLite
|
|
16
|
+
โ ClassSerializerInterceptor
|
|
17
|
+
โ Response
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Cada mรณdulo de domรญnio segue a mesma estrutura:
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
<modulo>/
|
|
24
|
+
โโโ dto/ # schemas Zod e DTOs
|
|
25
|
+
โโโ entities/ # entidades persistidas pelo TypeORM
|
|
26
|
+
โโโ <modulo>.controller.ts # recebe a request e chama o service
|
|
27
|
+
โโโ <modulo>.service.ts # regras de negรณcio
|
|
28
|
+
โโโ <modulo>.service.spec.ts
|
|
29
|
+
โโโ <modulo>.module.ts # dependรชncias, repositories e exports
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Controllers nรฃo acessam repositories diretamente. Toda operaรงรฃo passa pelo service, mantendo as regras de negรณcio centralizadas e testรกveis.
|
|
33
|
+
|
|
34
|
+
Os mรณdulos registram suas entidades com:
|
|
35
|
+
|
|
36
|
+
TypeOrmModule.forFeature([
|
|
37
|
+
UserEntity,
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
Os services recebem os repositories com:
|
|
41
|
+
|
|
42
|
+
@InjectRepository(UserEntity) private readonly usersRepository: Repository<UserEntity>
|
|
43
|
+
|
|
44
|
+
A conexรฃo global fica em src/database/database.module.ts. As opรงรตes especรญficas de PostgreSQL, MySQL e SQLite ficam em src/database/typeorm-options.ts.
|
|
45
|
+
|
|
46
|
+
## Decisรตes de design
|
|
47
|
+
|
|
48
|
+
### Por que Zod em vez de class-validator?
|
|
49
|
+
|
|
50
|
+
Com Zod, o schema รฉ a fonte principal para validaรงรฃo e documentaรงรฃo. O nestjs-zod transforma schemas em DTOs, enquanto patchNestJsSwagger() permite que o Swagger interprete esses schemas.
|
|
51
|
+
|
|
52
|
+
Isso reduz a duplicaรงรฃo entre decorators de validaรงรฃo e documentaรงรฃo.
|
|
53
|
+
|
|
54
|
+
### Por que usar os repositories do TypeORM diretamente?
|
|
55
|
+
|
|
56
|
+
Repository<Entity> jรก oferece uma abstraรงรฃo testรกvel e tipada para persistรชncia. Criar outra camada genรฉrica de repository por cima adicionaria indireรงรฃo sem trazer benefรญcio para este boilerplate.
|
|
57
|
+
|
|
58
|
+
Os testes unitรกrios substituem os repositories por objetos com vi.fn(), sem precisar iniciar banco ou aplicaรงรฃo Nest completa.
|
|
59
|
+
|
|
60
|
+
Uma camada adicional pode ser criada posteriormente se o projeto precisar de regras complexas de persistรชncia ou mรบltiplas fontes de dados.
|
|
61
|
+
|
|
62
|
+
### Por que synchronize fica desabilitado?
|
|
63
|
+
|
|
64
|
+
O template usa:
|
|
65
|
+
|
|
66
|
+
synchronize: false
|
|
67
|
+
|
|
68
|
+
Mudanรงas no banco devem passar por migrations versionadas. Isso evita alteraรงรตes automรกticas e potencialmente destrutivas no schema, principalmente em produรงรฃo.
|
|
69
|
+
|
|
70
|
+
As migrations sรฃo geradas e executadas com:
|
|
71
|
+
|
|
72
|
+
npm run migration:generate -- src/database/migrations/NomeDaMigration
|
|
73
|
+
npm run migration:run
|
|
74
|
+
|
|
75
|
+
### Por que permissions sรฃo um mapa em cรณdigo?
|
|
76
|
+
|
|
77
|
+
O mapa ROLE_PERMISSIONS atende projetos com poucas roles fixas e deixa as permissรตes fรกceis de auditar.
|
|
78
|
+
|
|
79
|
+
Se o projeto precisar de roles criadas dinamicamente, o mapa pode ser substituรญdo por entidades como Role, Permission e RolePermission.
|
|
80
|
+
|
|
81
|
+
### Por que BullMQ para envio de e-mails?
|
|
82
|
+
|
|
83
|
+
SMTP รฉ uma operaรงรฃo externa que pode falhar ou demorar. Colocar o envio em uma fila permite que a requisiรงรฃo respondadepois de enfileirar o trabalho, enquanto o MailProcessor realiza o envio e as tentativas posteriores.
|
|
84
|
+
|
|
85
|
+
### Por que armazenar o hash dos refresh tokens?
|
|
86
|
+
|
|
87
|
+
Um JWT nรฃo pode ser revogado antes de expirar. O armazenamento do hash permite:
|
|
88
|
+
|
|
89
|
+
- logout;
|
|
90
|
+
- rotaรงรฃo do refresh token;
|
|
91
|
+
- invalidaรงรฃo apรณs troca de senha;
|
|
92
|
+
- bloqueio da reutilizaรงรฃo de tokens revogados.
|
|
93
|
+
|
|
94
|
+
O token original nรฃo รฉ persistido.
|
|
95
|
+
|
|
96
|
+
### Por que UserEntity usa @Exclude()?
|
|
97
|
+
|
|
98
|
+
O repository precisa acessar passwordHash em operaรงรตes como login, mas esse campo nunca deve aparecer na resposta HTTP.
|
|
99
|
+
|
|
100
|
+
O @Exclude() combinado com ClassSerializerInterceptor cria uma barreira de serializaรงรฃo para impedir o vazamento do hash.
|
|
101
|
+
|
|
102
|
+
### Por que Session/Cookies usa armazenamento persistente?
|
|
103
|
+
|
|
104
|
+
A estratรฉgia Session/Cookies usa express-session com connect-typeorm. As sessรตes ficam na tabela sessions, em vez da memรณria do processo.
|
|
105
|
+
|
|
106
|
+
Isso permite reiniciar ou escalar a aplicaรงรฃo sem perder todas as sessรตes ativas.
|
|
107
|
+
|
|
108
|
+
### Como funciona a proteรงรฃo CSRF?
|
|
109
|
+
|
|
110
|
+
Na estratรฉgia Session/Cookies, a aplicaรงรฃo usa um token CSRF associado ร sessรฃo. Requisiรงรตes que alteram estado precisam enviar esse token pelo header:
|
|
111
|
+
|
|
112
|
+
x-csrf-token
|
|
113
|
+
|
|
114
|
+
O middleware compara o token recebido com o token armazenado na sessรฃo.
|
|
115
|
+
|
|
116
|
+
Na estratรฉgia JWT com Bearer token, o navegador nรฃo envia automaticamente a credencial no cookie, entรฃo esse fluxo de CSRF nรฃo รฉ necessรกrio.
|
|
117
|
+
|
|
118
|
+
## Estratรฉgias de autenticaรงรฃo
|
|
119
|
+
|
|
120
|
+
### JWT
|
|
121
|
+
|
|
122
|
+
1. Cadastro ou login valida o usuรกrio.
|
|
123
|
+
2. TokenService emite access e refresh tokens.
|
|
124
|
+
3. O hash do refresh token รฉ armazenado no banco.
|
|
125
|
+
4. JwtAuthGuard valida o Bearer token.
|
|
126
|
+
5. O refresh revoga o token anterior e emite um novo par.
|
|
127
|
+
6. O logout revoga o refresh token.
|
|
128
|
+
|
|
129
|
+
### Session/Cookies
|
|
130
|
+
|
|
131
|
+
1. Cadastro ou login valida o usuรกrio.
|
|
132
|
+
2. A sessรฃo รฉ regenerada para evitar session fixation.
|
|
133
|
+
3. O usuรกrio e o token CSRF sรฃo armazenados na sessรฃo.
|
|
134
|
+
4. O navegador recebe o cookie nestforge.sid.
|
|
135
|
+
5. SessionAuthGuard protege as rotas.
|
|
136
|
+
6. O logout destrรณi a sessรฃo.
|
|
137
|
+
|
|
138
|
+
### OAuth
|
|
139
|
+
|
|
140
|
+
Google e GitHub sรฃo vinculados por OAuthAccountEntity. Se o e-mail ainda nรฃo estiver cadastrado, um usuรกrio รฉ criado e associado ao provedor.
|
|
141
|
+
|
|
142
|
+
## Banco e entidades
|
|
143
|
+
|
|
144
|
+
As principais entidades sรฃo:
|
|
145
|
+
|
|
146
|
+
- UserEntity;
|
|
147
|
+
- OAuthAccountEntity;
|
|
148
|
+
- RefreshTokenEntity, quando tokens estiverem habilitados;
|
|
149
|
+
- SessionEntity, quando Session/Cookies estiver habilitada;
|
|
150
|
+
- entidades de recuperaรงรฃo e verificaรงรฃo de e-mail, quando aplicรกveis.
|
|
151
|
+
|
|
152
|
+
Entidades condicionais usam os marcadores do gerador para que apenas os arquivos e relacionamentos necessรกrios permaneรงam no projeto final.
|
|
153
|
+
|
|
154
|
+
## Onde adicionar um mรณdulo
|
|
155
|
+
|
|
156
|
+
Para adicionar um novo domรญnio, consulte docs/adding-a-module.md (docs/adding-a-module.md).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
**English** | [Portuguรชs](CODE_OF_CONDUCT.pt-BR.md)
|
|
4
|
+
|
|
5
|
+
## Our commitment
|
|
6
|
+
|
|
7
|
+
We, as members, contributors, and maintainers, pledge to make participation in this project a harassment-free experience for everyone, regardless of age, body, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual orientation.
|
|
8
|
+
|
|
9
|
+
## Our standards
|
|
10
|
+
|
|
11
|
+
Examples of behavior that contributes to a positive environment:
|
|
12
|
+
|
|
13
|
+
- Using welcoming and inclusive language
|
|
14
|
+
- Respecting different viewpoints and experiences
|
|
15
|
+
- Gracefully accepting constructive criticism
|
|
16
|
+
- Focusing on what is best for the community
|
|
17
|
+
|
|
18
|
+
Examples of unacceptable behavior:
|
|
19
|
+
|
|
20
|
+
- The use of sexualized language or imagery
|
|
21
|
+
- Offensive comments or personal/political attacks
|
|
22
|
+
- Public or private harassment
|
|
23
|
+
- Publishing other people's private information without permission
|
|
24
|
+
|
|
25
|
+
## Enforcement
|
|
26
|
+
|
|
27
|
+
Instances of abusive behavior may be reported by opening an issue marked as confidential or by contacting the project maintainer directly. All complaints will be reviewed and investigated.
|
|
28
|
+
|
|
29
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Cรณdigo de Conduta
|
|
2
|
+
|
|
3
|
+
[English](CODE_OF_CONDUCT.md) | **Portuguรชs**
|
|
4
|
+
|
|
5
|
+
## Nosso compromisso
|
|
6
|
+
|
|
7
|
+
Nรณs, como membros, contribuintes e mantenedores, nos comprometemos a fazer da participaรงรฃo neste projeto uma experiรชncia livre de assรฉdio para todos, independentemente de idade, corpo, deficiรชncia, etnia, identidade e expressรฃo de gรชnero, nรญvel de experiรชncia, nacionalidade, aparรชncia pessoal, raรงa, religiรฃo ou orientaรงรฃo sexual.
|
|
8
|
+
|
|
9
|
+
## Nossos padrรตes
|
|
10
|
+
|
|
11
|
+
Exemplos de comportamento que contribuem para um ambiente positivo:
|
|
12
|
+
- Usar linguagem acolhedora e inclusiva
|
|
13
|
+
- Respeitar pontos de vista e experiรชncias diferentes
|
|
14
|
+
- Aceitar crรญticas construtivas com elegรขncia
|
|
15
|
+
- Focar no que รฉ melhor para a comunidade
|
|
16
|
+
|
|
17
|
+
Exemplos de comportamento inaceitรกvel:
|
|
18
|
+
- Uso de linguagem ou imagens sexualizadas
|
|
19
|
+
- Comentรกrios ofensivos ou ataques pessoais/polรญticos
|
|
20
|
+
- Assรฉdio pรบblico ou privado
|
|
21
|
+
- Publicar informaรงรตes privadas de terceiros sem permissรฃo
|
|
22
|
+
|
|
23
|
+
## Aplicaรงรฃo
|
|
24
|
+
|
|
25
|
+
Casos de comportamento abusivo podem ser reportados abrindo uma issue marcada como confidencial ou entrando em contato diretamente com o mantenedor do projeto. Todas as reclamaรงรตes serรฃo revisadas e investigadas.
|
|
26
|
+
|
|
27
|
+
Este Cรณdigo de Conduta รฉ adaptado do [Contributor Covenant](https://www.contributor-covenant.org), versรฃo 2.1.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Contributing to NestForge
|
|
2
|
+
|
|
3
|
+
**English** | [Portuguรชs](CONTRIBUTING.pt-BR.md)
|
|
4
|
+
|
|
5
|
+
Thank you for considering contributing! ๐
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
1. Fork the repository
|
|
10
|
+
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/nestforge.git`
|
|
11
|
+
3. Create a branch: `git checkout -b feat/feature-name`
|
|
12
|
+
4. Start the environment: `docker compose up` (or `npm install` + `npm run start:dev`)
|
|
13
|
+
5. Make your changes
|
|
14
|
+
6. Run tests and lint before committing: `npm run test && npm run lint`
|
|
15
|
+
7. Commit according to the convention below
|
|
16
|
+
8. Open a Pull Request describing what was changed and why
|
|
17
|
+
|
|
18
|
+
## Commit convention
|
|
19
|
+
|
|
20
|
+
We use Portuguese commit messages following [Conventional Commits](https://www.conventionalcommits.org/):
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
feat: adiciona autenticaรงรฃo via Google OAuth
|
|
24
|
+
fix: corrige validaรงรฃo do refresh token
|
|
25
|
+
docs: atualiza guia de instalaรงรฃo
|
|
26
|
+
test: adiciona testes de integraรงรฃo para users
|
|
27
|
+
refactor: extrai lรณgica de hash para utils
|
|
28
|
+
chore: atualiza dependรชncias
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Code standards
|
|
32
|
+
|
|
33
|
+
- If your code is related to an optional CLI feature (Swagger, Redis, RBAC, etc.), mark it according to [`docs/feature-markers.md`](docs/feature-markers.md). Without this, the CLI cannot remove the code when someone disables the feature.
|
|
34
|
+
- Strict TypeScript (no unjustified `any`)
|
|
35
|
+
- Always validate input through Zod (DTOs)
|
|
36
|
+
- No business logic in controllers โ controllers only orchestrate, services handle the logic
|
|
37
|
+
- Every new route requires Swagger decorators (`@ApiTags`, `@ApiOperation`, etc.)
|
|
38
|
+
- Every new feature requires tests (at least unit tests)
|
|
39
|
+
|
|
40
|
+
## Reporting bugs
|
|
41
|
+
|
|
42
|
+
Open an issue containing:
|
|
43
|
+
|
|
44
|
+
- A description of the problem
|
|
45
|
+
- Steps to reproduce it
|
|
46
|
+
- Expected versus actual behavior
|
|
47
|
+
- Node version / environment (Docker or local)
|
|
48
|
+
|
|
49
|
+
## Suggesting features
|
|
50
|
+
|
|
51
|
+
Before implementing, open an issue with the `enhancement` label describing the problem the feature solves. This avoids rework if the approach needs to be discussed.
|
|
52
|
+
|
|
53
|
+
## Code of Conduct
|
|
54
|
+
|
|
55
|
+
By contributing, you agree to follow the project's [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
56
|
+
|
|
57
|
+
---
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Contribuindo com o NestForge
|
|
2
|
+
|
|
3
|
+
[English](CONTRIBUTING.md) | **Portuguรชs**
|
|
4
|
+
|
|
5
|
+
Obrigado por considerar contribuir! ๐
|
|
6
|
+
|
|
7
|
+
## Como comeรงar
|
|
8
|
+
|
|
9
|
+
1. Faรงa um fork do repositรณrio
|
|
10
|
+
2. Clone o seu fork: `git clone https://github.com/SEU_USUARIO/nestforge.git`
|
|
11
|
+
3. Crie uma branch: `git checkout -b feat/nome-da-feature`
|
|
12
|
+
4. Suba o ambiente: `docker compose up` (ou `npm install` + `npm run start:dev`)
|
|
13
|
+
5. Faรงa suas alteraรงรตes
|
|
14
|
+
6. Rode os testes e o lint antes de commitar: `npm run test && npm run lint`
|
|
15
|
+
7. Commit seguindo o padrรฃo abaixo
|
|
16
|
+
8. Abra um Pull Request descrevendo o que foi feito e por quรช
|
|
17
|
+
|
|
18
|
+
## Padrรฃo de commits
|
|
19
|
+
|
|
20
|
+
Usamos commits em portuguรชs, seguindo [Conventional Commits](https://www.conventionalcommits.org/):
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
feat: adiciona autenticaรงรฃo via Google OAuth
|
|
24
|
+
fix: corrige validaรงรฃo do refresh token
|
|
25
|
+
docs: atualiza guia de instalaรงรฃo
|
|
26
|
+
test: adiciona testes de integraรงรฃo para users
|
|
27
|
+
refactor: extrai lรณgica de hash para utils
|
|
28
|
+
chore: atualiza dependรชncias
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Padrรตes de cรณdigo
|
|
32
|
+
|
|
33
|
+
- Se o seu cรณdigo for ligado a um recurso opcional da CLI (Swagger, Redis, RBAC, etc.), marque ele seguindo [`docs/feature-markers.md`](docs/feature-markers.md) โ sem isso, a CLI nรฃo consegue remover o trecho quando alguรฉm desliga o recurso.
|
|
34
|
+
- TypeScript estrito (sem `any` sem justificativa)
|
|
35
|
+
- Validaรงรฃo de entrada sempre via Zod (DTOs)
|
|
36
|
+
- Nada de lรณgica de negรณcio no controller โ controller sรณ orquestra, service resolve
|
|
37
|
+
- Toda rota nova precisa de decorators de Swagger (`@ApiTags`, `@ApiOperation`, etc)
|
|
38
|
+
- Toda feature nova precisa de teste (unitรกrio no mรญnimo)
|
|
39
|
+
|
|
40
|
+
## Reportando bugs
|
|
41
|
+
|
|
42
|
+
Abra uma issue com:
|
|
43
|
+
- Descriรงรฃo do problema
|
|
44
|
+
- Passos para reproduzir
|
|
45
|
+
- Comportamento esperado vs. atual
|
|
46
|
+
- Versรฃo do Node / ambiente (Docker ou local)
|
|
47
|
+
|
|
48
|
+
## Sugerindo features
|
|
49
|
+
|
|
50
|
+
Abra uma issue com a tag `enhancement` descrevendo o problema que a feature resolve antes de sair implementando โ isso evita retrabalho caso a abordagem precise ser discutida.
|
|
51
|
+
|
|
52
|
+
## Cรณdigo de conduta
|
|
53
|
+
|
|
54
|
+
Ao contribuir, vocรช concorda em seguir o [Cรณdigo de Conduta](CODE_OF_CONDUCT.pt-BR.md) do projeto.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# --- Base ---
|
|
2
|
+
FROM node:20-alpine AS base
|
|
3
|
+
|
|
4
|
+
WORKDIR /app
|
|
5
|
+
|
|
6
|
+
COPY package*.json ./
|
|
7
|
+
|
|
8
|
+
# --- Dependencies ---
|
|
9
|
+
FROM base AS deps
|
|
10
|
+
|
|
11
|
+
RUN npm ci
|
|
12
|
+
|
|
13
|
+
# --- Development ---
|
|
14
|
+
FROM deps AS development
|
|
15
|
+
|
|
16
|
+
COPY . .
|
|
17
|
+
|
|
18
|
+
EXPOSE 3000
|
|
19
|
+
|
|
20
|
+
CMD ["npm", "run", "start:dev"]
|
|
21
|
+
|
|
22
|
+
# --- Build ---
|
|
23
|
+
FROM deps AS build
|
|
24
|
+
|
|
25
|
+
COPY . .
|
|
26
|
+
|
|
27
|
+
RUN npm run build
|
|
28
|
+
RUN npm prune --omit=dev
|
|
29
|
+
|
|
30
|
+
# --- Production ---
|
|
31
|
+
FROM node:20-alpine AS production
|
|
32
|
+
|
|
33
|
+
WORKDIR /app
|
|
34
|
+
|
|
35
|
+
ENV NODE_ENV=production
|
|
36
|
+
|
|
37
|
+
COPY --from=build /app/node_modules ./node_modules
|
|
38
|
+
COPY --from=build /app/dist ./dist
|
|
39
|
+
COPY --from=build /app/package.json ./package.json
|
|
40
|
+
|
|
41
|
+
EXPOSE 3000
|
|
42
|
+
|
|
43
|
+
CMD ["node", "dist/main.js"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeiel Jedson Leรฃo Alves
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# NestForge
|
|
2
|
+
|
|
3
|
+
**English** | [Portuguรชs](README.pt-BR.md)
|
|
4
|
+
|
|
5
|
+
> Production-ready NestJS starter with TypeORM, Authentication, Docker, Testing, CI/CD and Clean Architecture.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/jeiel2013/nestforge/actions/workflows/ci.yml)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](https://nestjs.com)
|
|
11
|
+
|
|
12
|
+
NestForge is a NestJS starter designed to accelerate the beginning of serious backend projects, with complete authentication, clean architecture, security, and observability already configured. The idea is to clone it, run `docker compose up`, and have an API ready to evolve.
|
|
13
|
+
|
|
14
|
+
## โจ Features
|
|
15
|
+
|
|
16
|
+
- ๐ **Configurable authentication** โ JWT with access/refresh tokens, TypeORM-backed Session/Cookies, OAuth-only, or no authentication
|
|
17
|
+
- ๐ **OAuth** โ Google and GitHub, integrated with the selected token or session strategy
|
|
18
|
+
- ๐ฅ **RBAC** โ Roles (Admin, Manager, User) and granular Permissions
|
|
19
|
+
- ๐ก๏ธ **Security** โ Helmet, CORS, Rate Limiting, validation, and serialization with Zod
|
|
20
|
+
- ๐๏ธ **Database** โ TypeORM with PostgreSQL, MySQL, or SQLite
|
|
21
|
+
- ๐จ **Email** โ queues with BullMQ + Redis, locally tested with Mailpit
|
|
22
|
+
- ๐ **Automatic documentation** โ Swagger
|
|
23
|
+
- ๐ชต **Structured logs** โ Pino
|
|
24
|
+
- โ
**Tests** โ unit and integration tests with Vitest
|
|
25
|
+
- ๐ณ **Docker** โ complete environment with a single command
|
|
26
|
+
- โ๏ธ **CI/CD** โ GitHub Actions (build, lint, test)
|
|
27
|
+
|
|
28
|
+
## ๐งฑ Stack
|
|
29
|
+
|
|
30
|
+
| Layer | Technology |
|
|
31
|
+
|---|---|
|
|
32
|
+
| Framework | NestJS + TypeScript |
|
|
33
|
+
| ORM | TypeORM |
|
|
34
|
+
| Database | PostgreSQL, MySQL, or SQLite |
|
|
35
|
+
| Cache / Queues | Redis + BullMQ |
|
|
36
|
+
| Authentication | JWT, Session/Cookies, or OAuth with Passport |
|
|
37
|
+
| Validation | Zod + nestjs-zod (schemas automatically become DTOs + Swagger) |
|
|
38
|
+
| Docs | Swagger |
|
|
39
|
+
| Email (dev) | Mailpit |
|
|
40
|
+
| Tests | Vitest |
|
|
41
|
+
| CI | GitHub Actions |
|
|
42
|
+
|
|
43
|
+
## ๐ Folder structure
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
src/
|
|
47
|
+
โ
|
|
48
|
+
โโโ auth/ # login, sessions/tokens, OAuth, guards, and strategies
|
|
49
|
+
โโโ users/ # user CRUD
|
|
50
|
+
โโโ common/ # decorators, filters, guards, interceptors, pipes, utilities
|
|
51
|
+
โโโ config/ # typed and validated configuration (env)
|
|
52
|
+
โโโ database/ # DataSource, configuration, migrations, and seed
|
|
53
|
+
โโโ modules/ # additional domain modules
|
|
54
|
+
โโโ shared/ # code shared between modules
|
|
55
|
+
โโโ jobs/ # queues and workers (BullMQ)
|
|
56
|
+
โโโ mail/ # email templates and delivery
|
|
57
|
+
โโโ main.ts
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## ๐ Getting started
|
|
61
|
+
|
|
62
|
+
### Prerequisites
|
|
63
|
+
|
|
64
|
+
- Node.js 20+
|
|
65
|
+
- Docker and Docker Compose
|
|
66
|
+
|
|
67
|
+
### Running with Docker (recommended)
|
|
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
|
+
This starts the API, PostgreSQL, Redis, and Mailpit (email interface at `http://localhost:8025`).
|
|
77
|
+
|
|
78
|
+
### Running locally
|
|
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
|
+
Swagger documentation is available at `http://localhost:3000/docs`.
|
|
90
|
+
|
|
91
|
+
## ๐ Roles & Permissions
|
|
92
|
+
|
|
93
|
+
| Role | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `ADMIN` | full system access |
|
|
96
|
+
| `MANAGER` | manages users and reports |
|
|
97
|
+
| `USER` | standard access |
|
|
98
|
+
|
|
99
|
+
Permissions are granular (`user:create`, `user:delete`, `report:read`, etc.) and combined with roles through decorators (`@Roles()`, `@Permissions()`).
|
|
100
|
+
|
|
101
|
+
## ๐บ๏ธ Roadmap
|
|
102
|
+
|
|
103
|
+
- [x] JWT authentication
|
|
104
|
+
- [x] Session/Cookies authentication
|
|
105
|
+
- [x] Google/GitHub OAuth
|
|
106
|
+
- [x] OAuth-only strategy
|
|
107
|
+
- [x] Generation without authentication
|
|
108
|
+
- [x] Refresh Token
|
|
109
|
+
- [x] Docker
|
|
110
|
+
- [x] CI (build, lint, test)
|
|
111
|
+
- [x] OAuth (Google/GitHub)
|
|
112
|
+
- [x] File uploads
|
|
113
|
+
- [x] Queues (BullMQ)
|
|
114
|
+
- [x] Transactional email
|
|
115
|
+
- [x] Complete RBAC (granular permissions)
|
|
116
|
+
- [x] Complete integration tests
|
|
117
|
+
- [x] Complete documentation (Swagger + architecture guide)
|
|
118
|
+
|
|
119
|
+
See the detailed [ROADMAP.md](ROADMAP.md).
|
|
120
|
+
|
|
121
|
+
### Configuring social login (OAuth)
|
|
122
|
+
|
|
123
|
+
To enable login through Google and GitHub, create an OAuth App with each provider and fill in `.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**: create credentials in the [Google Cloud Console](https://console.cloud.google.com/apis/credentials) and configure the callback URL as `{APP_URL}/auth/google/callback`.
|
|
136
|
+
- **GitHub**: create an OAuth App under `Settings > Developer settings > OAuth Apps` and configure the callback URL as `{APP_URL}/auth/github/callback`.
|
|
137
|
+
|
|
138
|
+
Then access `GET /auth/google` or `GET /auth/github`. On callback, the API issues access/refresh tokens or establishes a cookie-based session according to the selected strategy. On first access, an account is created and linked to the provider.
|
|
139
|
+
|
|
140
|
+
### Session/Cookies authentication
|
|
141
|
+
|
|
142
|
+
When the project is generated with Session/Cookies, registration and login create a session persisted in the database through `connect-typeorm`. The identifier is sent in the `nestforge.sid` cookie, configured with `httpOnly`, `sameSite=lax`, and `secure` in production.
|
|
143
|
+
|
|
144
|
+
Configure `.env`:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
SESSION_SECRET=use-a-secret-with-at-least-32-characters
|
|
148
|
+
SESSION_MAX_AGE=604800000
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Password recovery and email verification
|
|
152
|
+
|
|
153
|
+
Every registration (`POST /auth/register`) automatically sends a verification email. Emails are queued with BullMQ/Redis and processed by a worker that sends them over SMTP. In development, everything goes to Mailpit (`http://localhost:8025`), so nothing is actually sent over the internet.
|
|
154
|
+
|
|
155
|
+
| Route | What it does |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `POST /auth/forgot-password` | Receives an `email` and queues the password reset link (the response is always generic and does not reveal whether the email exists) |
|
|
158
|
+
| `POST /auth/reset-password` | Receives a `token` + `password` and changes the password; it also revokes the user's active refresh tokens |
|
|
159
|
+
| `GET /auth/verify-email?token=...` | Confirms the email from the received link |
|
|
160
|
+
|
|
161
|
+
Reset and verification tokens expire after 1 hour and 24 hours, respectively, and can only be used once.
|
|
162
|
+
|
|
163
|
+
## ๐ Roles & Permissions
|
|
164
|
+
|
|
165
|
+
| Role | Description |
|
|
166
|
+
|---|---|
|
|
167
|
+
| `ADMIN` | full system access |
|
|
168
|
+
| `MANAGER` | manages users and reports |
|
|
169
|
+
| `USER` | standard access |
|
|
170
|
+
|
|
171
|
+
Each role has a fixed set of permissions mapped in `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
|
+
On routes, use `@Permissions(Permission.UserCreate)` to require a specific permission or `@Roles(Role.ADMIN)` when role-based control is enough. Both guards (`RolesGuard` and `PermissionsGuard`) run globally and only block a route when it has the corresponding decorator.
|
|
182
|
+
|
|
183
|
+
## ๐ฅ Users: pagination, filters, and avatar
|
|
184
|
+
|
|
185
|
+
`GET /users` accepts query parameters for paginating and filtering the list:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
GET /users?page=2&limit=20&search=jeiel&role=ADMIN
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
| Parameter | Description |
|
|
192
|
+
|---|---|
|
|
193
|
+
| `page` | current page (default: 1) |
|
|
194
|
+
| `limit` | items per page, up to 100 (default: 10) |
|
|
195
|
+
| `search` | searches by name or email (case-insensitive) |
|
|
196
|
+
| `role` | filters by `ADMIN`, `MANAGER`, or `USER` |
|
|
197
|
+
|
|
198
|
+
The response uses the format `{ data, meta: { total, page, limit, totalPages } }`.
|
|
199
|
+
|
|
200
|
+
To change the authenticated user's avatar:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
curl -X POST http://localhost:3000/users/me/avatar \
|
|
204
|
+
-H "Authorization: Bearer <accessToken>" \
|
|
205
|
+
-F "file=@/path/to/photo.png"
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
PNG, JPEG, and WEBP files up to 2 MB are accepted. The file is saved under `./uploads/avatars` and served at `/uploads/avatars/<file>`.
|
|
209
|
+
|
|
210
|
+
## ๐ก๏ธ Security: serialization and CSRF
|
|
211
|
+
|
|
212
|
+
All input validation (`body`, `query`) uses **Zod** through [`nestjs-zod`](https://github.com/BenLorantfy/nestjs-zod): each DTO is a `z.object({...})` transformed into a class with `createZodDto(schema)` and globally validated by `ZodValidationPipe`. During bootstrap, `patchNestJsSwagger()` teaches Swagger to read these schemas automatically, so validation (Zod) and documentation (`@ApiProperty`) do not need to be duplicated as they would with `class-validator`. Exported schemas (for example, `createUserSchema`) can also be reused and combined (such as `updateUserSchema`, which is simply `createUserSchema.partial()`).
|
|
213
|
+
|
|
214
|
+
- ๐ชต **Observability** โ structured logs with Pino, health checks (`/health`), and Prometheus metrics (`/metrics`)
|
|
215
|
+
|
|
216
|
+
The seed creates three test accounts, one for each role:
|
|
217
|
+
|
|
218
|
+
| Email | Password | Role |
|
|
219
|
+
|---|---|---|
|
|
220
|
+
| `admin@nestforge.dev` | `admin123` | ADMIN |
|
|
221
|
+
| `manager@nestforge.dev` | `manager123` | MANAGER |
|
|
222
|
+
| `user@nestforge.dev` | `user1234` | USER |
|
|
223
|
+
|
|
224
|
+
## ๐ Observability
|
|
225
|
+
|
|
226
|
+
`GET /health` returns the aggregated status of the API โ database (TypeORM), Redis, memory (heap/RSS), and disk space โ using `@nestjs/terminus`. Each check appears individually in the response, making it clear which component failed.
|
|
227
|
+
|
|
228
|
+
`GET /metrics` exposes Prometheus-format metrics through `prom-client`: standard Node.js metrics (CPU, memory, event loop), plus `http_request_duration_seconds` (histogram) and `http_requests_total` (counter), both with `method`, `route`, and `status_code` labels. Simply point a Prometheus scrape job at this route.
|
|
229
|
+
|
|
230
|
+
## ๐งช Tests
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
npm run test # unit tests
|
|
234
|
+
npm run test:e2e # integration tests (E2E)
|
|
235
|
+
npm run test:cov # coverage
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
E2E tests (`test/*.e2e-spec.ts`) start the real application (Nest + TypeORM + Redis) and call its endpoints with `supertest`, using an isolated database (`.env.test`, the `nestforge_test` database โ never the development database). Before running them for the first time:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
createdb nestforge_test # or: psql -U nestforge -c "CREATE DATABASE nestforge_test;"
|
|
242
|
+
docker compose up -d postgres redis
|
|
243
|
+
npm run test:e2e
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
The `pretest:e2e` script automatically applies migrations to this database before every run. Each test cleans the tables before running (`test/utils/clean-database.ts`), so nothing needs to be reset manually between runs. Current coverage includes the complete authentication flow (registration, login, refresh, logout, duplicate email, invalid credentials) and user CRUD with RBAC (ADMIN can do everything, USER can read but cannot create, `/users/me`, and access without a token).
|
|
247
|
+
|
|
248
|
+
Unit tests (`src/**/*.spec.ts`) run in isolation with the TypeORM repositories and `ioredis` mocked (`vi.fn()` / `vi.mock()`), so they do not require a real database or Redis. Current coverage includes `AuthService` (registration/login), `UsersService` (complete CRUD + pagination + confirmation through `instanceToPlain` that `passwordHash` is not leaked during serialization), `RolesGuard`, `PermissionsGuard`, and health indicators (`TypeOrmHealthIndicator`, `RedisHealthIndicator`).
|
|
249
|
+
|
|
250
|
+
## ๐ Additional documentation
|
|
251
|
+
|
|
252
|
+
- [ARCHITECTURE.md](ARCHITECTURE.md) โ how the project is organized and why certain design decisions were made (Zod vs. class-validator, code-based vs. database-based permissions, BullMQ, etc.)
|
|
253
|
+
- [TESTING.md](TESTING.md) โ how to validate migrations, build, unit tests, and E2E tests
|
|
254
|
+
- [docs/adding-a-module.md](docs/adding-a-module.md) โ step-by-step instructions for adding a new feature according to the project's conventions
|
|
255
|
+
|
|
256
|
+
## ๐ค Contributing
|
|
257
|
+
|
|
258
|
+
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for the complete guide.
|
|
259
|
+
|
|
260
|
+
## ๐ License
|
|
261
|
+
|
|
262
|
+
This project is licensed under the MIT License โ see [LICENSE](LICENSE).
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
Made by [Jeiel Alves](https://github.com/jeiel2013) ยท [jeieldev.com.br](https://jeieldev.com.br)
|