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,267 @@
|
|
|
1
|
+
# NestForge
|
|
2
|
+
|
|
3
|
+
**English** | [Português](README.pt-BR.md)
|
|
4
|
+
|
|
5
|
+
> Production-ready NestJS starter with Prisma, 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, Prisma-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** — Prisma 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 | Prisma |
|
|
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/ # PrismaService / PrismaModule
|
|
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
|
+
npx prisma migrate dev
|
|
84
|
+
npx prisma db seed
|
|
85
|
+
npm run start:dev
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Swagger documentation is available at `http://localhost:3000/docs`.
|
|
89
|
+
|
|
90
|
+
## 🔑 Roles & Permissions
|
|
91
|
+
|
|
92
|
+
| Role | Description |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `ADMIN` | full system access |
|
|
95
|
+
| `MANAGER` | manages users and reports |
|
|
96
|
+
| `USER` | standard access |
|
|
97
|
+
|
|
98
|
+
Permissions are granular (`user:create`, `user:delete`, `report:read`, etc.) and combined with roles through decorators (`@Roles()`, `@Permissions()`).
|
|
99
|
+
|
|
100
|
+
## 🗺️ Roadmap
|
|
101
|
+
|
|
102
|
+
- [x] JWT authentication
|
|
103
|
+
- [x] Session/Cookies authentication
|
|
104
|
+
- [x] Google/GitHub OAuth
|
|
105
|
+
- [x] OAuth-only strategy
|
|
106
|
+
- [x] Generation without authentication
|
|
107
|
+
- [x] Refresh Token
|
|
108
|
+
- [x] Docker
|
|
109
|
+
- [x] CI (build, lint, test)
|
|
110
|
+
- [x] OAuth (Google/GitHub)
|
|
111
|
+
- [x] File uploads
|
|
112
|
+
- [x] Queues (BullMQ)
|
|
113
|
+
- [x] Transactional email
|
|
114
|
+
- [x] Complete RBAC (granular permissions)
|
|
115
|
+
- [x] Complete integration tests
|
|
116
|
+
- [x] Complete documentation (Swagger + architecture guide)
|
|
117
|
+
|
|
118
|
+
See the detailed [ROADMAP.md](ROADMAP.md).
|
|
119
|
+
|
|
120
|
+
### Configuring social login (OAuth)
|
|
121
|
+
|
|
122
|
+
To enable login through Google and GitHub, create an OAuth App with each provider and fill in `.env`:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
APP_URL=http://localhost:3000
|
|
126
|
+
|
|
127
|
+
GOOGLE_CLIENT_ID=
|
|
128
|
+
GOOGLE_CLIENT_SECRET=
|
|
129
|
+
|
|
130
|
+
GITHUB_CLIENT_ID=
|
|
131
|
+
GITHUB_CLIENT_SECRET=
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- **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`.
|
|
135
|
+
- **GitHub**: create an OAuth App under `Settings > Developer settings > OAuth Apps` and configure the callback URL as `{APP_URL}/auth/github/callback`.
|
|
136
|
+
|
|
137
|
+
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.
|
|
138
|
+
|
|
139
|
+
### Session/Cookies authentication
|
|
140
|
+
|
|
141
|
+
When the project is generated with Session/Cookies, registration and login create a session persisted in the database through `@quixo3/prisma-session-store`. The identifier is sent in the `nestforge.sid` cookie, configured with `httpOnly`, `sameSite=lax`, and `secure` in production.
|
|
142
|
+
|
|
143
|
+
Configure `.env`:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
SESSION_SECRET=use-a-secret-with-at-least-32-characters
|
|
147
|
+
SESSION_MAX_AGE=604800000
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Password recovery and email verification
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
| Route | What it does |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `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) |
|
|
157
|
+
| `POST /auth/reset-password` | Receives a `token` + `password` and changes the password; it also revokes the user's active refresh tokens |
|
|
158
|
+
| `GET /auth/verify-email?token=...` | Confirms the email from the received link |
|
|
159
|
+
|
|
160
|
+
Reset and verification tokens expire after 1 hour and 24 hours, respectively, and can only be used once.
|
|
161
|
+
|
|
162
|
+
## 🔑 Roles & Permissions
|
|
163
|
+
|
|
164
|
+
| Role | Description |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `ADMIN` | full system access |
|
|
167
|
+
| `MANAGER` | manages users and reports |
|
|
168
|
+
| `USER` | standard access |
|
|
169
|
+
|
|
170
|
+
Each role has a fixed set of permissions mapped in `src/common/constants/role-permissions.ts`:
|
|
171
|
+
|
|
172
|
+
| Permission | ADMIN | MANAGER | USER |
|
|
173
|
+
|---|:---:|:---:|:---:|
|
|
174
|
+
| `user:create` | ✅ | ❌ | ❌ |
|
|
175
|
+
| `user:read` | ✅ | ✅ | ✅ |
|
|
176
|
+
| `user:update` | ✅ | ✅ | ❌ |
|
|
177
|
+
| `user:delete` | ✅ | ❌ | ❌ |
|
|
178
|
+
| `report:read` | ✅ | ✅ | ❌ |
|
|
179
|
+
|
|
180
|
+
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.
|
|
181
|
+
|
|
182
|
+
## 👥 Users: pagination, filters, and avatar
|
|
183
|
+
|
|
184
|
+
`GET /users` accepts query parameters for paginating and filtering the list:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
GET /users?page=2&limit=20&search=jeiel&role=ADMIN
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
| Parameter | Description |
|
|
191
|
+
|---|---|
|
|
192
|
+
| `page` | current page (default: 1) |
|
|
193
|
+
| `limit` | items per page, up to 100 (default: 10) |
|
|
194
|
+
| `search` | searches by name or email (case-insensitive) |
|
|
195
|
+
| `role` | filters by `ADMIN`, `MANAGER`, or `USER` |
|
|
196
|
+
|
|
197
|
+
The response uses the format `{ data, meta: { total, page, limit, totalPages } }`.
|
|
198
|
+
|
|
199
|
+
To change the authenticated user's avatar:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
curl -X POST http://localhost:3000/users/me/avatar \
|
|
203
|
+
-H "Authorization: Bearer <accessToken>" \
|
|
204
|
+
-F "file=@/path/to/photo.png"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
PNG, JPEG, and WEBP files up to 2 MB are accepted. The file is saved under `./uploads/avatars` and served at `/uploads/avatars/<file>`.
|
|
208
|
+
|
|
209
|
+
## 🛡️ Security: serialization and CSRF
|
|
210
|
+
|
|
211
|
+
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()`).
|
|
212
|
+
|
|
213
|
+
- 🪵 **Observability** — structured logs with Pino, health checks (`/health`), and Prometheus metrics (`/metrics`)
|
|
214
|
+
|
|
215
|
+
The seed creates three test accounts, one for each role:
|
|
216
|
+
|
|
217
|
+
| Email | Password | Role |
|
|
218
|
+
|---|---|---|
|
|
219
|
+
| `admin@nestforge.dev` | `admin123` | ADMIN |
|
|
220
|
+
| `manager@nestforge.dev` | `manager123` | MANAGER |
|
|
221
|
+
| `user@nestforge.dev` | `user1234` | USER |
|
|
222
|
+
|
|
223
|
+
## 📈 Observability
|
|
224
|
+
|
|
225
|
+
`GET /health` returns the aggregated status of the API — database (Prisma), Redis, memory (heap/RSS), and disk space — using `@nestjs/terminus`. Each check appears individually in the response, making it clear which component failed.
|
|
226
|
+
|
|
227
|
+
`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.
|
|
228
|
+
|
|
229
|
+
## 🧪 Tests
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm run test # unit tests
|
|
233
|
+
npm run test:e2e # integration tests (E2E)
|
|
234
|
+
npm run test:cov # coverage
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
E2E tests (`test/*.e2e-spec.ts`) start the real application (Nest + Prisma + 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:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
createdb nestforge_test # or: psql -U nestforge -c "CREATE DATABASE nestforge_test;"
|
|
241
|
+
docker compose up -d postgres redis
|
|
242
|
+
npm run test:e2e
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
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).
|
|
246
|
+
|
|
247
|
+
Unit tests (`src/**/*.spec.ts`) run in isolation with Prisma 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` and `PermissionsGuard` (allowing/blocking, including multiple permissions required at the same time), and health indicators (`PrismaHealthIndicator`, `RedisHealthIndicator`).
|
|
248
|
+
|
|
249
|
+
Unit tests also cover `SessionService` and `SessionAuthGuard`. When Session/Cookies is enabled, the dedicated E2E test validates cookie creation, persistence of authentication across requests, and logout.
|
|
250
|
+
|
|
251
|
+
## 📚 Additional documentation
|
|
252
|
+
|
|
253
|
+
- [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.)
|
|
254
|
+
- [TESTING.md](TESTING.md) — how to validate migrations, build, unit tests, and E2E tests
|
|
255
|
+
- [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
|
|
256
|
+
|
|
257
|
+
## 🤝 Contributing
|
|
258
|
+
|
|
259
|
+
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for the complete guide.
|
|
260
|
+
|
|
261
|
+
## 📄 License
|
|
262
|
+
|
|
263
|
+
This project is licensed under the MIT License — see [LICENSE](LICENSE).
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
Made by [Jeiel Alves](https://github.com/jeiel2013) · [jeieldev.com.br](https://jeieldev.com.br)
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# NestForge
|
|
2
|
+
|
|
3
|
+
[English](README.md) | **Português**
|
|
4
|
+
|
|
5
|
+
> Production-ready NestJS starter with Prisma, 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 é 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 Prisma, 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** — Prisma 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 | Prisma |
|
|
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/ # PrismaService / PrismaModule
|
|
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
|
+
npx prisma migrate dev
|
|
84
|
+
npx prisma db seed
|
|
85
|
+
npm run start:dev
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A documentação Swagger fica disponível em `http://localhost:3000/docs`.
|
|
89
|
+
|
|
90
|
+
## 🔑 Roles & Permissions
|
|
91
|
+
|
|
92
|
+
| Role | Descrição |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `ADMIN` | acesso total ao sistema |
|
|
95
|
+
| `MANAGER` | gerencia usuários e relatórios |
|
|
96
|
+
| `USER` | acesso padrão |
|
|
97
|
+
|
|
98
|
+
Permissions são granulares (`user:create`, `user:delete`, `report:read`, etc) e combinadas com roles via decorators (`@Roles()`, `@Permissions()`).
|
|
99
|
+
|
|
100
|
+
## 🗺️ Roadmap
|
|
101
|
+
|
|
102
|
+
- [x] Autenticação por JWT
|
|
103
|
+
- [x] Autenticação por Session/Cookies
|
|
104
|
+
- [x] OAuth Google/GitHub
|
|
105
|
+
- [x] Estratégia OAuth-only
|
|
106
|
+
- [x] Geração sem autenticação
|
|
107
|
+
- [x] Refresh Token
|
|
108
|
+
- [x] Docker
|
|
109
|
+
- [x] CI (build, lint, test)
|
|
110
|
+
- [x] OAuth (Google/GitHub)
|
|
111
|
+
- [x] Upload de arquivos
|
|
112
|
+
- [x] Filas (BullMQ)
|
|
113
|
+
- [x] E-mails transacionais
|
|
114
|
+
- [x] RBAC completo (permissions granulares)
|
|
115
|
+
- [x] Testes de integração completos
|
|
116
|
+
- [x] Documentação completa (Swagger + guia de arquitetura)
|
|
117
|
+
|
|
118
|
+
Veja o [ROADMAP.pt-BR.md](ROADMAP.pt-BR.md) detalhado.
|
|
119
|
+
|
|
120
|
+
### Configurando o login social (OAuth)
|
|
121
|
+
|
|
122
|
+
Para habilitar login via Google e GitHub, crie um OAuth App em cada provedor e preencha no `.env`:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
APP_URL=http://localhost:3000
|
|
126
|
+
|
|
127
|
+
GOOGLE_CLIENT_ID=
|
|
128
|
+
GOOGLE_CLIENT_SECRET=
|
|
129
|
+
|
|
130
|
+
GITHUB_CLIENT_ID=
|
|
131
|
+
GITHUB_CLIENT_SECRET=
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- **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`.
|
|
135
|
+
- **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`.
|
|
136
|
+
|
|
137
|
+
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.
|
|
138
|
+
|
|
139
|
+
### Autenticação por Session/Cookies
|
|
140
|
+
|
|
141
|
+
Quando o projeto é gerado com Session/Cookies, cadastro e login criam uma sessão persistida no banco por `@quixo3/prisma-session-store`. O identificador é enviado no cookie `nestforge.sid`, configurado com `httpOnly`, `sameSite=lax` e `secure` em produção.
|
|
142
|
+
|
|
143
|
+
Configure no `.env`:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
SESSION_SECRET=use-um-segredo-com-pelo-menos-32-caracteres
|
|
147
|
+
SESSION_MAX_AGE=604800000
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Recuperação de senha e verificação de e-mail
|
|
151
|
+
|
|
152
|
+
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.
|
|
153
|
+
|
|
154
|
+
| Rota | O que faz |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `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) |
|
|
157
|
+
| `POST /auth/reset-password` | Recebe `token` + `password` e troca a senha; também revoga os refresh tokens ativos do usuário |
|
|
158
|
+
| `GET /auth/verify-email?token=...` | Confirma o e-mail a partir do link recebido |
|
|
159
|
+
|
|
160
|
+
Os tokens de reset e verificação expiram em 1 hora e 24 horas, respectivamente, e são de uso único.
|
|
161
|
+
|
|
162
|
+
## 🔑 Roles & Permissions
|
|
163
|
+
|
|
164
|
+
| Role | Descrição |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `ADMIN` | acesso total ao sistema |
|
|
167
|
+
| `MANAGER` | gerencia usuários e relatórios |
|
|
168
|
+
| `USER` | acesso padrão |
|
|
169
|
+
|
|
170
|
+
Cada role tem um conjunto fixo de permissões, mapeado em `src/common/constants/role-permissions.ts`:
|
|
171
|
+
|
|
172
|
+
| Permission | ADMIN | MANAGER | USER |
|
|
173
|
+
|---|:---:|:---:|:---:|
|
|
174
|
+
| `user:create` | ✅ | ❌ | ❌ |
|
|
175
|
+
| `user:read` | ✅ | ✅ | ✅ |
|
|
176
|
+
| `user:update` | ✅ | ✅ | ❌ |
|
|
177
|
+
| `user:delete` | ✅ | ❌ | ❌ |
|
|
178
|
+
| `report:read` | ✅ | ✅ | ❌ |
|
|
179
|
+
|
|
180
|
+
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.
|
|
181
|
+
|
|
182
|
+
## 👥 Usuários: paginação, filtros e avatar
|
|
183
|
+
|
|
184
|
+
`GET /users` aceita query params pra paginar e filtrar a listagem:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
GET /users?page=2&limit=20&search=jeiel&role=ADMIN
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
| Parâmetro | Descrição |
|
|
191
|
+
|---|---|
|
|
192
|
+
| `page` | página atual (padrão: 1) |
|
|
193
|
+
| `limit` | itens por página, até 100 (padrão: 10) |
|
|
194
|
+
| `search` | busca por nome ou e-mail (case-insensitive) |
|
|
195
|
+
| `role` | filtra por `ADMIN`, `MANAGER` ou `USER` |
|
|
196
|
+
|
|
197
|
+
A resposta vem no formato `{ data, meta: { total, page, limit, totalPages } }`.
|
|
198
|
+
|
|
199
|
+
Pra trocar o avatar do usuário autenticado:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
curl -X POST http://localhost:3000/users/me/avatar \
|
|
203
|
+
-H "Authorization: Bearer <accessToken>" \
|
|
204
|
+
-F "file=@/caminho/da/foto.png"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Aceita PNG, JPEG e WEBP até 2MB; o arquivo fica salvo em `./uploads/avatars` e é servido em `/uploads/avatars/<arquivo>`.
|
|
208
|
+
|
|
209
|
+
## 🛡️ Segurança: serialização e CSRF
|
|
210
|
+
|
|
211
|
+
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()`).
|
|
212
|
+
|
|
213
|
+
- 🪵 **Observabilidade** — logs estruturados com Pino, health checks (`/health`) e métricas Prometheus (`/metrics`)
|
|
214
|
+
|
|
215
|
+
O seed cria três contas de teste, uma por role:
|
|
216
|
+
|
|
217
|
+
| E-mail | Senha | Role |
|
|
218
|
+
|---|---|---|
|
|
219
|
+
| `admin@nestforge.dev` | `admin123` | ADMIN |
|
|
220
|
+
| `manager@nestforge.dev` | `manager123` | MANAGER |
|
|
221
|
+
| `user@nestforge.dev` | `user1234` | USER |
|
|
222
|
+
|
|
223
|
+
## 📈 Observabilidade
|
|
224
|
+
|
|
225
|
+
`GET /health` retorna o status agregado da API — banco (Prisma), 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.
|
|
226
|
+
|
|
227
|
+
`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.
|
|
228
|
+
|
|
229
|
+
## 🧪 Testes
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm run test # unitários
|
|
233
|
+
npm run test:e2e # integração (e2e)
|
|
234
|
+
npm run test:cov # cobertura
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Os testes e2e (`test/*.e2e-spec.ts`) sobem a aplicação real (Nest + Prisma + 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:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
createdb nestforge_test # ou: psql -U nestforge -c "CREATE DATABASE nestforge_test;"
|
|
241
|
+
docker compose up -d postgres redis
|
|
242
|
+
npm run test:e2e
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
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).
|
|
246
|
+
|
|
247
|
+
Os testes unitários (`src/**/*.spec.ts`) rodam isolados, com Prisma e `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 que o `passwordHash` não vaza na serialização via `instanceToPlain`), `RolesGuard` e `PermissionsGuard` (liberação/bloqueio, inclusive com múltiplas permissões exigidas ao mesmo tempo) e os indicadores de saúde (`PrismaHealthIndicator`, `RedisHealthIndicator`).
|
|
248
|
+
|
|
249
|
+
Os testes unitários também cobrem `SessionService` e `SessionAuthGuard`. Quando Session/Cookies está habilitada, o teste e2e específico valida criação do cookie, persistência da autenticação entre requisições e logout.
|
|
250
|
+
|
|
251
|
+
## 📚 Documentação adicional
|
|
252
|
+
|
|
253
|
+
- [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.)
|
|
254
|
+
- [TESTING.pt-BR.md](TESTING.pt-BR.md) — como validar migrations, build, testes unitários e testes E2E
|
|
255
|
+
- [docs/adding-a-module.md](docs/adding-a-module.md) — passo a passo pra adicionar um recurso novo seguindo as convenções do projeto
|
|
256
|
+
|
|
257
|
+
## 🤝 Contribuindo
|
|
258
|
+
|
|
259
|
+
Contribuições são bem-vindas! Veja o [CONTRIBUTING.pt-BR.md](CONTRIBUTING.pt-BR.md) para o guia completo.
|
|
260
|
+
|
|
261
|
+
## 📄 Licença
|
|
262
|
+
|
|
263
|
+
Este projeto está sob a licença MIT — veja [LICENSE](LICENSE).
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
Feito por [Jeiel Alves](https://github.com/jeiel2013) · [jeieldev.com.br](https://jeieldev.com.br)
|
|
@@ -0,0 +1,75 @@
|
|
|
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] Prisma
|
|
43
|
+
- [x] PostgreSQL
|
|
44
|
+
- [x] Migrations
|
|
45
|
+
- [x] Complete seed (roles, permissions, administrator user)
|
|
46
|
+
|
|
47
|
+
## Infrastructure
|
|
48
|
+
|
|
49
|
+
- [x] Docker / docker-compose (API, Postgres, Redis, Mailpit)
|
|
50
|
+
- [x] GitHub Actions CI (build, lint, test)
|
|
51
|
+
- [ ] Automated deployment (Railway/Fly.io example)
|
|
52
|
+
|
|
53
|
+
## Observability
|
|
54
|
+
|
|
55
|
+
- [x] Structured logging with Pino
|
|
56
|
+
- [x] Health checks (`/health`)
|
|
57
|
+
- [x] Metrics (optional Prometheus)
|
|
58
|
+
|
|
59
|
+
## Jobs & Email
|
|
60
|
+
|
|
61
|
+
- [x] BullMQ queue
|
|
62
|
+
- [x] Transactional email delivery (Mailpit in development)
|
|
63
|
+
- [x] Email templates
|
|
64
|
+
|
|
65
|
+
## Tests
|
|
66
|
+
|
|
67
|
+
- [x] Unit test structure (Vitest)
|
|
68
|
+
- [x] Integration tests (auth + users)
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
- [x] Initial README
|
|
73
|
+
- [x] Complete Swagger with request/response examples
|
|
74
|
+
- [x] Architecture guide (ADR / design decisions)
|
|
75
|
+
- [x] “How to add a new module” guide
|
|
@@ -0,0 +1,65 @@
|
|
|
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] Prisma
|
|
38
|
+
- [x] PostgreSQL
|
|
39
|
+
- [x] Migrations
|
|
40
|
+
- [x] Seed completo (roles, permissions, usuário admin)
|
|
41
|
+
|
|
42
|
+
## Infra
|
|
43
|
+
- [x] Docker / docker-compose (API, Postgres, Redis, Mailpit)
|
|
44
|
+
- [x] GitHub Actions CI (build, lint, test)
|
|
45
|
+
- [ ] Deploy automatizado (exemplo com Railway/Fly.io)
|
|
46
|
+
|
|
47
|
+
## Observabilidade
|
|
48
|
+
- [x] Logs estruturados com Pino
|
|
49
|
+
- [x] Health checks (`/health`)
|
|
50
|
+
- [x] Métricas (Prometheus opcional)
|
|
51
|
+
|
|
52
|
+
## Jobs & E-mail
|
|
53
|
+
- [x] Fila com BullMQ
|
|
54
|
+
- [x] Envio de e-mail transacional (Mailpit em dev)
|
|
55
|
+
- [x] Templates de e-mail
|
|
56
|
+
|
|
57
|
+
## Testes
|
|
58
|
+
- [x] Estrutura de testes unitários (Vitest)
|
|
59
|
+
- [x] Testes de integração (auth + users)
|
|
60
|
+
|
|
61
|
+
## Documentação
|
|
62
|
+
- [x] README inicial
|
|
63
|
+
- [x] Swagger completo com exemplos de request/response
|
|
64
|
+
- [x] Guia de arquitetura (ADR / decisões de design)
|
|
65
|
+
- [x] Guia "como adicionar um novo módulo"
|