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,78 @@
|
|
|
1
|
+
version: "3.9"
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
api:
|
|
5
|
+
build:
|
|
6
|
+
context: .
|
|
7
|
+
dockerfile: Dockerfile
|
|
8
|
+
container_name: nestforge-api
|
|
9
|
+
ports:
|
|
10
|
+
- "3000:3000"
|
|
11
|
+
env_file:
|
|
12
|
+
- .env
|
|
13
|
+
depends_on:
|
|
14
|
+
# nestforge:feature:database:postgres
|
|
15
|
+
- postgres
|
|
16
|
+
# nestforge:feature:database:postgres:end
|
|
17
|
+
# nestforge:feature:database:mysql
|
|
18
|
+
- mysql
|
|
19
|
+
# nestforge:feature:database:mysql:end
|
|
20
|
+
- redis
|
|
21
|
+
volumes:
|
|
22
|
+
- ./src:/app/src
|
|
23
|
+
command: npm run start:dev
|
|
24
|
+
|
|
25
|
+
# nestforge:feature:database:postgres
|
|
26
|
+
postgres:
|
|
27
|
+
image: postgres:16-alpine
|
|
28
|
+
container_name: nestforge-postgres
|
|
29
|
+
restart: unless-stopped
|
|
30
|
+
environment:
|
|
31
|
+
POSTGRES_USER: nestforge
|
|
32
|
+
POSTGRES_PASSWORD: nestforge
|
|
33
|
+
POSTGRES_DB: nestforge
|
|
34
|
+
ports:
|
|
35
|
+
- "5432:5432"
|
|
36
|
+
volumes:
|
|
37
|
+
- postgres_data:/var/lib/postgresql/data
|
|
38
|
+
# nestforge:feature:database:postgres:end
|
|
39
|
+
|
|
40
|
+
# nestforge:feature:database:mysql
|
|
41
|
+
mysql:
|
|
42
|
+
image: mysql:8
|
|
43
|
+
container_name: nestforge-mysql
|
|
44
|
+
restart: unless-stopped
|
|
45
|
+
environment:
|
|
46
|
+
MYSQL_USER: nestforge
|
|
47
|
+
MYSQL_PASSWORD: nestforge
|
|
48
|
+
MYSQL_ROOT_PASSWORD: nestforge
|
|
49
|
+
MYSQL_DATABASE: nestforge
|
|
50
|
+
ports:
|
|
51
|
+
- "3306:3306"
|
|
52
|
+
volumes:
|
|
53
|
+
- mysql_data:/var/lib/mysql
|
|
54
|
+
# nestforge:feature:database:mysql:end
|
|
55
|
+
|
|
56
|
+
redis:
|
|
57
|
+
image: redis:7-alpine
|
|
58
|
+
container_name: nestforge-redis
|
|
59
|
+
restart: unless-stopped
|
|
60
|
+
ports:
|
|
61
|
+
- "6379:6379"
|
|
62
|
+
|
|
63
|
+
mailpit:
|
|
64
|
+
image: axllent/mailpit:latest
|
|
65
|
+
container_name: nestforge-mailpit
|
|
66
|
+
restart: unless-stopped
|
|
67
|
+
ports:
|
|
68
|
+
- "8025:8025" # UI
|
|
69
|
+
- "1025:1025" # SMTP
|
|
70
|
+
|
|
71
|
+
# nestforge:feature:database:postgres
|
|
72
|
+
volumes:
|
|
73
|
+
postgres_data:
|
|
74
|
+
# nestforge:feature:database:postgres:end
|
|
75
|
+
# nestforge:feature:database:mysql
|
|
76
|
+
volumes:
|
|
77
|
+
mysql_data:
|
|
78
|
+
# nestforge:feature:database:mysql:end
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
# Adicionando um módulo
|
|
2
|
+
|
|
3
|
+
Este guia mostra como adicionar um módulo `posts` ao projeto usando NestJS, TypeORM e Zod.
|
|
4
|
+
|
|
5
|
+
## 1. Crie a entidade
|
|
6
|
+
|
|
7
|
+
Crie `src/posts/entities/post.entity.ts`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import {
|
|
11
|
+
Column,
|
|
12
|
+
CreateDateColumn,
|
|
13
|
+
Entity,
|
|
14
|
+
JoinColumn,
|
|
15
|
+
ManyToOne,
|
|
16
|
+
PrimaryGeneratedColumn,
|
|
17
|
+
UpdateDateColumn,
|
|
18
|
+
} from 'typeorm';
|
|
19
|
+
import { UserEntity } from '../../users/entities/user.entity';
|
|
20
|
+
|
|
21
|
+
@Entity({ name: 'posts' })
|
|
22
|
+
export class PostEntity {
|
|
23
|
+
@PrimaryGeneratedColumn('uuid')
|
|
24
|
+
id!: string;
|
|
25
|
+
|
|
26
|
+
@Column({
|
|
27
|
+
type: 'varchar',
|
|
28
|
+
length: 200,
|
|
29
|
+
})
|
|
30
|
+
title!: string;
|
|
31
|
+
|
|
32
|
+
@Column({
|
|
33
|
+
type: 'text',
|
|
34
|
+
})
|
|
35
|
+
content!: string;
|
|
36
|
+
|
|
37
|
+
@Column({
|
|
38
|
+
name: 'author_id',
|
|
39
|
+
type: 'varchar',
|
|
40
|
+
length: 36,
|
|
41
|
+
})
|
|
42
|
+
authorId!: string;
|
|
43
|
+
|
|
44
|
+
@ManyToOne(() => UserEntity, {
|
|
45
|
+
onDelete: 'CASCADE',
|
|
46
|
+
})
|
|
47
|
+
@JoinColumn({
|
|
48
|
+
name: 'author_id',
|
|
49
|
+
})
|
|
50
|
+
author!: UserEntity;
|
|
51
|
+
|
|
52
|
+
@CreateDateColumn({
|
|
53
|
+
name: 'created_at',
|
|
54
|
+
})
|
|
55
|
+
createdAt!: Date;
|
|
56
|
+
|
|
57
|
+
@UpdateDateColumn({
|
|
58
|
+
name: 'updated_at',
|
|
59
|
+
})
|
|
60
|
+
updatedAt!: Date;
|
|
61
|
+
|
|
62
|
+
constructor(partial?: Partial<PostEntity>) {
|
|
63
|
+
if (partial) {
|
|
64
|
+
Object.assign(this, partial);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 2. Crie os DTOs
|
|
71
|
+
|
|
72
|
+
Crie `src/posts/dto/create-post.dto.ts`:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { z } from 'zod';
|
|
76
|
+
import { createZodDto } from 'nestjs-zod';
|
|
77
|
+
|
|
78
|
+
export const createPostSchema = z.object({
|
|
79
|
+
title: z
|
|
80
|
+
.string()
|
|
81
|
+
.min(3)
|
|
82
|
+
.max(200),
|
|
83
|
+
content: z.string().min(1),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export class CreatePostDto extends createZodDto(
|
|
87
|
+
createPostSchema,
|
|
88
|
+
) {}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Crie `src/posts/dto/update-post.dto.ts`:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { createZodDto } from 'nestjs-zod';
|
|
95
|
+
import { createPostSchema } from './create-post.dto';
|
|
96
|
+
|
|
97
|
+
export const updatePostSchema =
|
|
98
|
+
createPostSchema.partial();
|
|
99
|
+
|
|
100
|
+
export class UpdatePostDto extends createZodDto(
|
|
101
|
+
updatePostSchema,
|
|
102
|
+
) {}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 3. Crie o service
|
|
106
|
+
|
|
107
|
+
Crie `src/posts/posts.service.ts`:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import {
|
|
111
|
+
Injectable,
|
|
112
|
+
NotFoundException,
|
|
113
|
+
} from '@nestjs/common';
|
|
114
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
115
|
+
import { Repository } from 'typeorm';
|
|
116
|
+
import { PostEntity } from './entities/post.entity';
|
|
117
|
+
import { CreatePostDto } from './dto/create-post.dto';
|
|
118
|
+
import { UpdatePostDto } from './dto/update-post.dto';
|
|
119
|
+
|
|
120
|
+
@Injectable()
|
|
121
|
+
export class PostsService {
|
|
122
|
+
constructor(
|
|
123
|
+
@InjectRepository(PostEntity)
|
|
124
|
+
private readonly postsRepository: Repository<PostEntity>,
|
|
125
|
+
) {}
|
|
126
|
+
|
|
127
|
+
async create(
|
|
128
|
+
authorId: string,
|
|
129
|
+
dto: CreatePostDto,
|
|
130
|
+
) {
|
|
131
|
+
const post = this.postsRepository.create({
|
|
132
|
+
...dto,
|
|
133
|
+
authorId,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return this.postsRepository.save(post);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async findAll() {
|
|
140
|
+
return this.postsRepository.find({
|
|
141
|
+
relations: {
|
|
142
|
+
author: true,
|
|
143
|
+
},
|
|
144
|
+
order: {
|
|
145
|
+
createdAt: 'DESC',
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async findOne(id: string) {
|
|
151
|
+
const post = await this.postsRepository.findOne({
|
|
152
|
+
where: { id },
|
|
153
|
+
relations: {
|
|
154
|
+
author: true,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!post) {
|
|
159
|
+
throw new NotFoundException(
|
|
160
|
+
'Post não encontrado',
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return post;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async update(
|
|
168
|
+
id: string,
|
|
169
|
+
dto: UpdatePostDto,
|
|
170
|
+
) {
|
|
171
|
+
const post = await this.findOne(id);
|
|
172
|
+
|
|
173
|
+
Object.assign(post, dto);
|
|
174
|
+
|
|
175
|
+
return this.postsRepository.save(post);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async remove(id: string) {
|
|
179
|
+
const post = await this.findOne(id);
|
|
180
|
+
|
|
181
|
+
await this.postsRepository.remove(post);
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
message: 'Post removido com sucesso',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 4. Crie o controller
|
|
191
|
+
|
|
192
|
+
Crie `src/posts/posts.controller.ts`:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import {
|
|
196
|
+
Body,
|
|
197
|
+
Controller,
|
|
198
|
+
Delete,
|
|
199
|
+
Get,
|
|
200
|
+
Param,
|
|
201
|
+
Patch,
|
|
202
|
+
Post,
|
|
203
|
+
Req,
|
|
204
|
+
} from '@nestjs/common';
|
|
205
|
+
import { Request } from 'express';
|
|
206
|
+
import { PostsService } from './posts.service';
|
|
207
|
+
import { CreatePostDto } from './dto/create-post.dto';
|
|
208
|
+
import { UpdatePostDto } from './dto/update-post.dto';
|
|
209
|
+
|
|
210
|
+
@Controller('posts')
|
|
211
|
+
export class PostsController {
|
|
212
|
+
constructor(
|
|
213
|
+
private readonly postsService: PostsService,
|
|
214
|
+
) {}
|
|
215
|
+
|
|
216
|
+
@Post()
|
|
217
|
+
create(
|
|
218
|
+
@Req() request: Request,
|
|
219
|
+
@Body() dto: CreatePostDto,
|
|
220
|
+
) {
|
|
221
|
+
return this.postsService.create(
|
|
222
|
+
request.user.id,
|
|
223
|
+
dto,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@Get()
|
|
228
|
+
findAll() {
|
|
229
|
+
return this.postsService.findAll();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@Get(':id')
|
|
233
|
+
findOne(@Param('id') id: string) {
|
|
234
|
+
return this.postsService.findOne(id);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@Patch(':id')
|
|
238
|
+
update(
|
|
239
|
+
@Param('id') id: string,
|
|
240
|
+
@Body() dto: UpdatePostDto,
|
|
241
|
+
) {
|
|
242
|
+
return this.postsService.update(id, dto);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@Delete(':id')
|
|
246
|
+
remove(@Param('id') id: string) {
|
|
247
|
+
return this.postsService.remove(id);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Se o projeto não usa autenticação, remova `@Req()` e receba `authorId` de outra forma adequada ao domínio.
|
|
253
|
+
|
|
254
|
+
## 5. Registre o repository no módulo
|
|
255
|
+
|
|
256
|
+
Crie `src/posts/posts.module.ts`:
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import { Module } from '@nestjs/common';
|
|
260
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
261
|
+
import { PostEntity } from './entities/post.entity';
|
|
262
|
+
import { PostsController } from './posts.controller';
|
|
263
|
+
import { PostsService } from './posts.service';
|
|
264
|
+
|
|
265
|
+
@Module({
|
|
266
|
+
imports: [
|
|
267
|
+
TypeOrmModule.forFeature([
|
|
268
|
+
PostEntity,
|
|
269
|
+
]),
|
|
270
|
+
],
|
|
271
|
+
controllers: [PostsController],
|
|
272
|
+
providers: [PostsService],
|
|
273
|
+
exports: [PostsService],
|
|
274
|
+
})
|
|
275
|
+
export class PostsModule {}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Depois importe `PostsModule` em `src/app.module.ts`.
|
|
279
|
+
|
|
280
|
+
## 6. Gere e aplique a migration
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
npm run migration:generate -- src/database/migrations/AddPosts
|
|
284
|
+
npm run migration:run
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Confira o arquivo gerado antes de executar a migration em produção.
|
|
288
|
+
|
|
289
|
+
Para desfazer a última migration:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
npm run migration:revert
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## 7. Adicione testes unitários
|
|
296
|
+
|
|
297
|
+
O teste unitário deve mockar o repository:
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
import { Repository } from 'typeorm';
|
|
301
|
+
import { vi } from 'vitest';
|
|
302
|
+
import { PostsService } from './posts.service';
|
|
303
|
+
import { PostEntity } from './entities/post.entity';
|
|
304
|
+
|
|
305
|
+
const postsRepository = {
|
|
306
|
+
findOne: vi.fn(),
|
|
307
|
+
find: vi.fn(),
|
|
308
|
+
create: vi.fn(),
|
|
309
|
+
save: vi.fn(),
|
|
310
|
+
remove: vi.fn(),
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const postsService = new PostsService(
|
|
314
|
+
postsRepository as unknown as Repository<PostEntity>,
|
|
315
|
+
);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Dessa forma, o teste não precisa iniciar o Nest nem conectar ao banco.
|
|
319
|
+
|
|
320
|
+
## 8. Atualize a limpeza E2E
|
|
321
|
+
|
|
322
|
+
Em `test/utils/clean-database.ts`, exclua posts antes de usuários:
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
await manager
|
|
326
|
+
.createQueryBuilder()
|
|
327
|
+
.delete()
|
|
328
|
+
.from(PostEntity)
|
|
329
|
+
.execute();
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
A ordem é importante por causa da chave estrangeira `posts.author_id`.
|
|
333
|
+
|
|
334
|
+
## 9. Use transações quando necessário
|
|
335
|
+
|
|
336
|
+
Quando várias operações precisarem ser atômicas, injete `DataSource`:
|
|
337
|
+
|
|
338
|
+
```ts
|
|
339
|
+
constructor(
|
|
340
|
+
private readonly dataSource: DataSource,
|
|
341
|
+
) {}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
E execute:
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
await this.dataSource.transaction(
|
|
348
|
+
async (manager) => {
|
|
349
|
+
await manager.save(...);
|
|
350
|
+
await manager.update(...);
|
|
351
|
+
},
|
|
352
|
+
);
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Se uma operação falhar, a transação inteira será revertida.
|
|
356
|
+
|
|
357
|
+
## Checklist
|
|
358
|
+
|
|
359
|
+
- [ ] Entidade criada
|
|
360
|
+
- [ ] DTOs Zod criados
|
|
361
|
+
- [ ] Service usa `Repository<Entity>`
|
|
362
|
+
- [ ] Repository registrado com `TypeOrmModule.forFeature`
|
|
363
|
+
- [ ] Controller criado
|
|
364
|
+
- [ ] Módulo importado no `AppModule`
|
|
365
|
+
- [ ] Migration gerada e revisada
|
|
366
|
+
- [ ] Migration aplicada
|
|
367
|
+
- [ ] Testes unitários adicionados
|
|
368
|
+
- [ ] Limpeza dos testes E2E atualizada
|
|
369
|
+
- [ ] Swagger e permissões adicionados, quando aplicáveis
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Marcadores de features (feature markers)
|
|
2
|
+
|
|
3
|
+
O `templates/typeorm` é usado tanto como projeto standalone quanto como fonte para a CLI (`packages/cli`) gerar projetos.
|
|
4
|
+
|
|
5
|
+
Se você está adicionando código ligado a um recurso que já existe como pergunta na CLI (ou propondo um recurso novo opcional), marque o trecho seguindo esta convenção.
|
|
6
|
+
|
|
7
|
+
## Marcador de bloco
|
|
8
|
+
|
|
9
|
+
Envolve um trecho de código (uma ou várias linhas) dentro de um arquivo que tem outras coisas não-opcionais também.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// nestforge:feature:swagger
|
|
13
|
+
@ApiTags('users')
|
|
14
|
+
// nestforge:feature:swagger:end
|
|
15
|
+
@Controller('users')
|
|
16
|
+
export class UsersController {
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Recurso **habilitado**: a CLI remove só as duas linhas de marcador, o `@ApiTags('users')` fica.
|
|
20
|
+
- Recurso **desabilitado**: a CLI remove o bloco inteiro (marcador + `@ApiTags('users')`).
|
|
21
|
+
|
|
22
|
+
O nome depois de `nestforge:feature:` tem que ser exatamente o mesmo nas duas linhas (abertura e `:end`), e bater com o nome usado no array `features` da CLI (`docker`, `swagger`, `validation`, `redis`, `rbac`).
|
|
23
|
+
|
|
24
|
+
Funciona em qualquer arquivo cuja linguagem use `//` para comentário (`.ts`, `.js`). **Não funciona em JSON** (`package.json`) — pra dependências, ver a seção final deste documento.
|
|
25
|
+
|
|
26
|
+
## Marcador de arquivo inteiro
|
|
27
|
+
|
|
28
|
+
Quando o arquivo **inteiro** só faz sentido se o recurso estiver ligado (ex: `src/mail/mail.service.ts`, que só existe por causa do Redis/BullMQ), marque a primeira linha do arquivo:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// nestforge:feature-file:redis
|
|
32
|
+
import { Injectable } from '@nestjs/common';
|
|
33
|
+
// ...resto do arquivo normalmente
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- Recurso **habilitado**: a CLI remove só essa primeira linha, o resto do arquivo fica intacto.
|
|
37
|
+
- Recurso **desabilitado**: a CLI apaga o arquivo inteiro.
|
|
38
|
+
|
|
39
|
+
Se, depois de remover arquivos, uma pasta ficar vazia (ex: `src/mail/` inteira desapareceu), a CLI remove a pasta também — não precisa se preocupar em limpar pasta manualmente.
|
|
40
|
+
|
|
41
|
+
## Dependências no `package.json`
|
|
42
|
+
|
|
43
|
+
JSON não aceita comentário, então marcador não funciona ali. Em vez disso, o mapeamento fica direto no código da CLI: `packages/cli/src/features/dependencies.ts`, no objeto `FEATURE_DEPENDENCIES`. Se seu recurso opcional adiciona uma dependência nova ao `package.json` do template, adicione ela nesse mapa também.
|
|
44
|
+
|
|
45
|
+
## Checklist ao adicionar um recurso opcional novo
|
|
46
|
+
|
|
47
|
+
- [ ] Todo trecho de código exclusivo do recurso está marcado (bloco ou arquivo inteiro)
|
|
48
|
+
- [ ] O nome do marcador bate com o valor usado em `features` na CLI (`packages/cli/src/prompts.ts`)
|
|
49
|
+
- [ ] Dependências novas do `package.json` estão em `FEATURE_DEPENDENCIES` (`packages/cli/src/features/dependencies.ts`)
|
|
50
|
+
- [ ] Testado gerando o projeto com o recurso ligado **e** desligado — o projeto tem que compilar/rodar dos dois jeitos
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nestforge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Production-ready NestJS starter with TypeORM, Authentication, Docker, Testing, CI/CD and Clean Architecture.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Jeiel Alves <https://github.com/jeiel2013>",
|
|
7
|
+
"private": true,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "nest build",
|
|
10
|
+
"start": "nest start",
|
|
11
|
+
"start:dev": "nest start --watch",
|
|
12
|
+
"start:debug": "nest start --debug --watch",
|
|
13
|
+
"start:prod": "node dist/main.js",
|
|
14
|
+
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"test:cov": "vitest run --coverage",
|
|
19
|
+
"test:e2e": "dotenv -e .env.test -- vitest run --config ./vitest.e2e.config.ts",
|
|
20
|
+
"typeorm": "dotenv -e .env -- typeorm-ts-node-commonjs -d src/database/data-source.ts",
|
|
21
|
+
"migration:generate": "npm run typeorm -- migration:generate",
|
|
22
|
+
"migration:create": "typeorm migration:create",
|
|
23
|
+
"migration:run": "npm run typeorm -- migration:run",
|
|
24
|
+
"migration:revert": "npm run typeorm -- migration:revert",
|
|
25
|
+
"pretest:e2e": "dotenv -e .env.test -- typeorm-ts-node-commonjs -d src/database/data-source.ts migration:run",
|
|
26
|
+
"seed": "dotenv -e .env -- ts-node src/database/seed.ts"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@nestjs/common": "^11.0.0",
|
|
30
|
+
"@nestjs/config": "^4.0.0",
|
|
31
|
+
"@nestjs/core": "^11.0.0",
|
|
32
|
+
"@nestjs/jwt": "^11.0.0",
|
|
33
|
+
"@nestjs/passport": "^11.0.0",
|
|
34
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
35
|
+
"@nestjs/swagger": "^11.0.0",
|
|
36
|
+
"@nestjs/throttler": "^6.5.0",
|
|
37
|
+
"@nestjs/bullmq": "^11.0.0",
|
|
38
|
+
"@nestjs/terminus": "^11.0.0",
|
|
39
|
+
"express-session": "^1.19.0",
|
|
40
|
+
"bullmq": "^5.0.0",
|
|
41
|
+
"bcryptjs": "^2.4.3",
|
|
42
|
+
"class-transformer": "^0.5.1",
|
|
43
|
+
"helmet": "^8.0.0",
|
|
44
|
+
"ioredis": "^5.4.1",
|
|
45
|
+
"multer": "^1.4.5-lts.1",
|
|
46
|
+
"nestjs-pino": "^4.1.0",
|
|
47
|
+
"nestjs-zod": "^3.0.0",
|
|
48
|
+
"nodemailer": "^6.9.15",
|
|
49
|
+
"passport": "^0.7.0",
|
|
50
|
+
"passport-jwt": "^4.0.1",
|
|
51
|
+
"passport-google-oauth20": "^2.0.0",
|
|
52
|
+
"passport-github2": "^0.1.12",
|
|
53
|
+
"pino-http": "^10.3.0",
|
|
54
|
+
"prom-client": "^15.1.3",
|
|
55
|
+
"reflect-metadata": "^0.2.2",
|
|
56
|
+
"rxjs": "^7.8.1",
|
|
57
|
+
"zod": "^3.23.8",
|
|
58
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
59
|
+
"typeorm": "^0.3.31",
|
|
60
|
+
"pg": "^8.23.0",
|
|
61
|
+
"mysql2": "^3.24.2",
|
|
62
|
+
"better-sqlite3": "^12.11.1",
|
|
63
|
+
"connect-typeorm": "^2.0.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@nestjs/cli": "^11.0.0",
|
|
67
|
+
"@nestjs/schematics": "^11.0.0",
|
|
68
|
+
"@nestjs/testing": "^11.0.0",
|
|
69
|
+
"@types/bcryptjs": "^2.4.6",
|
|
70
|
+
"@types/express-session": "^1.19.0",
|
|
71
|
+
"@types/multer": "^1.4.12",
|
|
72
|
+
"@types/node": "^22.0.0",
|
|
73
|
+
"@types/nodemailer": "^6.4.16",
|
|
74
|
+
"@types/passport-jwt": "^4.0.1",
|
|
75
|
+
"@types/passport-google-oauth20": "^2.0.16",
|
|
76
|
+
"@types/passport-github2": "^1.2.9",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
78
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
79
|
+
"@vitest/coverage-v8": "^2.1.0",
|
|
80
|
+
"@swc/core": "^1.13.0",
|
|
81
|
+
"unplugin-swc": "^1.5.10",
|
|
82
|
+
"eslint": "^9.0.0",
|
|
83
|
+
"eslint-config-prettier": "^9.1.0",
|
|
84
|
+
"pino-pretty": "^13.1.3",
|
|
85
|
+
"prettier": "^3.3.3",
|
|
86
|
+
"supertest": "^7.0.0",
|
|
87
|
+
"@types/supertest": "^6.0.2",
|
|
88
|
+
"dotenv-cli": "^7.4.2",
|
|
89
|
+
"ts-node": "^10.9.2",
|
|
90
|
+
"typescript": "^5.6.0",
|
|
91
|
+
"vitest": "^2.1.0",
|
|
92
|
+
"@types/pg": "^8.23.1",
|
|
93
|
+
"@types/better-sqlite3": "^7.6.13"
|
|
94
|
+
},
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": ">=20"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
|
3
|
+
import { ThrottlerModule } from '@nestjs/throttler';
|
|
4
|
+
// nestforge:feature:redis
|
|
5
|
+
import { BullModule } from '@nestjs/bullmq';
|
|
6
|
+
// nestforge:feature:redis:end
|
|
7
|
+
import { LoggerModule } from 'nestjs-pino';
|
|
8
|
+
// nestforge:feature:auth:enabled
|
|
9
|
+
import { AuthModule } from './auth/auth.module';
|
|
10
|
+
import { UsersModule } from './users/users.module';
|
|
11
|
+
// nestforge:feature:auth:enabled:end
|
|
12
|
+
import { DatabaseModule } from './database/database.module';
|
|
13
|
+
// nestforge:feature:redis
|
|
14
|
+
import { MailModule } from './mail/mail.module';
|
|
15
|
+
// nestforge:feature:redis:end
|
|
16
|
+
import { HealthModule } from './health/health.module';
|
|
17
|
+
import { MetricsModule } from './metrics/metrics.module';
|
|
18
|
+
// nestforge:feature:auth:session
|
|
19
|
+
import { CsrfMiddleware } from './common/middleware/csrf.middleware';
|
|
20
|
+
// nestforge:feature:auth:session:end
|
|
21
|
+
import { validateEnv } from './config/env.validation';
|
|
22
|
+
|
|
23
|
+
@Module({
|
|
24
|
+
imports: [
|
|
25
|
+
ConfigModule.forRoot({
|
|
26
|
+
isGlobal: true,
|
|
27
|
+
validate: validateEnv,
|
|
28
|
+
}),
|
|
29
|
+
LoggerModule.forRoot({
|
|
30
|
+
pinoHttp: {
|
|
31
|
+
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
|
|
32
|
+
transport:
|
|
33
|
+
process.env.NODE_ENV === 'development'
|
|
34
|
+
? { target: 'pino-pretty', options: { singleLine: true } }
|
|
35
|
+
: undefined,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
ThrottlerModule.forRoot([
|
|
39
|
+
{
|
|
40
|
+
ttl: Number(process.env.THROTTLE_TTL ?? 60) * 1000,
|
|
41
|
+
limit: Number(process.env.THROTTLE_LIMIT ?? 100),
|
|
42
|
+
},
|
|
43
|
+
]),
|
|
44
|
+
// nestforge:feature:redis
|
|
45
|
+
BullModule.forRoot({
|
|
46
|
+
connection: {
|
|
47
|
+
host: process.env.REDIS_HOST ?? 'localhost',
|
|
48
|
+
port: Number(process.env.REDIS_PORT ?? 6379),
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
// nestforge:feature:redis:end
|
|
52
|
+
DatabaseModule,
|
|
53
|
+
// nestforge:feature:auth:enabled
|
|
54
|
+
AuthModule,
|
|
55
|
+
UsersModule,
|
|
56
|
+
// nestforge:feature:auth:enabled:end
|
|
57
|
+
// nestforge:feature:redis
|
|
58
|
+
MailModule,
|
|
59
|
+
// nestforge:feature:redis:end
|
|
60
|
+
HealthModule,
|
|
61
|
+
MetricsModule,
|
|
62
|
+
],
|
|
63
|
+
})
|
|
64
|
+
export class AppModule implements NestModule {
|
|
65
|
+
configure(consumer: MiddlewareConsumer) {
|
|
66
|
+
// nestforge:feature:auth:session
|
|
67
|
+
if (process.env.ENABLE_CSRF === 'true') {
|
|
68
|
+
consumer.apply(CsrfMiddleware).forRoutes('*');
|
|
69
|
+
}
|
|
70
|
+
// nestforge:feature:auth:session:end
|
|
71
|
+
}
|
|
72
|
+
}
|