GithubHelp home page GithubHelp logo

anantharajuc / reddit-clone Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 4.0 675 KB

Backend to the clone of the popular social media platform Reddit

License: MIT License

Java 99.75% HTML 0.25%
spring-boot jwt spring-security spring-security-jwt mysql role-based-access-control

reddit-clone's Introduction

Reddit Clone

FOSSA Status GitHub issues GitHub forks GitHub stars

Backend to the clone of the popular social media platform reddit

Summary

Technology Stack

Data

  • Flyway - Version control for database
  • MySQL - Open-Source Relational Database Management System

Server - Backend

  • JDK - Java™ Platform, Standard Edition Development Kit
  • Spring Boot - Framework to ease the bootstrapping and development of new Spring Applications
  • Maven - Dependency Management

Libraries and Plugins

  • Lombok - Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.
  • Swagger - Open-Source software framework backed by a large ecosystem of tools that helps developers design, build, document, and consume RESTful Web services.

Others

  • git - Free and Open-Source distributed version control system

External Tools & Services

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

  • You need to have MySQL installed on your machine to run the application in dev profile. Using the MySQL Workbench or on any other MySQL client/console, create a database/schema named reddit_clone.
-- create schema
CREATE SCHEMA reddit_clone;

-- use schema
USE reddit_clone;

-- Create user 
create user 'reddit_clone'@'localhost' identified by 'reddit_clone';

-- Grant privileges to user
grant all privileges on *.* to 'reddit_clone'@'localhost' with grant option;

After creating the database/schema, you need to add your MySQL username and password in the application-dev.properties file on src/main/resource. The lines that must be modified are as follows:

spring.datasource.url=jdbc:mysql://localhost:3306/reddit_clone?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=reddit_clone
spring.datasource.password=reddit_clone
  • A Java Keystore File is required to generate JSON Web Token.
keytool -genkey -alias redditclone -keyalg RSA -keystore redditclone.jks -keysize 2048

EER Diagram

Installing

Running the application with IDE

There are several ways to run a Spring Boot application on your local machine. One way is to execute the main method in the io.github.anantharajuc.rc.RedditCloneApplication class from your IDE.

  • Download the zip or clone the Git repository.
  • Unzip the zip file (if you downloaded one)
  • Open Command Prompt and Change directory (cd) to folder containing pom.xml
  • Open Eclipse
    • File -> Import -> Existing Maven Project -> Navigate to the folder where you unzipped the zip
    • Select the project
  • Choose the Spring Boot Application file (search for @SpringBootApplication)
  • Right Click on the file and Run as Java Application

Running the application with Maven

Alternatively you can use the Spring Boot Maven plugin like so:

$ git clone https://github.com/Spring-Boot-Framework/Reddit-Clone.git
$ cd Reddit-Clone
$ mvn spring-boot:run

Running the application with Executable JAR

The code can also be built into a jar and then executed/run. Once the jar is built, run the jar by double clicking on it or by using the command

$ git clone https://github.com/Spring-Boot-Framework/Reddit-Clone.git
$ cd Reddit-Clone
$ mvn package -DskipTests
$ java -jar target/Reddit-Clone-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev

To shutdown the jar, follow the below mentioned steps on a Windows machine.

  • In command prompt execute the jcmd command to print a list of all running Java processes
  • Taskkill /PID PROCESS_ID_OF_RUNNING_APP /F execute this command by replacing the PROCESS_ID_OF_RUNNING_APP with the actual process id of the running jar found out from executing the previous command

Documentation

  • Swagger - http://localhost:8080/swagger-ui.html- Documentation & Testing
  • Postman Collection for offline testing is available in the documents folder.

Explore the APIs

Actuator URL

URL Method
http://localhost:8080/actuator/ GET

Application URLs

Username Password Role Permission Resource
johndoe password PERSON /user
AdminUser password ADMIN PERSON_CREATE,PERSON_READ,PERSON_UPDATE,PERSON_DELETE /user
AdminTraineeUser password ADMINTRAINEE PERSON_READ /user
URL Method Remarks Sample Valid Request Body
http://localhost:8080/api/v1/auth/signup POST JSON
http://localhost:8080/api/v1/auth/verification/{verification-token} GET
http://localhost:8080/api/v1/auth/login POST Bearer Token, Refresh Token is generated JSON
http://localhost:8080/api/v1/subreddit POST Bearer Token should be passed for authorization JSON
http://localhost:8080/api/v1/auth/refresh/token POST Refresh Token from login should be passed JSON

Sample Valid JSON Request Bodys

{
    "username":"johndoe",
    "email":"[email protected]",
    "password":"abcd1234"
}
{
    "username":"johndoe",
    "password":"abcd1234"
}
{
    "name":"my-cool-subreddit",
    "description":"My subreddit for all thing cool."
}
{
    "token":"1178cd43-21d2-45b4-8b5f-c79aa1d5b76e",
    "username":"johndoe"
}

Running the tests

$ mvn test       //Run all the unit test classes.

Break down into end to end tests

Explain what these tests test and why

Give an example

And coding style tests

Explain what these tests test and why

Give an example

Deployment

Add additional notes about how to deploy this on a live system

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Reporting Issues and Suggesting Improvements

This Project uses GitHub's integrated issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:

  • Before you log a bug, please search the issue tracker to see if someone has already reported the problem.
  • If the issue doesn't already exist, create a new issue
  • Please provide as much information as possible with the issue report.
  • If you need to paste code, or include a stack trace use Markdown +++```+++ escapes before and after your text.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository

Authors

See also the list of contributors who participated in this project.

License

  • This project is licensed under the MIT License - see the LICENSE.md file for details

  • FOSSA third-party code, license compliance and vulnerabilities

FOSSA Status

Acknowledgments

reddit-clone's People

Contributors

anantharajuc avatar dependabot-preview[bot] avatar fossabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.