Skip to content

kondim23/connectify-springboot-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connectify back-end – Spring Boot Web Application

Note: This backend project is designed to work seamlessly with the companion frontend project kondim23/connectify-reactjs-frontend (React.js). For a complete experience, clone and run both the backend and frontend repositories.

Description

Connectify is a professional networking web application inspired by LinkedIn, built with Spring Boot, Spring Security, JWT authentication, MySQL, and Maven. It enables users to register, create posts, connect with others, apply for jobs, exchange messages, and receive personalized recommendations. The backend provides secure REST APIs, robust authentication, and scalable architecture for modern web development.

Features

  • User registration, authentication, and profile management
  • JWT-based stateless security
  • Post creation, likes, and media attachments
  • MySQL database integration
  • RESTful API endpoints
  • File upload support (up to 10GB)
  • HTTPS/SSL support
  • CORS configuration for frontend integration

Technologies Used

  • Java 17+ (or Java 21 with Spring Boot 3.x)
  • Spring Boot
  • Spring Security
  • Spring Data JPA (Hibernate)
  • MySQL
  • Maven
  • Lombok
  • JUnit 5 & MockMvc (for testing)

Prerequisites

  • Java 17 or 21
  • Maven 3.6+
  • MySQL 8.x
  • (Optional) IDE: VS Code, IntelliJ IDEA, Eclipse

Getting Started

  1. Clone the repository
    git clone https://github.com/kondim23/connectify-springboot-backend.git
    cd connectify-springboot-backend
  2. Database setup
    CREATE DATABASE connectify;
    CREATE USER 'connectify-test-user'@'localhost' IDENTIFIED BY 'connectify-test-password';
    GRANT ALL PRIVILEGES ON connectify.* TO 'connectify-test-user'@'localhost';
    FLUSH PRIVILEGES;
  3. Configuration Edit src/main/resources/application.properties if needed:
    spring.datasource.url=jdbc:mysql://127.0.0.1:3306/connectify
    spring.datasource.username=connectify-test-user
    spring.datasource.password=connectify-test-password
  4. Build instructions
    ./mvnw clean package
  5. Run instructions
    ./mvnw spring-boot:run
    # or
    java -jar target/connectify-0.0.1-SNAPSHOT.jar
    The app will be available at https://localhost:8443.

Database Architecture

The application uses a MySQL database with the following main entities and relationships:

  • User: Stores user profile and authentication data. Related to posts, likes, views, connections, messages, jobs, job requests, and job views.
  • Post: Represents user posts. Related to users, media, likes, views, and comments.
  • Media: Stores media files attached to posts.
  • Likes: Represents user likes on posts.
  • View: Tracks which users have viewed which posts.
  • Connection: Represents user-to-user connections (friendships, pending/accepted).
  • Message: Stores messages exchanged between users.
  • Job: Represents job listings created by users.
  • JobRequest: Represents applications to job listings.
  • JobView: Tracks which users have viewed which jobs.
  • Comment: Stores comments on posts.
  • Notification: Stores notifications for likes and comments.
  • PostMatrixElement / JobMatrixElement: Used for recommendation system (matrix factorization).

All tables use auto-generated primary keys and foreign keys to manage relationships. The schema supports all main features: users, posts, jobs, connections, messaging, notifications, comments, and recommendations.

Software Architecture

This application follows a layered architecture typical for Spring Boot projects:

Controller Layer

  • Handles HTTP requests and maps them to service methods.
  • Located in packages like com.connectify.User, com.connectify.Posts, com.connectify.Likes, etc.
  • Example: UserController, PostController, LikesController.
  • Uses annotations like @RestController, @RequestMapping, and @PostMapping.

Service Layer

  • Contains business logic and orchestrates data flow between controllers and repositories.
  • Example classes: UserService, PostService, LikeService (if present).
  • Handles validation, security checks, and transactional operations.
  • Uses @Service and @Transactional annotations.

Repository Layer

  • Interfaces with the database using Spring Data JPA.
  • Example: UserRepository, PostRepository, LikesRepository, MediaRepository, ViewRepository.
  • Extends JpaRepository or CrudRepository for CRUD operations.
  • Uses @Repository annotation.

Security

  • Uses Spring Security with JWT for stateless authentication.
  • Custom filters like JWTAuthenticationFilter and JWTAuthorizationFilter handle token creation and validation.
  • Security configuration is managed in a class (e.g., WebSecurity) using a SecurityFilterChain bean.
  • Passwords are hashed using BCryptPasswordEncoder.
  • Endpoints are protected by roles and JWT tokens; only registration and login are public.

Security Flow:

  1. User logs in with credentials.
  2. If valid, a JWT token is generated and returned.
  3. For protected endpoints, the JWT token must be included in the Authorization header.
  4. Filters validate the token and set the authentication context.

Configuration

  • application.properties configures database, SSL, file upload limits, and security settings.
  • SSL is enabled for HTTPS on port 8443 using a PKCS12 keystore (server.p12).
  • CORS is configured to allow cross-origin requests from any origin.

API Endpoints (Actual from Codebase)

User

  • POST /users/new-user – Register a new user
  • GET /users – List all users
  • GET /user – Get user by email (param: userEmail)
  • GET /search/{searchData} – Search users
  • GET /signin – User login (params: userEmail, userPass)
  • PUT /user/{oldEmail} – Update user profile
  • POST /userimage – Upload user profile image
  • GET /user/image – Get user profile image (param: userEmail)
  • GET /user/image/remove – Remove user profile image (param: userEmail)

Admin

  • POST /admin/users – Get info for a list of users
  • POST /admin – Create/setup a new admin

Posts

  • POST /posts – Create a post
  • GET /allPosts – List all posts
  • GET /posts – Get home page posts (param: userEmail)

Likes

  • POST /likes – Like a post
  • DELETE /likes – Unlike a post (params: userEmail, postId)

Comments

  • POST /comments – Add a comment to a post
  • GET /comments – Get comments of a post (param: postID)

Views

  • POST /views – Register a view on a post

Connections

  • GET /connections – List all connections
  • GET /connections/{email} – Get connections of user
  • GET /connections/users – Get users connected with user (param: userEmail)
  • GET /connections/pending/{email} – Get pending connections of user
  • GET /connections/exist – Check if connection exists (params: email1, email2)
  • POST /connections – Create a new connection request
  • PUT /connections/accept – Accept a connection (params: userId, senderId)
  • DELETE /connections/discard – Discard a connection (params: userId, userToDisconnectId)

Media

  • POST /media/upload – Upload media to a post
  • GET /media/type – Get media of a post (param: postId)
  • GET /media/download – Download media by ID (param: mediaId)

Jobs

  • GET /jobs – Get recommended jobs for user (param: userEmail)
  • POST /jobs – Create a job listing

Job Requests

  • POST /jobs/requests – Apply to a job
  • GET /jobs/requests – Get job requests for user (param: userEmail)
  • GET /jobs/requests/single – Get single job request (params: userEmail, jobId)

Job Views

  • POST /job-views – Register a view on a job

Messages

  • GET /messages – List all messages
  • POST /messages – Post a new message
  • GET /messages/{userEmail} – Get chat messages (param: connectedEmail)
  • GET /messages/chatters/{senderEmail} – Get all acceptors for sender

Notifications

  • GET /notifications/likecomment – Get like/comment notifications (param: userEmail)

Recommendation System: Matrix Factorization for Post and Job Suggestions

This application already integrates matrix factorization techniques for personalized post and job recommendations. Matrix factorization is a collaborative filtering approach commonly used in recommendation systems (such as those for movies, products, or social feeds).

How It Works

  • User-Item Matrix: The system constructs a matrix where rows represent users and columns represent posts or jobs. Each cell contains a score (e.g., like, view, application, or implicit feedback) based on user interactions.
  • Factorization: This matrix is decomposed into two lower-dimensional matrices—one representing user features and one representing item (post/job) features. This reveals latent factors that explain observed interactions.
  • Prediction: By multiplying the user and item feature matrices, the system predicts missing scores (i.e., how likely a user is to like or engage with a post/job they haven't seen yet).

Application in This Project

  • Posts: The application suggests posts to users based on their previous likes, views, and interactions, as well as those of similar users, using the matrix factorization model.
  • Jobs: Job postings are recommended by analyzing user profiles, applications, and engagement history, leveraging the same collaborative filtering approach.
  • Workflow Example:
    1. The backend collects user-post and user-job interaction data (likes, views, applications).
    2. The user-item matrix is built and updated regularly.
    3. Matrix factorization (e.g., SVD or ALS algorithms) is applied to learn latent features.
    4. For each user, the system recommends top-N posts or jobs with the highest predicted scores.

Integration

  • The recommendation engine is implemented as a scheduled service within the backend, updating recommendations as new data arrives.
  • Currently, matrix factorization is not directly exposed via REST endpoints, but its results can be used internally to enhance user experience and drive personalized suggestions in the application.
  • The implementation uses Java-based libraries and custom logic for matrix factorization and prediction.

This approach enables scalable, data-driven recommendations that improve as more users interact with the platform.

Dataset

  • The recommendation system is tested with a dataset generated in DatabaseInitialization.java.
  • ApplicationConstants.java contains the IMPORT_DATASET flag, which, when set to true, imports test records into the database.
  • The dataset includes users of four specialties (programmer, engineer, economist, doctor) with a specific connection pattern and random connections between specialties.
  • Each user has created one post and one job listing, and has viewed and expressed interest in posts and job listings of connected users.
  • The recommendation system ranks posts and job listings based on a dynamically calculated score.

About

Spring Boot backend for Connectify, a social networking platform, enabling API and data management.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages