2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Nest.jsでドメイン駆動開発をする場合のディレクトリ構成を考えてみる

Posted at

概要

Nest.jsを使ったドメイン駆動開発をするに当たり、両方について学ぶ必要があった。
ディレクトリ構成にすればいいか考えることで、理解が深まったため、現状の認識を覚えておく意味でもメモを残しておく(間違っているかもしれないので、それも含めて)
プロジェクトの規模などによって、うまくメリットを享受できるように調整すべきなので、千差万別で参考にならないかとは思っています。そこが難しいところ

アーキテクチャ

オニオンやらヘキサゴナルやらクリーンやらありますが、ざっくり下記を想定。

ドメイン層

ビジネスロジックを実装する

アプリケーション層

ユースケースを実装する

プレゼンテーション層

MVCでいうコントローラーを実装する(Nest.jsの機能をそのまま使う)

インフラ層

データベースやほかサービスなどとの通信周りを実装する

構成

/src
    /@core プレゼンテーション以外を閉じ込める
        /domain
            /entity
                some.entity.ts
                some.value-object.ts
                some.aggregate.ts
            /service
                some.service.ts
                unit-of-work.ts トランザクションのインターフェース 場所難しい
            /repository
                user.repositoty.ts
        /application
            /user
                create-user.use-case.ts
                create-user.input.ts
                create-user.output.ts レスポンスの形式(ここは微妙かも)
        /infra
            /prisma
                /migrations
                /seed
                /repository
                    user.prisma.repository.ts
                    unit-of-work.prisma.ts
                prisma.service.ts
                prisma.module.ts
            /redis
            /stripe
    /user
            /dto
                create-user.dto.ts
            user.controller.ts
            user.module.ts
    /common
        /middlewares
        /guards
        /pipes
        /intercepters
        /pipes
    /job
        /some-batch nest-commanderで実行するバッジなど?
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?