TypeScript Clean Architecture 项目教程

TypeScript Clean Architecture 项目教程

typescript-clean-architectureAn experiment on creating a Clean Architecture based Application in Typescript项目地址:https://gitcode.com/gh_mirrors/typ/typescript-clean-architecture

1. 项目的目录结构及介绍

typescript-clean-architecture/
├── src/
│   ├── adapters/
│   ├── app/
│   ├── domain/
│   ├── infrastructure/
│   ├── presentation/
│   ├── use-cases/
│   └── index.ts
├── test/
├── .eslintrc
├── .gitignore
├── LICENSE
├── README.md
├── docker-compose.local.yaml
├── docker-compose.test.yaml
├── jest.json
├── ormconfig.json
├── package-lock.json
├── package.json
├── sonar-project.properties
├── tsconfig.build.json
└── tsconfig.json

目录结构介绍

  • src/: 项目的主要源代码目录。

    • adapters/: 包含适配器代码,用于将基础设施层的接口适配为用例层熟悉的接口。
    • app/: 包含应用程序的业务逻辑。
    • domain/: 包含核心业务逻辑和领域模型。
    • infrastructure/: 包含基础设施代码,如数据库访问、外部服务调用等。
    • presentation/: 包含用户界面相关的代码,如API控制器、视图等。
    • use-cases/: 包含应用程序的业务用例。
    • index.ts: 项目的入口文件。
  • test/: 包含测试代码。

  • .eslintrc: ESLint 配置文件。

  • .gitignore: Git 忽略文件配置。

  • LICENSE: 项目许可证。

  • README.md: 项目说明文档。

  • docker-compose.local.yaml: 本地开发环境的 Docker 配置文件。

  • docker-compose.test.yaml: 测试环境的 Docker 配置文件。

  • jest.json: Jest 测试框架配置文件。

  • ormconfig.json: 对象关系映射配置文件。

  • package-lock.json: npm 依赖锁定文件。

  • package.json: 项目依赖和脚本配置文件。

  • sonar-project.properties: SonarQube 代码质量分析配置文件。

  • tsconfig.build.json: TypeScript 编译配置文件(用于构建)。

  • tsconfig.json: TypeScript 编译配置文件。

2. 项目的启动文件介绍

项目的启动文件是 src/index.ts。这个文件是应用程序的入口点,负责初始化应用程序并启动服务器。

// src/index.ts
import { App } from './app';

const app = new App();
app.start();

3. 项目的配置文件介绍

package.json

package.json 文件包含了项目的依赖、脚本和其他元数据。

{
  "name": "typescript-clean-architecture",
  "version": "1.0.0",
  "scripts": {
    "start": "ts-node src/index.ts",
    "build": "tsc -p tsconfig.build.json",
    "test": "jest"
  },
  "dependencies": {
    "express": "^4.17.1",
    "typescript": "^4.1.3"
  },
  "devDependencies": {
    "@types/express": "^4.17.9",
    "ts-node": "^9.1.1",
    "jest": "^26.6.3"
  }
}

tsconfig.json

tsconfig.json 文件是 TypeScript 的编译配置文件,定义了 TypeScript 编译器的行为。

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}

.eslintrc

.eslintrc 文件是 ESLint 的配置文件,用于代码风格检查和错误检测。

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": ["plugin:@typescript-eslint/recommended

typescript-clean-architectureAn experiment on creating a Clean Architecture based Application in Typescript项目地址:https://gitcode.com/gh_mirrors/typ/typescript-clean-architecture

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

解然嫚Keegan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值