Skip to content

Latest commit

 

History

History
 
 

server-java

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

☕ NexaSphere Java Backend

Spring Boot 3 REST API

Enterprise-grade REST API for NexaSphere community platform with real-time data synchronization



📌 Overview


Purpose

Spring Boot 3 backend service providing:

  • ✓ Event management (CRUD operations)
  • ✓ Core team member management
  • ✓ User form submission handling
  • ✓ Admin authentication & authorization
  • ✓ Real-time data synchronization

Key Specifications

Specification Details
Runtime Java 17+
Framework Spring Boot 3
Build Tool Maven 3.8+
Default Database H2 (development)
Production Database PostgreSQL
Port 8080


⚙️ Prerequisites


Before starting, ensure you have:

Tool Version Download
Java JDK 17+ https://www.oracle.com/java/technologies/
Maven 3.8+ https://maven.apache.org/download.cgi
PostgreSQL Latest https://www.postgresql.org/download/


🚀 Quick Start


1️⃣ Build Project


cd server-java
mvn clean install

What this does:

  • Downloads all dependencies
  • Compiles source code
  • Runs unit tests
  • Creates executable JAR


2️⃣ Run Development Server


Using H2 (in-memory database):

mvn spring-boot:run

✅ Server Running on: http://localhost:8080



3️⃣ Run Production Server


Setup PostgreSQL:

# Export environment variables
export DB_URL=jdbc:postgresql://localhost:5432/nexasphere
export DB_DRIVER=org.postgresql.Driver
export DB_USER=postgres
export DB_PASS=yourpassword

# Run the server
mvn spring-boot:run


📋 Environment Variables


Essential Variables

Variable Example Purpose
ADMIN_EMAIL [email protected] Admin login email
ADMIN_PASSWORD your-secure-password Admin login password
CORS_ORIGIN http://localhost:5173 Allowed frontend origins

Database Configuration

Variable Dev Value Prod Value
DB_URL jdbc:h2:mem:nexaspheredb jdbc:postgresql://host:5432/nexasphere
DB_DRIVER org.h2.Driver org.postgresql.Driver
DB_USER sa postgres
DB_PASS (empty) your-password

application.properties File


Create src/main/resources/application.properties:

# ========== Server Configuration ==========
server.port=8080
spring.profiles.active=dev

# ========== Database (H2 - Development) ==========
spring.datasource.url=jdbc:h2:mem:nexaspheredb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# ========== Database (PostgreSQL - Production) ==========
# Uncomment for production
# spring.datasource.url=jdbc:postgresql://localhost:5432/nexasphere
# spring.datasource.driverClassName=org.postgresql.Driver
# spring.datasource.username=postgres
# spring.datasource.password=yourpassword

# ========== JPA/Hibernate Configuration ==========
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=true

# ========== Admin Credentials — set via environment variables only, never commit real values ==========
app.admin.email[email protected]
app.admin.password=your-secure-password

# ========== CORS Configuration ==========
app.cors.origin=http://localhost:5173,https://nexasphere-glbajaj.vercel.app

# ========== Logging ==========
logging.level.root=INFO
logging.level.org.nexasphere=DEBUG
logging.level.org.springframework.web=DEBUG


📁 Project Structure


server-java/
│
├── src/
│   ├── main/
│   │   ├── java/org/nexasphere/
│   │   │   ├── NexaSphereApplication.java      ← Spring Boot Entry Point
│   │   │   ├── controller/                     ← REST Endpoints
│   │   │   ├── service/                        ← Business Logic
│   │   │   ├── model/                          ← JPA Entities
│   │   │   ├── repository/                     ← Data Access Layer
│   │   │   ├── config/                         ← Spring Configuration
│   │   │   ├── exception/                      ← Custom Exceptions
│   │   │   └── util/                           ← Utility Classes
│   │   └── resources/
│   │       ├── application.properties          ← Configuration
│   │       └── data.sql                        ← Seed Data
│   └── test/
│       └── java/org/nexasphere/
│           └── NexaSphereApplicationTests.java
│
├── pom.xml                                     ← Maven Dependencies
├── mvnw & mvnw.cmd                            ← Maven Wrapper
└── README.md


🧪 Testing


Run All Tests

mvn test

Run with Coverage Report

mvn clean test jacoco:report

📊 View Coverage: target/site/jacoco/index.html


Run Full Verification

mvn verify


🏛️ Architecture


Layer Breakdown

🎯 Controller Layer

  • REST endpoint handlers
  • Request/response mapping
  • Input validation
  • CORS configuration

🔧 Service Layer

  • Business logic
  • Data processing
  • Business rules
  • Transaction management

🗄️ Repository Layer

  • Database queries
  • CRUD operations
  • JPA interfaces
  • Custom queries

📦 Model Layer

  • JPA entities
  • Database tables
  • Entity relationships
  • Validation annotations


🌐 API Endpoints


Public Endpoints


GET  /api/content/events
GET  /api/content/events/{id}
GET  /api/content/activity-events/{activityKey}
GET  /api/content/core-team
GET  /api/content/core-team/{id}
POST /api/forms/membership
POST /api/forms/recruitment
POST /api/core-team/apply

Admin Endpoints (Requires Authentication)


POST   /api/admin/events
PUT    /api/admin/events/{id}
DELETE /api/admin/events/{id}

POST   /api/admin/core-team
PUT    /api/admin/core-team/{id}
DELETE /api/admin/core-team/{id}

POST   /api/admin/login
POST   /api/admin/logout

📚 API Documentation (Swagger UI)


NexaSphere includes interactive API documentation powered by OpenAPI 3 (Swagger UI). Once the server is running, you can access the documentation using the following URLs:

To test secure admin endpoints directly from Swagger UI, click the Authorize button and input your Bearer JWT token obtained from /api/admin/login.



🔐 Authentication


Admin Login

curl -X POST http://localhost:8080/api/admin/login \
  -H "Content-Type: application/json" \
  -d '{
    "email":"<ADMIN_EMAIL>",
    "password":"<ADMIN_PASSWORD>"
  }'

Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expiresIn": 3600
}

Using Token

curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  http://localhost:8080/api/admin/events


📚 Database Setup


Development (H2)

Automatic Setup:

  • ✓ Creates in-memory database on startup
  • ✓ Creates tables from JPA entities
  • ✓ Loads seed data from data.sql
  • ✓ No manual configuration needed

Production (PostgreSQL)


Step 1: Create Database

createdb nexasphere

Step 2: Configure Connection

Update application.properties with PostgreSQL credentials


Step 3: Initialize

Spring Boot auto-creates tables on startup via JPA



🚀 Deployment


Railway Deployment


1. Install Railway CLI

npm i -g @railway/cli

2. Login & Deploy

railway login
cd server-java
railway init
railway up

3. Set Environment Variables

In Railway Dashboard, add:

[email protected]
ADMIN_PASSWORD=your-secure-password
CORS_ORIGIN=https://nexasphere-glbajaj.vercel.app
DB_URL=jdbc:postgresql://[rail-host]:5432/railway
DB_DRIVER=org.postgresql.Driver
DB_USER=postgres
DB_PASS=[from-dashboard]


🐛 Troubleshooting


Build Issues


❌ Maven command not found

# Solution: Add Maven to PATH
# Or use Maven wrapper
./mvnw clean install

❌ Java 17 not found

# Solution: Download Java 17+
# Verify: java -version

Runtime Issues


❌ Connection refused on port 8080

# Solution: Port already in use
# Change port in application.properties
server.port=9090

❌ Database connection failed

# Solution: Verify PostgreSQL is running
# Check credentials in application.properties


📖 Additional Resources





Questions? 📧 Contact [email protected]

Backend Version: 1.0 | Last Updated: May 2026