|
| 1 | +# Jazzy Framework |
| 2 | + |
| 3 | +Jazzy is a lightweight web framework for Java. It provides a minimal and easy-to-understand API for developing fast web applications. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Simple and intuitive API |
| 8 | +- Routing system with HTTP method support (GET, POST, PUT, DELETE, PATCH) |
| 9 | +- URL path parameter support |
| 10 | +- Automatic parameter mapping |
| 11 | +- Simple metrics collection and reporting |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +To develop a web application with Jazzy, you can follow this example code: |
| 16 | + |
| 17 | +```java |
| 18 | +// App.java |
| 19 | +package com.example; |
| 20 | + |
| 21 | +import jazzyframework.core.Config; |
| 22 | +import jazzyframework.core.Server; |
| 23 | +import jazzyframework.routing.Router; |
| 24 | + |
| 25 | +public class App { |
| 26 | + public static void main(String[] args) { |
| 27 | + // Create configuration |
| 28 | + Config config = new Config(); |
| 29 | + config.setEnableMetrics(true); // "/metrics" endpoint is automatically added |
| 30 | + config.setServerPort(8088); |
| 31 | + |
| 32 | + // Create router |
| 33 | + Router router = new Router(); |
| 34 | + |
| 35 | + // Define routes |
| 36 | + router.GET("/user/{id}", "getUserById", UserController.class); |
| 37 | + router.POST("/user/{id}", "updateUser", UserController.class); |
| 38 | + router.GET("/users", "getAllUsers", UserController.class); |
| 39 | + router.DELETE("/user/{id}", "deleteUser", UserController.class); |
| 40 | + router.PUT("/user/{id}", "putUser", UserController.class); |
| 41 | + |
| 42 | + // Start the server |
| 43 | + Server server = new Server(router, config); |
| 44 | + server.start(config.getServerPort()); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +// UserController.java |
| 49 | +package com.example; |
| 50 | + |
| 51 | +public class UserController { |
| 52 | + // Method with path parameter |
| 53 | + public String getUserById(String id) { |
| 54 | + return "User ID: " + id; |
| 55 | + } |
| 56 | + |
| 57 | + // Method without parameters |
| 58 | + public String getAllUsers() { |
| 59 | + return "All users"; |
| 60 | + } |
| 61 | + |
| 62 | + // Method with path parameter and request body |
| 63 | + public String updateUser(String id, String requestBody) { |
| 64 | + return "Updated user " + id + " with data: " + requestBody; |
| 65 | + } |
| 66 | + |
| 67 | + // Method for handling DELETE requests |
| 68 | + public String deleteUser(String id) { |
| 69 | + return "Deleted user " + id; |
| 70 | + } |
| 71 | + |
| 72 | + // Method for handling PUT requests |
| 73 | + public String putUser(String id, String requestBody) { |
| 74 | + return "Updated user " + id + " with data: " + requestBody; |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +For a more detailed example, check the `src/main/java/examples/basic` directory. |
| 80 | + |
| 81 | +## Development |
| 82 | + |
| 83 | +Jazzy is developed with Maven. After cloning the project, you can use the following commands: |
| 84 | + |
| 85 | +```bash |
| 86 | +# Install dependencies and build the project |
| 87 | +mvn clean install |
| 88 | + |
| 89 | +# Run tests |
| 90 | +mvn test |
| 91 | + |
| 92 | +# Run the example application |
| 93 | +mvn exec:java -Dexec.mainClass="examples.basic.App" |
| 94 | +``` |
| 95 | + |
| 96 | +## Project Structure |
| 97 | + |
| 98 | +- `core/`: Core framework components |
| 99 | + - `Server.java`: HTTP server |
| 100 | + - `RequestHandler.java`: HTTP request processor |
| 101 | + - `Config.java`: Configuration management |
| 102 | + - `Metrics.java`: Performance metrics |
| 103 | +- `routing/`: Routing system |
| 104 | + - `Router.java`: Route management |
| 105 | + - `Route.java`: Route data structure |
| 106 | +- `controllers/`: System controllers |
| 107 | + - `MetricsController.java`: Metrics reporting |
| 108 | +- `examples/`: Example applications |
| 109 | + - `basic/`: A simple web API example |
| 110 | + |
| 111 | +## Tests |
| 112 | + |
| 113 | +Unit tests have been written to ensure the reliability of the framework. Test coverage includes: |
| 114 | + |
| 115 | +- `RouterTest`: Tests for adding routes, finding routes, and path parameter operations |
| 116 | +- `RouteTest`: Tests for the route data structure |
| 117 | +- `MetricsTest`: Tests for metric counters and calculations |
| 118 | +- `MetricsControllerTest`: Tests for the metrics controller |
| 119 | + |
| 120 | +When adding new features or modifying existing code, it's important to update existing tests or add new tests to maintain the stability of the framework. |
| 121 | + |
| 122 | +## Vision and Roadmap |
| 123 | + |
| 124 | +Jazzy aims to simplify Java web development with a low learning curve, inspired by the elegance and developer-friendliness of Laravel in the PHP world. Our mission is to create a framework that enables developers to quickly build production-ready applications without the typical complexity associated with Java web frameworks. |
| 125 | + |
| 126 | +We believe Java development doesn't have to be verbose or complicated. By bringing Laravel-like simplicity and expressiveness to Java, we want to make web development more accessible and enjoyable for Java developers. |
| 127 | + |
| 128 | +Key principles: |
| 129 | +- Simplicity over complexity |
| 130 | +- Convention over configuration |
| 131 | +- Rapid development without sacrificing performance |
| 132 | +- Low learning curve for developers new to Java or web development |
| 133 | + |
| 134 | +## Future Features |
| 135 | + |
| 136 | +### Core Improvements |
| 137 | +- JSON support with automatic serialization/deserialization |
| 138 | +- Simple template engine |
| 139 | +- Middleware system |
| 140 | +- Form validation |
| 141 | +- Database integration with simple ORM |
| 142 | + |
| 143 | +### Developer Experience |
| 144 | +- Centralized routing configuration (similar to Laravel's routes.php) |
| 145 | +- Authentication system with easy JWT integration |
| 146 | +- Simple project setup and scaffolding |
| 147 | +- Comprehensive documentation with examples |
| 148 | + |
| 149 | +## Contributing |
| 150 | + |
| 151 | +**Jazzy is actively maintained and we welcome contributions of any size!** |
| 152 | + |
| 153 | +We believe that open source thrives with community involvement, and we appreciate all types of contributions, whether you're fixing a typo, improving documentation, adding a new feature, or reporting a bug. |
| 154 | + |
| 155 | +### Ways to Contribute |
| 156 | + |
| 157 | +- **Code Contributions**: New features, bug fixes, performance improvements |
| 158 | +- **Documentation**: Improving README, adding examples, writing tutorials |
| 159 | +- **Testing**: Adding new tests, improving existing tests |
| 160 | +- **Feedback**: Reporting bugs, suggesting features |
| 161 | +- **Spreading the Word**: Telling others about Jazzy |
| 162 | + |
| 163 | +### Getting Started |
| 164 | + |
| 165 | +1. Fork the project |
| 166 | +2. Clone your fork (`git clone https://github.com/yourusername/jazzy.git`) |
| 167 | +3. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 168 | +4. Make your changes (don't forget to add tests if applicable) |
| 169 | +5. Run tests to make sure everything works (`mvn test`) |
| 170 | +6. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 171 | +7. Push to the branch (`git push origin feature/amazing-feature`) |
| 172 | +8. Open a Pull Request |
| 173 | + |
| 174 | +### Pull Request Guidelines |
| 175 | + |
| 176 | +- Keep your changes focused on a single issue |
| 177 | +- Make sure all tests pass |
| 178 | +- Update documentation if needed |
| 179 | +- Follow existing code style |
| 180 | + |
| 181 | +No contribution is too small, and we're happy to help newcomers get started! |
| 182 | + |
| 183 | +## License |
| 184 | + |
| 185 | +MIT License |
0 commit comments