Skip to content

lovekumardixit/Journal-Backend-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Journal Backend API

A production-ready, enterprise-grade backend for a personal journaling application with JWT authentication, MongoDB, Redis caching, and AWS cloud deployment.

Live API: https://journalapilav.tech
Swagger UI: https://journalapilav/swagger-ui.html
Author: Lav Kumar Dixit | GitHub: @lovekumardixit


πŸš€ Key Features

  • JWT-based Authentication with refresh tokens and role-based access (USER / ADMIN)
  • Secure User Registration with strict validation (username, password, email)
  • User Profile Management with profile photo upload/update/delete (AWS S3 storage)
  • Complete Journal CRUD Operations with partial update support
  • Sentiment Tracking (HAPPY, SAD, ANGRY, NEUTRAL) with filtering
  • Weather API Integration for personalized greetings
  • Email (SMTP) & Kafka Integration for event-driven architecture
  • OpenAPI/Swagger auto-generated documentation with Bearer Authentication
  • Redis Caching for improved performance
  • HTTPS/SSL Secured with Let's Encrypt
  • Production-Ready Deployment on AWS EC2 with Docker & Nginx

πŸ› οΈ Tech Stack

Backend

  • Java 17 with Spring Boot 3.x
  • Spring Security with JWT Authentication
  • Spring Data MongoDB for persistence
  • Spring Data Redis for caching
  • Spring Kafka for event streaming
  • OAuth2 (Google Login support)
  • REST APIs with comprehensive documentation

Database & Caching

  • MongoDB Atlas for scalable NoSQL database
  • Redis Cache for session & query caching

Messaging & Event Streaming

  • Apache Kafka with Zookeeper
  • Event-Driven Architecture for asynchronous processing

Cloud & Deployment

  • AWS EC2 (Ubuntu Server) for hosting
  • AWS S3 for profile image storage
  • Docker & Docker Compose for containerization
  • Nginx Reverse Proxy for load balancing
  • HTTPS/SSL with Let's Encrypt certificate
  • GitHub Actions for CI/CD automation

Security

  • JWT-based authentication with secure token management
  • Role-based access control (RBAC)
  • OAuth2 authentication (Google Login)
  • Environment-based configuration (dev, staging, prod)
  • Secure HTTPS/TLS encryption
  • Protected AWS credentials and sensitive data

πŸ“‹ Quick Start

Prerequisites

  • Java 17+
  • Maven 3.x
  • Docker & Docker Compose (optional)
  • Linux/Unix environment for production

Run Locally

  1. Clone the repository
git clone https://github.com/lovekumardixit/Journal-Backend-API.git
cd Journal-Backend-API
  1. Configure environment variables
export MONGO_URI='mongodb+srv://<user>:<pass>@cluster.mongodb.net/userdb'
export JWT_SECRET='your-strong-secret-key-here'
export SERVER_PORT=8081
export WEATHER_API_KEY='your-api-key'
export MAIL_USERNAME='your-email@gmail.com'
export MAIL_PASSWORD='your-app-password'
export KAFKA_BOOTSTRAP_SERVERS='localhost:9092'
export AWS_ACCESS_KEY_ID='your-aws-key'
export AWS_SECRET_ACCESS_KEY='your-aws-secret'
export AWS_S3_BUCKET='your-bucket-name'
  1. Build & Run
# With Maven (dev profile)
mvn clean package
mvn -Dspring-boot.run.profiles=dev spring-boot:run

# With Java
java -jar target/Backend-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev

Local server: http://localhost:8081

Docker Deployment

# Build Docker image
docker build -t journal-backend-api:latest .

# Run container
docker run -p 8081:8081 \
  -e MONGO_URI='<your-mongodb-uri>' \
  -e JWT_SECRET='<your-secret>' \
  -e AWS_ACCESS_KEY_ID='<your-key>' \
  -e AWS_SECRET_ACCESS_KEY='<your-secret>' \
  journal-backend-api:latest

# With Docker Compose
docker-compose up -d

🌐 API Documentation

Access Points

Core Endpoints

Authentication

  • POST /auth/register β€” Register new user
  • POST /auth/login β€” Login and receive JWT tokens
  • POST /auth/refresh β€” Refresh access token
  • POST /auth/logout β€” Logout user

User Profile

  • GET /user/me β€” Get current user profile
  • GET /user/profile β€” Get profile with photo URL
  • GET /user/get/{city} β€” Get weather greeting
  • POST /user/profile-photo/upload β€” Upload profile photo (multipart)
  • DELETE /user/profile-photo β€” Delete profile photo

Journal Entries

  • POST /entry β€” Create new entry
  • GET /entry/{id} β€” Get entry by ID
  • PUT /entry/{id} β€” Update entry
  • PATCH /entry/{id} β€” Partial update
  • DELETE /entry/{id} β€” Delete entry
  • GET /entry/user/{userId} β€” Get user's entries

Filters & Analytics

  • GET /sentiment β€” Filter entries by sentiment
  • GET /sentiment/stats β€” Get sentiment statistics

For complete API details, visit: Swagger UI


πŸ”’ Authentication in Swagger UI

  1. Click the "Authorize" button in Swagger UI
  2. Enter your token in the format: Bearer YOUR_JWT_TOKEN
  3. Execute requests directly from the UI

πŸ“ Project Structure

src/main/java/com/love/Backend/
β”œβ”€β”€ controller/       # REST endpoints (Auth, User, Entry, Sentiment)
β”œβ”€β”€ service/          # Business logic & core services
β”œβ”€β”€ repository/       # Spring Data repositories
β”œβ”€β”€ entity/           # JPA domain models
β”œβ”€β”€ dto/              # Request/Response DTOs
β”œβ”€β”€ config/           # Spring config (Security, Swagger, Redis, AWS S3)
β”œβ”€β”€ kafka/            # Event producers & consumers
β”œβ”€β”€ exception/        # Custom exceptions & error handlers
β”œβ”€β”€ util/             # Utility classes & helpers
└── BackendApplication.java

πŸ§ͺ Testing

Run all tests with Maven:

mvn test

Validation Tests: Comprehensive test cases for user registration, authentication, and input validation.

See related documentation:

  • VALIDATION_RULES.md β€” User validation rules & best practices
  • TEST_VALIDATION.md β€” Step-by-step test scenarios

πŸš€ Production Deployment (AWS EC2)

Infrastructure Setup

  • OS: Ubuntu 20.04+ LTS
  • Java 17 installed
  • MongoDB Atlas for managed database
  • Redis for caching layer
  • Nginx reverse proxy with SSL
  • Let's Encrypt for HTTPS/TLS

Deployment Steps

  1. Push Docker image to registry
docker tag journal-backend-api:latest your-registry/journal-backend-api:latest
docker push your-registry/journal-backend-api:latest
  1. Deploy on EC2
ssh ec2-user@your-ec2-ip
cd /opt/journal-api
docker pull your-registry/journal-backend-api:latest
docker-compose up -d
  1. Configure Nginx
server {
    listen 443 ssl http2;
    server_name your-api-url.com;
    
    ssl_certificate /etc/letsencrypt/live/your-api-url.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-api-url.com/privkey.pem;
    
    location / {
        proxy_pass http://localhost:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Environment Configuration

Production uses profile-based configuration. Set environment variables:

export SPRING_PROFILES_ACTIVE=prod
export MONGO_URI='mongodb+srv://user:pass@cluster.mongodb.net/journal'
export JWT_SECRET='<strong-production-secret>'
export AWS_S3_BUCKET='journal-profile-photos'

πŸ” Security Best Practices

βœ… JWT Secret: Strong, random, environment-specific
βœ… HTTPS/TLS: Let's Encrypt SSL certificates
βœ… Database: MongoDB Atlas with authentication & IP whitelist
βœ… AWS Credentials: Stored in EC2 IAM roles (not hardcoded)
βœ… Environment Variables: Profile-based, never committed to VCS
βœ… CORS: Configured for trusted domains only
βœ… Rate Limiting: Implemented on authentication endpoints


πŸ“š Documentation

  • VALIDATION_RULES.md β€” Comprehensive validation standards
  • TEST_VALIDATION.md β€” Test case scenarios
  • KAFKA_GUIDE.md β€” Event streaming setup
  • EC2_S3_DEPLOYMENT.md β€” AWS deployment guide
  • QUICK_START.md β€” 5-minute quick setup

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License β€” see LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Love Dixit


Last Updated: May 20, 2026 | Status: Production Ready βœ…

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors