Skip to content

Debayan-Guha/internetcommunication

Repository files navigation

Internet Communication - Microservices Architecture

🏗️ System Architecture

This is a distributed microservices application with the following architecture:

┌─────────────────────────────────────────────────┐
│           API Gateway (Spring Cloud)            │
│          JWT Validation & Routing                │
└────────────┬───────────────���────────────────────┘
             │
    ┌────────┴──────────────────────┬──────────────────┬──────────────┐
    │                               │                  │              │
┌───▼───┐  ┌──────────┐  ┌────────▼───┐  ┌──────────▼──┐  ┌───────▼──┐
│ Auth  │  │ Profile  │  │   Order    │  │   Bill      │  │ Discovery│
│Service│  │ Service  │  │  Service   │  │  Service    │  │ Service  │
└───┬───┘  └────┬─────┘  └────┬───────┘  └───────┬─────┘  └──────────┘
    │           │             │                  │
    └───────────┴─────────────┴──────────────────┘
             │
    ┌────────┴──────────────┐
    │                       │
┌───▼──────┐        ┌──────▼────┐
│  MySQL   │        │   Redis   │
│Database  │        │  Cache    │
└──────────┘        └───────────┘

🚀 Services Overview

1. Auth Service (auth-service/)

Manages user authentication with hybrid JWT and stateful session control.

Key Features:

  • ✅ Hybrid JWT Authentication (stateless + stateful)
  • ✅ AES-192 Password Encryption
  • ✅ Redis-based Token Session Management
  • ✅ Employee Role-Based Access Control
  • ✅ Immediate Token Revocation Support

Technology Stack:

  • Spring Boot 4.0.1
  • Spring Security
  • JWT (JSON Web Tokens)
  • Redis
  • MySQL

Key Files:

  • AuthService.md - Hybrid JWT documentation
  • TokenService.java - Token generation, validation, logout
  • EmployeeService.java - Employee CRUD operations
  • AES.java - Password encryption/decryption

2. Profile Service (profile-service/)

Manages client and publication profiles with caching and circuit breaker protection.

Key Features:

  • ✅ Client Profile Management
  • ✅ Publication Management
  • ✅ Redis Cache-First Pattern
  • ✅ Circuit Breaker (Resilience4j)
  • ✅ GST & State Code Management
  • ✅ Pagination Support

Technology Stack:

  • Spring Boot 3.5.7
  • Spring Data JPA
  • Redis (Caching)
  • MySQL
  • Swagger/OpenAPI

Key Files:

  • ClientService.md - Cache-first pattern & circuit breaker documentation
  • PublicationRepo.java - Publication data access
  • GstRepo.java - GST management
  • SecurityConfig.java - Role-based access control

3. Order Service (order-service/)

Manages orders and release orders (RO) for publications.

Key Features:

  • ✅ Estimate Creation & Management
  • ✅ Release Order (RO) Generation
  • ✅ PDF Report Generation
  • ✅ Publication Rate Management
  • ✅ Order Status Tracking
  • ✅ Service-to-service Communication

Technology Stack:

  • Spring Boot 4.0.1
  • Spring Data JPA
  • Redis
  • MySQL
  • Thymeleaf (HTML Templates)

Key Templates:

  • estimateMultiPageFirstPage.html - Estimate document
  • roPage.html - Release order document

4. Bill Service (bill-service/)

Manages billing and invoice generation with automatic bill ID generation.

Key Features:

  • ✅ Monthly Auto-Reset Bill Counter
  • ✅ Financial Year Calculation (April-March cycle)
  • ✅ Tax Invoice Generation
  • ✅ Publication-wise Billing
  • ✅ Discount & GST Calculation
  • ✅ Thread-Safe Bill ID Generation

Bill ID Format: MM/COUNT/YY-YY

  • Example: 01/1/24-25 (First bill of January 2025)
  • Auto-resets to 1 each month
  • Financial year: April to March

Technology Stack:

  • Spring Boot 4.0.1
  • Spring Cloud (Circuit Breaker, Load Balancer)
  • Thymeleaf (HTML Templates)
  • MySQL

Key Files:

  • BillIdGenerator.md - Complete ID generation documentation
  • BillService.java - Bill operations
  • billSinglePage.html - Single-page invoice
  • billMultiPageLastPage.html - Multi-page invoice

5. Discovery Service (discovery-service/)

Eureka service registry for microservice discovery.

Key Features:

  • ✅ Service Registration & Discovery
  • ✅ Health Checks
  • ✅ Load Balancing Support

Technology Stack:

  • Spring Cloud Netflix Eureka
  • Spring Boot 4.0.1

Ports:

  • Development: 8086
  • Production: Configurable via ${PORT}

6. Gateway Service (gateway-service/)

API Gateway with JWT validation and request routing.

Key Features:

  • ✅ JWT Token Validation
  • ✅ Request Routing to Microservices
  • ✅ Custom Gateway Filters
  • ✅ Path Blocking
  • ✅ Service Discovery Integration

Gateway Routes:

  • /api/v1/auth/** → Auth Service
  • /api/v1/profile/** → Profile Service
  • /api/v1/order/** → Order Service
  • /api/v1/billing/** → Bill Service

Technology Stack:

  • Spring Cloud Gateway
  • Spring Cloud Netflix Eureka Client
  • Reactive (WebFlux)

Key Files:

  • JwtValidationGatewayFilterFactory.java - Token validation filter
  • BlockValidateGatewayFilterFactory.java - Path blocking filter
  • application-dev.yml - Development routes configuration

📋 Database Schema

Four separate databases for each service:

CREATE DATABASE icProfile;    -- Client & Publication data
CREATE DATABASE icOrder;      -- Orders & Estimates
CREATE DATABASE icBill;       -- Billing & Invoices
CREATE DATABASE icAuth;       -- Employee & Authentication

Shared Sequences Table:

CREATE TABLE `id_sequence` (
  `sequence_name` varchar(30) NOT NULL,
  `current_value` bigint NOT NULL DEFAULT '0',
  PRIMARY KEY (`sequence_name`)
);

Sequences:

  • BILLCOUNT - Bill ID counter
  • CLIENTID - Client identifier
  • EMPLOYEEID - Employee identifier
  • ESTIMATEID - Estimate identifier
  • PUBLICATIONID - Publication identifier
  • REPRESENTATIVEID - Representative identifier
  • ROID - Release Order identifier

🐳 Docker & Deployment

Running with Docker Compose

docker-compose up -d

🔐 Authentication & Security

Hybrid JWT Approach

Stateless JWT:

  • Claims: empId, role, jti (JWT ID)
  • Fast authentication without database hits

Stateful Server Control:

  • Redis stores jti for each employee
  • Immediate token revocation capability
  • Single active session per employee (configurable)

Benefits:

  • ✅ High security (stolen tokens can be revoked)
  • ✅ High performance (stateless JWT verification)
  • ✅ Admin control (force logout, session management)
  • ✅ Device-specific session management

Password Encryption

Algorithm: AES-192 (ECB mode with PKCS5Padding)

  • Configured in AES.java
  • Secret key length: 24 characters

Role-Based Access Control (RBAC)

Roles:

  • USER - Basic user access
  • EDITOR - Create/update content
  • ADMIN - Full administrative access
  • ORDER_SERVICE - Service-to-service calls
  • BILLING_SERVICE - Service-to-service calls

🔄 Service-to-Service Communication

Communication Pattern

Services communicate through:

  • HTTP/REST via Spring WebClient
  • Service Discovery via Eureka
  • Load Balancing via Spring Cloud LoadBalancer
  • Circuit Breaker via Resilience4j

Example: Bill Service to Profile Service

// Fetch client details from Profile Service
profile-service://ic-profile-service/v1/profile/clients/{clientId}

📊 Caching Strategy

Redis Cache Implementation

Profile Service:

  • Key Format: Entity ID or custom patterns
  • TTL: 10 minutes (configurable)
  • Fallback: Database query on cache miss

Cache-First Pattern:

  1. Check Redis cache
  2. If miss, fetch from database
  3. Update cache with fresh data
  4. Return to client

Circuit Breaker Configuration

Profile Service (Read Operations):

  • Name: clientServiceRead
  • Failure Rate: 50%
  • Sliding Window: 100 calls
  • Minimum Calls: 10
  • Wait Duration (OPEN): 30 seconds
  • Fallback: Return cached data if available

📝 API Documentation

Each service provides Swagger/OpenAPI documentation:

  • Auth Service: /auth/api-docs
  • Profile Service: /profile/api-docs
  • Order Service: /order/api-docs
  • Bill Service: /billing/api-docs

Gateway routes these to Swagger UI:

  • http://localhost:8082/auth/swagger-ui.html
  • http://localhost:8082/profile/swagger-ui.html
  • etc.

🛠️ Development

Prerequisites

  • Java 21 (Auth, Bill, Order, Discovery, Gateway services)
  • Java 17 (Gateway service)
  • Maven 3.9.9
  • Docker & Docker Compose
  • MySQL 8.0+
  • Redis Alpine

Build Individual Services

# Build Auth Service
cd auth-service
mvn clean package

# Build Profile Service
cd profile-service
mvn clean package

# Similar for other services

Build Docker Images

# From each service directory
docker build -t debayan2003/ic-{service-name}:v1 .

Local Development (Without Docker)

  1. Start MySQL and Redis locally
  2. Create databases using db create.txt script
  3. Run each service from IDE or command line:
cd auth-service
mvn spring-boot:run

🔍 Monitoring & Logging

Actuator Endpoints

Each service exposes:

  • /actuator/health - Service health status
  • /actuator/metrics - Application metrics
  • /actuator/** - Full actuator endpoints

Available via Gateway

  • http://localhost:8082/auth/actuator/**
  • http://localhost:8082/profile/actuator/**
  • etc.

Logging

📜 License

This project is managed by Debayan-Guha.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors