Giter VIP home page Giter VIP logo

jivejdon's Introduction

Jivejdon

Jivejdon is a full DDD application with Event Soucing/CQRS and clean architecture/Hexagonalarchitecture, powered by jdonframework ,running for over ten years in: https://www.jdon.com/forum

Use Case

avatar

DDD Aggregate Model

avatar

com.jdon.jivejdon.model.ForumMessage is the aggregate root entity of post bounded context, it is a rich model not anemic model, no "public" setter method, all setter methods are "private":

avatar

Aggregate root entity builder pattern: avatar

Domain Model principles:

  1. High level of encapsulation

All members setter method are private by default, then internal. need heavy builder pattern to create aggregate root!

  1. High level of PI (Persistence Ignorance)

No dependencies to infrastructure, databases, other stuff. All classes are POJO.

The customer/supply model from jdonframework can seperate domain model from Persistence/Repository.

All datas out of domain is packed in a DTO anemic model(AnemicMessageDTO), so business rules in the aggregate root entity will not leak outside domain.

avatar

these DTO anemic models can alseo be packed in Command and Domain Events,so they be managed in DDD ubiquitous business language.

  1. Rich in behavior

All business logic is located in Domain Model. No leaks to application layer or other places.

  1. Low level of primitive obssesion

Primitive attributes of Entites grouped together using ValueObjects. MessageVO is a valueObject of aggregate root entityForumMessage, inlcude message content: subject and body, it will be processed with complex business filter logic, these filters have many implements,such as: TEXT to HTML.

  1. Business language

All classes, methods and other members named in business language used in the Bounded Context.

Event Sourcing

Posting a message is a event, modifying the last replies status for one thread.

avatar

How to get the the last replies status for one thread?we must iterate all posted events collection.

JiveMessage is a posted events collection database table, with a SQL select we can get the last message posted event:


SELECT messageID from jiveMessage WHERE  threadID = ? ORDER BY modifiedDate DESC

This sql can quickly find the last replies, No need to play back all posted events.

In jiveThread table there is no special field for last replyies state , all states are from posted events projection. (projection can use SQL!)

When a user post a new ForumMessage, a ReplyMessageCreatedEvent event will be saved to event store: JiveMessage, simultaneously refresh the snapshot of event: ForumThreadState.

Clean architecture/Hexagonal architecture

JiveJdon is developed with JdonFramework that supports Customer/Supply or pub-sub model, this model can seperate domain logic from infrastructure, databases, other stuff.

avatar

JiveJdon and Hexagonal_architecture:

avatar

models.xml is a adapter, it is XML configure acting as a controller.

	<model key="messageId" class="com.jdon.jivejdon.model.message.AnemicMessageDTO">
		<actionForm name="messageForm"/>
		<handler>
			<service ref="forumMessageService">
			
				<createMethod name="createReplyMessage"/>
					
			</service>
		</handler>
	</model>

When post a replies message, a POST command will action createReplyMessage method of forumMessageService :

public interface ForumMessageService {

	Long createReplyMessage(EventModel em) throws Exception;
	....
	
}

Domain sevice forumMessageService will delegate responsibility to business logic object:the aggregate root entity ForumMessage, that has two types: topic post and rely post, topic is a root message and has many replies messages, all messages compose one Thread(ForumThread)

Business/domain logic is in the addChild message method of ForumMessage

avatar

@OnCommand("postReplyMessageCommand") annotation is a command handler in pub-sub model from jdonframework, it can make this method executed in a single-writer pattern - no blocked, no lock, high concurrent. only one thread/process invoking this update method.

"eventSourcing.addReplyMessage" will send a "ReplyMessageCreatedEvent" domain Event to infrastructure layer such as Repository. with the pub-sub model of jdonframework, make domain no dependencies to infrastructure, databases, other stuff.

Domain event "ReplyMessageCreatedEvent" occurring in the domain will be saved in event store "jiveMessage" that is a posted events table to project the last replies state of a thread.(Event Sourcing)

CQRS architecture

CQRS addresses separates reads and writes into separate models, using commands to update data, and queries to read data.

avatar

In jivejdon ForumThread and ForumMessage are saved in cache, cache is a snapshot of even logs, if a update command activate one of these models, they will send domain events to clear the cache datas, the cache is similar as the database for query/read model, the consistency between with cache and the database for commmand model is maintained by the domain events such as "ReplyMessageCreatedEvent".

The domain event "ReplyMessageCreatedEvent" do three things:

  1. add a new post message to "jiveMessage" (events log)
  2. clear the query cache (CQRS)
  3. update/project the last replies state of a thread (event project to state)

Install

Docker:

  1. mvn package
  2. docker build -t jivejdondb -f Dockerfile.db .
  3. docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 jivejdondb
  4. docker build -t jivejdonweb -f Dockerfile.web .
  5. docker run -p 8080:8080 jivejdonweb

browser : http://$DOCKER_HOST_IP:8080

Document

english install doc

chinese install doc

chinese design doc

jivejdon's People

Contributors

banq avatar orangeyts avatar

Watchers

James Cloos 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.