{"id":28680665,"url":"https://github.com/CabinJV/CabinJv","last_synced_at":"2025-06-14T02:03:43.028Z","repository":{"id":269543600,"uuid":"907735968","full_name":"CabinJV/CabinJv","owner":"CabinJV","description":"Simple and lightweight Web server framework for Java","archived":false,"fork":false,"pushed_at":"2025-06-13T08:30:48.000Z","size":13681,"stargazers_count":31,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-13T09:36:42.700Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://cabinj.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CabinJV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-24T09:07:02.000Z","updated_at":"2025-06-13T07:32:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"28e8f107-ac98-4e39-ae6a-6950718f9022","html_url":"https://github.com/CabinJV/CabinJv","commit_stats":null,"previous_names":["sangqle/cabinjv","cabinjv/cabinjv"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/CabinJV/CabinJv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CabinJV%2FCabinJv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CabinJV%2FCabinJv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CabinJV%2FCabinJv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CabinJV%2FCabinJv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CabinJV","download_url":"https://codeload.github.com/CabinJV/CabinJv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CabinJV%2FCabinJv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259747197,"owners_count":22905308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-14T02:01:10.075Z","updated_at":"2025-06-14T02:03:43.019Z","avatar_url":"https://github.com/CabinJV.png","language":"Java","funding_links":[],"categories":["开发框架"],"sub_categories":[],"readme":"[CabinJV]: src/main/java/com/cabin/express\n\n# CabinJ Framework\n\n## Introduction\n\nCabinJ is a high-performance, lightweight HTTP server framework built with Java NIO for efficient non-blocking I/O\noperations. It provides a simple yet powerful API for creating web applications with features like routing, middleware\nsupport, and efficient request/response handling.\n\n## 📦 Releases\n\nSee [RELEASE.md](RELEASE.md) for full release history and upgrade notes.\n\n## Benchmark Results\nSee [BENCHMARK.md](BENCHMARK.md) for detailed performance benchmarks.\n\n## Framework Architecture\n\n### Core Components\n\n#### Server Layer\n\n- [**CabinServer**](src/main/java/com/cabin/express/server/CabinServer.java): The main entry point that manages server lifecycle, socket connections, and request delegation\n- [**ServerBuilder**](src/main/java/com/cabin/express/server/ServerBuilder.java): Builder pattern implementation for configuring and creating CabinServer instances\n- [**BufferPool**](src/main/java/com/cabin/express/server/BufferPool.java): Manages reusable ByteBuffer instances for memory efficiency\n\n#### Request/Response Handling\n\n- [**Request**](src/main/java/com/cabin/express/http/Request.java): Represents an HTTP request with methods to access headers, parameters, body, etc.\n- [**Response**](src/main/java/com/cabin/express/http/Response.java): Represents an HTTP response with methods for headers, status codes, and writing the response body\n- [**Router**](src/main/java/com/cabin/express/router/Router.java): Defines and handles HTTP routes and maps them to appropriate handlers\n\n#### Middleware System\n\n- [**Middleware**](src/main/java/com/cabin/express/interfaces/Middleware.java): Interface for creating middleware components\n- [**MiddlewareChain**](src/main/java/com/cabin/express/middleware/MiddlewareChain.java): Manages the execution flow of middleware and route handlers\n- **Built-in Middleware**:\n   - [**CORS**](src/main/java/com/cabin/express/middleware/Cors.java): Cross-Origin Resource Sharing support\n   - [**GzipMiddleware**](src/main/java/com/cabin/express/middleware/GzipMiddleware.java): Compresses responses with gzip encoding\n\n#### Concurrency Management\n\n- [**CabinWorkerPool**](src/main/java/com/cabin/express/worker/CabinWorkerPool.java): Thread pool implementation for handling concurrent requests\n\n#### Configuration \u0026 Utilities\n\n- [**ConfigLoader**](src/main/java/com/cabin/express/config/ConfigLoader.java): Loads configuration properties from various sources\n- [**Environment**](src/main/java/com/cabin/express/config/Environment.java): Provides access to configuration values throughout the application\n- [**CabinLogger**](src/main/java/com/cabin/express/logger/CabinLogger.java): Logging utilities for the framework\n\n## Framework Flow\n\n1. **Initialization**:\n    - Create a [CabinServer](src/main/java/com/cabin/express/server/CabinServer.java) instance\n      using [ServerBuilder](src/main/java/com/cabin/express/server/ServerBuilder.java)\n    - Configure routes with [Router](src/main/java/com/cabin/express/router/Router.java) instances\n    - Apply global middleware\n    - Start the server\n\n2. **Request Processing**:\n    - Server accepts incoming connections via NIO Selector\n    - Requests are read asynchronously into ByteBuffer pools\n    - Complete requests are parsed into [Request](src/main/java/com/cabin/express/http/Request.java) objects\n    - Requests are dispatched to worker threads for processing\n\n3. **Route Handling**:\n    - Router matches request path and method to registered routes\n    - [Middleware](src/main/java/com/cabin/express/interfaces/Middleware.java) is applied in sequence\n      via [MiddlewareChain](src/main/java/com/cabin/express/middleware/MiddlewareChain.java)\n    - Route handler processes the request and populates the response\n    - [Response](src/main/java/com/cabin/express/http/Response.java) is sent back to the client\n\n4. **Resource Management**:\n    - Idle connections are monitored and cleaned up\n    - [ByteBuffer](src/main/java/com/cabin/express/server/BufferPool.java) pools are reused for memory efficiency\n    - Worker thread pools scale based on load\n      via [CabinWorkerPool](src/main/java/com/cabin/express/worker/CabinWorkerPool.java)\n\n\n## Example Usage\n\n### Simple HTTP Server\n\n```java\npublic class CabinServerSimple {\n   public static void main(String[] args) throws IOException {\n      CabinServer server = new ServerBuilder().setPort(8080).build();\n      Router router = new Router();\n      router.get(\"/\", (req, res) -\u003e {\n         res.writeBody(\"Hello World\");\n         res.send();\n      });\n      server.use(router);\n      server.start();\n      System.err.println(\"Server started at http://localhost:8080\");\n   }\n}\n```\n\n### CabinServer with Middleware\n\n```java\nclass JwtMiddleware implements Middleware {\n\n    @Override\n    public void apply(Request request, Response response, MiddlewareChain next) throws IOException {\n        System.err.println(\"Authentication here and call next()\");\n        next.next(request, response);\n    }\n}\n\nclass CustomMiddleware implements Middleware {\n    @Override\n    public void apply(Request request, Response response, MiddlewareChain next) throws IOException {\n        System.err.println(\"Custom middleware logic here\");\n        // You can modify the request or response if needed\n        next.next(request, response);\n    }\n}\n\nclass AppRouter {\n    public Router create() {\n        Router router = new Router();\n        router.get(\"/hello\", this::hello);\n        return router;\n    }\n\n    private void hello(Request req, Response resp) {\n        resp.send(\"Hello from Cabin\");\n    }\n}\n\npublic class CabinServerWithMiddleware {\n    private static final Logger logger = LoggerFactory.getLogger(CabinServerWithMiddleware.class);\n\n    public static void main(String[] args) throws IOException {\n        CabinServer server;\n        server = new ServerBuilder()\n                .setPort(8888)\n                .enableProfiler(true)\n                .enableProfilerDashboard(true)\n                .build();\n\n\n        Router appRouter = new AppRouter().create();\n        appRouter.use(new JwtMiddleware());\n        appRouter.use(new CustomMiddleware());\n\n        server.use(\"/api\", appRouter);\n\n        server.start();\n    }\n}\n```\n\n## Getting Started for Contributors\n\n### Setting Up the Development Environment\n\n1. **Clone the repository**:\n\n```shell script\ngit clone https://github.com/sangqle/CabinJv.git\n   cd CabinJv\n```\n\n2. **Build the project**:\n\n```shell script\n./gradlew clean build\n```\n\n3. **Run the tests**:\n\n```shell script\n./gradlew test\n```\n\n### Project Structure\n\n```\ncom.cabin.express/\n├── config/             # Configuration classes\n│   ├── ConfigLoader.java\n│   └── Environment.java\n├── http/               # HTTP request/response handling\n│   ├── Request.java\n│   ├── Response.java\n│   ├── MultipartParser.java\n│   └── UploadedFile.java\n├── interfaces/         # Core interfaces\n│   ├── Handler.java\n│   └── Middleware.java\n├── loggger/            # Logging utilities\n│   └── CabinLogger.java\n├── middleware/         # Middleware implementations\n│   ├── Cors.java\n│   ├── GzipMiddleware.java\n│   └── MiddlewareChain.java\n├── router/             # Routing system\n│   └── Router.java\n├── server/             # Server implementation\n│   ├── BufferPool.java\n│   ├── CabinServer.java\n│   ├── Monitor.java\n│   └── ServerBuilder.java\n├── stream/             # Stream implementations\n│   ├── NonBlockingOutputStream.java\n│   └── SimpleChunkedOutputStream.java\n└── worker/             # Concurrency utilities\n    └── CabinWorkerPool.java\n```\n\n### How to Contribute\n\n1. **Understanding the codebase**:\n    - Start with the simple examples (HServerSample.java)\n    - Explore the core classes (CabinServer, Router, Request, Response)\n    - Review the middleware system for extension points\n\n2. **Adding a new feature**:\n    - For new middleware: Implement the Middleware interface\n    - For utility functions: Add them to appropriate classes\n    - For new core components: Discuss with maintainers first\n\n3. **Testing**:\n    - Write unit tests for your code\n    - Use SimpleMainTests to create integration tests\n\n4. **Submitting changes**:\n    - Create a branch for your feature\n    - Submit a pull request with a clear description\n    - Ensure all tests pass\n\n\n## Performance Considerations\n\n- The framework uses NIO for non-blocking I/O, making it efficient for handling many concurrent connections\n- Worker pools manage thread usage to prevent resource exhaustion\n- Buffer pooling reduces memory allocation/garbage collection overhead\n- Connection timeouts and idle connection cleanup prevent resource leaks\n- Monitoring tools are available to track resource usage\n\n## Next Steps for New Contributors\n\n1. Review the existing code to understand the framework design\n2. Run the example applications to see the framework in action\n3. Check the issue tracker for beginner-friendly tasks\n4. Consider implementing a small feature or enhancement\n5. Contribute documentation improvements\n\n## People\nThe CabinJ framework is maintained by [Sang Qle](https://github.com/sangqle)\n\nBy following this guide, you'll be able to understand, use, and contribute to the CabinJ framework efficiently.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCabinJV%2FCabinJv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCabinJV%2FCabinJv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCabinJV%2FCabinJv/lists"}