Twitter Clone

VIEW ON GITHUB

General Summary

The idea behind Twitter Clone was to make a web app with the most defining features that twitter has. Users in Twitter Clone can write tweets, follow others and view a feed that orders all tweets by time.

What was it built with?

Twitter Clone was built with Java, Spring, CSS and MySQL.

How does it work?

The application utilizes Spring and the MVC design pattern to separate concerns and consolidate the responsibilities of each class for the project. The basis of the program is its ability to manipulate and persist user data and tweets. This is done with the User Repository, User Service and Hibernate. The User Repository is a Spring CRUD Repository, and the User Service is the class used to manipulate and fetch that repo's data through get, save and delete methods.

User data is stored in a MySQL database and the passwords are encrypted with BCrypt.

Spring Security is used to manage user authentication. It allows the app to require logins on certain pages so they cannot be viewed unless the user is logged in. It has a session system as well that allows you to stay logged in until your IP changes.

The view is built with HTML, Thymeleaf and minimal CSS for pure functionality. It's not fancy, but it's not supposed to be! Thymeleaf in this application is used for consuming and displaying Spring models as readable text for the end-user.

How is the code structured?

The application is separated into 6 different sub-packages. This makes it easy to navigate and understand for both myself and any other developers who would potentially be working with it.

Controllers

There are four controllers. One for the home page, one for profile pages, one for registering, and one for the user feed.

Repositories

There is one repository for users.

Security

The security package contains the Spring Security Configuration class which allows me to configure various web security features Spring offers.

There are two settings I had to configure for this application: authentication and http.

The authentication manager of Spring needs to know what credentials to validate users with. In this case it is using Spring's UserDetailsService, which I implemented in CustomUserDetailsService. The purpose of this is to override the default user loading method to load users from application's User Service.

Services

There are two services: CustomUserDetailsService and UserService.

The UserService is the class used for getting, updating or deleting specific users. It uses the UserRepository and adapts the methods to the context of the application. It also contains a method for getting the current authenticated user so the app knows what user is accessing a page, and whether or not they are authenticated.

Model Utilities

Model utilities are used to help model information sent or received from the user.

The only one needed was an object for holding user input text-data for information that had no corresponding object.

User

The user package contains the core business objects including: User, Tweet and Feed.

All of these classes use JPA annotations which hook to Hibernate in this case.

User Class

The User class has 5 fields as follows: username, password, tweets, followers and following. The username is the unique key, and tweets, followers and following are all lists that have a OneToMany relationship with the the User.

Resources

CSS

I used CSS to create an aesthetically pleasing and functional way for users to interact with the site.

Templates

There are 5 HTML templates as followers: home, profile, register, feed and currentprofile. These templates are consumed and shown by the view layer in the application. Thymeleaf is used in order to display and manipulate data generated by the user and application.

VIEW ON GITHUB