Git Product home page Git Product logo

spetstore's Introduction

Scala Pet Store API (開発中)

Build Status

目的

DDDに基づいた、一つの実装を示すこと(DDDは設計**なので具体的な実装方式は複数あり得ますが、私が考える最良の実装という意味)。

特徴

  • DDDに準拠した設計方針
  • 対象ドメインはペットストア
  • Scala 2.11対応
  • Play 2.5.x対応
  • アプリケーションとしては REST like API

対象ドメイン

レイヤー構造

DDDのレイヤー化アーキテクチャに従い、次のとおりのレイヤーに分割します。

  • アプリケーション層
  • ドメイン層
  • インフラストラクチャ層

もっとも重要なのは、メンタルモデルを反映したドメイン層です。 このドメイン層を、非ドメイン層の知識から侵蝕されることを防ぐために、隔離します。

ドメイン層

ドメインの目的は、ペットストアの運営です。 ペットやペットフード、アクセサリーなどを仕入れて、顧客に販売するためのドメインです(仕入れの概念が現在ないので実装中です)。

ドメインモデル

GE = グローバルな識別子を持つエンティティ
VO = 値オブジェクト
A = 集約

Specs

とりあえず、重要なところだけSpecを書いています。

ここで重要なのは、モデルの表現(クラス名、属性名、振る舞いの名前(引数・戻り値も))にユビキタス言語以外の言葉を利用しないことです。
原則的に、これらの要素に、実装技術の言葉を含めてはいけません(実装技術の言葉を含めてしまうとメンタルモデルが離れていきドメインについて理解することが難しくなるため。ただし、StringやIntなどのデータ型や、ListやMap, Try, Option, Futureなどのコンテナ型は例外とする)。実装技術に関する知識は、アプリケーション層かインフラストラクチャ層に対応づけましょう。

  • TODO
    • 仕入れ先の導入
    • 在庫の導入
    • 商品モデルにサブ型を導入する

インフラストラクチャ層

DDD基盤コード

わかりやすくするために、特別なライブラリを用意せず、簡単な基盤コードを含めています。

  • Entity = DDDにおけるエンティティの責務
  • Repository = DDDにおけるリポジトリの責務
    • RepositoryOnJDBC
      JDBCに対応したリポジトリの骨格実装。ScalikeJDBCで実装。ちなみに、1エンティティが複数テーブルにマッピングされるような実装は今のところ作っていません。そのうち作ります。Specはこちら
    • RepositoryOnMemory メモリに対応したリポジトリの骨格実装。内部実装はMapですがRepositoryとして操作できる。Specはこちら
    • RepositoryOnMemcached(TODO)
      Memcachedに対応したリポジトリの骨格実装。
    • CacheManagementRepository(TODO)
      キャッシュのマネジメントを行うリポジトリ実装。

アプリケーション層

  • コントローラ(TODO)
  • アプリケーションサービス(TODO)

利用している主なフレームワーク/ライブラリ

  • Play Framework 2.5.x
  • Google Guice
  • ScalikeJDBC 2.x
  • play-circe
  • nscala-time
  • specs2
  • mockito

参考にしたコード

spetstore's People

Contributors

j5ik2o avatar x7c1 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.