@node-initializr/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/dist/generate.d.ts +12 -0
- package/dist/generate.js +77 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +14 -0
- package/dist/template-engine.d.ts +24 -0
- package/dist/template-engine.js +472 -0
- package/dist/templates/arch-clean/express/src/application/use-cases/get-users.use-case.hbs +39 -0
- package/dist/templates/arch-clean/express/src/config/env.hbs +4 -0
- package/dist/templates/arch-clean/express/src/domain/entities/user.entity.hbs +7 -0
- package/dist/templates/arch-clean/express/src/index.hbs +66 -0
- package/dist/templates/arch-clean/express/src/infrastructure/http/health.routes.hbs +7 -0
- package/dist/templates/arch-clean/express/src/infrastructure/http/users.routes.hbs +9 -0
- package/dist/templates/arch-clean/express/src/shared/errors/app.error.hbs +5 -0
- package/dist/templates/arch-clean/fastify/src/application/use-cases/get-users.use-case.hbs +39 -0
- package/dist/templates/arch-clean/fastify/src/domain/entities/user.entity.hbs +7 -0
- package/dist/templates/arch-clean/fastify/src/index.hbs +53 -0
- package/dist/templates/arch-clean/fastify/src/infrastructure/http/routes.hbs +8 -0
- package/dist/templates/arch-clean/fastify/src/shared/errors/app.error.hbs +5 -0
- package/dist/templates/arch-clean/nestjs/src/app.module.ts.hbs +58 -0
- package/dist/templates/arch-clean/nestjs/src/application/use-cases/get-users.use-case.ts.hbs +14 -0
- package/dist/templates/arch-clean/nestjs/src/config/config.module.ts.hbs +4 -0
- package/dist/templates/arch-clean/nestjs/src/domain/entities/user.entity.ts.hbs +7 -0
- package/dist/templates/arch-clean/nestjs/src/domain/repositories/user.repository.ts.hbs +7 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/http/health.controller.ts.hbs +11 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/http/users.controller.ts.hbs +22 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/persistence/drizzle-user.repository.ts.hbs +15 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/persistence/in-memory-user.repository.ts.hbs +10 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/persistence/prisma-user.repository.ts.hbs +14 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/persistence/sequelize-user.repository.ts.hbs +18 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/persistence/typeorm-user.repository.ts.hbs +19 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/prisma/prisma.module.ts.hbs +6 -0
- package/dist/templates/arch-clean/nestjs/src/infrastructure/prisma/prisma.service.ts.hbs +8 -0
- package/dist/templates/arch-clean/nestjs/src/main.ts.hbs +21 -0
- package/dist/templates/arch-clean/nestjs/src/shared/errors/app.error.ts.hbs +9 -0
- package/dist/templates/arch-clean/nestjs/tests/health.spec.ts.hbs +17 -0
- package/dist/templates/arch-modular/express/src/index.hbs +46 -0
- package/dist/templates/arch-modular/express/src/infra/database.hbs +3 -0
- package/dist/templates/arch-modular/express/src/modules/health/health.routes.hbs +7 -0
- package/dist/templates/arch-modular/express/src/modules/users/users.routes.hbs +55 -0
- package/dist/templates/arch-modular/express/src/shared/constants.hbs +1 -0
- package/dist/templates/arch-modular/fastify/src/index.hbs +33 -0
- package/dist/templates/arch-modular/fastify/src/infra/database.hbs +3 -0
- package/dist/templates/arch-modular/fastify/src/modules/health/health.routes.hbs +9 -0
- package/dist/templates/arch-modular/fastify/src/modules/users/users.routes.hbs +48 -0
- package/dist/templates/arch-modular/fastify/src/shared/constants.hbs +1 -0
- package/dist/templates/arch-modular/nestjs/src/app.module.ts.hbs +63 -0
- package/dist/templates/arch-modular/nestjs/src/config/config.module.ts.hbs +4 -0
- package/dist/templates/arch-modular/nestjs/src/infra/prisma/prisma.module.ts.hbs +9 -0
- package/dist/templates/arch-modular/nestjs/src/infra/prisma/prisma.service.ts.hbs +13 -0
- package/dist/templates/arch-modular/nestjs/src/main.ts.hbs +28 -0
- package/dist/templates/arch-modular/nestjs/src/modules/health/health.controller.ts.hbs +17 -0
- package/dist/templates/arch-modular/nestjs/src/modules/health/health.module.ts.hbs +7 -0
- package/dist/templates/arch-modular/nestjs/src/modules/users/users.controller.ts.hbs +24 -0
- package/dist/templates/arch-modular/nestjs/src/modules/users/users.module.ts.hbs +10 -0
- package/dist/templates/arch-modular/nestjs/src/modules/users/users.service.ts.hbs +60 -0
- package/dist/templates/arch-modular/nestjs/src/shared/constants.ts.hbs +1 -0
- package/dist/templates/arch-modular/nestjs/tests/health.spec.ts.hbs +16 -0
- package/dist/templates/arch-mvc/express/src/controllers/health.controller.hbs +7 -0
- package/dist/templates/arch-mvc/express/src/controllers/users.controller.hbs +10 -0
- package/dist/templates/arch-mvc/express/src/index.hbs +60 -0
- package/dist/templates/arch-mvc/express/src/models/user.model.hbs +7 -0
- package/dist/templates/arch-mvc/express/src/services/users.service.hbs +39 -0
- package/dist/templates/arch-mvc/fastify/src/controllers/users.controller.hbs +9 -0
- package/dist/templates/arch-mvc/fastify/src/index.hbs +53 -0
- package/dist/templates/arch-mvc/fastify/src/models/user.model.hbs +7 -0
- package/dist/templates/arch-mvc/fastify/src/services/users.service.hbs +39 -0
- package/dist/templates/arch-mvc/nestjs/src/app.module.ts.hbs +44 -0
- package/dist/templates/arch-mvc/nestjs/src/config/config.module.ts.hbs +4 -0
- package/dist/templates/arch-mvc/nestjs/src/controllers/health.controller.ts.hbs +11 -0
- package/dist/templates/arch-mvc/nestjs/src/controllers/users.controller.ts.hbs +22 -0
- package/dist/templates/arch-mvc/nestjs/src/infra/prisma/prisma.module.ts.hbs +6 -0
- package/dist/templates/arch-mvc/nestjs/src/infra/prisma/prisma.service.ts.hbs +8 -0
- package/dist/templates/arch-mvc/nestjs/src/main.ts.hbs +21 -0
- package/dist/templates/arch-mvc/nestjs/src/models/user.model.ts.hbs +7 -0
- package/dist/templates/arch-mvc/nestjs/src/services/users.service.ts.hbs +61 -0
- package/dist/templates/arch-mvc/nestjs/tests/health.spec.ts.hbs +17 -0
- package/dist/templates/base-express/.env.example.hbs +21 -0
- package/dist/templates/base-express/.gitignore.hbs +6 -0
- package/dist/templates/base-express/README.md.hbs +10 -0
- package/dist/templates/base-express/docker/Dockerfile.hbs +21 -0
- package/dist/templates/base-express/docker/docker-compose.yml.hbs +61 -0
- package/dist/templates/base-express/drizzle/drizzle.config.hbs +10 -0
- package/dist/templates/base-express/github-actions/ci.yml.hbs +40 -0
- package/dist/templates/base-express/package.json.hbs +54 -0
- package/dist/templates/base-express/prisma/schema.prisma.hbs +16 -0
- package/dist/templates/base-express/tests/health.test.hbs +8 -0
- package/dist/templates/base-express/tsconfig.json.hbs +13 -0
- package/dist/templates/base-fastify/.env.example.hbs +21 -0
- package/dist/templates/base-fastify/.gitignore.hbs +6 -0
- package/dist/templates/base-fastify/README.md.hbs +10 -0
- package/dist/templates/base-fastify/docker/Dockerfile.hbs +21 -0
- package/dist/templates/base-fastify/docker/docker-compose.yml.hbs +61 -0
- package/dist/templates/base-fastify/drizzle/drizzle.config.hbs +10 -0
- package/dist/templates/base-fastify/github-actions/ci.yml.hbs +40 -0
- package/dist/templates/base-fastify/package.json.hbs +50 -0
- package/dist/templates/base-fastify/prisma/schema.prisma.hbs +16 -0
- package/dist/templates/base-fastify/tests/health.test.hbs +8 -0
- package/dist/templates/base-fastify/tsconfig.json.hbs +13 -0
- package/dist/templates/base-nestjs/.env.example.hbs +24 -0
- package/dist/templates/base-nestjs/.gitignore.hbs +10 -0
- package/dist/templates/base-nestjs/README.md.hbs +46 -0
- package/dist/templates/base-nestjs/docker/Dockerfile.hbs +21 -0
- package/dist/templates/base-nestjs/docker/docker-compose.yml.hbs +69 -0
- package/dist/templates/base-nestjs/drizzle/drizzle.config.ts.hbs +10 -0
- package/dist/templates/base-nestjs/github-actions/ci.yml.hbs +38 -0
- package/dist/templates/base-nestjs/nest-cli.json.hbs +8 -0
- package/dist/templates/base-nestjs/package.json.hbs +65 -0
- package/dist/templates/base-nestjs/prisma/schema.prisma.hbs +16 -0
- package/dist/templates/base-nestjs/tsconfig.json.hbs +19 -0
- package/dist/templates/shared-express/src/infra/auth/clerk.middleware.hbs +12 -0
- package/dist/templates/shared-express/src/infra/auth/jwt.middleware.hbs +18 -0
- package/dist/templates/shared-express/src/infra/drizzle/client.hbs +18 -0
- package/dist/templates/shared-express/src/infra/drizzle/schema.hbs +22 -0
- package/dist/templates/shared-express/src/infra/prisma/client.hbs +15 -0
- package/dist/templates/shared-express/src/infra/sequelize/models/user.model.ts.hbs +22 -0
- package/dist/templates/shared-express/src/infra/sequelize/sequelize.ts.hbs +16 -0
- package/dist/templates/shared-express/src/infra/swagger/setup.hbs +19 -0
- package/dist/templates/shared-express/src/infra/typeorm/data-source.hbs +17 -0
- package/dist/templates/shared-express/src/infra/typeorm/entities/user.entity.hbs +25 -0
- package/dist/templates/shared-fastify/src/infra/auth/clerk.middleware.hbs +16 -0
- package/dist/templates/shared-fastify/src/infra/auth/jwt.middleware.hbs +14 -0
- package/dist/templates/shared-fastify/src/infra/drizzle/client.hbs +18 -0
- package/dist/templates/shared-fastify/src/infra/drizzle/schema.hbs +22 -0
- package/dist/templates/shared-fastify/src/infra/prisma/client.hbs +15 -0
- package/dist/templates/shared-fastify/src/infra/sequelize/models/user.model.ts.hbs +22 -0
- package/dist/templates/shared-fastify/src/infra/sequelize/sequelize.ts.hbs +16 -0
- package/dist/templates/shared-fastify/src/infra/swagger/setup.hbs +16 -0
- package/dist/templates/shared-fastify/src/infra/typeorm/data-source.hbs +17 -0
- package/dist/templates/shared-fastify/src/infra/typeorm/entities/user.entity.hbs +25 -0
- package/dist/templates/shared-nestjs/src/infra/auth/clerk/clerk-auth.guard.ts.hbs +25 -0
- package/dist/templates/shared-nestjs/src/infra/auth/jwt/jwt-auth.guard.ts.hbs +5 -0
- package/dist/templates/shared-nestjs/src/infra/auth/jwt/jwt.module.ts.hbs +17 -0
- package/dist/templates/shared-nestjs/src/infra/auth/jwt/jwt.strategy.ts.hbs +18 -0
- package/dist/templates/shared-nestjs/src/infra/drizzle/drizzle.module.ts.hbs +9 -0
- package/dist/templates/shared-nestjs/src/infra/drizzle/drizzle.service.ts.hbs +31 -0
- package/dist/templates/shared-nestjs/src/infra/drizzle/schema.ts.hbs +22 -0
- package/dist/templates/shared-nestjs/src/infra/sequelize/models/user.model.ts.hbs +22 -0
- package/dist/templates/shared-nestjs/src/infra/sequelize/sequelize.module.ts.hbs +18 -0
- package/dist/templates/shared-nestjs/src/infra/typeorm/entities/user.entity.ts.hbs +25 -0
- package/dist/templates/shared-nestjs/src/infra/typeorm/typeorm.module.ts.hbs +18 -0
- package/dist/templates/shared-nestjs/src/infrastructure/drizzle/drizzle.module.ts.hbs +9 -0
- package/dist/templates/shared-nestjs/src/infrastructure/drizzle/drizzle.service.ts.hbs +31 -0
- package/dist/templates/shared-nestjs/src/infrastructure/drizzle/schema.ts.hbs +22 -0
- package/dist/templates/shared-nestjs/src/infrastructure/sequelize/models/user.model.ts.hbs +22 -0
- package/dist/templates/shared-nestjs/src/infrastructure/sequelize/sequelize.module.ts.hbs +18 -0
- package/dist/templates/shared-nestjs/src/infrastructure/typeorm/entities/user.entity.ts.hbs +25 -0
- package/dist/templates/shared-nestjs/src/infrastructure/typeorm/typeorm.module.ts.hbs +18 -0
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +41 -0
- package/dist/zip.d.ts +2 -0
- package/dist/zip.js +20 -0
- package/package.json +37 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
NODE_ENV=development
|
|
2
|
+
PORT=3000
|
|
3
|
+
{{#if usePostgres}}
|
|
4
|
+
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/{{projectSlug}}
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if useMysql}}
|
|
7
|
+
DATABASE_URL=mysql://root:root@localhost:3306/{{projectSlug}}
|
|
8
|
+
{{/if}}
|
|
9
|
+
{{#if useMongodb}}
|
|
10
|
+
DATABASE_URL=mongodb://localhost:27017/{{projectSlug}}
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{#if hasRedis}}
|
|
13
|
+
REDIS_URL=redis://localhost:6379
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#if useJwt}}
|
|
16
|
+
JWT_SECRET=change-me-in-production
|
|
17
|
+
JWT_EXPIRES_IN=7d
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{#if useClerk}}
|
|
20
|
+
CLERK_SECRET_KEY=sk_test_xxx
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if useRabbitmq}}
|
|
23
|
+
RABBITMQ_URL=amqp://guest:guest@localhost:5672
|
|
24
|
+
{{/if}}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# {{projectSlug}}
|
|
2
|
+
|
|
3
|
+
{{description}}
|
|
4
|
+
|
|
5
|
+
Projeto gerado pelo [Node Initializr](https://github.com/node-initializr).
|
|
6
|
+
|
|
7
|
+
## Stack
|
|
8
|
+
|
|
9
|
+
| Tecnologia | Escolha |
|
|
10
|
+
|------------|---------|
|
|
11
|
+
| Framework | {{framework}} |
|
|
12
|
+
| Linguagem | {{language}} |
|
|
13
|
+
| Arquitetura | {{architecture}} |
|
|
14
|
+
| Banco | {{database}} |
|
|
15
|
+
| ORM | {{orm}} |
|
|
16
|
+
| Auth | {{auth}} |
|
|
17
|
+
| Mensageria | {{messageBroker}} |
|
|
18
|
+
| Redis | {{#if hasRedis}}Sim{{else}}Não{{/if}} |
|
|
19
|
+
| Pacotes | {{packageManager}} |
|
|
20
|
+
|
|
21
|
+
## Como rodar
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
{{pmInstallDev}}
|
|
25
|
+
{{#if usePrisma}}
|
|
26
|
+
cp .env.example .env
|
|
27
|
+
{{#if isPnpm}}pnpm run db:generate
|
|
28
|
+
pnpm run db:migrate{{else}}{{#if isYarn}}yarn db:generate
|
|
29
|
+
yarn db:migrate{{else}}npm run db:generate
|
|
30
|
+
npm run db:migrate{{/if}}{{/if}}
|
|
31
|
+
{{/if}}
|
|
32
|
+
{{#if docker}}
|
|
33
|
+
docker compose up -d
|
|
34
|
+
{{/if}}
|
|
35
|
+
{{pmRunDev}}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Estrutura
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
src/
|
|
42
|
+
├── modules/ # Módulos de domínio
|
|
43
|
+
├── shared/ # Utilitários compartilhados
|
|
44
|
+
├── infra/ # Integrações externas
|
|
45
|
+
└── config/ # Configuração da aplicação
|
|
46
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
FROM node:{{nodeVersion}}-alpine
|
|
2
|
+
WORKDIR /app
|
|
3
|
+
ENV NODE_ENV=production
|
|
4
|
+
|
|
5
|
+
{{#if isPnpm}}RUN corepack enable
|
|
6
|
+
COPY package.json ./
|
|
7
|
+
RUN pnpm install --prod
|
|
8
|
+
{{else}}{{#if isYarn}}COPY package.json yarn.lock* ./
|
|
9
|
+
RUN yarn install --frozen-lockfile --production
|
|
10
|
+
{{else}}COPY package*.json ./
|
|
11
|
+
RUN npm ci --omit=dev
|
|
12
|
+
{{/if}}{{/if}}COPY . .
|
|
13
|
+
{{#if usePrisma}}
|
|
14
|
+
RUN npx prisma generate
|
|
15
|
+
{{/if}}
|
|
16
|
+
{{#if isTypescript}}
|
|
17
|
+
RUN {{pmRunBuild}}
|
|
18
|
+
{{/if}}
|
|
19
|
+
|
|
20
|
+
EXPOSE 3000
|
|
21
|
+
CMD ["node", "dist/main.js"]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
services:
|
|
2
|
+
app:
|
|
3
|
+
build: ..
|
|
4
|
+
ports:
|
|
5
|
+
- "3000:3000"
|
|
6
|
+
env_file:
|
|
7
|
+
- ../.env
|
|
8
|
+
depends_on:
|
|
9
|
+
{{#if hasDatabase}}
|
|
10
|
+
db:
|
|
11
|
+
condition: service_healthy
|
|
12
|
+
{{/if}}
|
|
13
|
+
{{#if needsRedis}}
|
|
14
|
+
redis:
|
|
15
|
+
condition: service_started
|
|
16
|
+
{{/if}}
|
|
17
|
+
|
|
18
|
+
{{#if usePostgres}}
|
|
19
|
+
db:
|
|
20
|
+
image: postgres:16-alpine
|
|
21
|
+
environment:
|
|
22
|
+
POSTGRES_USER: postgres
|
|
23
|
+
POSTGRES_PASSWORD: postgres
|
|
24
|
+
POSTGRES_DB: {{projectSlug}}
|
|
25
|
+
ports:
|
|
26
|
+
- "5432:5432"
|
|
27
|
+
healthcheck:
|
|
28
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
29
|
+
interval: 5s
|
|
30
|
+
timeout: 5s
|
|
31
|
+
retries: 5
|
|
32
|
+
{{/if}}
|
|
33
|
+
|
|
34
|
+
{{#if useMysql}}
|
|
35
|
+
db:
|
|
36
|
+
image: mysql:8
|
|
37
|
+
environment:
|
|
38
|
+
MYSQL_ROOT_PASSWORD: root
|
|
39
|
+
MYSQL_DATABASE: {{projectSlug}}
|
|
40
|
+
ports:
|
|
41
|
+
- "3306:3306"
|
|
42
|
+
healthcheck:
|
|
43
|
+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
|
|
44
|
+
interval: 5s
|
|
45
|
+
timeout: 5s
|
|
46
|
+
retries: 5
|
|
47
|
+
{{/if}}
|
|
48
|
+
|
|
49
|
+
{{#if useMongodb}}
|
|
50
|
+
db:
|
|
51
|
+
image: mongo:7
|
|
52
|
+
ports:
|
|
53
|
+
- "27017:27017"
|
|
54
|
+
{{/if}}
|
|
55
|
+
|
|
56
|
+
{{#if needsRedis}}
|
|
57
|
+
redis:
|
|
58
|
+
image: redis:7-alpine
|
|
59
|
+
ports:
|
|
60
|
+
- "6379:6379"
|
|
61
|
+
{{/if}}
|
|
62
|
+
|
|
63
|
+
{{#if useRabbitmq}}
|
|
64
|
+
rabbitmq:
|
|
65
|
+
image: rabbitmq:3-management-alpine
|
|
66
|
+
ports:
|
|
67
|
+
- "5672:5672"
|
|
68
|
+
- "15672:15672"
|
|
69
|
+
{{/if}}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from 'drizzle-kit';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
schema: './src/{{#if isCleanArch}}infrastructure{{else}}infra{{/if}}/drizzle/schema.ts',
|
|
5
|
+
out: './drizzle/migrations',
|
|
6
|
+
dialect: '{{#if usePostgres}}postgresql{{/if}}{{#if useMysql}}mysql{{/if}}',
|
|
7
|
+
dbCredentials: {
|
|
8
|
+
url: process.env.DATABASE_URL!,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
{{#if isPnpm}} - uses: pnpm/action-setup@v4
|
|
15
|
+
with:
|
|
16
|
+
version: 9
|
|
17
|
+
- uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: '{{nodeVersion}}'
|
|
20
|
+
cache: pnpm
|
|
21
|
+
- run: {{pmInstall}}
|
|
22
|
+
{{else}}{{#if isYarn}} - uses: actions/setup-node@v4
|
|
23
|
+
with:
|
|
24
|
+
node-version: '{{nodeVersion}}'
|
|
25
|
+
cache: yarn
|
|
26
|
+
- run: {{pmInstall}}
|
|
27
|
+
{{else}} - uses: actions/setup-node@v4
|
|
28
|
+
with:
|
|
29
|
+
node-version: '{{nodeVersion}}'
|
|
30
|
+
cache: npm
|
|
31
|
+
- run: {{pmInstall}}
|
|
32
|
+
{{/if}}{{/if}}{{#if usePrisma}}
|
|
33
|
+
- run: npx prisma generate
|
|
34
|
+
{{/if}}
|
|
35
|
+
- run: {{pmRunBuild}}
|
|
36
|
+
{{#if jest}}
|
|
37
|
+
- run: {{pmRunTest}}
|
|
38
|
+
{{/if}}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectSlug}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "{{description}}",
|
|
5
|
+
"private": true,{{#if isPnpm}}
|
|
6
|
+
"packageManager": "pnpm@9.15.0",{{/if}}{{#if isYarn}}
|
|
7
|
+
"packageManager": "yarn@1.22.22",{{/if}}
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "nest build",
|
|
10
|
+
"start": "nest start",
|
|
11
|
+
"start:dev": "nest start --watch",
|
|
12
|
+
"start:prod": "node dist/main",
|
|
13
|
+
{{#if jest}}"test": "jest",{{/if}}
|
|
14
|
+
{{#if usePrisma}}"db:generate": "prisma generate",
|
|
15
|
+
"db:migrate": "prisma migrate dev",{{/if}}
|
|
16
|
+
{{#if useDrizzle}}"db:generate": "drizzle-kit generate",
|
|
17
|
+
"db:migrate": "drizzle-kit migrate",{{/if}}
|
|
18
|
+
"lint": "eslint \"{src,test}/**/*.{{ext}}\" --fix"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@nestjs/common": "^11.0.0",
|
|
22
|
+
"@nestjs/core": "^11.0.0",
|
|
23
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
24
|
+
"reflect-metadata": "^0.2.2",
|
|
25
|
+
"rxjs": "^7.8.1"{{#if swagger}},
|
|
26
|
+
"@nestjs/swagger": "^11.0.0"{{/if}}{{#if useJwt}},
|
|
27
|
+
"@nestjs/jwt": "^11.0.0",
|
|
28
|
+
"@nestjs/passport": "^11.0.0",
|
|
29
|
+
"passport": "^0.7.0",
|
|
30
|
+
"passport-jwt": "^4.0.1",
|
|
31
|
+
"bcrypt": "^5.1.1"{{/if}}{{#if useClerk}},
|
|
32
|
+
"@clerk/clerk-sdk-node": "^5.0.0"{{/if}}{{#if usePrisma}},
|
|
33
|
+
"@prisma/client": "^6.0.0"{{/if}}{{#if useTypeorm}},
|
|
34
|
+
"typeorm": "^0.3.20",
|
|
35
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
36
|
+
"{{dbDriver}}": "latest"{{/if}}{{#if useDrizzle}},
|
|
37
|
+
"drizzle-orm": "^0.38.0",
|
|
38
|
+
"{{dbDriver}}": "latest"{{/if}}{{#if useSequelize}},
|
|
39
|
+
"sequelize": "^6.37.0",
|
|
40
|
+
"sequelize-typescript": "^2.1.6",
|
|
41
|
+
"@nestjs/sequelize": "^11.0.0",
|
|
42
|
+
"{{dbDriver}}": "latest"{{/if}}{{#if hasRedis}},
|
|
43
|
+
"@nestjs/cache-manager": "^3.0.0",
|
|
44
|
+
"cache-manager": "^6.0.0",
|
|
45
|
+
"cache-manager-redis-yet": "^5.0.0"{{/if}}{{#if useBullmq}},
|
|
46
|
+
"@nestjs/bullmq": "^11.0.0",
|
|
47
|
+
"bullmq": "^5.0.0"{{/if}}{{#if useRabbitmq}},
|
|
48
|
+
"@golevelup/nestjs-rabbitmq": "^5.0.0",
|
|
49
|
+
"amqplib": "^0.10.0"{{/if}}
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@nestjs/cli": "^11.0.0",
|
|
53
|
+
"@nestjs/schematics": "^11.0.0"{{#if isTypescript}},
|
|
54
|
+
"typescript": "^5.7.0",
|
|
55
|
+
"@types/node": "^22.0.0"{{/if}}{{#if jest}},
|
|
56
|
+
"jest": "^30.0.0",
|
|
57
|
+
"@nestjs/testing": "^11.0.0",
|
|
58
|
+
"ts-jest": "^29.0.0"{{/if}} {{#if usePrisma}},
|
|
59
|
+
"prisma": "^6.0.0"{{/if}}{{#if useDrizzle}},
|
|
60
|
+
"drizzle-kit": "^0.30.0"{{/if}}
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">={{nodeVersion}}.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "{{#if usePostgres}}postgresql{{/if}}{{#if useMysql}}mysql{{/if}}{{#if useMongodb}}mongodb{{/if}}"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
model User {
|
|
11
|
+
id String @id @default(cuid())
|
|
12
|
+
email String @unique
|
|
13
|
+
name String?
|
|
14
|
+
createdAt DateTime @default(now())
|
|
15
|
+
updatedAt DateTime @updatedAt
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "ES2022",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"strict": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "dist"]
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { clerkMiddleware, getAuth } from '@clerk/express';
|
|
2
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
3
|
+
|
|
4
|
+
export const clerkAuth = clerkMiddleware();
|
|
5
|
+
|
|
6
|
+
export function requireClerkAuth(req: Request, res: Response, next: NextFunction) {
|
|
7
|
+
const auth = getAuth(req);
|
|
8
|
+
if (!auth?.userId) {
|
|
9
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
3
|
+
|
|
4
|
+
export function jwtMiddleware(req: Request, res: Response, next: NextFunction) {
|
|
5
|
+
const token = req.headers.authorization?.replace('Bearer ', '');
|
|
6
|
+
if (!token) {
|
|
7
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
(req as Request & { user?: unknown }).user = jwt.verify(
|
|
11
|
+
token,
|
|
12
|
+
process.env.JWT_SECRET ?? 'change-me',
|
|
13
|
+
);
|
|
14
|
+
next();
|
|
15
|
+
} catch {
|
|
16
|
+
return res.status(401).json({ message: 'Invalid token' });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{{#if usePostgres}}
|
|
2
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if useMysql}}
|
|
6
|
+
import { drizzle } from 'drizzle-orm/mysql2';
|
|
7
|
+
import mysql from 'mysql2/promise';
|
|
8
|
+
{{/if}}
|
|
9
|
+
import * as schema from './schema.js';
|
|
10
|
+
|
|
11
|
+
{{#if usePostgres}}
|
|
12
|
+
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
13
|
+
export const db = drizzle(pool, { schema });
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#if useMysql}}
|
|
16
|
+
const pool = mysql.createPool(process.env.DATABASE_URL!);
|
|
17
|
+
export const db = drizzle(pool, { schema, mode: 'default' });
|
|
18
|
+
{{/if}}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{#if usePostgres}}
|
|
2
|
+
import { pgTable, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
|
|
3
|
+
|
|
4
|
+
export const users = pgTable('users', {
|
|
5
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
6
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
7
|
+
name: varchar('name', { length: 255 }),
|
|
8
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
9
|
+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
10
|
+
});
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{#if useMysql}}
|
|
13
|
+
import { mysqlTable, timestamp, varchar } from 'drizzle-orm/mysql-core';
|
|
14
|
+
|
|
15
|
+
export const users = mysqlTable('users', {
|
|
16
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
17
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
18
|
+
name: varchar('name', { length: 255 }),
|
|
19
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
20
|
+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
21
|
+
});
|
|
22
|
+
{{/if}}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
|
|
3
|
+
const globalForPrisma = globalThis as typeof globalThis & {
|
|
4
|
+
prisma?: PrismaClient;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const prisma =
|
|
8
|
+
globalForPrisma.prisma ??
|
|
9
|
+
new PrismaClient({
|
|
10
|
+
log: process.env.NODE_ENV === 'development' ? ['query', 'error'] : ['error'],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
+
globalForPrisma.prisma = prisma;
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Column,
|
|
3
|
+
DataType,
|
|
4
|
+
Default,
|
|
5
|
+
Model,
|
|
6
|
+
PrimaryKey,
|
|
7
|
+
Table,
|
|
8
|
+
} from 'sequelize-typescript';
|
|
9
|
+
|
|
10
|
+
@Table({ tableName: 'users' })
|
|
11
|
+
export class User extends Model {
|
|
12
|
+
@PrimaryKey
|
|
13
|
+
@Default(DataType.UUIDV4)
|
|
14
|
+
@Column(DataType.UUID)
|
|
15
|
+
declare id: string;
|
|
16
|
+
|
|
17
|
+
@Column({ unique: true })
|
|
18
|
+
declare email: string;
|
|
19
|
+
|
|
20
|
+
@Column({ allowNull: true })
|
|
21
|
+
declare name: string | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
2
|
+
import { User } from './models/user.model.js';
|
|
3
|
+
|
|
4
|
+
export const sequelize = new Sequelize(process.env.DATABASE_URL!, {
|
|
5
|
+
dialect: '{{sequelizeDialect}}',
|
|
6
|
+
models: [User],
|
|
7
|
+
logging: false,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export async function initSequelize() {
|
|
11
|
+
await sequelize.authenticate();
|
|
12
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
13
|
+
await sequelize.sync();
|
|
14
|
+
}
|
|
15
|
+
return sequelize;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import swaggerJsdoc from 'swagger-jsdoc';
|
|
2
|
+
import swaggerUi from 'swagger-ui-express';
|
|
3
|
+
import type { Express } from 'express';
|
|
4
|
+
|
|
5
|
+
export function setupSwagger(app: Express) {
|
|
6
|
+
const spec = swaggerJsdoc({
|
|
7
|
+
definition: {
|
|
8
|
+
openapi: '3.0.0',
|
|
9
|
+
info: {
|
|
10
|
+
title: '{{projectSlug}}',
|
|
11
|
+
description: '{{description}}',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
apis: ['./src/**/*.{{ext}}'],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
app.use('/docs', swaggerUi.serve, swaggerUi.setup(spec));
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { DataSource } from 'typeorm';
|
|
3
|
+
import { UserEntity } from './entities/user.entity.js';
|
|
4
|
+
|
|
5
|
+
export const AppDataSource = new DataSource({
|
|
6
|
+
type: '{{typeormDriver}}',
|
|
7
|
+
url: process.env.DATABASE_URL,
|
|
8
|
+
entities: [UserEntity],
|
|
9
|
+
synchronize: process.env.NODE_ENV !== 'production',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export async function initTypeorm() {
|
|
13
|
+
if (!AppDataSource.isInitialized) {
|
|
14
|
+
await AppDataSource.initialize();
|
|
15
|
+
}
|
|
16
|
+
return AppDataSource;
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Column,
|
|
3
|
+
CreateDateColumn,
|
|
4
|
+
Entity,
|
|
5
|
+
PrimaryGeneratedColumn,
|
|
6
|
+
UpdateDateColumn,
|
|
7
|
+
} from 'typeorm';
|
|
8
|
+
|
|
9
|
+
@Entity('users')
|
|
10
|
+
export class UserEntity {
|
|
11
|
+
@PrimaryGeneratedColumn('uuid')
|
|
12
|
+
id!: string;
|
|
13
|
+
|
|
14
|
+
@Column({ unique: true })
|
|
15
|
+
email!: string;
|
|
16
|
+
|
|
17
|
+
@Column({ nullable: true })
|
|
18
|
+
name!: string | null;
|
|
19
|
+
|
|
20
|
+
@CreateDateColumn()
|
|
21
|
+
createdAt!: Date;
|
|
22
|
+
|
|
23
|
+
@UpdateDateColumn()
|
|
24
|
+
updatedAt!: Date;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createClerkClient } from '@clerk/backend';
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
|
+
|
|
4
|
+
const clerk = createClerkClient({ secretKey: process.env.CLERK_SECRET_KEY });
|
|
5
|
+
|
|
6
|
+
export async function clerkMiddleware(request: FastifyRequest, reply: FastifyReply) {
|
|
7
|
+
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
8
|
+
if (!token) {
|
|
9
|
+
return reply.status(401).send({ message: 'Unauthorized' });
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
request.user = await clerk.verifyToken(token);
|
|
13
|
+
} catch {
|
|
14
|
+
return reply.status(401).send({ message: 'Invalid token' });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
|
+
|
|
4
|
+
export async function jwtMiddleware(request: FastifyRequest, reply: FastifyReply) {
|
|
5
|
+
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
6
|
+
if (!token) {
|
|
7
|
+
return reply.status(401).send({ message: 'Unauthorized' });
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
request.user = jwt.verify(token, process.env.JWT_SECRET ?? 'change-me');
|
|
11
|
+
} catch {
|
|
12
|
+
return reply.status(401).send({ message: 'Invalid token' });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{{#if usePostgres}}
|
|
2
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if useMysql}}
|
|
6
|
+
import { drizzle } from 'drizzle-orm/mysql2';
|
|
7
|
+
import mysql from 'mysql2/promise';
|
|
8
|
+
{{/if}}
|
|
9
|
+
import * as schema from './schema.js';
|
|
10
|
+
|
|
11
|
+
{{#if usePostgres}}
|
|
12
|
+
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
13
|
+
export const db = drizzle(pool, { schema });
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#if useMysql}}
|
|
16
|
+
const pool = mysql.createPool(process.env.DATABASE_URL!);
|
|
17
|
+
export const db = drizzle(pool, { schema, mode: 'default' });
|
|
18
|
+
{{/if}}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{#if usePostgres}}
|
|
2
|
+
import { pgTable, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
|
|
3
|
+
|
|
4
|
+
export const users = pgTable('users', {
|
|
5
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
6
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
7
|
+
name: varchar('name', { length: 255 }),
|
|
8
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
9
|
+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
10
|
+
});
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{#if useMysql}}
|
|
13
|
+
import { mysqlTable, timestamp, varchar } from 'drizzle-orm/mysql-core';
|
|
14
|
+
|
|
15
|
+
export const users = mysqlTable('users', {
|
|
16
|
+
id: varchar('id', { length: 36 }).primaryKey(),
|
|
17
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
18
|
+
name: varchar('name', { length: 255 }),
|
|
19
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
20
|
+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
|
|
21
|
+
});
|
|
22
|
+
{{/if}}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
|
|
3
|
+
const globalForPrisma = globalThis as typeof globalThis & {
|
|
4
|
+
prisma?: PrismaClient;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const prisma =
|
|
8
|
+
globalForPrisma.prisma ??
|
|
9
|
+
new PrismaClient({
|
|
10
|
+
log: process.env.NODE_ENV === 'development' ? ['query', 'error'] : ['error'],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
+
globalForPrisma.prisma = prisma;
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Column,
|
|
3
|
+
DataType,
|
|
4
|
+
Default,
|
|
5
|
+
Model,
|
|
6
|
+
PrimaryKey,
|
|
7
|
+
Table,
|
|
8
|
+
} from 'sequelize-typescript';
|
|
9
|
+
|
|
10
|
+
@Table({ tableName: 'users' })
|
|
11
|
+
export class User extends Model {
|
|
12
|
+
@PrimaryKey
|
|
13
|
+
@Default(DataType.UUIDV4)
|
|
14
|
+
@Column(DataType.UUID)
|
|
15
|
+
declare id: string;
|
|
16
|
+
|
|
17
|
+
@Column({ unique: true })
|
|
18
|
+
declare email: string;
|
|
19
|
+
|
|
20
|
+
@Column({ allowNull: true })
|
|
21
|
+
declare name: string | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
2
|
+
import { User } from './models/user.model.js';
|
|
3
|
+
|
|
4
|
+
export const sequelize = new Sequelize(process.env.DATABASE_URL!, {
|
|
5
|
+
dialect: '{{sequelizeDialect}}',
|
|
6
|
+
models: [User],
|
|
7
|
+
logging: false,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export async function initSequelize() {
|
|
11
|
+
await sequelize.authenticate();
|
|
12
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
13
|
+
await sequelize.sync();
|
|
14
|
+
}
|
|
15
|
+
return sequelize;
|
|
16
|
+
}
|