Skip to content

SabarishAV/Study-Hive-Backend

Repository files navigation

Study Hive Backend

Study Hive Backend is the REST API and business logic layer for the Study Hive learning resource platform. It powers user authentication, study resource publishing, carts, orders, payments, file storage, user profiles, leaderboards, and account workflows for the Study Hive frontend.

This service is built with Spring Boot and uses PostgreSQL for persistence, Redis for supporting data workflows, Cloudinary for file storage, Stripe for payments, and Spring Security with JWT for protected API access.

Repository Links

Features

  • User registration and login
  • JWT authentication and Spring Security integration
  • Email-based sign-in and password reset flows
  • User profile management
  • Study resource creation, update, soft delete, hard delete, and retrieval
  • Multipart resource upload support
  • Cloudinary file upload, retrieval, and deletion support
  • Liked resource tracking
  • Cart management
  • Bought resource tracking
  • Order and order item management
  • Stripe checkout, webhook confirmation, and Connect onboarding support
  • Seller earnings and wallet transaction models
  • Leaderboard and user rank endpoints
  • PostgreSQL persistence through Spring Data JPA
  • Redis integration
  • Swagger/OpenAPI documentation
  • Dockerfile for containerized deployment
  • Seed up and seed down utilities

Tech Stack

  • Java 21
  • Spring Boot 3.4.1
  • Spring Web
  • Spring Security
  • Spring Data JPA
  • PostgreSQL
  • Redis / Jedis
  • Spring Mail
  • JWT with JJWT
  • Stripe Java SDK
  • Cloudinary Java SDK
  • Springdoc OpenAPI / Swagger UI
  • Lombok
  • Maven
  • Docker

Project Structure

Study-Hive-Backend/
├── src/main/java/com/studyhive/studyhive/
│   ├── config/              # Security, Swagger, CORS, storage, payment config
│   ├── controllers/         # REST API controllers
│   ├── models/              # JPA entities and DTOs
│   ├── repositories/        # Repository abstraction and primitive JPA repositories
│   ├── seeders/             # Database seed up/down entry points
│   ├── services/            # Business logic services
│   ├── shared/              # Shared types, exceptions, and utilities
│   ├── support/             # Supporting jobs and helpers
│   └── StudyhiveApplication.java
├── src/main/resources/
│   └── application.properties
├── src/test/                # Spring Boot tests
├── Dockerfile               # Container build definition
├── env.exmaple.ps1          # Windows environment variable example
├── env.exmaple.sh           # Linux/macOS environment variable example
├── run.sh                   # Helper script for app, Redis, Stripe CLI, and seed tasks
└── pom.xml                  # Maven dependencies and build configuration

Getting Started

Prerequisites

  • Java 21
  • Maven, or the included Maven wrapper
  • PostgreSQL
  • Redis
  • Cloudinary account
  • Stripe account and webhook secret
  • SMTP email account, such as Gmail with an app password

Environment Variables

Create your own environment file from the provided examples.

For Windows PowerShell:

Copy-Item env.exmaple.ps1 env.ps1
.\env.ps1

For Linux/macOS:

cp env.exmaple.sh env.sh
source env.sh

Required variables:

Variable Description
DB_USERNAME PostgreSQL username
DB_PASSWORD PostgreSQL password
DB_HOST PostgreSQL host
DB_PORT PostgreSQL port, usually 5432
DB_NAME PostgreSQL database name
EMAIL SMTP sender email
EMAIL_PASSWORD SMTP app password
STRIPE_SECRET_KEY Stripe secret key
STRIPE_CLIENT_ID Stripe Connect client ID
STRIPE_WEBHOOK_KEY Stripe webhook signing secret
FE_URL Frontend application URL for CORS and redirects
CLOUDINARY_CLOUD_NAME Cloudinary cloud name
CLOUDINARY_API_KEY Cloudinary API key
CLOUDINARY_API_SECRET Cloudinary API secret
ENCRYPTION_KEY 32-character encryption key
REDIS_HOST Redis host
REDIS_PORT Redis port, usually 6379

Run Locally

Using the Maven wrapper:

./mvnw spring-boot:run

On Windows:

.\mvnw.cmd spring-boot:run

The API starts on port 8080 by default.

Build

./mvnw clean package

To skip tests during packaging:

./mvnw clean package -DskipTests

Test

./mvnw test

Docker

Build the image:

docker build -t study-hive-backend .

Run the container with the required environment variables configured:

docker run -p 8080:8080 study-hive-backend

Swagger Documentation

Swagger UI is available after the application starts:

http://localhost:8080/swagger-ui/index.html

The project also configures:

/swagger-ui.html

API Overview

Area Base Path Purpose
Authentication /auth/user/ Register, login, email sign-in, forgot password, reset password
Users /user User listing, profile lookup, profile updates, user resources
Resources /resources Add, list, view, update, delete, like, bought and liked resources
Cart /user/cart Add resources to cart, remove items, view cart resources
Orders /orders Retrieve order resources
Payments /payment Stripe checkout, webhook confirmation, Connect onboarding
Leaderboard /leaderboard Leaderboard list and user rank
Cloudinary Files /file/cloudinary Upload, delete, and retrieve Cloudinary files
Email /email Email sending utility endpoint

Development Utilities

The run.sh helper script includes shortcuts for:

  • Running the app
  • Starting Redis through Docker
  • Running Stripe CLI webhook forwarding
  • Seeding the database
  • Cleaning seeded data
  • Resetting seeded data

The Stripe CLI webhook target used by the script is:

localhost:8080/payment/confirm/stripe/webhook

Frontend Integration

Set FE_URL to the frontend application URL so CORS and redirect-based payment flows work correctly. The frontend should set VITE_BE_URL to this backend's base URL.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Releases

No releases published

Packages

 
 
 

Contributors

Languages