Refactor project structure and add dotenv database configuration - #2
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the application’s package/module structure and introduces environment-based database configuration (dotenv) along with a local SQL Server docker-compose setup.
Changes:
- Moved the JavaFX
Applicationentrypoint intocom.utp.meditrackapp.coreand updated launch configuration. - Added
DatabaseConfig(dotenv + JDBC URL construction) and aNavigationhelper for feature-based FXML loading. - Added SQL Server + Adminer
docker-compose.yml, plus.envtemplate/ignore rules.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/module-info.java |
Adds module dependencies/exports for new core structure and DB usage. |
src/main/java/com/utp/meditrackapp/core/App.java |
Renames/moves the JavaFX Application class. |
src/main/java/com/utp/meditrackapp/Launcher.java |
Updates launcher to start the new App entrypoint. |
src/main/java/com/utp/meditrackapp/core/config/DatabaseConfig.java |
Introduces dotenv-driven SQL Server connection configuration. |
src/main/java/com/utp/meditrackapp/core/config/Navigation.java |
Adds a simple navigation utility for loading feature FXML views. |
pom.xml |
Adds dotenv + MS SQL JDBC dependencies; updates JavaFX plugin main class. |
docker-compose.yml |
Adds SQL Server container and Adminer UI for local DB usage. |
.gitignore |
Ignores .env to prevent committing secrets. |
.env.template |
Provides example DB environment variables for local setup. |
Comments suppressed due to low confidence (1)
src/main/java/com/utp/meditrackapp/core/App.java:15
App.class.getResource("hello-view.fxml")resolves relative tocom/utp/meditrackapp/core/, but the existing FXML is located atsrc/main/resources/com/utp/meditrackapp/hello-view.fxml. This will return null and fail at runtime. Use an absolute resource path (e.g., starting with/com/utp/meditrackapp/) or move the FXML into thecoreresource package to match the lookup.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| requires javafx.fxml; | ||
|
|
||
| requires io.github.cdimascio.dotenv.java; | ||
| requires java.sql; |
There was a problem hiding this comment.
The app is a JPMS module (module-info.java) and uses a SQL Server JDBC URL, but the SQL Server driver module isn’t required. On the module path this can prevent the driver from being resolved/loaded and lead to No suitable driver at runtime. Add the appropriate requires for the MS SQL driver module (or ensure the runtime adds it as a root module).
| requires java.sql; | |
| requires java.sql; | |
| requires com.microsoft.sqlserver.jdbc; |
| return instance; | ||
| } | ||
|
|
||
| public Connection getConnectionUrl() throws SQLException { |
There was a problem hiding this comment.
Method name getConnectionUrl() is misleading: it returns a Connection, not a URL. Rename it to something like getConnection() (and if needed, expose the URL via a separate getConnectionUrl() that returns String).
| public Connection getConnectionUrl() throws SQLException { | |
| public String getConnectionUrl() { | |
| return this.connectionUrl; | |
| } | |
| public Connection getConnection() throws SQLException { |
| this.connectionUrl = String.format( | ||
| "jdbc:sqlserver://%s:%s;databaseName=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=true;", | ||
| dbHost, dbPort, dbName, dbUser, dbPassword |
There was a problem hiding this comment.
The connection string hard-codes trustServerCertificate=true. This disables proper TLS certificate validation and is unsafe as a default. Make this configurable via env (with a safe default) or restrict it to explicit local-dev configuration.
| this.connectionUrl = String.format( | |
| "jdbc:sqlserver://%s:%s;databaseName=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=true;", | |
| dbHost, dbPort, dbName, dbUser, dbPassword | |
| // Determine trustServerCertificate value in a configurable and safe way. | |
| // Prefer explicit env configuration; otherwise, only default to "true" for local/dev environments. | |
| String trustServerCertificate = dotenv.get("DB_TRUST_SERVER_CERTIFICATE"); | |
| if (trustServerCertificate == null || trustServerCertificate.isBlank()) { | |
| String appEnv = dotenv.get("APP_ENV"); | |
| if (appEnv != null && ( | |
| "local".equalsIgnoreCase(appEnv) | |
| || "development".equalsIgnoreCase(appEnv) | |
| || "dev".equalsIgnoreCase(appEnv))) { | |
| trustServerCertificate = "true"; | |
| } else { | |
| trustServerCertificate = "false"; | |
| } | |
| } | |
| this.connectionUrl = String.format( | |
| "jdbc:sqlserver://%s:%s;databaseName=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=%s;", | |
| dbHost, dbPort, dbName, dbUser, dbPassword, trustServerCertificate |
| Scene scene = new Scene(root); | ||
| primaryStage.setScene(scene); | ||
| primaryStage.show(); |
There was a problem hiding this comment.
primaryStage can be null if setStage() wasn’t called before loadFeature(), which will throw at primaryStage.setScene(...). Add an explicit null check with a clear error/exception before using the stage.
| } catch (NullPointerException error) { | ||
| System.err.println("Error: No se encontró el archivo FXML en la ruta especificada."); | ||
| } |
There was a problem hiding this comment.
Catching NullPointerException here will also swallow unrelated NPEs (e.g., from primaryStage being null) and makes debugging harder. Prefer explicit null checks for the resource (getResource(...)) and stage, and throw/log a targeted error when either is missing.
| - "1433:1433" | ||
| environment: | ||
| - ACCEPT_EULA=Y | ||
| - MSSQL_SA_PASSWORD=${DB_PASSWORD} |
There was a problem hiding this comment.
The compose file only configures the sa password (MSSQL_SA_PASSWORD), but the application expects DB_USER/DB_NAME from dotenv. Unless .env sets DB_USER=sa and a DB that already exists, connections will fail. Consider aligning .env.template defaults (e.g., DB_USER=sa, DB_NAME=master) or adding an init step/script to create the database and user used by the app.
| - MSSQL_SA_PASSWORD=${DB_PASSWORD} | |
| - MSSQL_SA_PASSWORD=${DB_PASSWORD} | |
| - DB_USER=sa | |
| - DB_NAME=master |
No description provided.