create-pardx-scaffold 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/README.md +45 -0
- package/cli.js +104 -0
- package/package.json +15 -0
- package/template/.cursorrules +479 -0
- package/template/.prettierignore +29 -0
- package/template/.prettierrc +11 -0
- package/template/.vscode/extensions.json +8 -0
- package/template/.vscode/settings.json +122 -0
- package/template/CLAUDE.md +762 -0
- package/template/README.md +125 -0
- package/template/apps/api/.env.example +11 -0
- package/template/apps/api/.eslintrc.js +222 -0
- package/template/apps/api/config.local.yaml +397 -0
- package/template/apps/api/libs/domain/auth/package.json +11 -0
- package/template/apps/api/libs/domain/auth/src/README.md +189 -0
- package/template/apps/api/libs/domain/auth/src/auth-validation.service.ts +37 -0
- package/template/apps/api/libs/domain/auth/src/auth.guard.ts +173 -0
- package/template/apps/api/libs/domain/auth/src/auth.module.ts +23 -0
- package/template/apps/api/libs/domain/auth/src/auth.service.ts +198 -0
- package/template/apps/api/libs/domain/auth/src/auth.ts +66 -0
- package/template/apps/api/libs/domain/auth/src/decorators/presets.decorator.ts +50 -0
- package/template/apps/api/libs/domain/auth/src/decorators/rbac.decorator.ts +67 -0
- package/template/apps/api/libs/domain/auth/src/decorators/resource-owner.decorator.ts +67 -0
- package/template/apps/api/libs/domain/auth/src/dto/auth.dto.ts +10 -0
- package/template/apps/api/libs/domain/auth/src/guards/streaming-asr-session.guard.ts +179 -0
- package/template/apps/api/libs/domain/auth/src/index.ts +12 -0
- package/template/apps/api/libs/domain/auth/src/types/auth.interface.ts +52 -0
- package/template/apps/api/libs/domain/auth/tsconfig.lib.json +9 -0
- package/template/apps/api/libs/domain/db/package.json +11 -0
- package/template/apps/api/libs/domain/db/src/index.ts +14 -0
- package/template/apps/api/libs/domain/db/src/modules/country-code/country-code.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/country-code/country-code.service.ts +140 -0
- package/template/apps/api/libs/domain/db/src/modules/country-code/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/discord-auth/discord-auth.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/discord-auth/discord-auth.service.ts +101 -0
- package/template/apps/api/libs/domain/db/src/modules/discord-auth/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/email-auth/email-auth.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/email-auth/email-auth.service.ts +101 -0
- package/template/apps/api/libs/domain/db/src/modules/email-auth/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/file-source/file-source.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/file-source/file-source.service.ts +109 -0
- package/template/apps/api/libs/domain/db/src/modules/file-source/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/google-auth/google-auth.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/google-auth/google-auth.service.ts +101 -0
- package/template/apps/api/libs/domain/db/src/modules/google-auth/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/message/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/message/message.module.ts +10 -0
- package/template/apps/api/libs/domain/db/src/modules/message/message.service.ts +314 -0
- package/template/apps/api/libs/domain/db/src/modules/mobile-auth/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/mobile-auth/mobile-auth.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/mobile-auth/mobile-auth.service.ts +101 -0
- package/template/apps/api/libs/domain/db/src/modules/risk-detection-record/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/risk-detection-record/risk-detection-record.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/risk-detection-record/risk-detection-record.service.ts +101 -0
- package/template/apps/api/libs/domain/db/src/modules/system-task-queue/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/system-task-queue/system-task-queue.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/system-task-queue/system-task-queue.service.ts +101 -0
- package/template/apps/api/libs/domain/db/src/modules/user-info/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/user-info/user-info.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/user-info/user-info.service.ts +139 -0
- package/template/apps/api/libs/domain/db/src/modules/wechat-auth/index.ts +2 -0
- package/template/apps/api/libs/domain/db/src/modules/wechat-auth/wechat-auth.module.ts +12 -0
- package/template/apps/api/libs/domain/db/src/modules/wechat-auth/wechat-auth.service.ts +101 -0
- package/template/apps/api/libs/domain/db/tsconfig.lib.json +9 -0
- package/template/apps/api/libs/infra/clients/internal/ai/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/ai/risk-detection.client.ts +301 -0
- package/template/apps/api/libs/infra/clients/internal/ai/risk-detection.module.ts +22 -0
- package/template/apps/api/libs/infra/clients/internal/crypt/crypt-client.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/clients/internal/crypt/crypt.client.ts +37 -0
- package/template/apps/api/libs/infra/clients/internal/crypt/crypt.module.ts +10 -0
- package/template/apps/api/libs/infra/clients/internal/crypt/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/email/dto/email.dto.ts +75 -0
- package/template/apps/api/libs/infra/clients/internal/email/index.ts +11 -0
- package/template/apps/api/libs/infra/clients/internal/email/sendcloud.client.ts +400 -0
- package/template/apps/api/libs/infra/clients/internal/file-cdn/README.md +255 -0
- package/template/apps/api/libs/infra/clients/internal/file-cdn/dto/file-cdn.dto.ts +96 -0
- package/template/apps/api/libs/infra/clients/internal/file-cdn/file-cdn-client.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/clients/internal/file-cdn/file-cdn.client.ts +620 -0
- package/template/apps/api/libs/infra/clients/internal/file-cdn/file-cdn.module.ts +19 -0
- package/template/apps/api/libs/infra/clients/internal/file-cdn/index.ts +40 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/config/file.config.ts +14 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/dto/file.dto.ts +127 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/file-gcs.client.ts +154 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/file-qiniu.client.ts +729 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/file-s3.client.ts +1097 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/file-storage.interface.ts +114 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/file-tos.client.ts +767 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/file-us3.client.ts +176 -0
- package/template/apps/api/libs/infra/clients/internal/file-storage/index.ts +16 -0
- package/template/apps/api/libs/infra/clients/internal/ocr/dto/ocr.dto.ts +61 -0
- package/template/apps/api/libs/infra/clients/internal/ocr/index.ts +3 -0
- package/template/apps/api/libs/infra/clients/internal/ocr/ocr.client.ts +123 -0
- package/template/apps/api/libs/infra/clients/internal/ocr/ocr.module.ts +15 -0
- package/template/apps/api/libs/infra/clients/internal/openai/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/openai/openai.client.ts +135 -0
- package/template/apps/api/libs/infra/clients/internal/openai/openai.module.ts +17 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/README.md +508 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/index.ts +44 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/openspeech.client.ts +441 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/openspeech.factory.ts +450 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/openspeech.module.ts +56 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/providers/aliyun.provider.ts +308 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/providers/base.provider.ts +114 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/providers/index.ts +10 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/providers/volcengine-streaming.provider.ts +1689 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/providers/volcengine.provider.ts +387 -0
- package/template/apps/api/libs/infra/clients/internal/openspeech/types.ts +467 -0
- package/template/apps/api/libs/infra/clients/internal/sms/dto/sms.dto.ts +97 -0
- package/template/apps/api/libs/infra/clients/internal/sms/index.ts +15 -0
- package/template/apps/api/libs/infra/clients/internal/sms/sms-aliyun.client.ts +52 -0
- package/template/apps/api/libs/infra/clients/internal/sms/sms-http.client.ts +111 -0
- package/template/apps/api/libs/infra/clients/internal/sms/sms-tencent.client.ts +54 -0
- package/template/apps/api/libs/infra/clients/internal/sms/sms-volcengine.client.ts +165 -0
- package/template/apps/api/libs/infra/clients/internal/sms/sms-zxjc.client.ts +47 -0
- package/template/apps/api/libs/infra/clients/internal/sse/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/sse/sse-client.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/clients/internal/sse/sse.client.ts +360 -0
- package/template/apps/api/libs/infra/clients/internal/sse/sse.module.ts +17 -0
- package/template/apps/api/libs/infra/clients/internal/third-party-sse/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/third-party-sse/third-party-sse.client.ts +51 -0
- package/template/apps/api/libs/infra/clients/internal/third-party-sse/third-party-sse.module.ts +10 -0
- package/template/apps/api/libs/infra/clients/internal/third-party-sse/third-party-sse.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/clients/internal/verify/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/verify/verify.client.ts +42 -0
- package/template/apps/api/libs/infra/clients/internal/verify/verify.module.ts +10 -0
- package/template/apps/api/libs/infra/clients/internal/volcengine-tts/dto/tts.dto.ts +64 -0
- package/template/apps/api/libs/infra/clients/internal/volcengine-tts/index.ts +3 -0
- package/template/apps/api/libs/infra/clients/internal/volcengine-tts/volcengine-tts.client.ts +846 -0
- package/template/apps/api/libs/infra/clients/internal/volcengine-tts/volcengine-tts.module.ts +21 -0
- package/template/apps/api/libs/infra/clients/internal/wechat/index.ts +2 -0
- package/template/apps/api/libs/infra/clients/internal/wechat/wechat-client.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/clients/internal/wechat/wechat.client.ts +4 -0
- package/template/apps/api/libs/infra/clients/internal/wechat/wechat.module.ts +8 -0
- package/template/apps/api/libs/infra/clients/plugin/decorators/inject-client.decorator.ts +60 -0
- package/template/apps/api/libs/infra/clients/plugin/index.ts +21 -0
- package/template/apps/api/libs/infra/clients/plugin/interceptors/http-logging.interceptor.ts +130 -0
- package/template/apps/api/libs/infra/clients/plugin/interfaces/client.interface.ts +86 -0
- package/template/apps/api/libs/infra/clients/plugin/utils/retry.util.ts +157 -0
- package/template/apps/api/libs/infra/common/adapters/base.adapter.ts +94 -0
- package/template/apps/api/libs/infra/common/adapters/index.ts +38 -0
- package/template/apps/api/libs/infra/common/config/README.md +254 -0
- package/template/apps/api/libs/infra/common/config/agentx.config.ts +91 -0
- package/template/apps/api/libs/infra/common/config/configuration.ts +289 -0
- package/template/apps/api/libs/infra/common/config/constant/config.constants.ts +92 -0
- package/template/apps/api/libs/infra/common/config/dto/config.dto.ts +282 -0
- package/template/apps/api/libs/infra/common/config/package.json +11 -0
- package/template/apps/api/libs/infra/common/config/validation/env.validation.ts +161 -0
- package/template/apps/api/libs/infra/common/config/validation/index.ts +188 -0
- package/template/apps/api/libs/infra/common/config/validation/keys.validation.ts +564 -0
- package/template/apps/api/libs/infra/common/config/validation/yaml.validation.ts +582 -0
- package/template/apps/api/libs/infra/common/decorators/app-version/app-version.controller.ts +135 -0
- package/template/apps/api/libs/infra/common/decorators/app-version/app-version.interceptor.ts +36 -0
- package/template/apps/api/libs/infra/common/decorators/app-version/app-version.module.ts +27 -0
- package/template/apps/api/libs/infra/common/decorators/app-version/app-version.service.ts +252 -0
- package/template/apps/api/libs/infra/common/decorators/app-version/index.ts +13 -0
- package/template/apps/api/libs/infra/common/decorators/cache/cache.decorator.ts +437 -0
- package/template/apps/api/libs/infra/common/decorators/cache/cache.interceptor.ts +268 -0
- package/template/apps/api/libs/infra/common/decorators/cache/cache.module.ts +24 -0
- package/template/apps/api/libs/infra/common/decorators/cache/index.ts +33 -0
- package/template/apps/api/libs/infra/common/decorators/event/event.decorator.ts +229 -0
- package/template/apps/api/libs/infra/common/decorators/event/event.interceptor.ts +155 -0
- package/template/apps/api/libs/infra/common/decorators/event/event.module.ts +47 -0
- package/template/apps/api/libs/infra/common/decorators/event/handlers/cache-event.handler.ts +159 -0
- package/template/apps/api/libs/infra/common/decorators/event/index.ts +29 -0
- package/template/apps/api/libs/infra/common/decorators/feature-flag/feature-flag.decorator.ts +221 -0
- package/template/apps/api/libs/infra/common/decorators/feature-flag/feature-flag.interceptor.ts +150 -0
- package/template/apps/api/libs/infra/common/decorators/feature-flag/feature-flag.module.ts +27 -0
- package/template/apps/api/libs/infra/common/decorators/feature-flag/feature-flag.service.spec.ts +330 -0
- package/template/apps/api/libs/infra/common/decorators/feature-flag/feature-flag.service.ts +423 -0
- package/template/apps/api/libs/infra/common/decorators/feature-flag/index.ts +28 -0
- package/template/apps/api/libs/infra/common/decorators/rate-limit/dto/rate-limit.dto.ts +201 -0
- package/template/apps/api/libs/infra/common/decorators/rate-limit/index.ts +54 -0
- package/template/apps/api/libs/infra/common/decorators/rate-limit/rate-limit.decorator.ts +216 -0
- package/template/apps/api/libs/infra/common/decorators/rate-limit/rate-limit.exception.ts +74 -0
- package/template/apps/api/libs/infra/common/decorators/rate-limit/rate-limit.module.ts +37 -0
- package/template/apps/api/libs/infra/common/decorators/rate-limit/rate-limit.service.ts +430 -0
- package/template/apps/api/libs/infra/common/decorators/response.decorator.ts +67 -0
- package/template/apps/api/libs/infra/common/decorators/skip-version-check.decorator.ts +27 -0
- package/template/apps/api/libs/infra/common/decorators/transaction/index.ts +12 -0
- package/template/apps/api/libs/infra/common/decorators/transaction/transactional.decorator.ts +677 -0
- package/template/apps/api/libs/infra/common/decorators/ts-rest-controller.decorator.ts +63 -0
- package/template/apps/api/libs/infra/common/decorators/validation.decorator.ts +120 -0
- package/template/apps/api/libs/infra/common/decorators/version/index.ts +24 -0
- package/template/apps/api/libs/infra/common/decorators/version/version.decorator.ts +168 -0
- package/template/apps/api/libs/infra/common/decorators/version/version.interceptor.ts +97 -0
- package/template/apps/api/libs/infra/common/decorators/version/version.module.ts +21 -0
- package/template/apps/api/libs/infra/common/enums/action.enum.ts +7 -0
- package/template/apps/api/libs/infra/common/enums/error-codes.ts +71 -0
- package/template/apps/api/libs/infra/common/enums/role.enum.ts +4 -0
- package/template/apps/api/libs/infra/common/filter/exception/api.exception.ts +168 -0
- package/template/apps/api/libs/infra/common/filter/exception/exception.ts +47 -0
- package/template/apps/api/libs/infra/common/filter/exception/http.exception.ts +126 -0
- package/template/apps/api/libs/infra/common/guards/index.ts +1 -0
- package/template/apps/api/libs/infra/common/guards/version.guard.ts +312 -0
- package/template/apps/api/libs/infra/common/interceptor/mask/index.ts +1 -0
- package/template/apps/api/libs/infra/common/interceptor/mask/mask.interceptor.ts +242 -0
- package/template/apps/api/libs/infra/common/interceptor/rate-limit/no-rate-limit.interceptor.ts +14 -0
- package/template/apps/api/libs/infra/common/interceptor/rate-limit/rate-limit.interceptor.ts +230 -0
- package/template/apps/api/libs/infra/common/interceptor/transform/transform.interceptor.spec.ts +7 -0
- package/template/apps/api/libs/infra/common/interceptor/transform/transform.interceptor.ts +75 -0
- package/template/apps/api/libs/infra/common/interceptor/version/index.ts +1 -0
- package/template/apps/api/libs/infra/common/interceptor/version/version-header.interceptor.ts +62 -0
- package/template/apps/api/libs/infra/common/middleware/request.middleware.ts +109 -0
- package/template/apps/api/libs/infra/common/package.json +11 -0
- package/template/apps/api/libs/infra/common/pipes/transform-root.pipe.ts +12 -0
- package/template/apps/api/libs/infra/common/ts-rest/index.ts +26 -0
- package/template/apps/api/libs/infra/common/ts-rest/response.helper.ts +233 -0
- package/template/apps/api/libs/infra/i18n/en/errors.json +77 -0
- package/template/apps/api/libs/infra/i18n/en/events.json +1 -0
- package/template/apps/api/libs/infra/i18n/package.json +11 -0
- package/template/apps/api/libs/infra/i18n/zh-CN/errors.json +77 -0
- package/template/apps/api/libs/infra/i18n/zh-CN/events.json +1 -0
- package/template/apps/api/libs/infra/jwt/dto/jwt.dto.ts +1 -0
- package/template/apps/api/libs/infra/jwt/jwt.module.ts +26 -0
- package/template/apps/api/libs/infra/jwt/package.json +11 -0
- package/template/apps/api/libs/infra/prisma/db-metrics/package.json +11 -0
- package/template/apps/api/libs/infra/prisma/db-metrics/src/db-metrics.module.ts +141 -0
- package/template/apps/api/libs/infra/prisma/db-metrics/src/db-metrics.service.ts +456 -0
- package/template/apps/api/libs/infra/prisma/db-metrics/src/index.ts +2 -0
- package/template/apps/api/libs/infra/prisma/db-metrics/tsconfig.lib.json +9 -0
- package/template/apps/api/libs/infra/prisma/middleware/soft-delete.middleware.ts +179 -0
- package/template/apps/api/libs/infra/prisma/package.json +11 -0
- package/template/apps/api/libs/infra/prisma/prisma/index.ts +3 -0
- package/template/apps/api/libs/infra/prisma/prisma/prisma.module.ts +12 -0
- package/template/apps/api/libs/infra/prisma/prisma/prisma.service.ts +18 -0
- package/template/apps/api/libs/infra/prisma/prisma/types.ts +6 -0
- package/template/apps/api/libs/infra/prisma/prisma-read/prisma-read.module.ts +11 -0
- package/template/apps/api/libs/infra/prisma/prisma-read/prisma-read.service.ts +280 -0
- package/template/apps/api/libs/infra/prisma/prisma-write/prisma-write.module.ts +11 -0
- package/template/apps/api/libs/infra/prisma/prisma-write/prisma-write.service.ts +278 -0
- package/template/apps/api/libs/infra/prisma/prometheus/index.ts +1 -0
- package/template/apps/api/libs/infra/prisma/prometheus/prometheus.module.ts +231 -0
- package/template/apps/api/libs/infra/rabbitmq/package.json +11 -0
- package/template/apps/api/libs/infra/rabbitmq/src/dto/rabbitmq.dto.ts +13 -0
- package/template/apps/api/libs/infra/rabbitmq/src/index.ts +5 -0
- package/template/apps/api/libs/infra/rabbitmq/src/rabbitmq-events.module.ts +132 -0
- package/template/apps/api/libs/infra/rabbitmq/src/rabbitmq-events.service.ts +199 -0
- package/template/apps/api/libs/infra/rabbitmq/src/rabbitmq.module.ts +101 -0
- package/template/apps/api/libs/infra/rabbitmq/src/rabbitmq.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/rabbitmq/src/rabbitmq.service.ts +543 -0
- package/template/apps/api/libs/infra/rabbitmq/tsconfig.lib.json +9 -0
- package/template/apps/api/libs/infra/redis/dto/redis.dto.ts +3 -0
- package/template/apps/api/libs/infra/redis/package.json +11 -0
- package/template/apps/api/libs/infra/redis/src/index.ts +2 -0
- package/template/apps/api/libs/infra/redis/src/redis.module.ts +63 -0
- package/template/apps/api/libs/infra/redis/src/redis.service.spec.ts +18 -0
- package/template/apps/api/libs/infra/redis/src/redis.service.ts +730 -0
- package/template/apps/api/libs/infra/redis/tsconfig.lib.json +9 -0
- package/template/apps/api/libs/infra/shared-db/index.ts +14 -0
- package/template/apps/api/libs/infra/shared-db/transaction-context.ts +51 -0
- package/template/apps/api/libs/infra/shared-db/transaction.module.ts +15 -0
- package/template/apps/api/libs/infra/shared-db/transaction.perf.spec.ts +226 -0
- package/template/apps/api/libs/infra/shared-db/transactional-service.base.ts +102 -0
- package/template/apps/api/libs/infra/shared-db/unit-of-work.service.ts +142 -0
- package/template/apps/api/libs/infra/shared-services/email/dto/email.dto.ts +87 -0
- package/template/apps/api/libs/infra/shared-services/email/email.module.ts +27 -0
- package/template/apps/api/libs/infra/shared-services/email/email.service.ts +258 -0
- package/template/apps/api/libs/infra/shared-services/email/index.ts +5 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/README.md +376 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/bucket-resolver.ts +306 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/file-storage.factory.ts +347 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/file-storage.module.ts +62 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/file-storage.service.ts +849 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/index.ts +57 -0
- package/template/apps/api/libs/infra/shared-services/file-storage/types.ts +210 -0
- package/template/apps/api/libs/infra/shared-services/ip-info/index.ts +2 -0
- package/template/apps/api/libs/infra/shared-services/ip-info/ip-info.module.ts +18 -0
- package/template/apps/api/libs/infra/shared-services/ip-info/ip-info.service.ts +118 -0
- package/template/apps/api/libs/infra/shared-services/sms/index.ts +11 -0
- package/template/apps/api/libs/infra/shared-services/sms/sms.factory.ts +367 -0
- package/template/apps/api/libs/infra/shared-services/sms/sms.module.ts +27 -0
- package/template/apps/api/libs/infra/shared-services/sms/sms.service.ts +315 -0
- package/template/apps/api/libs/infra/shared-services/sms/types.ts +297 -0
- package/template/apps/api/libs/infra/shared-services/streaming-asr/index.ts +50 -0
- package/template/apps/api/libs/infra/shared-services/streaming-asr/streaming-asr.module.ts +47 -0
- package/template/apps/api/libs/infra/shared-services/streaming-asr/streaming-asr.service.ts +1336 -0
- package/template/apps/api/libs/infra/shared-services/streaming-asr/types.ts +208 -0
- package/template/apps/api/libs/infra/shared-services/system-health/index.ts +3 -0
- package/template/apps/api/libs/infra/shared-services/system-health/system-health.controller.ts +61 -0
- package/template/apps/api/libs/infra/shared-services/system-health/system-health.module.ts +16 -0
- package/template/apps/api/libs/infra/shared-services/system-health/system-health.service.ts +69 -0
- package/template/apps/api/libs/infra/shared-services/uploader/index.ts +2 -0
- package/template/apps/api/libs/infra/shared-services/uploader/uploader.module.ts +11 -0
- package/template/apps/api/libs/infra/shared-services/uploader/uploader.service.ts +265 -0
- package/template/apps/api/libs/infra/utils/array-buffer.util.ts +8 -0
- package/template/apps/api/libs/infra/utils/array.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/bcrypt.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/bigint.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/bytes.convert.util.ts +13 -0
- package/template/apps/api/libs/infra/utils/crypto.util.ts +206 -0
- package/template/apps/api/libs/infra/utils/download.ts +21 -0
- package/template/apps/api/libs/infra/utils/enviroment.util.ts +130 -0
- package/template/apps/api/libs/infra/utils/ffmpeg.util.ts +29 -0
- package/template/apps/api/libs/infra/utils/file.util.ts +448 -0
- package/template/apps/api/libs/infra/utils/folder.util.ts +11 -0
- package/template/apps/api/libs/infra/utils/frame.util.ts +24 -0
- package/template/apps/api/libs/infra/utils/http-client.ts +133 -0
- package/template/apps/api/libs/infra/utils/ip.util.ts +22 -0
- package/template/apps/api/libs/infra/utils/json.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/load-env.util.ts +53 -0
- package/template/apps/api/libs/infra/utils/logger.util.ts +121 -0
- package/template/apps/api/libs/infra/utils/object.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/package.json +11 -0
- package/template/apps/api/libs/infra/utils/prisma-error.util.ts +397 -0
- package/template/apps/api/libs/infra/utils/response.ts +23 -0
- package/template/apps/api/libs/infra/utils/serialize.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/string.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/timer.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/urlencode.util.ts +3 -0
- package/template/apps/api/libs/infra/utils/validate.util.ts +3 -0
- package/template/apps/api/nest-cli.json +25 -0
- package/template/apps/api/package.json +174 -0
- package/template/apps/api/prisma/schema.prisma +352 -0
- package/template/apps/api/prisma/seed.ts +30 -0
- package/template/apps/api/scripts/generate-db-crud.js +344 -0
- package/template/apps/api/scripts/insert-country-codes.ts +325 -0
- package/template/apps/api/scripts/link-prisma.js +44 -0
- package/template/apps/api/scripts/validate-api-versions.ts +273 -0
- package/template/apps/api/src/app.module.ts +208 -0
- package/template/apps/api/src/main.ts +298 -0
- package/template/apps/api/src/modules/health/health.controller.ts +13 -0
- package/template/apps/api/src/modules/health/health.module.ts +7 -0
- package/template/apps/api/tsconfig.build.json +4 -0
- package/template/apps/api/tsconfig.json +123 -0
- package/template/apps/web/.env.example +5 -0
- package/template/apps/web/app/globals.css +27 -0
- package/template/apps/web/app/layout.tsx +19 -0
- package/template/apps/web/app/page.tsx +42 -0
- package/template/apps/web/hooks/useAspectRatioSize.ts +187 -0
- package/template/apps/web/hooks/useDebouncedValue.ts +25 -0
- package/template/apps/web/hooks/useErrorHandler.ts +113 -0
- package/template/apps/web/hooks/useHotkeys.ts +251 -0
- package/template/apps/web/hooks/useI18nToast.ts +240 -0
- package/template/apps/web/hooks/useI18nValidation.ts +262 -0
- package/template/apps/web/hooks/useNotificationSSE.ts +270 -0
- package/template/apps/web/hooks/useOperationFeedback.ts +108 -0
- package/template/apps/web/hooks/usePerformanceMonitor.ts +105 -0
- package/template/apps/web/hooks/usePermissions.ts +17 -0
- package/template/apps/web/hooks/useTask.ts +489 -0
- package/template/apps/web/hooks/useVersionCheck.ts +329 -0
- package/template/apps/web/i18n/config.ts +50 -0
- package/template/apps/web/i18n/index.ts +30 -0
- package/template/apps/web/i18n/navigation.ts +26 -0
- package/template/apps/web/i18n/request.ts +50 -0
- package/template/apps/web/i18n/routing.ts +21 -0
- package/template/apps/web/i18n/types.ts +57 -0
- package/template/apps/web/lib/actions/auth.ts +81 -0
- package/template/apps/web/lib/actions/chat.ts +129 -0
- package/template/apps/web/lib/actions/common.ts +13 -0
- package/template/apps/web/lib/actions/task.ts +20 -0
- package/template/apps/web/lib/agent/chat-client.ts +42 -0
- package/template/apps/web/lib/agent/prompts.ts +43 -0
- package/template/apps/web/lib/analytics/components/PageTracker.tsx +137 -0
- package/template/apps/web/lib/analytics/hooks/usePageTracking.ts +137 -0
- package/template/apps/web/lib/analytics/index.ts +180 -0
- package/template/apps/web/lib/api/agents.ts +7 -0
- package/template/apps/web/lib/api/agno-chat.ts +263 -0
- package/template/apps/web/lib/api/auth-server.ts +244 -0
- package/template/apps/web/lib/api/avatar-upload.ts +96 -0
- package/template/apps/web/lib/api/cache-config.ts +236 -0
- package/template/apps/web/lib/api/client.ts +649 -0
- package/template/apps/web/lib/api/contracts/client.ts +336 -0
- package/template/apps/web/lib/api/contracts/hooks/index.ts +25 -0
- package/template/apps/web/lib/api/contracts/hooks/notification.ts +180 -0
- package/template/apps/web/lib/api/contracts/hooks/setting.ts +33 -0
- package/template/apps/web/lib/api/contracts/index.ts +18 -0
- package/template/apps/web/lib/api/contracts/server-client.ts +145 -0
- package/template/apps/web/lib/api/hooks/use-python-task.ts +154 -0
- package/template/apps/web/lib/api/queries/analytics.ts +51 -0
- package/template/apps/web/lib/api/queries/message.ts +75 -0
- package/template/apps/web/lib/api.ts +179 -0
- package/template/apps/web/lib/aspect-ratio.ts +10 -0
- package/template/apps/web/lib/audio-buffer-queue.ts +273 -0
- package/template/apps/web/lib/config.ts +163 -0
- package/template/apps/web/lib/data/industry.json +369 -0
- package/template/apps/web/lib/data/region.json +501 -0
- package/template/apps/web/lib/errors/error-handler.ts +194 -0
- package/template/apps/web/lib/errors/index.ts +16 -0
- package/template/apps/web/lib/errors/streaming-asr-errors.ts +434 -0
- package/template/apps/web/lib/form/index.ts +23 -0
- package/template/apps/web/lib/form/use-form.ts +143 -0
- package/template/apps/web/lib/icons-usage.md +99 -0
- package/template/apps/web/lib/icons.tsx +395 -0
- package/template/apps/web/lib/performance/monitor.ts +225 -0
- package/template/apps/web/lib/requests.ts +177 -0
- package/template/apps/web/lib/storage/index.ts +158 -0
- package/template/apps/web/lib/upload/api.ts +260 -0
- package/template/apps/web/lib/upload/batch-uploader.ts +286 -0
- package/template/apps/web/lib/upload/errors.ts +44 -0
- package/template/apps/web/lib/upload/folder-utils.ts +295 -0
- package/template/apps/web/lib/upload/uploader.ts +439 -0
- package/template/apps/web/lib/utils/reconnect.ts +223 -0
- package/template/apps/web/lib/utils/transcript-export.ts +321 -0
- package/template/apps/web/lib/version-mismatch.ts +147 -0
- package/template/apps/web/lib/version.ts +60 -0
- package/template/apps/web/next-env.d.ts +6 -0
- package/template/apps/web/next.config.ts +97 -0
- package/template/apps/web/package.json +89 -0
- package/template/apps/web/providers/app-provider.tsx +45 -0
- package/template/apps/web/providers/index.tsx +45 -0
- package/template/apps/web/providers/query-provider.tsx +181 -0
- package/template/apps/web/providers/theme-provider.tsx +26 -0
- package/template/apps/web/tsconfig.json +30 -0
- package/template/package.json +91 -0
- package/template/packages/config/eslint/base.js +32 -0
- package/template/packages/config/eslint/next.js +134 -0
- package/template/packages/config/eslint/react-internal.js +41 -0
- package/template/packages/config/eslint.config.mjs +26 -0
- package/template/packages/config/eslint.nestjs.config.mjs +62 -0
- package/template/packages/config/index.ts +2 -0
- package/template/packages/config/package.json +44 -0
- package/template/packages/config/postcss.config.mjs +8 -0
- package/template/packages/config/prettier.config.mjs +14 -0
- package/template/packages/config/tsconfig.json +19 -0
- package/template/packages/config/typescript/base.json +20 -0
- package/template/packages/config/typescript/nextjs.json +12 -0
- package/template/packages/config/typescript/react-library.json +8 -0
- package/template/packages/constants/README.md +111 -0
- package/template/packages/constants/package.json +25 -0
- package/template/packages/constants/src/index.ts +243 -0
- package/template/packages/constants/tsconfig.build.json +13 -0
- package/template/packages/constants/tsconfig.json +12 -0
- package/template/packages/contracts/ERROR-MIGRATION.md +179 -0
- package/template/packages/contracts/README.md +203 -0
- package/template/packages/contracts/jest.config.js +11 -0
- package/template/packages/contracts/package.json +60 -0
- package/template/packages/contracts/src/api/analytics.contract.ts +45 -0
- package/template/packages/contracts/src/api/download.contract.ts +66 -0
- package/template/packages/contracts/src/api/index.ts +12 -0
- package/template/packages/contracts/src/api/message.contract.ts +70 -0
- package/template/packages/contracts/src/api/risk-words.contract.ts +44 -0
- package/template/packages/contracts/src/api/setting.contract.ts +127 -0
- package/template/packages/contracts/src/api/sign.contract.ts +269 -0
- package/template/packages/contracts/src/api/sms.contract.ts +95 -0
- package/template/packages/contracts/src/api/system.contract.ts +52 -0
- package/template/packages/contracts/src/api/task.contract.ts +58 -0
- package/template/packages/contracts/src/api/uploader.contract.ts +93 -0
- package/template/packages/contracts/src/api/user.contract.ts +60 -0
- package/template/packages/contracts/src/api/webhook.contract.ts +73 -0
- package/template/packages/contracts/src/base.ts +319 -0
- package/template/packages/contracts/src/errors/codes.ts +55 -0
- package/template/packages/contracts/src/errors/domains/common.errors.ts +212 -0
- package/template/packages/contracts/src/errors/domains/index.ts +7 -0
- package/template/packages/contracts/src/errors/domains/user.errors.ts +51 -0
- package/template/packages/contracts/src/errors/error-response.ts +145 -0
- package/template/packages/contracts/src/errors/index.ts +16 -0
- package/template/packages/contracts/src/errors/messages.ts +240 -0
- package/template/packages/contracts/src/index.ts +16 -0
- package/template/packages/contracts/src/schemas/analytics.schema.ts +81 -0
- package/template/packages/contracts/src/schemas/download.schema.ts +59 -0
- package/template/packages/contracts/src/schemas/index.ts +18 -0
- package/template/packages/contracts/src/schemas/message.schema.ts +83 -0
- package/template/packages/contracts/src/schemas/risk-words.schema.ts +25 -0
- package/template/packages/contracts/src/schemas/setting.schema.ts +84 -0
- package/template/packages/contracts/src/schemas/sign.schema.ts +171 -0
- package/template/packages/contracts/src/schemas/sms.schema.ts +53 -0
- package/template/packages/contracts/src/schemas/sse.schema.ts +30 -0
- package/template/packages/contracts/src/schemas/system.schema.ts +26 -0
- package/template/packages/contracts/src/schemas/tag.schema.ts +65 -0
- package/template/packages/contracts/src/schemas/task.schema.ts +47 -0
- package/template/packages/contracts/src/schemas/uploader.schema.ts +121 -0
- package/template/packages/contracts/src/schemas/user.schema.ts +75 -0
- package/template/packages/contracts/src/schemas/webhook.schema.ts +72 -0
- package/template/packages/contracts/tsconfig.build.json +20 -0
- package/template/packages/contracts/tsconfig.json +12 -0
- package/template/packages/types/README.md +143 -0
- package/template/packages/types/ai.ts +30 -0
- package/template/packages/types/auth.ts +99 -0
- package/template/packages/types/common.ts +13 -0
- package/template/packages/types/creative.ts +68 -0
- package/template/packages/types/image-factory.ts +122 -0
- package/template/packages/types/index.ts +8 -0
- package/template/packages/types/package.json +21 -0
- package/template/packages/types/task.ts +27 -0
- package/template/packages/types/tsconfig.json +11 -0
- package/template/packages/ui/README.md +30 -0
- package/template/packages/ui/components.json +22 -0
- package/template/packages/ui/eslint.config.js +4 -0
- package/template/packages/ui/package.json +58 -0
- package/template/packages/ui/postcss.config.mjs +6 -0
- package/template/packages/ui/src/components/accordion.tsx +66 -0
- package/template/packages/ui/src/components/alert.tsx +61 -0
- package/template/packages/ui/src/components/avatar.tsx +57 -0
- package/template/packages/ui/src/components/badge.tsx +38 -0
- package/template/packages/ui/src/components/button.tsx +60 -0
- package/template/packages/ui/src/components/calendar.tsx +71 -0
- package/template/packages/ui/src/components/card.tsx +92 -0
- package/template/packages/ui/src/components/carousel.tsx +241 -0
- package/template/packages/ui/src/components/checkbox.tsx +32 -0
- package/template/packages/ui/src/components/command.tsx +184 -0
- package/template/packages/ui/src/components/dialog.tsx +134 -0
- package/template/packages/ui/src/components/dropdown-menu.tsx +257 -0
- package/template/packages/ui/src/components/empty.tsx +104 -0
- package/template/packages/ui/src/components/field.tsx +248 -0
- package/template/packages/ui/src/components/form.tsx +172 -0
- package/template/packages/ui/src/components/input-group.tsx +170 -0
- package/template/packages/ui/src/components/input.tsx +21 -0
- package/template/packages/ui/src/components/item.tsx +193 -0
- package/template/packages/ui/src/components/label.tsx +24 -0
- package/template/packages/ui/src/components/password-strength.tsx +248 -0
- package/template/packages/ui/src/components/popover.tsx +48 -0
- package/template/packages/ui/src/components/progress.tsx +35 -0
- package/template/packages/ui/src/components/scroll-area.tsx +48 -0
- package/template/packages/ui/src/components/select.tsx +190 -0
- package/template/packages/ui/src/components/separator.tsx +28 -0
- package/template/packages/ui/src/components/sheet.tsx +139 -0
- package/template/packages/ui/src/components/sidebar.tsx +729 -0
- package/template/packages/ui/src/components/skeleton.tsx +13 -0
- package/template/packages/ui/src/components/slider.tsx +87 -0
- package/template/packages/ui/src/components/sonner.tsx +40 -0
- package/template/packages/ui/src/components/switch.tsx +31 -0
- package/template/packages/ui/src/components/tabs.tsx +66 -0
- package/template/packages/ui/src/components/textarea.tsx +18 -0
- package/template/packages/ui/src/components/tooltip.tsx +61 -0
- package/template/packages/ui/src/hooks/use-mobile.ts +21 -0
- package/template/packages/ui/src/index.ts +38 -0
- package/template/packages/ui/src/lib/utils.ts +6 -0
- package/template/packages/ui/src/styles/globals.css +134 -0
- package/template/packages/ui/tsconfig.json +11 -0
- package/template/packages/ui/tsconfig.lint.json +8 -0
- package/template/packages/utils/README.md +173 -0
- package/template/packages/utils/array.util.ts +335 -0
- package/template/packages/utils/bcrypt.util.ts +10 -0
- package/template/packages/utils/bigint.util.ts +111 -0
- package/template/packages/utils/cn.ts +6 -0
- package/template/packages/utils/encrypt.ts +104 -0
- package/template/packages/utils/fetch.ts +170 -0
- package/template/packages/utils/file.ts +275 -0
- package/template/packages/utils/headers.ts +116 -0
- package/template/packages/utils/index.ts +22 -0
- package/template/packages/utils/jest.config.js +28 -0
- package/template/packages/utils/json.util.ts +9 -0
- package/template/packages/utils/mask.util.ts +348 -0
- package/template/packages/utils/object.util.ts +149 -0
- package/template/packages/utils/package.json +112 -0
- package/template/packages/utils/serialize.util.ts +17 -0
- package/template/packages/utils/string.util.ts +159 -0
- package/template/packages/utils/timer.util.ts +210 -0
- package/template/packages/utils/tsconfig.build.json +17 -0
- package/template/packages/utils/tsconfig.json +13 -0
- package/template/packages/utils/urlencode.util.ts +18 -0
- package/template/packages/utils/validate.util.ts +25 -0
- package/template/packages/validators/README.md +149 -0
- package/template/packages/validators/jest.config.js +20 -0
- package/template/packages/validators/package.json +32 -0
- package/template/packages/validators/src/index.ts +178 -0
- package/template/packages/validators/tsconfig.build.json +19 -0
- package/template/packages/validators/tsconfig.json +12 -0
- package/template/pnpm-lock.yaml +21574 -0
- package/template/pnpm-workspace.yaml +4 -0
- package/template/scripts/generate-i18n-errors.ts +371 -0
- package/template/scripts/generate-prisma-enums.js +170 -0
- package/template/scripts/generate-prisma-enums.ts +172 -0
- package/template/scripts/init-project.js +232 -0
- package/template/turbo.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# create-pardx-scaffold
|
|
2
|
+
|
|
3
|
+
通过一行命令生成基于 PardxAI Monorepo 的项目脚手架,包含该仓库 git 中几乎全部文件(源码、配置、文档、脚本、迁移等)。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx create-pardx-scaffold <项目目录名>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
示例:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx create-pardx-scaffold my-app
|
|
15
|
+
cd my-app
|
|
16
|
+
pnpm install
|
|
17
|
+
pnpm db:generate # 若使用 API + Prisma
|
|
18
|
+
pnpm dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
生成后可在此项目中执行 `node scripts/init-project.js`,交互式配置端口、数据库、Redis、作者等。
|
|
22
|
+
|
|
23
|
+
## 模板内容
|
|
24
|
+
|
|
25
|
+
- 来源:本仓库(pardx-scaffold)中 `git ls-files` 所列文件
|
|
26
|
+
- 排除:`packages/create-pardx-scaffold/` 自身不会被打进新项目
|
|
27
|
+
|
|
28
|
+
## 发布本包前
|
|
29
|
+
|
|
30
|
+
模板目录 `template/` 由脚本生成、不提交到 git。发布前需在**仓库根目录**执行:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm run export-scaffold
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
再在 `packages/create-pardx-scaffold` 下执行 `npm publish`,以便把最新模板打进包内。
|
|
37
|
+
|
|
38
|
+
## 在本仓库内本地试用
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# 在仓库根目录
|
|
42
|
+
pnpm run export-scaffold
|
|
43
|
+
node packages/create-pardx-scaffold/cli.js ../my-new-project
|
|
44
|
+
cd ../my-new-project && pnpm install && pnpm dev
|
|
45
|
+
```
|
package/cli.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* create-pardx-scaffold
|
|
4
|
+
*
|
|
5
|
+
* 用法:npx create-pardx-scaffold <项目目录名>
|
|
6
|
+
* 将模板(当前仓库 git 中的文件)复制到目标目录,并做基础项目名替换。
|
|
7
|
+
*
|
|
8
|
+
* 使用前需在仓库根目录执行:node scripts/export-scaffold-for-create.js
|
|
9
|
+
* 以生成 packages/create-pardx-scaffold/template/
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const RED = '\x1b[31m';
|
|
16
|
+
const GREEN = '\x1b[32m';
|
|
17
|
+
const YELLOW = '\x1b[33m';
|
|
18
|
+
const CYAN = '\x1b[36m';
|
|
19
|
+
const RESET = '\x1b[0m';
|
|
20
|
+
|
|
21
|
+
const log = {
|
|
22
|
+
info: (msg) => console.log(`${CYAN}ℹ${RESET} ${msg}`),
|
|
23
|
+
ok: (msg) => console.log(`${GREEN}✓${RESET} ${msg}`),
|
|
24
|
+
warn: (msg) => console.log(`${YELLOW}⚠${RESET} ${msg}`),
|
|
25
|
+
err: (msg) => console.log(`${RED}✗${RESET} ${msg}`),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const templateDir = path.join(__dirname, 'template');
|
|
29
|
+
|
|
30
|
+
function main() {
|
|
31
|
+
const name = process.argv[2];
|
|
32
|
+
if (!name || name.startsWith('-')) {
|
|
33
|
+
console.log('Usage: npx create-pardx-scaffold <project-directory>');
|
|
34
|
+
console.log('Example: npx create-pardx-scaffold my-app');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const cwd = process.cwd();
|
|
39
|
+
const targetDir = path.resolve(cwd, name);
|
|
40
|
+
|
|
41
|
+
if (!fs.existsSync(templateDir)) {
|
|
42
|
+
log.err(
|
|
43
|
+
'Template not found. In this repo run first: node scripts/export-scaffold-for-create.js'
|
|
44
|
+
);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync(targetDir)) {
|
|
49
|
+
const entries = fs.readdirSync(targetDir);
|
|
50
|
+
if (entries.length > 0) {
|
|
51
|
+
log.err(`Target directory "${name}" already exists and is not empty.`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
log.info(`Copying scaffold to ${name}...`);
|
|
59
|
+
copyRecursive(templateDir, targetDir);
|
|
60
|
+
log.ok('Files copied.');
|
|
61
|
+
|
|
62
|
+
const pkgPath = path.join(targetDir, 'package.json');
|
|
63
|
+
if (fs.existsSync(pkgPath)) {
|
|
64
|
+
try {
|
|
65
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
66
|
+
const prev = pkg.name || 'pardx-ai';
|
|
67
|
+
const next = name.replace(/\s+/g, '-').replace(/[^a-z0-9.-]/gi, '') || 'my-app';
|
|
68
|
+
pkg.name = next;
|
|
69
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
70
|
+
if (prev !== next) {
|
|
71
|
+
log.ok(`package.json name set to "${next}".`);
|
|
72
|
+
}
|
|
73
|
+
} catch (e) {
|
|
74
|
+
log.warn('Could not update package.json name: ' + e.message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('');
|
|
79
|
+
console.log(`${GREEN}Done.${RESET} Next steps:`);
|
|
80
|
+
console.log(` ${CYAN}cd ${name}${RESET}`);
|
|
81
|
+
console.log(` ${CYAN}pnpm install${RESET}`);
|
|
82
|
+
console.log(` ${CYAN}pnpm db:generate${RESET} # if using API + Prisma`);
|
|
83
|
+
console.log(` ${CYAN}pnpm dev${RESET} # start dev servers`);
|
|
84
|
+
console.log('');
|
|
85
|
+
console.log('Optional: run interactive init for ports, DB, Redis, etc.');
|
|
86
|
+
console.log(` ${CYAN}node scripts/init-project.js${RESET}`);
|
|
87
|
+
console.log('');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function copyRecursive(src, dest) {
|
|
91
|
+
const st = fs.statSync(src);
|
|
92
|
+
if (st.isDirectory()) {
|
|
93
|
+
if (!fs.existsSync(dest)) {
|
|
94
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
95
|
+
}
|
|
96
|
+
for (const entry of fs.readdirSync(src)) {
|
|
97
|
+
copyRecursive(path.join(src, entry), path.join(dest, entry));
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
fs.copyFileSync(src, dest);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-pardx-scaffold",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a new project from PardxAI monorepo (git-tracked files)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": "./cli.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"cli.js",
|
|
9
|
+
"template",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18.0.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
# Cursor Rules - PardxAI 项目编码规范
|
|
2
|
+
|
|
3
|
+
本文件定义了使用 Cursor 或 Claude 进行实时编码(vibecoding)时的前置要求。
|
|
4
|
+
|
|
5
|
+
## 📋 代码质量标准
|
|
6
|
+
|
|
7
|
+
所有代码必须遵循以下质量标准:
|
|
8
|
+
|
|
9
|
+
1. **遵循架构分层规范**
|
|
10
|
+
- 严格遵循4层架构:API层 → Service层 → DB层/Client层
|
|
11
|
+
- API层不能直接访问数据库或外部API
|
|
12
|
+
- Service层通过DB Service访问数据库,通过Client层访问外部API
|
|
13
|
+
- DB层负责数据访问,Client层负责外部API调用
|
|
14
|
+
|
|
15
|
+
2. **使用Zod-first验证**
|
|
16
|
+
- 所有API请求/响应必须使用Zod Schema进行验证
|
|
17
|
+
- 禁止在Controller或Service层手动进行类型断言
|
|
18
|
+
- 必须依赖Zod Schema验证确保类型安全
|
|
19
|
+
|
|
20
|
+
3. **类型安全的API契约**
|
|
21
|
+
- 使用`@repo/contracts`定义API契约
|
|
22
|
+
- 使用ts-rest实现前后端类型安全
|
|
23
|
+
- 后端使用`@ts-rest/nest`,前端使用`@ts-rest/react-query`
|
|
24
|
+
- 编译时类型检查,运行时Zod验证
|
|
25
|
+
|
|
26
|
+
4. **统一使用Winston Logger**
|
|
27
|
+
- 禁止使用NestJS内置的`Logger`
|
|
28
|
+
- 禁止使用`console.log`、`console.error`等(启动日志除外)
|
|
29
|
+
- 必须使用Winston Logger(通过`WINSTON_MODULE_PROVIDER`注入)
|
|
30
|
+
- 统一日志级别:`info`、`warn`、`error`、`debug`
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ⚠️ 核心架构规则(必须严格遵守)
|
|
35
|
+
|
|
36
|
+
在进行任何代码修改之前,AI 助手**必须**严格遵守以下三条核心规则:
|
|
37
|
+
|
|
38
|
+
1. **禁止在非 DB 层直接进行数据库读写操作**
|
|
39
|
+
- **允许**:在非 DB 层使用 Prisma 的**类型定义**(如 `Prisma.MeetingRecordUpdateInput`、`Prisma.MeetingRecordWhereInput` 等)
|
|
40
|
+
- **禁止**:在非 DB 层直接进行数据库读写操作
|
|
41
|
+
- 只有 DB Service 层(继承 `TransactionalServiceBase` 的服务)可以直接进行数据库读写
|
|
42
|
+
- Service 层(如 `MeetingService`、`WebhookService`)必须通过 DB Service 的函数进行数据库读写
|
|
43
|
+
- **禁止在 Service 层**:
|
|
44
|
+
- 直接使用 `prisma.write`、`prisma.read`
|
|
45
|
+
- 直接使用 `getWriteClient()`、`getReadClient()`(这些是受保护的方法)
|
|
46
|
+
- 直接调用 Prisma 的数据库操作方法(如 `updateMany`、`findMany`、`create`、`update`、`delete` 等)
|
|
47
|
+
- **允许在 Service 层**:
|
|
48
|
+
- 使用 Prisma 类型定义作为函数参数类型或返回值类型
|
|
49
|
+
- 使用 Prisma 类型定义构建查询条件对象(传递给 DB Service)
|
|
50
|
+
|
|
51
|
+
2. **Zod-first:所有 API 必须使用 Zod Schema 进行验证**
|
|
52
|
+
- 所有 API 请求/响应必须使用 Zod Schema 进行验证
|
|
53
|
+
- 使用 `tsRestHandler` 时,会自动使用 contract 中定义的 Zod Schema 进行验证
|
|
54
|
+
- 禁止在 Controller 或 Service 层手动进行类型断言,必须依赖 Zod Schema 验证
|
|
55
|
+
- Webhook 回调等外部接口也必须使用 Zod Schema 定义
|
|
56
|
+
|
|
57
|
+
3. **所有外部服务调用必须放在 Client 层,使用 @nestjs/axios**
|
|
58
|
+
- 所有第三方 API 调用、外部服务集成必须封装在 Client 层(`apps/api/libs/clients/`)
|
|
59
|
+
- Client 层必须使用 `@nestjs/axios` 的 `HttpService`,禁止直接使用 `axios`
|
|
60
|
+
- Service 层(业务逻辑层)不能直接调用外部 API,必须通过 Client 层
|
|
61
|
+
- Client 层职责:仅负责 HTTP 调用,不包含业务逻辑,不访问数据库
|
|
62
|
+
- 在 Module 中导入 `HttpModule`,在 Client 中注入 `HttpService`
|
|
63
|
+
- 使用 `firstValueFrom` 将 RxJS Observable 转换为 Promise
|
|
64
|
+
|
|
65
|
+
4. **日志记录必须使用 Winston Logger**
|
|
66
|
+
- **禁止**:使用 NestJS 内置的 `Logger`(`import { Logger } from '@nestjs/common'`)
|
|
67
|
+
- **禁止**:使用 `console.log`、`console.error`、`console.warn` 等(启动时的日志除外,如 `main.ts`、`app.module.ts`)
|
|
68
|
+
- **必须**:使用 Winston Logger(通过 `nest-winston` 集成)
|
|
69
|
+
- **使用方式**:
|
|
70
|
+
```typescript
|
|
71
|
+
import { Injectable, Inject } from '@nestjs/common';
|
|
72
|
+
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
|
73
|
+
import { Logger } from 'winston';
|
|
74
|
+
|
|
75
|
+
@Injectable()
|
|
76
|
+
export class YourService {
|
|
77
|
+
constructor(
|
|
78
|
+
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
|
|
79
|
+
) {}
|
|
80
|
+
|
|
81
|
+
someMethod() {
|
|
82
|
+
this.logger.info('Info message');
|
|
83
|
+
this.logger.warn('Warning message');
|
|
84
|
+
this.logger.error('Error message', error);
|
|
85
|
+
this.logger.debug('Debug message');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
- **日志级别**:
|
|
90
|
+
- `logger.info()` - 一般信息日志(替代 `logger.log()`)
|
|
91
|
+
- `logger.warn()` - 警告日志
|
|
92
|
+
- `logger.error()` - 错误日志
|
|
93
|
+
- `logger.debug()` - 调试日志
|
|
94
|
+
- **注意**:Winston Logger 已在 `AppModule` 中全局配置,无需在子模块中单独导入 `WinstonModule`
|
|
95
|
+
|
|
96
|
+
5. **infra / domain 边界(后端 libs 必须遵守)**
|
|
97
|
+
- **infra**(`apps/api/libs/infra/`):common、clients、prisma、redis、rabbitmq、jwt、utils、i18n、shared-db、shared-services。与产品/领域无关,可复用。**禁止**依赖 `libs/domain/**` 下任何内容。
|
|
98
|
+
- **domain**(`apps/api/libs/domain/`):auth、db。与 Pardx 领域/业务流程强相关。**可**依赖 infra。
|
|
99
|
+
- **依赖方向**:`src` → `domain` → `infra`。infra 内模块可相互依赖,**不得** import domain。
|
|
100
|
+
- **导入约定**:infra 内统一使用 `@/`、`@app/` 等 tsconfig 路径别名,不得使用 `libs/domain/**` 或相对路径穿越到 domain。
|
|
101
|
+
- 详见:`apps/api/docs/业务与基础设施拆分方案.md`。
|
|
102
|
+
|
|
103
|
+
## ⚠️ 重要:编码前的必读文档
|
|
104
|
+
|
|
105
|
+
在进行任何代码修改、重构或新功能开发之前,AI 助手**必须**首先阅读并理解以下规范文档:
|
|
106
|
+
|
|
107
|
+
### 前端开发规范
|
|
108
|
+
|
|
109
|
+
1. **代码质量与类型定义规范**
|
|
110
|
+
- 路径:`apps/web/docs/代码质量与类型定义规范.md`
|
|
111
|
+
- 内容:类型定义规范、类型导入规范、Props 类型定义、工具类型使用、类型检查清单
|
|
112
|
+
- **必须遵循**:
|
|
113
|
+
- 使用 `@repo/contracts` 类型(而非本地定义 API 相关类型)
|
|
114
|
+
- 使用 `type-only` imports(`import type`)
|
|
115
|
+
- Props 类型使用 `interface`(而非 `React.FC`)
|
|
116
|
+
- 避免使用 `any` 类型(必要时使用 `unknown`)
|
|
117
|
+
- 扩展类型使用 `extends` 或交叉类型
|
|
118
|
+
|
|
119
|
+
2. **前端架构与交互优化方案**
|
|
120
|
+
- 路径:`apps/web/docs/前端架构与交互优化方案.md`
|
|
121
|
+
- 内容:架构设计、性能优化方案、代码分割策略、网络请求优化、图片加载优化
|
|
122
|
+
- **必须遵循**:
|
|
123
|
+
- 组件拆分策略(大型组件拆分)
|
|
124
|
+
- 代码分割优化(使用 `next/dynamic`)
|
|
125
|
+
- 网络请求优化(并行查询、缓存策略)
|
|
126
|
+
- 图片加载优化(使用 Next.js Image 组件)
|
|
127
|
+
- 虚拟滚动实现(长列表)
|
|
128
|
+
|
|
129
|
+
### 后端开发规范
|
|
130
|
+
|
|
131
|
+
3. **架构分层与事务管理方案**
|
|
132
|
+
- 路径:`apps/api/docs/架构分层与事务管理方案-new.md`
|
|
133
|
+
- 内容:架构分层设计、事务管理、错误处理、软删除、批量操作、缓存策略
|
|
134
|
+
- **必须遵循**:
|
|
135
|
+
- DB Service 继承 `TransactionalServiceBase`
|
|
136
|
+
- 使用 `getWriteClient()` / `getReadClient()`(而非直接 `this.prisma.write/read`)
|
|
137
|
+
- 使用 `@HandlePrismaError` 装饰器处理错误
|
|
138
|
+
- 跨服务事务使用 `UnitOfWorkService.execute()`
|
|
139
|
+
- 单服务内事务使用 `@Transactional` 装饰器
|
|
140
|
+
- **禁止**:API Service 层直接进行数据库读写操作(必须通过 DB Service)
|
|
141
|
+
- **⚠️ 重要规则 1**:**不要在非 DB 层直接进行数据库读写操作**
|
|
142
|
+
- **允许**:在非 DB 层使用 Prisma 的**类型定义**(如 `Prisma.MeetingRecordUpdateInput`、`Prisma.MeetingRecordWhereInput` 等)
|
|
143
|
+
- **禁止**:在非 DB 层直接进行数据库读写操作
|
|
144
|
+
- 只有 DB Service 层(继承 `TransactionalServiceBase` 的服务)可以直接进行数据库读写
|
|
145
|
+
- Service 层必须通过 DB Service 的函数进行数据库读写
|
|
146
|
+
- 禁止在 Service 层直接使用 `prisma.write`、`prisma.read`、`getWriteClient()`、`getReadClient()` 等
|
|
147
|
+
- 禁止在 Service 层直接调用 Prisma 的数据库操作方法(如 `updateMany`、`findMany`、`create`、`update`、`delete` 等)
|
|
148
|
+
- **示例**:Service 层可以使用 `Prisma.MeetingRecordUpdateInput` 作为参数类型,但必须调用 `meetingRecordDb.updateMeetingRecord()` 而不是直接调用 `update()`
|
|
149
|
+
|
|
150
|
+
4. **API 版本兼容方案**
|
|
151
|
+
- 路径:`apps/api/docs/API版本兼容方案-统一设计.md`
|
|
152
|
+
- 内容:版本体系设计、Contract 适配器模式、版本校验流程
|
|
153
|
+
- **必须遵循**:
|
|
154
|
+
- Web 客户端使用 Generation(代际号)
|
|
155
|
+
- APP 客户端使用 Contract(合约版本)
|
|
156
|
+
- 版本校验流程和 Header 协议
|
|
157
|
+
|
|
158
|
+
5. **业务与基础设施拆分方案(infra/domain 边界)**
|
|
159
|
+
- 路径:`apps/api/docs/业务与基础设施拆分方案.md`
|
|
160
|
+
- 内容:libs 按 infra/domain 的目录划分、依赖方向、路径别名、检查清单
|
|
161
|
+
- **必须遵循**(涉及 `apps/api/libs/` 的修改或新增模块时):
|
|
162
|
+
- infra(`libs/infra/**`)**禁止**依赖 domain(`libs/domain/**`)
|
|
163
|
+
- domain 可依赖 infra;依赖方向为 `src` → `domain` → `infra`
|
|
164
|
+
- 使用 tsconfig 中已定义的 `@/`、`@app/` 等路径别名,不写死 `libs/domain/**` 或 `libs/infra/**` 的相对路径穿越
|
|
165
|
+
|
|
166
|
+
### API 契约设计规范
|
|
167
|
+
|
|
168
|
+
6. **ts-rest Zod-first REST 协议框架设计方案**
|
|
169
|
+
- 路径:`docs/ts-rest_Zod-first_REST_协议框架设计方案.md`
|
|
170
|
+
- 内容:API 契约定义、前后端类型安全、Zod Schema 定义
|
|
171
|
+
- **必须遵循**:
|
|
172
|
+
- 使用 `@repo/contracts` 定义 API 契约
|
|
173
|
+
- 使用 Zod Schema 定义请求/响应结构
|
|
174
|
+
- 后端使用 `@ts-rest/nest` 实现 Controller
|
|
175
|
+
- 前端使用 `@ts-rest/react-query` 调用 API
|
|
176
|
+
- 类型安全:编译时类型检查
|
|
177
|
+
- **⚠️ 重要规则 2**:**Zod-first**
|
|
178
|
+
- 所有 API 请求/响应必须使用 Zod Schema 进行验证
|
|
179
|
+
- 使用 `tsRestHandler` 时,会自动使用 contract 中定义的 Zod Schema 进行验证
|
|
180
|
+
- 禁止在 Controller 或 Service 层手动进行类型断言,必须依赖 Zod Schema 验证
|
|
181
|
+
- Webhook 回调等外部接口也必须使用 Zod Schema 定义(如使用 `z.any()` 需有合理原因)
|
|
182
|
+
|
|
183
|
+
## 编码工作流
|
|
184
|
+
|
|
185
|
+
### 步骤 1:理解需求
|
|
186
|
+
- 阅读用户请求,理解需要修改的功能或添加的特性
|
|
187
|
+
|
|
188
|
+
### 步骤 2:查阅规范文档
|
|
189
|
+
- **前端代码修改**:查阅前端规范文档(1-2)
|
|
190
|
+
- **后端代码修改**:查阅后端规范文档(3-5);涉及 libs 划分或新增模块时必读《业务与基础设施拆分方案》
|
|
191
|
+
- **API 相关修改**:查阅 API 契约设计规范(6)
|
|
192
|
+
|
|
193
|
+
### 步骤 3:检查现有代码
|
|
194
|
+
- 检查相关文件是否遵循规范
|
|
195
|
+
- 识别需要优化的点(类型定义、代码分割、事务管理等)
|
|
196
|
+
|
|
197
|
+
### 步骤 4:实施修改
|
|
198
|
+
- 遵循规范文档中的最佳实践
|
|
199
|
+
- 使用规范推荐的模式和工具
|
|
200
|
+
- 确保代码符合架构约束
|
|
201
|
+
- **格式化规范**:
|
|
202
|
+
- 所有代码必须遵循 `.prettierrc` 中的格式规范
|
|
203
|
+
- 使用 `import type` 进行类型导入
|
|
204
|
+
- 使用 `interface` 定义 Props 类型
|
|
205
|
+
- 避免使用 `any` 类型(必要时使用 `unknown`)
|
|
206
|
+
|
|
207
|
+
### 步骤 5:验证与测试
|
|
208
|
+
- 检查类型错误(TypeScript)
|
|
209
|
+
- 检查架构约束(ESLint)
|
|
210
|
+
- 验证代码格式化(Prettier)
|
|
211
|
+
- 验证功能正确性
|
|
212
|
+
|
|
213
|
+
## 代码格式化和质量检查
|
|
214
|
+
|
|
215
|
+
### ESLint 配置
|
|
216
|
+
|
|
217
|
+
项目使用 ESLint 进行代码质量检查,配置位于 `packages/config/eslint/next-js`。ESLint 配置:
|
|
218
|
+
|
|
219
|
+
1. **Prettier 集成**:
|
|
220
|
+
- 使用 `eslint-plugin-prettier` 强制执行 Prettier 格式化
|
|
221
|
+
- Prettier 配置从 `.prettierrc` 读取
|
|
222
|
+
- 所有代码必须符合 Prettier 格式规范
|
|
223
|
+
|
|
224
|
+
2. **TypeScript 代码质量规则**(基于 `代码质量与类型定义规范.md`):
|
|
225
|
+
- 禁止使用 `any` 类型(`@typescript-eslint/no-explicit-any`)
|
|
226
|
+
- 要求使用 `type-only` imports(`@typescript-eslint/consistent-type-imports`)
|
|
227
|
+
- 优先使用 `interface` 而不是 `type`(`@typescript-eslint/consistent-type-definitions`)
|
|
228
|
+
- 禁止未使用的变量(`@typescript-eslint/no-unused-vars`)
|
|
229
|
+
- 禁止非空断言(`@typescript-eslint/no-non-null-assertion`)
|
|
230
|
+
- 禁止使用 `@ts-ignore`(`@typescript-eslint/ban-ts-comment`)
|
|
231
|
+
|
|
232
|
+
### 代码格式化要求
|
|
233
|
+
|
|
234
|
+
1. **Prettier 配置**(`.prettierrc`):
|
|
235
|
+
- `printWidth: 80`
|
|
236
|
+
- `singleQuote: true`
|
|
237
|
+
- `semi: true`
|
|
238
|
+
- `trailingComma: "all"`
|
|
239
|
+
- `tabWidth: 2`
|
|
240
|
+
- `useTabs: false`
|
|
241
|
+
- `arrowParens: "always"`
|
|
242
|
+
|
|
243
|
+
2. **Vibe Coding 要求**:
|
|
244
|
+
- 所有生成的代码必须符合 Prettier 格式规范
|
|
245
|
+
- 使用 `import type` 进行类型导入
|
|
246
|
+
- 使用 `interface` 定义 Props 类型
|
|
247
|
+
- 避免使用 `any` 类型
|
|
248
|
+
|
|
249
|
+
### 运行代码检查
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
# 检查代码质量和格式
|
|
253
|
+
pnpm lint
|
|
254
|
+
|
|
255
|
+
# 自动修复可修复的问题
|
|
256
|
+
pnpm lint:fix
|
|
257
|
+
|
|
258
|
+
# 类型检查
|
|
259
|
+
pnpm type-check
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## 常见违规模式
|
|
263
|
+
|
|
264
|
+
### ❌ 前端违规示例
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
// ❌ 错误:使用 any 类型
|
|
268
|
+
const handleError = (error: any) => { ... }
|
|
269
|
+
|
|
270
|
+
// ✅ 正确:使用 unknown 类型
|
|
271
|
+
const handleError = (error: unknown) => {
|
|
272
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
273
|
+
// ...
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ❌ 错误:直接导入类型(未使用 type-only)
|
|
277
|
+
import { UserInfo } from '@repo/contracts';
|
|
278
|
+
|
|
279
|
+
// ✅ 正确:使用 type-only import
|
|
280
|
+
import type { UserInfo } from '@repo/contracts';
|
|
281
|
+
|
|
282
|
+
// ❌ 错误:使用 React.FC
|
|
283
|
+
const UserCard: React.FC<UserCardProps> = ({ user }) => { ... }
|
|
284
|
+
|
|
285
|
+
// ✅ 正确:使用 interface 定义 Props
|
|
286
|
+
interface UserCardProps {
|
|
287
|
+
user: UserInfo;
|
|
288
|
+
}
|
|
289
|
+
export function UserCard({ user }: UserCardProps) { ... }
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### ❌ 后端违规示例
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
// ❌ 错误:API Service 直接进行数据库读写操作
|
|
296
|
+
@Injectable()
|
|
297
|
+
export class UserApiService {
|
|
298
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
299
|
+
|
|
300
|
+
async getUser(id: string) {
|
|
301
|
+
// ❌ 错误:直接调用 Prisma 进行数据库查询
|
|
302
|
+
return this.prisma.write.userInfo.findUnique({ where: { id } });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ✅ 正确:通过 DB Service 访问
|
|
307
|
+
@Injectable()
|
|
308
|
+
export class UserApiService {
|
|
309
|
+
constructor(private readonly userService: UserService) {}
|
|
310
|
+
|
|
311
|
+
async getUser(id: string) {
|
|
312
|
+
return this.userService.getUserById(id);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ❌ 错误:在非 DB Service 层直接进行数据库写入操作
|
|
317
|
+
@Injectable()
|
|
318
|
+
export class UserService {
|
|
319
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
320
|
+
|
|
321
|
+
async createUser(data: CreateUserInput) {
|
|
322
|
+
// ❌ 错误:直接调用 Prisma 进行数据库写入
|
|
323
|
+
return this.prisma.write.userInfo.create({ data });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ✅ 正确:在 DB Service 层使用 getWriteClient()(事务感知)
|
|
328
|
+
@Injectable()
|
|
329
|
+
export class UserService extends TransactionalServiceBase {
|
|
330
|
+
@HandlePrismaError(DbOperationType.CREATE)
|
|
331
|
+
async createUser(data: CreateUserInput) {
|
|
332
|
+
// ✅ 正确:DB Service 层可以直接进行数据库操作
|
|
333
|
+
return this.getWriteClient().userInfo.create({ data });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ❌ 错误:Service 层直接进行数据库读写操作
|
|
338
|
+
@Injectable()
|
|
339
|
+
export class MeetingService {
|
|
340
|
+
constructor(private readonly meetingRecordDb: MeetingRecordService) {}
|
|
341
|
+
|
|
342
|
+
async batchUpdateTranscripts(meetingIds: string[], data: UpdateTranscriptDto) {
|
|
343
|
+
// ❌ 错误:在 Service 层直接使用 getWriteClient() 和 updateMany(数据库读写操作)
|
|
344
|
+
await this.meetingRecordDb.getWriteClient().meetingRecord.updateMany({
|
|
345
|
+
where: { id: { in: meetingIds } },
|
|
346
|
+
data: { ... }
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ✅ 正确:Service 层可以使用 Prisma 类型定义
|
|
352
|
+
@Injectable()
|
|
353
|
+
export class MeetingService {
|
|
354
|
+
constructor(private readonly meetingRecordDb: MeetingRecordService) {}
|
|
355
|
+
|
|
356
|
+
// ✅ 正确:使用 Prisma 类型定义作为参数类型
|
|
357
|
+
async updateMeeting(id: string, data: Prisma.MeetingRecordUpdateInput) {
|
|
358
|
+
// ✅ 正确:通过 DB Service 函数进行数据库读写
|
|
359
|
+
return await this.meetingRecordDb.updateMeetingRecord(id, data);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ✅ 正确:使用 Prisma 类型定义构建查询条件(传递给 DB Service)
|
|
363
|
+
async listMeetings(where: Prisma.MeetingRecordWhereInput) {
|
|
364
|
+
// ✅ 正确:通过 DB Service 函数进行数据库查询
|
|
365
|
+
return await this.meetingRecordDb.listMeetingRecords(where, {});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// ✅ 正确:在 DB Service 层实现批量更新方法
|
|
370
|
+
@Injectable()
|
|
371
|
+
export class MeetingRecordService extends TransactionalServiceBase {
|
|
372
|
+
@HandlePrismaError(DbOperationType.UPDATE)
|
|
373
|
+
async batchUpdateTranscripts(meetingIds: string[], data: Prisma.MeetingRecordUpdateInput) {
|
|
374
|
+
// ✅ 正确:在 DB Service 层使用 Prisma
|
|
375
|
+
return await this.getWriteClient().meetingRecord.updateMany({
|
|
376
|
+
where: { id: { in: meetingIds } },
|
|
377
|
+
data,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// ✅ 正确:Service 层调用 DB Service 方法
|
|
383
|
+
@Injectable()
|
|
384
|
+
export class MeetingService {
|
|
385
|
+
constructor(private readonly meetingRecordDb: MeetingRecordService) {}
|
|
386
|
+
|
|
387
|
+
async batchUpdateTranscripts(meetingIds: string[], data: UpdateTranscriptDto) {
|
|
388
|
+
// ✅ 正确:通过 DB Service 访问数据库
|
|
389
|
+
await this.meetingRecordDb.batchUpdateTranscripts(meetingIds, updateData);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// ❌ 错误:Service 层直接调用外部 API
|
|
394
|
+
@Injectable()
|
|
395
|
+
export class MeetingService {
|
|
396
|
+
constructor(private readonly httpService: HttpService) {}
|
|
397
|
+
|
|
398
|
+
async fetchExternalData() {
|
|
399
|
+
// ❌ 错误:Service 层直接调用外部 API
|
|
400
|
+
const response = await axios.get('https://api.example.com/data');
|
|
401
|
+
return response.data;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ✅ 正确:在 Client 层封装外部 API 调用
|
|
406
|
+
@Injectable()
|
|
407
|
+
export class ExternalApiClient {
|
|
408
|
+
constructor(private readonly httpService: HttpService) {}
|
|
409
|
+
|
|
410
|
+
async fetchData() {
|
|
411
|
+
// ✅ 正确:Client 层使用 @nestjs/axios
|
|
412
|
+
const response = await firstValueFrom(
|
|
413
|
+
this.httpService.get('https://api.example.com/data')
|
|
414
|
+
);
|
|
415
|
+
return response.data;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// ✅ 正确:Service 层通过 Client 层调用外部 API
|
|
420
|
+
@Injectable()
|
|
421
|
+
export class MeetingService {
|
|
422
|
+
constructor(private readonly externalApiClient: ExternalApiClient) {}
|
|
423
|
+
|
|
424
|
+
async processData() {
|
|
425
|
+
// ✅ 正确:通过 Client 层访问外部 API
|
|
426
|
+
const data = await this.externalApiClient.fetchData();
|
|
427
|
+
// ... 业务逻辑处理
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
## 架构约束检查清单
|
|
433
|
+
|
|
434
|
+
在进行代码修改前,确认:
|
|
435
|
+
|
|
436
|
+
### 代码质量标准检查
|
|
437
|
+
- [ ] **遵循架构分层规范** - 是否严格遵循4层架构(API → Service → DB/Client)
|
|
438
|
+
- [ ] **使用Zod-first验证** - 所有API是否使用Zod Schema进行验证
|
|
439
|
+
- [ ] **类型安全的API契约** - 是否使用`@repo/contracts`定义契约,前后端类型是否安全
|
|
440
|
+
- [ ] **统一使用Winston Logger** - 是否使用Winston Logger而非NestJS Logger或console
|
|
441
|
+
|
|
442
|
+
### 架构约束检查
|
|
443
|
+
- [ ] 是否遵循了架构分层(前端/后端)
|
|
444
|
+
- [ ] 是否使用了正确的类型定义方式
|
|
445
|
+
- [ ] 是否遵循了事务管理模式
|
|
446
|
+
- [ ] 是否使用了正确的错误处理方式
|
|
447
|
+
- [ ] 是否遵循了 API 契约设计规范
|
|
448
|
+
- [ ] 是否避免了已知的违规模式
|
|
449
|
+
- [ ] **⚠️ 是否在非 DB 层直接进行数据库读写**(禁止:Service 层必须通过 DB Service 函数访问数据库,但可以使用 Prisma 类型定义)
|
|
450
|
+
- [ ] **⚠️ 是否使用了 Zod-first 验证**(所有 API 请求/响应必须使用 Zod Schema)
|
|
451
|
+
- [ ] **⚠️ 外部服务调用是否放在 Client 层**(禁止:Service 层不能直接调用外部 API,必须使用 @nestjs/axios)
|
|
452
|
+
- [ ] **⚠️ 是否遵守 infra/domain 边界**(禁止:`libs/infra/**` 不得 import `libs/domain/**`;domain 可依赖 infra)
|
|
453
|
+
|
|
454
|
+
## 参考文档路径
|
|
455
|
+
|
|
456
|
+
所有规范文档均位于项目根目录或子目录的 `docs/` 文件夹中:
|
|
457
|
+
|
|
458
|
+
- `apps/api/docs/业务与基础设施拆分方案.md` - infra/domain 目录划分、依赖方向、路径别名
|
|
459
|
+
- `apps/web/docs/代码质量与类型定义规范.md`
|
|
460
|
+
- `apps/web/docs/前端架构与交互优化方案.md`
|
|
461
|
+
- `apps/api/docs/架构分层与事务管理方案-new.md`
|
|
462
|
+
- `apps/api/docs/API版本兼容方案-统一设计.md`
|
|
463
|
+
- `docs/ts-rest_Zod-first_REST_协议框架设计方案.md`
|
|
464
|
+
- `apps/api/CLAUDE.md` - HTTP Client Usage Rules (@nestjs/axios) 和 Client Layer Architecture
|
|
465
|
+
|
|
466
|
+
## 参考实现示例
|
|
467
|
+
|
|
468
|
+
### Client 层实现示例
|
|
469
|
+
|
|
470
|
+
以下文件展示了如何正确实现 Client 层:
|
|
471
|
+
|
|
472
|
+
- `apps/api/libs/clients/internal/agentx/agentx-client.service.ts` - AgentX API client(使用 @nestjs/axios)
|
|
473
|
+
- `apps/api/libs/clients/internal/ocr/ocr.client.ts` - OCR service client(使用 @nestjs/axios)
|
|
474
|
+
- `apps/api/libs/clients/internal/sms/sms-zxjc.client.ts` - SMS service client(使用 @nestjs/axios)
|
|
475
|
+
- `apps/api/libs/clients/internal/openspeech/openspeech.client.ts` - 语音识别服务 client
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
**注意**:这些规范文档是项目的核心开发标准,所有代码修改都应该遵循这些规范。如有疑问,请先查阅相关文档,再进行编码。
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
**/node_modules/
|
|
4
|
+
|
|
5
|
+
# Build outputs
|
|
6
|
+
dist/
|
|
7
|
+
.next/
|
|
8
|
+
out/
|
|
9
|
+
build/
|
|
10
|
+
coverage/
|
|
11
|
+
|
|
12
|
+
# Turbo
|
|
13
|
+
.turbo/
|
|
14
|
+
|
|
15
|
+
# Generated files
|
|
16
|
+
*.generated.*
|
|
17
|
+
prisma/client/
|
|
18
|
+
|
|
19
|
+
# Lock files
|
|
20
|
+
pnpm-lock.yaml
|
|
21
|
+
package-lock.json
|
|
22
|
+
yarn.lock
|
|
23
|
+
|
|
24
|
+
# Logs
|
|
25
|
+
*.log
|
|
26
|
+
|
|
27
|
+
# IDE
|
|
28
|
+
.idea/
|
|
29
|
+
.vscode/
|