Skip to content

farbodbj/Twitter-Server

Repository files navigation

Twitter Server

A pure-java implementation of Twitter's server using a REST API and no additional frameworks.

About the project

This project has been done as the final project of the advanced programming course in AUT. As one of the projects' constraints, use of any backened-related frameworks was not allowed (e.g. Spring Boot etc).

Technologies

For addressing various needs in the Twitter server such as the database, serialization etc, different technologies were researched carefully and then chosen:

Database

Regarding the relational nature of most of the saved data in the project, MySQL database was chosen as a robust and scalable SQL database that provides one with many feasible features. Some others databases were also investigated such as PostgreSQL and MongoDB but MySQL still seemed like a better fit for my use. Querying the database was done using SQL queries only.

used libraries:

Serialization protocol

As one of the most robust and vastly used serialization protocols, JSON was used, but for larger data structures (photos, videos etc) Apache Commons IO was utilized as the serializer/deserializer.

used libraries:

Request handling

A REST API was designed and implemented from scratch using HttpServer library (built-in to java). For method validation, request format validation, sending responses etc no frameworks were used due to project constraints.

used libraries:

Design and Architecture

To address various neeeds in the project and also achieving important software engineering principles such as separation of concerns, encapsulation, maintainability, scalability, etc, many different design patterns were used:

• As the main communication way between the server and the client, RSET API was used. After the needed methods were identified, related actions were put in the well-defined hierarchy of the API which separated them according to their responsibilities. An ER schema of the implemented design is shown below: ER schema

• The main design in the server part was The Layered architecture as it could best help encapsulate different components and separate the concerns of accessing data (both on disk and database) from concerns of request handling and controlling.

• Although the MVVM design pattern is mostly related to the client part, but in the whole project (server and client together) the so-called Model components were kept in a module named Commons and were only used as data entities with no buissiness related logic in them. The UML schema for the commons module can be seen below: Commons module UML

DAO design pattern was effectively applied in the database part to encapsulate the database access logic from other parts. each table in the database has a corresponding class which is the only class that can add, remove or modify the data in that table. The database schematic can be seen below: database schema

Implementation details

Authorization

As suggested in the project description, JSON Web Tokens (known as Jwt) were used for authorizing almost every action a user could take. the access token which were kept in the client would be sent in the header of every request and the server would let the user take the desired action after validating that token.

Error handling

Mnay different custom exceptions had been defined in the project which are raised in related situation and they are most often handled by sending the client the appropriate Http status code and message related to that error.

Handling files

As the clients could demand sending and recieving different types of video and pictures for various purposes, the need of being able to effectively was handled in the project. In almost all cases, the uniqueness of ids (e.g tweet_id, user_id etc) was used along with a prefix/suffix which showed the kind of file (e.g profile picture, tweet attachment etc).

Future enhancements

• Using a logger for better monitoring the server

• Keeping hashed passwords instead of actuall passwords in the database

• Encrypting the Http connection between the server and the client

• Putting server configurations in a separate file instead of hardcoding.

Releases

No releases published

Packages

No packages published

Languages