Skip to content

Refactor project structure and add dotenv database configuration - #2

Merged
iJosueeh merged 2 commits into
mainfrom
features/core-docker
Mar 30, 2026
Merged

Refactor project structure and add dotenv database configuration#2
iJosueeh merged 2 commits into
mainfrom
features/core-docker

Conversation

@iJosueeh

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Application entrypoint into com.utp.meditrackapp.core and updated launch configuration.
  • Added DatabaseConfig (dotenv + JDBC URL construction) and a Navigation helper for feature-based FXML loading.
  • Added SQL Server + Adminer docker-compose.yml, plus .env template/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 to com/utp/meditrackapp/core/, but the existing FXML is located at src/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 the core resource 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;

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
requires java.sql;
requires java.sql;
requires com.microsoft.sqlserver.jdbc;

Copilot uses AI. Check for mistakes.
return instance;
}

public Connection getConnectionUrl() throws SQLException {

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
public Connection getConnectionUrl() throws SQLException {
public String getConnectionUrl() {
return this.connectionUrl;
}
public Connection getConnection() throws SQLException {

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +25
this.connectionUrl = String.format(
"jdbc:sqlserver://%s:%s;databaseName=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=true;",
dbHost, dbPort, dbName, dbUser, dbPassword

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +26
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +32
} catch (NullPointerException error) {
System.err.println("Error: No se encontró el archivo FXML en la ruta especificada.");
}

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=${DB_PASSWORD}

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- MSSQL_SA_PASSWORD=${DB_PASSWORD}
- MSSQL_SA_PASSWORD=${DB_PASSWORD}
- DB_USER=sa
- DB_NAME=master

Copilot uses AI. Check for mistakes.
@iJosueeh
iJosueeh merged commit 0320ef1 into main Mar 30, 2026
9 checks passed
@iJosueeh
iJosueeh deleted the features/core-docker branch March 30, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants