Prompt file imported from Rakibul1411/Software-Metrics-Calculation (
.github/prompts/plan-antMetricsCalculator.prompt.md). Copyright stays with the author.
Prompt: Software Defect Prediction System
Project Title
Static Java Source Code Defect Prediction Using Eclipse JDT AST Parser, CORAL Transfer Learning, and KNN Classification
Objective
Develop a full-stack software defect prediction system that predicts defect-prone Java classes in a new software project by using static source-code metrics and labelled historical defect datasets.
The system must support:
- Java source-code metrics extraction.
- PROMISE-compatible metrics generation.
- AEEEM-compatible static metric subset generation.
- Transfer learning/domain adaptation using CORAL.
- Classification using K-Nearest Neighbors (KNN).
- Prediction output mapped back to Java class names or file paths.
- Angular frontend, Java Spring Boot backend, and Python FastAPI ML service.
The system should be understood as a defect-proneness prediction and testing-prioritization tool, not an exact bug detector. It predicts which Java classes are more likely to be buggy based on historical patterns.
Core Concept
The system has two dataset types:
1. Source Dataset
The source dataset is a labelled historical defect dataset, such as PROMISE or AEEEM.
It contains:
metric columns + label column
The label column may be named:
bug
class
label
The label indicates whether a class/module is:
buggy / clean
or:
1 / 0
2. Target Dataset
The target dataset is generated from the user's new Java source code.
It contains:
identifier column + metric columns
The identifier column may be:
class_name
file_path
name
The target dataset does not contain a true defect label, because the new project's actual buggy/clean status is unknown.
Therefore:
Source dataset = labelled training data
Target dataset = unlabelled prediction data
Complete System Workflow
- The user opens the Angular frontend.
- The user selects the dataset format:
PROMISEorAEEEM. - The user provides Java source code by uploading a ZIP file or entering a GitHub repository URL.
- Angular calls the Java Spring Boot backend.
- The Java backend parses the Java files using Eclipse JDT AST Parser.
- The system extracts the required static metrics for the selected dataset format.
- The system generates a target metrics CSV file containing
class_nameorfile_pathplus metric columns. - Angular displays a preview of the extracted metrics CSV file.
- The user uploads one or multiple labelled source datasets.
- Angular calls the Java backend prediction API.
- The Java backend sends the generated target CSV and labelled source datasets to the Python FastAPI model service.
- The Python service validates feature compatibility between source and target datasets.
- The Python service preprocesses the data, including numeric conversion, missing value handling, and scaling.
- The Python service applies CORAL using source metrics and target metrics.
- The Python service trains KNN using adapted source metrics and source labels.
- The Python service predicts buggy or clean labels for the target classes.
- The Python service returns the prediction results to the Java backend.
- The Java backend returns the final prediction result to the Angular frontend.
- Angular displays the result as
class_name/file_path,predicted_label, and optionalrisk_score.
High-Level Architecture
Angular Frontend
↓
Java Spring Boot Backend
↓
Eclipse JDT AST Parser
↓
Generated Target Metrics CSV
↓
Python FastAPI ML Service
↓
Preprocessing + CORAL + KNN
↓
Prediction JSON
↓
Java Spring Boot Backend
↓
Angular Result Table
Angular should call only the Java backend. The Java backend should internally call the Python FastAPI service.
Main Modules
Module 1: Metrics Extraction Module
The metrics extraction module is implemented in Java.
Responsibilities:
- Receive Java source code from Angular.
- Support GitHub repository URL.
- Support uploaded ZIP file.
- Extract Java files.
- Parse Java files using Eclipse JDT AST Parser.
- Calculate static object-oriented metrics.
- Generate PROMISE-compatible or AEEEM static-subset-compatible target CSV.
- Save generated CSV on the server.
- Return preview data and
targetDatasetIdto Angular.
The generated CSV must contain:
class_name, file_path, metric_1, metric_2, metric_3, ...
The identifier columns are used only for result mapping, not for model training.
Module 2: Prediction Module
The prediction module uses both Java and Python.
Java backend responsibilities:
- Receive
targetDatasetId. - Receive one or multiple labelled source datasets.
- Receive settings such as
labelColumn,idColumn,kValue, anduseCoral. - Load the generated target CSV.
- Send target CSV and source datasets to Python FastAPI.
- Receive prediction result from Python.
- Return result to Angular.
Python FastAPI responsibilities:
- Read source and target datasets.
- Combine multiple source datasets.
- Separate source features and labels.
- Separate target identifiers and target features.
- Validate feature compatibility.
- Apply preprocessing.
- Apply CORAL.
- Train KNN.
- Predict target labels.
- Return JSON prediction results.
Important Machine Learning Rules
Rule 1: Do not use identifier columns as ML features
Columns like these must not be used for CORAL or KNN:
class_name
file_path
name
They must be stored separately and attached back after prediction.
Rule 2: Only the source dataset has labels
The source dataset contains:
metrics + label
The target dataset contains:
identifier + metrics
The target dataset does not need a label for prediction.
Rule 3: Labels are required only for evaluation
For a new unlabelled project, the system can only provide predictions. It cannot calculate accuracy, precision, recall, F1-score, MCC, or AUC because true labels are unavailable.
To evaluate the model, use labelled benchmark datasets. In evaluation mode, hide the target labels during prediction and compare predictions with actual labels after prediction.
Rule 4: Source and target feature columns must match
Before CORAL and KNN:
X_source columns == X_target columns
The columns must have:
- Same feature names.
- Same order.
- Compatible numeric data types.
- Same preprocessing steps.
If feature columns are mismatched, the system should show an error or use a validated common static metric subset.
Rule 5: AEEEM full dataset may contain non-static metrics
AEEEM may include process/history metrics such as:
CvsEntropy
CvsLogEntropy
numberOfBugsFoundUntil
numberOfCriticalBugsFoundUntil
numberOfMajorBugsFoundUntil
These cannot be extracted from Java source code using Eclipse JDT AST Parser alone.
Therefore, if AEEEM is selected, use only the AEEEM static metric subset that can be extracted from Java source code.
CORAL + KNN Workflow
- Read labelled source dataset.
- Read unlabelled generated target dataset.
- Separate source features:
X_source = source metric columns
y_source = source label column
- Separate target features:
target_ids = target class_name/file_path
X_target = target metric columns
- Validate feature compatibility.
- Convert all metric columns to numeric.
- Handle missing values.
- Apply scaling/normalization.
- Apply CORAL using:
X_source + X_target
- Train KNN using:
adapted X_source + y_source
- Predict:
X_target → predicted_label
- Attach predictions back to identifiers:
class_name/file_path + predicted_label + risk_score
Final Prediction Output
The final output should be JSON and CSV-compatible.
Example:
{
"status": "success",
"message": "Prediction completed successfully",
"results": [
{
"class_name": "com.project.PaymentService",
"file_path": "src/main/java/com/project/PaymentService.java",
"predicted_label": "buggy",
"risk_score": 0.82
},
{
"class_name": "com.project.LoginController",
"file_path": "src/main/java/com/project/LoginController.java",
"predicted_label": "clean",
"risk_score": 0.21
}
]
}
Frontend result table:
Class Name File Path Prediction Risk Score
com.project.PaymentService src/main/java/com/project/PaymentService.java buggy 0.82
com.project.LoginController src/main/java/com/project/LoginController.java clean 0.21
Recommended API Flow
API 1: Extract Metrics
POST /api/metrics/extract
Called by:
Angular → Java Spring Boot
Request type:
multipart/form-data
Request fields:
datasetType = PROMISE / AEEEM
sourceType = GITHUB / ZIP
githubUrl = optional
sourceZip = optional
Response:
{
"status": "success",
"message": "Metrics extracted successfully",
"targetDatasetId": "target_001",
"fileName": "target_metrics.csv",
"columns": ["class_name", "file_path", "wmc", "dit", "noc", "cbo", "rfc", "lcom", "loc"],
"preview": [
{
"class_name": "com.project.PaymentService",
"file_path": "src/main/java/com/project/PaymentService.java",
"wmc": 35,
"dit": 2,
"noc": 0,
"cbo": 18,
"rfc": 70,
"lcom": 45,
"loc": 420
}
],
"downloadUrl": "/api/metrics/download/target_001"
}
API 2: Download Generated Metrics CSV
GET /api/metrics/download/{targetDatasetId}
Called by:
Angular → Java Spring Boot
Purpose:
- Download
target_metrics.csv.
API 3: Run Prediction
POST /api/prediction/run
Called by:
Angular → Java Spring Boot
Request type:
multipart/form-data
Request fields:
targetDatasetId = generated target dataset ID
datasetType = PROMISE / AEEEM
sourceFiles = one or multiple labelled source dataset files
labelColumn = bug / class / label
idColumn = class_name / file_path / name
knnValue = 5
coralOption = true / false
Java should internally call Python.
API 4: Python Prediction API
POST /ml/predict
Called by:
Java Spring Boot → Python FastAPI
Request type:
multipart/form-data
Request fields:
target_file
source_files
dataset_type
label_column
id_column
k_value
use_coral
Response:
{
"status": "success",
"message": "Prediction completed successfully",
"results": [
{
"class_name": "com.project.PaymentService",
"file_path": "src/main/java/com/project/PaymentService.java",
"predicted_label": "buggy",
"risk_score": 0.82
}
]
}
Recommended Folder Structure
defect-prediction-system/
│
├── frontend-angular/
│ ├── src/
│ │ ├── app/
│ │ │ ├── core/
│ │ │ │ ├── services/
│ │ │ │ │ ├── metrics-api.service.ts
│ │ │ │ │ └── prediction-api.service.ts
│ │ │ │ └── models/
│ │ │ │ ├── metrics-preview.model.ts
│ │ │ │ └── prediction-result.model.ts
│ │ │ │
│ │ │ ├── features/
│ │ │ │ ├── metrics-extraction/
│ │ │ │ │ ├── metrics-extraction.component.ts
│ │ │ │ │ ├── metrics-extraction.component.html
│ │ │ │ │ └── metrics-extraction.component.css
│ │ │ │ │
│ │ │ │ └── prediction/
│ │ │ │ ├── prediction.component.ts
│ │ │ │ ├── prediction.component.html
│ │ │ │ └── prediction.component.css
│ │ │ │
│ │ │ ├── shared/
│ │ │ │ ├── components/
│ │ │ │ │ ├── file-upload/
│ │ │ │ │ └── data-table/
│ │ │ │ └── utils/
│ │ │ │
│ │ │ └── app.module.ts
│ │ │
│ │ └── environments/
│ │ └── environment.ts
│ │
│ ├── angular.json
│ ├── package.json
│ └── README.md
│
├── backend-java/
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── org/
│ │ │ │ └── metrics/
│ │ │ │ ├── MetricsCalculatorMain.java
│ │ │ │ ├── controller/
│ │ │ │ │ ├── MetricsController.java
│ │ │ │ │ └── PredictionController.java
│ │ │ │ ├── service/
│ │ │ │ │ ├── MetricsExtractionService.java
│ │ │ │ │ ├── PredictionService.java
│ │ │ │ │ ├── FileStorageService.java
│ │ │ │ │ ├── GitHubCloneService.java
│ │ │ │ │ └── ZipExtractionService.java
│ │ │ │ ├── client/
│ │ │ │ │ └── PythonPredictionClient.java
│ │ │ │ ├── common/
│ │ │ │ │ ├── enums/
│ │ │ │ │ │ └── DatasetType.java
│ │ │ │ │ ├── dto/
│ │ │ │ │ │ ├── MetricsExtractionResponse.java
│ │ │ │ │ │ ├── PredictionRequest.java
│ │ │ │ │ │ └── PredictionResponse.java
│ │ │ │ │ ├── exception/
│ │ │ │ │ │ └── GlobalExceptionHandler.java
│ │ │ │ │ ├── validation/
│ │ │ │ │ │ └── FeatureSchemaValidator.java
│ │ │ │ │ └── csv/
│ │ │ │ │ └── CsvWriterService.java
│ │ │ │ ├── promise/
│ │ │ │ │ ├── parser/
│ │ │ │ │ │ └── PromiseJavaSourceParser.java
│ │ │ │ │ ├── calculator/
│ │ │ │ │ │ ├── PromiseMetricsCalculator.java
│ │ │ │ │ │ ├── WmcCalculator.java
│ │ │ │ │ │ ├── DitCalculator.java
│ │ │ │ │ │ ├── NocCalculator.java
│ │ │ │ │ │ ├── CboCalculator.java
│ │ │ │ │ │ ├── RfcCalculator.java
│ │ │ │ │ │ ├── LcomCalculator.java
│ │ │ │ │ │ └── LocCalculator.java
│ │ │ │ │ ├── model/
│ │ │ │ │ │ └── PromiseMetricResult.java
│ │ │ │ │ └── export/
│ │ │ │ │ └── PromiseCsvExporter.java
│ │ │ │ └── aeeem/
│ │ │ │ ├── parser/
│ │ │ │ │ └── AeeemJavaSourceParser.java
│ │ │ │ ├── calculator/
│ │ │ │ │ └── AeeemStaticMetricsCalculator.java
│ │ │ │ ├── model/
│ │ │ │ │ └── AeeemMetricResult.java
│ │ │ │ └── export/
│ │ │ │ └── AeeemCsvExporter.java
│ │ │ │
│ │ │ └── resources/
│ │ │ ├── application.properties
│ │ │ └── metric-profiles/
│ │ │ ├── promise-metrics.json
│ │ │ └── aeeem-static-metrics.json
│ │ │
│ │ └── test/
│ │ └── java/
│ │
│ ├── storage/
│ │ ├── uploads/
│ │ ├── extracted-projects/
│ │ ├── generated-datasets/
│ │ └── prediction-results/
│ │
│ ├── pom.xml
│ ├── .gitignore
│ └── README.md
│
├── ml-service-python/
│ ├── app/
│ │ ├── main.py
│ │ ├── api/
│ │ │ └── prediction_routes.py
│ │ ├── core/
│ │ │ └── config.py
│ │ ├── services/
│ │ │ ├── prediction_service.py
│ │ │ ├── preprocessing_service.py
│ │ │ ├── coral_service.py
│ │ │ └── knn_service.py
│ │ ├── validation/
│ │ │ └── feature_schema_validator.py
│ │ ├── schemas/
│ │ │ └── prediction_schema.py
│ │ └── utils/
│ │ ├── file_reader.py
│ │ └── response_builder.py
│ │
│ ├── temp/
│ ├── requirements.txt
│ └── README.md
│
├── docs/
│ ├── system-workflow.md
│ ├── api-documentation.md
│ └── dataset-format.md
│
├── .gitignore
└── README.md
Implementation Requirements
Java Backend
Use Spring Boot.
Responsibilities:
- Provide REST APIs.
- Handle file upload.
- Handle ZIP extraction.
- Handle GitHub cloning.
- Run Eclipse JDT AST Parser.
- Generate metrics CSV.
- Store generated target dataset.
- Call Python FastAPI prediction service.
- Return prediction results to Angular.
Recommended Java server port:
http://localhost:8080
Python ML Service
Use FastAPI.
Responsibilities:
- Provide
/ml/predict. - Receive target dataset and one or multiple source datasets.
- Validate feature compatibility.
- Combine multiple source datasets.
- Preprocess metric columns.
- Apply CORAL.
- Train KNN.
- Return prediction JSON.
Recommended Python server port:
http://localhost:8000
Angular Frontend
Responsibilities:
- Dataset type selection: PROMISE/AEEEM.
- Source code input: GitHub URL or ZIP upload.
- Call
/api/metrics/extract. - Show generated target metrics preview.
- Upload one or multiple labelled source datasets.
- Call
/api/prediction/run. - Display final prediction result table.
Recommended Angular server port:
http://localhost:4200
Runtime Commands
Run Angular
cd frontend-angular
npm install
ng serve
Run Java Backend
cd backend-java
mvn spring-boot:run
Run Python ML Service
cd ml-service-python
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000
Git Ignore Requirements
Use this root .gitignore:
# Java
target/
*.class
# Angular
node_modules/
dist/
.angular/
# Python
__pycache__/
*.pyc
.venv/
venv/
# Runtime storage
backend-java/storage/uploads/
backend-java/storage/extracted-projects/
backend-java/storage/generated-datasets/
backend-java/storage/prediction-results/
ml-service-python/temp/
# OS/editor
.DS_Store
.idea/
.vscode/
Expected Final Behavior
The user should be able to:
- Select PROMISE or AEEEM.
- Upload Java source project or provide GitHub URL.
- Extract static metrics.
- Preview generated target metrics dataset.
- Upload one or multiple labelled source datasets.
- Run CORAL + KNN prediction.
- View final defect-prone class predictions.
Final output example:
class_name,file_path,predicted_label,risk_score
com.project.PaymentService,src/main/java/com/project/PaymentService.java,buggy,0.82
com.project.LoginController,src/main/java/com/project/LoginController.java,clean,0.21
Development Priority
Implement in this order:
- Java Spring Boot metrics extraction API.
- CSV generation and storage.
- Angular metrics extraction UI.
- Python FastAPI prediction endpoint.
- Java-to-Python API client.
- Angular prediction UI.
- Feature validation and error handling.
- Model evaluation mode using labelled benchmark datasets.
Final Note
For a new unlabelled Java project, the system cannot know the true correctness of each prediction immediately. It can only predict defect-prone classes. Evaluation requires labelled test data. The system should therefore present the result as:
Predicted Defect-Prone
Predicted Clean
rather than:
Bug Found
No Bug Found