https://github.com/vimalyad/studi.io_backend
A comprehensive Spring Boot backend for Studi.io - a collaborative study platform with real-time chat, room management, and secure authentication.
https://github.com/vimalyad/studi.io_backend
Last synced: 15 days ago
JSON representation
A comprehensive Spring Boot backend for Studi.io - a collaborative study platform with real-time chat, room management, and secure authentication.
- Host: GitHub
- URL: https://github.com/vimalyad/studi.io_backend
- Owner: vimalyad
- Created: 2025-11-10T16:51:02.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-19T08:07:47.000Z (7 months ago)
- Last Synced: 2026-02-10T18:38:02.236Z (5 months ago)
- Language: Java
- Homepage:
- Size: 135 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Studi.io Backend
A comprehensive Spring Boot backend for Studi.io - a collaborative study platform with real-time chat, room management, and secure authentication.
## โจ Features
### ๐ฏ Core Features
* ๐ช **Create & Join Rooms** โ Easily create or join public/private study rooms
* ๐ฌ **Real-time Chat** โ Instant messaging with WebSocket (STOMP) for seamless communication
* ๐ **Privacy Control** โ Public or private rooms with customizable access
* ๐ผ๏ธ **Room Customization** โ Set custom names, descriptions, and room images
* โ๏ธ **Cloud Image Uploads** โ Profile and room images hosted on Cloudinary
* โ๏ธ **Room Management** โ Full CRUD operations for room owners and admins
* ๐ฅ **Member Management** โ Admin controls and member permissions
* ๐ **Secure Authentication** โ JWT-based auth with access/refresh tokens stored in HTTP-only cookies
* ๐ง **Email Service** โ OTP verification and email notifications via SendGrid
* ๐ก๏ธ **Rate Limiting** โ Bucket4j-based rate limiting for API endpoints (general, login, signup, user-specific)
* ๐ **Message Pagination** โ Efficient message retrieval with pagination support
* ๐ **Collaborative Whiteboard** โ Real-time drawing and note-taking
* ๐๏ธ **ResourceHub** โ Centralized document and link management
### ๐ Upcoming Features
* ๐ฅ **Video Chat** โ Built-in video conferencing
* ๐ **Study Analytics** โ Track study time and productivity
* ๐ **Push Notifications** โ Browser push notifications for updates
## ๐ ๏ธ Tech Stack
### Backend
- **Framework:** Spring Boot 3.x
- **Language:** Java 17+
- **Database:** MongoDB (via Spring Data MongoDB)
- **Authentication:** JWT (JJWT)
- **Real-time:** WebSocket (STOMP protocol)
- **File Upload:** Cloudinary
- **Email:** SendGrid (JavaMail)
- **Rate Limiting:** Bucket4j + Caffeine Cache
- **Security:** Spring Security 6
- **Validation:** Jakarta Validation
### Dependencies
```xml
- spring-boot-starter-web
- spring-boot-starter-data-mongodb
- spring-boot-starter-security
- spring-boot-starter-websocket
- spring-boot-starter-mail
- jjwt-api / jjwt-impl / jjwt-jackson
- cloudinary-http44
- bucket4j-core
- caffeine
- dotenv-java
- lombok
```
## ๐ Project Structure
```
src/main/java/io/studi/backend/
โโโ config/
โ โโโ websocket/ # WebSocket configuration & session management
โ โโโ AppInfoConfig.java
โ โโโ CloudinaryConfig.java
โ โโโ CorsConfig.java
โ โโโ DotenvProcessor.java
โ โโโ MongoConfig.java
โ โโโ RateLimitFilter.java
โ โโโ SecurityConfig.java
โโโ controllers/ # REST API endpoints
โโโ dtos/ # Data Transfer Objects
โ โโโ Requests/
โ โโโ common/
โ โโโ messages/
โ โโโ rooms/
โ โโโ users/
โโโ exceptions/ # Custom exceptions & global handler
โโโ helpers/ # Utility classes
โโโ models/ # MongoDB entities
โโโ repositories/ # Data access layer
โโโ security/ # Authentication & authorization
โโโ services/ # Business logic
โโโ utils/ # JWT utilities
```
## ๐ Getting Started
### Prerequisites
- Java 17 or higher
- Maven 3.6+
- MongoDB instance (local or cloud)
- Cloudinary account
- SendGrid account
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/yamiSukehiro2907/studi.io_backend
cd studi-backend
```
2. **Configure environment variables**
Create a `.env` file in the root directory:
```env
MONGODB_URI=mongodb://localhost:27017/studiodb
MONGODB_DB=studiodb
ACCESS_TOKEN_SECRET=your_access_token_secret_min_32_chars
REFRESH_TOKEN_SECRET=your_refresh_token_secret_min_32_chars
ACCESS_TOKEN_EXPIRATION=3600000
REFRESH_TOKEN_EXPIRATION=604800000
EMAIL=your-email@example.com
SENDGRID_APIKEY=your_sendgrid_api_key
CLOUDINARY_CLOUDNAME=your_cloud_name
CLOUDINARY_APISECRET=your_api_secret
CLOUDINARY_APIKEY=your_api_key
```
3. **Build the project**
```bash
mvn clean install
```
4. **Run the application**
```bash
mvn spring-boot:run
```
The server will start on `http://localhost:8081`
## ๐ API Documentation
### Authentication Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/auth/register` | Register a new user |
| POST | `/auth/login` | Login and receive JWT tokens |
| POST | `/auth/logout` | Logout and clear tokens |
| POST | `/auth/refresh` | Refresh access token |
### User Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/user/profile` | Get current user profile |
| PUT | `/user/update` | Update user profile (multipart) |
| PUT | `/user/change-password` | Change password (authenticated) |
| PUT | `/user/change-password-with-current` | Change password with current verification |
### Study Room Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/rooms/create` | Create a new study room |
| GET | `/rooms/` | Get all rooms for current user |
| GET | `/rooms/{id}` | Get room details by ID |
| POST | `/rooms/{id}/join` | Join a public room |
| PUT | `/rooms/{id}/update` | Update room info (multipart) |
| DELETE | `/rooms/{id}` | Delete a room (owner only) |
### Message Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/messages/{id}?page=1` | Get paginated messages for a room |
### OTP Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/otp/send-otp` | Send OTP to email |
| POST | `/otp/verify-otp` | Verify OTP |
### WebSocket Endpoints
| Endpoint | Description |
|----------|-------------|
| `/ws` | WebSocket connection endpoint |
| `/server/sendMessage` | Client sends message |
| `/server/room/{roomId}` | Subscribe to room updates |
## ๐ Security Features
- **JWT Authentication** with access and refresh tokens
- **HTTP-only cookies** for secure token storage
- **CORS configuration** with allowed origins
- **Rate limiting** at multiple levels:
- General: 100 requests/minute per IP
- Login: 5 attempts/minute per IP
- Signup: 2 attempts/minute per IP
- User-specific: 100 requests/minute per user
- **Password encryption** with BCrypt
- **Email verification** with OTP
## ๐ WebSocket Architecture
The application uses STOMP over WebSocket for real-time communication:
- **Connection:** `/ws` with JWT authentication via handshake interceptor
- **Message Broker:** Simple in-memory broker on `/client` prefix
- **Application Prefix:** `/server` for client-to-server messages
- **Session Management:** Custom session registry tracks user-room mappings
- **Events:** Automatic user-joined/user-left notifications
## ๐ฆ Rate Limiting
Rate limits are enforced using Bucket4j with Caffeine cache:
```java
- Global: 100 requests/min per IP
- Login: 5 attempts/min per IP
- Signup: 2 attempts/min per IP
- Authenticated: 100 requests/min per user
```
## ๐๏ธ Database Schema
### Collections
- **users** - User accounts and profiles
- **studyrooms** - Study room information and settings
- **messages** - Chat messages with sender and room references
- **otps** - Time-limited OTP codes (10 min expiry via TTL index)
## ๐ง Configuration
Key configuration files:
- `application.yaml` - Main application configuration
- `.env` - Environment variables (not committed)
- `src/main/resources/META-INF/spring.factories` - Environment post-processor registration
## ๐งช Testing
Run tests with:
```bash
mvn test
```
## ๐ฅ Author
**Vimal Kumar Yadav**
- Email: vimalyadavkr001@gmail.com
- GitHub: [@yamiSukehiro2907](https://github.com/yamiSukehiro2907)
## ๐ค Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request