How khushalsehrawat/suems works
Project type and purpose
• This is a standalone backend service, implemented in Spring Boot 3 (Java 21), exposing a REST API for managing energy sources and streaming time-series sensor data. It includes a built-in scheduler that synthesizes readings. There is no bundled frontend—clients (e.g., web apps or scripts) consume the API over HTTP/JSON.
File structure
• Top-level configuration: pom.xml, Maven wrapper, application.properties.
• src/main/java/com/suems:
• SuemsApplication.java – Spring Boot entry point (annotated with @SpringBootApplication and @EnableScheduling).
• config/ – CorsConfig, jacksonConfig for global CORS and JSON date/time settings.
• controller/ – EnergySourceController, SensorDataController (HTTP endpoints).
• exception/ – GlobalExceptionHandler, NotFoundException.
• mappers/ – entity↔DTO conversions.
• model/ – JPA entities and enums (EnergySource, SensorData, EnergyType, EnergyStatus).
• repository/ – Spring Data JPA interfaces.
• service/ – business logic and summary calculations.
• simulator/ – DataSimulator (scheduled bean that pushes fake sensor readings into the service).
• Resources: application.properties drives DB connection, JPA DDL, scheduling flags.
• Tests: a basic SuemsApplicationTests.
README for additional insights
• It states core features: CRUD endpoints, recent/after/summary queries, toggleable simulator.
• Technology stack: Spring Boot, Spring Data JPA, MySQL, Maven, Java 21.
a. Main components
• External Client(s) (e.g., Web UI, curl scripts, other services)
• Spring Boot REST API container
• Controllers layer
• Services layer (business logic + summary calc)
• Simulator (Scheduled task component)
• Repositories (Spring Data JPA)
• MySQL database
b. Relationships and interactions
• Client → API (HTTP/JSON)
• API → Controller classes (request mapping)
• Controller → Service (method calls)
• Service → Repository (save/query)
• Repository → MySQL (SQL via JDBC/Hibernate)
• Simulator (Spring @Scheduled) → Service.saveSensorData() → Repository → DB
c. Architectural patterns & design principles
• Layered architecture (Controller → Service → Repository)
• Dependency injection (Spring-managed beans)
• Scheduler pattern for periodic synthetic data generation
• DTO pattern decoupling API schema from internal entities
• Global exception handling (ControllerAdvice)
d. Key technologies/frameworks/libraries
• Java 21, Spring Boot 3 (Web, Data JPA, Scheduling)
• MySQL 8
• Jackson (JavaTimeModule)
• Maven
• Lombok (if present) / Java records (not used here)
• Spring’s CORS support