Skip to content

A Fullstack application, it is written in Java language & Spring Framework on the server side and in React Library on the client side

Notifications You must be signed in to change notification settings

itsmechelly/coupon-system-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

coupon-system-server

This application is the final project I created during my software studies.
The application is a Fullstack project, it is written in Java language on the server side and in React on the client side.

πŸ€” What is the purpose of this application?

This is a coupon management system that allows companies to generate coupons as part of advertising and marketing campaigns that they run.
The system also has registered customers, the customers can purchase coupons, coupons are limited in quantity and validity, a customer is limited to one coupon of each type.
The system records the coupons purchased by each customer.
The revenue of the system is from the purchase of coupons by the customers and by the creation of new coupons by the companies.

πŸ’» Access to the system is divided into three types of clients:

  1. Administrator - manages the system, managing the lists of companies and the customers.
  2. Company – managing a list of coupons associated with the company.
  3. Customer - who buy coupons.

The reason I created 3 versions of the server side

Since I always had a great passion and a special connection while working on the server side, during the software studying, I decided to do the server side in 3 different ways, each of them focusing on a different technological technique.

Now, let's dive into the 3 types of projects I created

1️⃣ The 1st Project: Java

Writing the server side in plain old Java.
For the database I used:

  • SQL
  • JDBC
  • ConnectionPool that manage the connections queries sent to the database.

In this project I used simple login() method for authentication & authorization.

Click here to see this project on Github:
https://github.com/itsmechelly/CouponSystem_JavaProject

2️⃣ The 2nd Project: Spring Framework and Session Technique for Authentication & Authorization

In the second project I rewrite the core system for more recent technology - I used Java language and Spring Framework.
For the database I used:

  • Spring Hibernate JPA.

For the authentication & authorization I used the Sessions technique.

Click here to see this project on Github:
https://github.com/itsmechelly/CouponSystem_SpringProject_SessionTechnique

3️⃣ The 3ed Project: Spring Framework and JWT Technique for Authentication & Authorization

In the second project I rewrite the core system for more recent technology - I used Java language and Spring Framework.
For the database I used:

  • Spring Hibernate JPA.

For the authentication & authorization I used the JTW technique.

πŸ‘‰ The current repo represent this 3rd project.
https://github.com/itsmechelly/coupon-system-server

πŸ‘‰ NOTE: this project is the final version and deployed to AWS cloud, click to browse the website:
CLICK HERE TO SEE THE WEBSITE!

πŸ‘‰ To login, use those details:
Admin: ➑️ e-mail: admin@admin.com password: admin
Company: ➑️ e-mail: zootAllures@company.com password: zootAllures
Customer: ➑️ e-mail: cust1@cust.com password: 1111

And what about the Client side?

This part of the application was written using React libraries and is built as a Single Page Application (SPA).
The communication between server side and client side was done using Json and RESTful API.

Click here to see this project on Github:
https://github.com/itsmechelly/coupon-system-client

πŸ‘‰ NOTE: this project is the final version and deployed to AWS cloud, click to browse the website:
CLICK HERE TO SEE THE WEBSITE!

πŸ‘‰ To login, use those details:
Admin: ➑️ e-mail: admin@admin.com password: admin
Company: ➑️ e-mail: zootAllures@company.com password: zootAllures
Customer: ➑️ e-mail: cust1@cust.com password: 1111

Application Architecture – 3rd Project:

Creating Java Beans that represent the Spring Entities in the database:

Java Beans are pure information classes that represent the information managed by the application.
Below is the diagram of the Java Beans classes:

image

MVC Architecture:

As we will see below, this project implements an MVC architecture.
After the user performs a request on the client side, the first layer that is activated on the server side is the controller layer.

The first controller – LoginController – manage Authentication & Authorization:

The first controller the client encounters is the login controller.
Login Controller calls to Login Service.
The login service contains a method that checks the type of the client, then, according to the client type, generates a new Token that will be valid for 30 minutes.
This token addresses the specific service type of the client.
And then this service returns the generated token to the controller and inserts it into a new HttpHeaders object.
Then, whenever a request comes from the client endpoint, the HttpHeader requests this token. In each such request - the system will check whether the token transferred in the header is indeed compatible with the real token.
For securely transmitting the login information I used JSON Web Token (JWT) library (SignatureAlgorithm.HS256).
The token is automatically updated every 30 minutes.
This is how it looks in macro view:

image

Diagram of login class in details:

image

Now, when the user is logged in – other controllers can be in use:

According to the client type, and after the client's first request has been made - the login, and after the client has a token that is activated behind the scenes - now, with every request the client sends - the relevant controller will be activated (as mentioned, the token and the client type are stored in the HttpHeader).
The request is passed to the Service Layer into the specific method, which in turn checks whether the token is valid.
The service layer contains an operates the business logic and then passes the request to another layer I created - Impl Layer (I created this layer to create separation in access to the Repository layer - this creates extra protection).
And finally - there is a repository Layer that is managed by Spring Hibernate JPA and it is the one that adds, updates, deletes, and manages the information stored in the database.

A Facade Design Pattern is used here.
Such a design allows simple operations to be outsourced, which behind the scenes use a series of extra operations.
Because there is three classes need to use the service components, each by his client type - I defined an abstract base class – ClientService that reference to the service classes (it will first login() and then direct to the relevant service layer according to the client type).

image

Building a daily job to delete expired coupons from the system (Spring Scheduling):

A basic infrastructure service named CouponExpirationDailyJob was established to clean the system from expired coupons.
The job is a process that runs in the background regularly and checks and cleans coupons once every 24 hours.
The job is executed using a Spring Scheduling that runs parallel to the system activity.
Below is the job diagram for this job activity:

image

Using Custom Exceptions:

In addition to the Java exceptions, I created system-specific exceptions:

image

Endpoints

Please click the link below to browse the website:
CLICK HERE TO SEE THE WEBSITE!


πŸ‘‰ Note: to login, use those details:
Admin: ➑️ e-mail: admin@admin.com password: admin
Company: ➑️ e-mail: zootAllures@company.com password: zootAllures
Customer: ➑️ e-mail: cust1@cust.com password: 1111

Admin Controller:

πŸ‘‰ Note: to enter those routes you should first login, you can use those details: e-mail: admin@admin.com password: admin

admin/addCompany 
admin/addCompany 
/admin/updateCompany 
/admin/deleteCompany/{companyId} 
/admin/getOneCompanyById/{companyId} 
/admin/getAllCompanies 
/admin/addCustomer 
/admin/updateCustomer 
/admin/deleteCustomer/{customerId} 
/admin/getOneCustomerById/{customerId} 
/admin/getAllCustomers 

Company Controller:

πŸ‘‰ Note: to enter those routes you should first login, you can use those details: e-mail: zootAllures@company.com password: zootAllures

/company/addCompanyCoupon 
/company/updateCompanyCoupon 
/company/deleteCompanyCoupon 
/company/getAllCompaniesCoupons 
/company/getAllCouponsByCategory/{couponCategory} 
/company/getAllCouponsUnderMaxPrice 
/company/getCompanyDetails 

Customer Controller:

πŸ‘‰ Note: to enter those routes you should first login, you can use those details: e-mail: cust1@cust.com password: 1111

/customer/purchaseCoupon 
/customer/getAllCustomerCoupons 
/customer/getAllCouponsByCategory/{couponCategory} 
/customer/getAllCouponsUnderMaxPrice 
/customer/getCustomerDetails 

βš’οΈ Tech Stack

Language & Framework: Java Language, Spring Framework
Database: Spring Hibernate, Spring JPA (MySQL Driver), SQL, MySQL
Authentication & Authorization: JSON Web Token (JWT) library
Scheduling Mechanisms: Spring Scheduling
Architecture & Design Patterns: Spring MVC Layers, Singleton Pattern, Facade Pattern, Factory Pattern
Communication between Client side and Server side: Restful API
Client-Side: React, JavaScript, Typescript, Bootstrap 5, HTML, CSS


Thanks for reading,
Chelly πŸ‘©πŸ»β€πŸ’»

About

A Fullstack application, it is written in Java language & Spring Framework on the server side and in React Library on the client side

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages