Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize DDD namespaces and centralize common objects #243

Merged
merged 19 commits into from
Apr 19, 2021

Conversation

Whathecode
Copy link
Member

@Whathecode Whathecode commented Mar 28, 2021

According to DDD the semantics of namespaces should be:

  • application: classes which are exposed to consuming clients
  • domain: internal domain logic, not exposed to clients
  • infrastructure: implementations specific to one particular infrastructure (e.g., database or serialization technology)

The current codebase did not follow this strictly. There are many classes which live in the domain namespace yet are exposed to clients. We want to have a strict separation so that people who want to develop clients on other tech stacks know which classes need to be implemented by them (the application namespace). Or, in case we do some type of code generation we know for which classes code needs to be generated.

In addition, many of these classes (erroneously residing in the domain namespace) are reused across multiple subsystems. This is for historic reasons mostly, since the implementation of CARP started with the protocols subsystem. However, we have since discovered most of these classes (such as DeviceDescriptor) are in fact more of a shared kernel (a DDD concept) and are therefore best moved to the common module in a application namespace. The goal should be that only the common module has base types which are extensible and passed across the architecture (protocols now).

While making such big namespace changes we should probably also look at:

  • Proper DDD namespaces for:
    • protocols
    • deployment
    • studies
  • Move InputElement to the element namespace. It seems inconsistent Data and the concrete types live in the same namespace, but this is not the case for input elements.
  • Move application service types (such as ApplicationService and EventBus) to a services namespace. It seems disorganized that these live side-by-side with common types such as DateTime right now.
  • Move StudyProtocol.Id to carp.common.
  • Clean up/remove subfolders in carp.protocols.domain. (Moved devices, triggers, and tasks namespace to one carp.protocols.domain.configuration namespace since they only contained configuration classes for StudyProtocol.)
  • Clean up/organize 'carp.common.infrastructure.serialization' (both main and test). Remove the subsystem-specific SerializersModule as all these types should be moved to common.
  • Investigate whether dependencies on protocols can be removed (because so much is moved to common). (Nope, StudyProtocol and StudyProtocolSnapshot remains in protocols and best belongs there for now.)
  • Update readme architecture structure. carp-protocols.md contains mostly carp.common stuff.
  • Use singular/plural form consistently in module and package names

The suggested outline for new namespaces. Changes (and intended changes) in this PR are shown in bold.

  • dk.cachet.carp
    • clients (or maybe, while we are at it, we should rename this to something more concrete/intuitive? e.g., 'runtimes')
      • domain
        • data
    • common
      • application
        • data
          • input (plural form?)
            • elements
        • devices
        • sampling (plural form?)
        • services (holds base classes and helpers for application services)
        • tasks
        • triggers
        • users
      • domain
        • users
    • deployments
      • application
        • users
      • domain
        • users
    • protocols
      • domain (I don't think plural forms for the two namespaces below make sense here)
        • configuration (this now groups the previous tasks, triggers, and devices since most of its contents were moved to common)
        • deployment
    • studies
      • application
        • users
      • domain
        • users

@Whathecode Whathecode changed the title Refactor: split common module types into DDD namespaces. Stabilize DDD namespaces Mar 28, 2021
@Whathecode Whathecode changed the title Stabilize DDD namespaces Stabilize DDD namespaces and centralize common objects Mar 28, 2021
@Whathecode Whathecode linked an issue Mar 28, 2021 that may be closed by this pull request
As part of this, I also removed the now superfluous `tasks`, `devices`, and `triggers` subfolders in the protocols subsystem and merged them under one `configuration` folder.
This also means we no longer need separate serializers per subsystem. All subystems now use `createDefaultJSON`. And, I added a `createTestJSON` which also registeres the stub types.
@Whathecode Whathecode requested a review from ltj April 15, 2021 22:21
@Whathecode Whathecode linked an issue Apr 15, 2021 that may be closed by this pull request
Copy link
Collaborator

@ltj ltj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner. Good job

@Whathecode Whathecode marked this pull request as ready for review April 19, 2021 09:01
@Whathecode Whathecode merged commit 2990766 into develop Apr 19, 2021
@Whathecode Whathecode deleted the ddd-namespaces branch April 19, 2021 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants