This project was built using Spring Boot framework starter framework.
- Springboot
- Postgres
- Create a copy of
application.properties
file by from.application.properties.example
file. - Update
.application.properties
file with the necessary credentials - Application Endpoint:
http://localhost:8080
You can run the app in 3 ways:
- Without Docker
- Using Docker as an image
- Using Docker Compose (Recommended)
Install the application dependencies by running this command:
./mvnw clean install -U
After installing the dependencies and configuring application.properties
file, start the applications using:
./mvnw spring-boot:run
Build the application docker image using the command:
docker build -t [name:tag] .
Example:
docker build -t agavitalis/tweets:latest .
Run the generated docker image in a container using the command:
docker run -d -p [host_port]:[container_port] --name [container_name] [image_id/image_tag]
Example:
docker run -d -p 8080:8080 --name tweets agavitalis/tweets:latest
Verify that your docker container is running using the command:
docker container ps
To delete a docker container use the command:
docker stop <container_id>
To delete a docker container use the command:
docker rm <container_id>
Build the application docker image using the command:
docker compose build
Run the app using:
docker compose up
You can also run in detached mood using:
docker compose up -d
To quit and delete use the command:
docker compose down
The access the app while running via docker use the URL: http://0.0.0.0:8070
- User, Post, Comment, and Like Entities: Key business concepts, including users, posts, comments, and likes, are modeled as entities. Each entity encapsulates both data and behavior relevant to its domain.
- User as Aggregate Root: The
User
entity serves as an aggregate root, managing related entities such asPost
,Comment
,Like
, and the new entityFollow
(representing the follow relationship).
- UserRepository, PostRepository, CommentRepository, LikeRepository, FollowRepository: Repositories abstract the data access layer, providing a way to retrieve and store aggregates. Each entity type has its corresponding repository, facilitating seamless data access.
- Post and Comment content as Value Objects: Certain aspects, such as the content of a post or comment, can be modeled as value objects if they lack a conceptual identity and are immutable.
- UserService, PostService, CommentService, FollowService: A service layer is introduced to encapsulate business logic that extends beyond the domain of a specific entity. The
FollowService
manages user follow/unfollow operations, introducing a many-to-many relationship.
- One-to-Many and Many-to-Many Relationships:
- One-to-many relationships exist between
User
andPost
,User
andComment
, as well asUser
andLike
. - A many-to-many relationship is established through the
Follow
entity, allowing users to follow and unfollow each other.
- One-to-many relationships exist between
- User Authentication: Authentication mechanisms, such as token-based authentication or OAuth, are integrated to secure user access. Authentication services validate user credentials and generate tokens for authorized access to protected resources.
- Comment Entity and Repository: The introduction of the
Comment
entity and repository allows users to post comments on posts, expanding the interaction possibilities within the system.
-
Consistency in Aggregates:
- Ensuring consistency within aggregates is crucial, especially when dealing with multiple entities. Maintaining the integrity of related entities within the same aggregate and managing consistency across aggregates is a primary concern.
-
Transaction Management:
- Careful handling of transactions is necessary, especially when dealing with multiple aggregates. Ensuring that operations are atomic and that the system remains in a consistent state is a key consideration.
-
Complexity of Domain Logic:
- As more business logic is encapsulated within the domain layer, managing the complexity of domain logic, especially when dealing with intricate rules, relationships, and user interactions, can be challenging.
-
Query Performance:
- Balancing a rich domain model with efficient querying is essential. Denormalization or other strategies might be employed for complex query scenarios involving user posts, comments, likes, and follow relationships.
-
Evolution of the Domain Model:
- Evolving the domain model as business requirements change, especially with the introduction of new features like follows/unfollows, is a challenge. DDD encourages an iterative approach, but managing changes while ensuring backward compatibility is crucial.
In summary, the application architecture combines DDD principles with additional features like authentication, comments, and a many-to-many relationship for user follows/unfollows. Addressing challenges related to consistency, transactions, complexity, and evolution is vital for building a robust and adaptable system.
Author - Ogbonna Vitalis