πΉ Production Version
Click here to access the live production version
The backend of Social Network is developed using Java & Spring Boot, offering a secure, scalable, and optimized REST API.
The architecture follows a layered design, ensuring clear separation of concerns:
π Entities β Repositories β Services β Controllers β DTOs β Responses
This backend provides authentication, caching, real-time updates, email & SMS verification, and scheduled jobs for maintenance. It is fully Dockerized and deployed with CI/CD using GitHub Actions and Render.
π Backend Framework: Spring Boot, Java
π Security: Spring Security, JWT (JSON Web Tokens), Password Hashing (SHA-256 + Salt)
π‘ Real-Time Updates: SSE (Server-Sent Events)
π¦ Database: MySQL (optimized queries & indexes using JPA)
π¨ Email & SMS Verification: Twilio, Mailgun
πΈ Cloud Storage: Cloudinary for media uploads
β‘ Caching: Spring Boot Caching for optimized performance
π Scheduled Jobs: CRON Job (session tracking, expired token cleanup)
π Environment Configuration: Dotenv for managing variables
π³ Containerization & Deployment: Docker + Render + GitHub Actions (CI/CD)
- The client (React) sends requests using Axios to RESTful API endpoints.
- Backend controllers handle the request, then delegate to services.
- Services process the business logic and interact with repositories.
- Repositories execute JPA queries on the MySQL database.
- Caching optimizes responses, and SSE provides real-time updates.
- All operations are containerized in Docker for scalable deployment.
-
User Registration:
- Strong password validation & uniqueness check (email/phone).
- If valid, an email is sent with account details.
- Password is hashed & salted (SHA-256) before storage.
-
Login Process:
- User enters credentials β JWT is generated.
- 2FA SMS verification is sent to the phone.
- On success, session starts & user gains access.
-
Password Reset:
- User requests reset β Receives email with a unique token.
- User enters token & new password β New hashed & salted password is saved.
- Confirmation email is sent.
- MySQL database with efficient JPA queries and indexes.
- User content (posts, comments, media) stored with Cloudinary integration.
- Spring Boot Caching improves response times and reduces redundant queries.
- SSE (Server-Sent Events) used for real-time notifications/messages.
- Users get instant alerts for likes, follows, and comments.
- CRON Jobs run monthly to check for inactive users & send reminders.
- Token expiration handling ensures security by removing stale sessions.
- Dockerized environment ensures consistency across deployments.
- CI/CD pipeline (GitHub Actions) automates deployment to Render.
- Environment variables managed securely with
.env
files.
Social-Network-Server/
βββ π .github
β βββ workflow
β βββ deploy.yml # CI/CD GitHub Actions for auto-deployment
βββ π src/main/java/org.server.socialnetworkserver
β βββ π config # Security, JWT, Caching & Environment Management
β βββ π controllers # API endpoints for handling requests
β βββ π dtos # Data transfer objects for request/response
β βββ π entities # Database entities (User, Post, Comment, etc.)
β βββ π jobs # Scheduled tasks (CronJobs)
β βββ π repositories # JPA repositories for database interaction
β βββ π responses # Custom API responses
β βββ π services # Business logic layer
β βββ π test # Unit & integration tests
β βββ π utils # Helper functions, token & password generators & utilities
β βββ SocialNetworkServerApplication # Main application with enabled annotations
βββ π resources # Application properties settings
β
βββ Dockerfile # Docker container setup
βββ .env # Environment variable template for local use
βββ README.md # Project documentation
# Clone repository
git clone https://github.com/your-repo/social-network-server.git
cd social-network-server
# Build and run with Maven
mvn clean install
mvn spring-boot:run
#DotEnv Example
DB_URL_LOCAL=yourLocalDb
DB_HOST_LOCAL=yourHost
DB_USERNAME_LOCAL=yourUsername
DB_PASSWORD_LOCAL=yourPassword
DB_NAME_LOCAL=yourDBname
SMS_TOKEN=You Need SMS Token or Cancel it
SENDER_EMAIL=yourMail
SENDER_PASSWORD=yourPassAppMail
URL_CLIENT_PC=http://localhost:3000
URL_TEST=http://localhost:8080/social-network/slow-endpoint
# Running with Docker
docker build -t social-network-server .
docker run -p 8080:8080 social-network-server
@PostMapping("/add-user")
public ValidationResponse addUser(@RequestBody User user) {
return userService.addUser(user);
}
@PostMapping("/login-user")
public LoginResponse loginUser(@RequestBody Map<String, String> loginDetails) {
return userService.loginUser(loginDetails);
}
@PostMapping("/verify-code")
public Map<String, String> verifyCode(@RequestBody Map<String, String> verificationDetails) {
return userService.verifyCode(verificationDetails);
}
@GetMapping("/reset-password/{email}&{username}")
public BasicResponse resetPasswordForThisUser(@PathVariable String email, @PathVariable String username) {
return userService.resetPasswordForThisUser(email,username);
}
@PostMapping("/confirm-reset-password")
public BasicResponse confirmResetPassword(@RequestParam String token){
return userService.confirmPasswordReset(token);
}
β
JWT Authentication with Expiration Handling
β
Two-Factor Authentication (2FA) via SMS
β
Password Hashing (SHA-256 + Salt)
β
Rate Limiting to Prevent Abuse
β
Spring Boot Caching for Optimized Performance
β
CORS & Helmet for API Security
π‘ SSE for Instant Updates
- Notifications for likes, comments, follows, messages.
- Real-time updates without excessive polling.
π’ Automated Email & SMS Alerts
- Registration confirmation via email.
- Password reset email with unique token.
π Runs once per month
- Sends reminder emails to inactive users.
- Checks for expired authentication tokens and removes them.
π Dockerized for scalable deployment
π CI/CD with GitHub Actions
π Hosted on Render (auto-deployment on commit)
π‘ Contributions are welcome via Pull Requests.
Feel free to reach out via email: π§ yakovbenhemo5@gmail.com
π Built for a seamless and secure social networking experience! π