Domain-Driven Approach Towards Software Design

A practical design guide for the complex systems

Photo by Safar Safarov on Unsplash
Photo by Alex wong on Unsplash

Domain-driven architecture

  1. Presentation Layer handles user interface responsibilities. It depends on the application layer to execute user action.
  2. Application Layer has the entities which are exposed to the outside world like rest controllers, VOs, classes that keep track of tasks progress, etc. This layer defines job/action which uses multiple domain layer services, entities, etc. to perform user action. This layer handles application security.
  3. Domain Layer entities encapsulate the business logic of the system. It has services, repositories, etc.
  4. Infrastructure Layer contains all the implementation details of repositories that handle persistence, inter-node communication, caching, etc.

Use Case

Epic:

  1. Parking space capabilities like adding parking floors, a new vehicle type parking, etc.
  2. Customer options to pre-book parking, getting a ticket, a pass.
  3. Payment options for customers
  4. Admin capability to reserve some slots, change parking ticket prices, issue passes.
  5. Entry console capability to scan a ticket.
  6. Exit console capability to scan and output the total payable amount

Writing fine-grained user stories is a foremost step towards developing a great software.

User Stories

User stories are like children, they both need your time and attention.

  • Parking Space should provide admin registration capability.
  • As an Admin, I should be able to add/remove the parking floor to the parking space.
  • As an Admin, I should be able to add/remove vehicle type from the parking space.
  • As an Admin, I should be able to add/remove parking attendant from the parking space.
  • As an Admin, I should be able to add/remove entry and exit points to the parking space.
  • As an Admin, I should be able to issue a pass to a customer.
  • As an Admin, I should be able to suspend an issued pass.
  • As an Admin, I should be able to change parking rates.
  • As an Admin, I should be to add/remove new payment options.
  • As an Admin, I should be able to reserve some parking slots for some groups.

2. Parking Attendants

  • As a Parking Attendant, I should be able to scan the ticket at the exit and get the total payable amount.
  • As a Parking Attendant, I should be able to make some parking slots available /not-available for some vehicle types.
  • As a Parking Attendant, I should be able to suspend/resume parking on floors.

3. Customer interaction

  • As a Customer, I should be able to get the ticket at the entry for a vehicle.
  • As a Customer, if I have a pass, I should be able to scan pass at entry and should be allowed to park.
  • As a Customer, if total reserved parking is full, I should be able to get the ticket.
  • As a Customer, I should be able to pay at any exit.
  • As a Customer, I should be able to pre-book a slot for a day/week/month.

Extract Nouns and Verbs

Nouns

  • Parking Space
  • Customer
  • Entry
  • Exit
  • Admin
  • Ticket
  • Parking Slot
  • Parking Attendant
  • Vehicle
  • Vehicle Type
  • Pass

Verbs

  • register admin
  • add/remove parking floors
  • add/remove vehicle types
  • add/remove parking attendant
  • add/remove entry/exit points
  • get the ticket
  • pay at exit
  • pre-book a slot
  • reserve a slot
  • add/remove/disable payment option
  • change parking rates
  • register/de-register user
  • scan ticket

Object Interaction Diagram

Object Interaction Diagram

Object Responsibility Diagram

Object Interaction Diagram

Class Diagram

  1. Controllers that will receive user action are part of the application layer (not present in this diagram).
  2. Controllers like ParkingAttendantController will use domain layer service ParkingAttendantService to perform a user action of managing ParkingAttendant.
  3. Domain layer service would create composite objects from entities called aggregate and persist it using repository like ParkingAttendantRepository. Repository definition is part of the domain layer but implementation lies with the infrastructure layer.
  4. The infrastructure layer implements domain layer repositories. This layer could implement first-level caching of aggregates for faster retrieval. This decision of speeding up a retrieval using caching or some alternate mechanism completely lies with the infrastructure layer.

Presentation -> Application -> Domain <- Infrastructure

--

--

Technology Enthusiast | Big Data Developer | Amateur Cricketer | Technical Lead Engineer @ eQ Technologic | https://www.bugdbug.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amar Gajbhiye

Technology Enthusiast | Big Data Developer | Amateur Cricketer | Technical Lead Engineer @ eQ Technologic | https://www.bugdbug.com