How romelteja7/userlogs-api-rest works
Project Overview and Purpose
• Project Type: It is a full-stack web application that demonstrates a REST API built using Java EE 8. The application offers endpoints to retrieve users by ID or username and to register new users. It is supported by a basic HTML/JavaScript client (found under the ConsumeApp directory) and uses technologies like Tomcat, Bootstrap, and a relational database (hinted by the users.sql file and persistence configuration).
Main Components
a. Client Side:
• The ConsumeApp folder contains static HTML pages (index, allUsers, getById, getByUsername) that serve as the web interface.
• These pages likely use JavaScript to perform HTTP requests (GET, POST, etc.) against the REST API.
b. Server Side (Java Backend):
• REST API: Implemented in Java under the Java/src directory.
• MainApp.java serves as the entry point or bootstrap for the application.
• Controller Layer: The UserController.java acts as the REST endpoints provider.
• Data Access Object (DAO) Layer: UserDAO.java handles communication with the data store.
• Model: Users.java defines the data structure for user entities.
• Utility: ConnectionDB.java in the util package to manage database connections.
• Resources & Configurations: Files like persistence.xml, web.xml, beans.xml, and context.xml define persistence, dependency injection, and web app configurations.
c. Database:
• Based on users.sql and persistence.xml, there is an underlying relational database that stores user information. This is accessed via the DAO layer with ConnectionDB.
Relationships and Interactions
• The Clients (HTML/JS pages) make HTTP calls (using RESTful methods) to the UserController endpoints.
• The Controller (UserController) processes these requests and uses the DAO (UserDAO) to fetch or update user data.
• The DAO layer interacts with the database (via the ConnectionDB utility) which is configured in persistence.xml.
• The models (Users.java) tie in to represent and validate the user data being transferred between layers.
Architectural Patterns and Design Principles
• Layered Architecture: The project clearly separates concerns into distinct layers (presentation, controller, DAO, model, database).
• RESTful API Design: HTTP methods are used for user operations (creating, retrieving).
• MVC-like Separation: Although not a formal MVC, the clear separation between the client (views) and the backend’s control logic follows this principle.
• Dependency Injection & Configuration: With configuration files such as beans.xml and context.xml, the application leverages Java EE’s DI practices.
• Use clear labels for each component.