Skip to content

gogojames/lightWeb-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LightWeb Framework 🚀

中文 English

A high-performance lightweight web framework based on Java 25 TLS version, with no dependencies on any existing WEB frameworks. Fully utilizes Java 25 new features, designed specifically for modern web applications.

✨ Core Features

🏗️ Architecture Design

  • Zero Dependencies: No reliance on any third-party web frameworks
  • Modular: Clear module separation design
  • High Performance: Optimized for high concurrency scenarios
  • Lightweight: Low memory footprint, fast startup

⚡ Performance Metrics

  • High Concurrency Support: 10K+ QPS processing capability
  • Fast Cold Start: <500ms startup time
  • Low Memory Usage: Optimized memory management
  • Virtual Threads: Java 25 virtual thread support

🛡️ Security Protection

  • XSS Filtering: Automatic detection and filtering of XSS attacks
  • CSRF Protection: Token verification mechanism
  • Input Validation: Automatic request parameter validation
  • Security Headers: Automatic setting of security HTTP headers

🔧 Technical Features

  • Java 25 New Features: Comprehensive application of record classes, pattern matching, text blocks, etc.
  • RESTful API: Complies with RESTful design principles
  • Middleware Support: Flexible middleware pipeline
  • Error Handling: Unified exception handling mechanism
  • Performance Monitoring: Real-time performance metrics monitoring

🚀 Quick Start

Requirements

  • Java 25 or higher
  • Maven 3.6+

Installation & Run

# Clone project
git clone <repository-url>
cd lightweb-framework

# Compile project
mvn clean compile

# Run example application
mvn exec:java -Dexec.mainClass="com.lightweb.example.ExampleApp"

Basic Usage

import com.lightweb.framework.LightWebServer;
import com.lightweb.framework.core.Request;
import com.lightweb.framework.core.Response;
import com.lightweb.framework.router.Router;

public class MyApp {
    public static void main(String[] args) throws Exception {
        Router router = new Router();
        
        // Add routes
        router.get("/hello", (req, res) -> {
            res.json("{\"message\": \"Hello, World!\"}");
        });
        
        router.get("/users/:id", (req, res) -> {
            String userId = req.getPathParam("id").orElse("unknown");
            res.json(String.format("{\"user_id\": \"%s\"}", userId));
        });
        
        // Start server
        LightWebServer server = LightWebServer.builder()
            .port(8080)
            .router(router)
            .build();
            
        server.start();
    }
}

📁 Project Structure

src/main/java/com/lightweb/
├── framework/
│   ├── LightWebServer.java      # Server main class
│   ├── core/                    # Core components
│   │   ├── Request.java         # Request wrapper
│   │   ├── Response.java        # Response wrapper
│   │   └── RequestParser.java   # Request parser
│   ├── router/                  # Routing system
│   │   └── Router.java          # Router implementation
│   ├── security/                # Security module
│   │   └── SecurityFilter.java  # Security filter
│   ├── error/                   # Error handling
│   │   └── ErrorHandler.java    # Error handler
│   └── util/                    # Utility classes
│       └── PerformanceMonitor.java # Performance monitoring
├── example/                     # Example applications
│   └── ExampleApp.java          # Complete example
└── test/                        # Unit tests
    └── LightWebServerTest.java  # Test cases

🔌 API Documentation

Routing System

Basic Routing

router.get("/path", (req, res) -> { /* handling logic */ });
router.post("/path", (req, res) -> { /* handling logic */ });
router.put("/path", (req, res) -> { /* handling logic */ });
router.delete("/path", (req, res) -> { /* handling logic */ });

Path Parameters

router.get("/users/:id", (req, res) -> {
    String userId = req.getPathParam("id").orElse("unknown");
    // Use userId
});

Middleware

router.use((req, res) -> {
    // Authentication, logging, etc.
    return true; // Continue processing
});

Request Handling

Getting Request Data

// Headers
String value = req.getHeader("header-name").orElse("default");

// Query parameters
String param = req.getQueryParam("param-name").orElse("default");

// Path parameters
String pathParam = req.getPathParam("param-name").orElse("default");

// Request body
String body = req.body();

Response Generation

Setting Response

// Status codes
res.status(200);
res.ok();        // 200
res.created();   // 201
res.notFound();  // 404

// Content type
res.contentType("application/json");

// Response body
res.body("Text content");
res.json("{\"key\": \"value\"}");
res.html("<html>Content</html>");

// Cookies
res.cookie("name", "value");
res.cookie("name", "value", Map.of("max-age", "3600"));

🛡️ Security Features

Automatic Security Protection

The framework automatically provides the following security protections:

  • XSS Detection: Automatically identifies and blocks XSS attacks
  • CSRF Tokens: Secures form submissions
  • Input Validation: All parameters automatically validated
  • Path Traversal Protection: Prevents directory traversal attacks

Security Configuration

SecurityFilter filter = new SecurityFilter()
    .enableXssFilter(true)
    .enableCsrfProtection(true)
    .enableInputValidation(true)
    .addAllowedOrigin("https://trusted-domain.com");

📊 Performance Monitoring

Built-in performance monitoring system:

PerformanceMonitor monitor = PerformanceMonitor.getInstance();

// Get performance metrics
double qps = monitor.getQps();
double successRate = monitor.getSuccessRate();
MemoryStats memory = monitor.getMemoryStats();

// Generate detailed report
String report = monitor.generateReport();

🧪 Testing

Run the complete test suite:

mvn test

Test coverage includes:

  • Routing system tests
  • Request/response handling tests
  • Security filter tests
  • Performance monitoring tests
  • Error handling tests

🚀 Deployment

Local Deployment

mvn clean package
java -jar target/lightweb-framework-1.0.0.jar

Production Environment Recommendations

  • Use reverse proxy (Nginx)
  • Configure SSL/TLS encryption
  • Set appropriate JVM parameters
  • Enable monitoring and logging

📈 Performance Benchmarks

Metric Value Description
Startup Time <500ms Cold start to service-ready state
Memory Usage ~50MB Basic runtime memory requirement
QPS Capability 10,000+ Concurrent request processing capability
Response Time <10ms Average request processing time

🔄 Development Plan

  • WebSocket support
  • Template engine integration
  • Database connection pool
  • Caching system
  • Cluster support
  • More security features

🤝 Contributing

Welcome to submit Issues and Pull Requests!

📄 License

MIT License - See LICENSE file for details


LightWeb Framework - A high-performance web framework born for modern Java applications!

About

基于Java 25 TLS 版本开发的高性能轻量级网络框架,不依赖任何现有WEB框架。全面应用Java 25新特性,专为现代Web应用设计

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages