# Project export: Credit Score Predictor

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: Cal Hacks 11.0
- Tagline: This project forecasts future credit scores using AI, helping lenders and insurers offer better rates and assess risks while allowing clients to access more competitive financial products.
- Devpost: https://devpost.com/software/credit-score-predictor
- GitHub: https://github.com/alanrodgz/credit-score-estimator
- Team: 3 GitHub contributor(s) — 17wolfgwang (3 commits), Alan Rodriguez (2 commits), davidrlzzz (1 commits)

## Devpost submission (written by the team)

### Inspiration

Wanting to access higher financial products as a responsible young professional.

### What it does

Generates a projection of a person's future creditworthiness based on past and current financial habits.

## README (from the GitHub repository)

# Credit Score Estimator

## Overview

The Credit Score Estimator is a web application that allows users to estimate their credit score based on key financial factors. This project uses Java with Spring Boot to create a simple, user-friendly interface for credit score estimation.

## Features

- Web-based interface for inputting financial data
- Server-side processing of credit score estimation
- Responsive design for use on various devices

## Prerequisites

Before you begin, ensure you have met the following requirements:

- Java Development Kit (JDK) 11 or higher
- Maven 3.6 or higher
- Git (for version control)

## Installation

To install the Credit Score Estimator, follow these steps:

1. Clone the repository:
   ```
   git clone https://github.com/yourusername/credit-score-estimator.git
   ```

2. Navigate to the project directory:
   ```
   cd credit-score-estimator
   ```

3. Build the project using Maven:
   ```
   mvn clean package
   ```

## Usage

To run the Credit Score Estimator:

1. Start the application:
   ```
   java -jar target/credit-score-estimator-1.0-SNAPSHOT.jar
   ```

2. Open a web browser and go to `http://localhost:8080`

3. Fill in the required information:
   - Annual Income
   - Monthly Debt
   - Credit History (in years)

4. Click "Calculate" to see your estimated credit score

## Project Structure


## Detected evidence (automated analysis)

Indexed codebase: 6 recognized source files, 5 KB.
- CSS (language) — detected in the code
- Express (technology) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- OpenAI (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (10 of 10)

```
.env
.gitignore
.vscode/settings.json
app.js
index.js
package.json
public/ai.js
public/index.html
public/styles.css
README.md
```

### Dependencies

- package.json: express@^4.21.1

### Recent commits (newest first)

- Create README.md
- ADD:ai.js, app.js
- ADD:ai.js,app,js
- ADD:app.js, ai.js
- we got postgress, New DB in this B
- first commit

## Key source files (fetched from GitHub, selected and truncated for size)

### package.json

```
{
  "name": "calhacks",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "express": "^4.21.1"
  }
}
```

### index.js

```javascript
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;

app.use(express.static('public'));

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

app.listen(port, () => {
  console.log(`Server running at http://localhost:${port}`);
});
```

### app.js

```javascript
import express from 'express';
import fetch from 'node-fetch';
import 'dotenv/config';

const app = express();
app.use(express.json());
app.use(express.static('public'));

// OpenAI API 호출하는 엔드포인트
app.post('/api/credit-check', async (req, res) => {
    const { userInput } = req.body;

    try {
        const response = await fetch('https://api.openai.com/v1/chat/completions', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
            },
            body: JSON.stringify({
                model: 'gpt-3.5-turbo',
                messages: [
                    {
                        role: 'system', content: `
                        You are a credit evaluation assistant. You only respond to questions related to credit assessments.
                        Use the following criteria to evaluate creditworthiness:
                        1. Payment history: If payments are on time for the last 12 months, increase the credit score.
                        2. Debt ratio: If the debt ratio is below 30%, increase the credit score.
                        3. Credit history length: Longer than 5 years increases the credit score.
                        4. New credit inquiries: More than 2 new inquiries in the last 6 months decreases the credit score.
                        Only respond with a creditworthiness score and short explanation.
                        `
                    },
                    { role: 'user', content: userInput }
                ],
                max_tokens: 150
            })
        });

        const data = await response.json();
        res.json({ result: data.choices[0].message.content });  // 결과를 클라이언트로 반환
    } catch (error) {
        console.error('Error fetching data from OpenAI API:', error);
        res.status(500).json({ error: 'Failed to fetch data from OpenAI API' });
    }
});

// 서버 실행
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});
```

### public/styles.css

```css
body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: #f4f4f4;
}

h1 {
    color: #333;
}
```

### public/index.html

```html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Credit Evaluation</title>
</head>

<body>
    <h1>Credit Evaluation Assistant</h1>
    <input type="text" id="userInput" placeholder="Enter credit history data">
    <button id="submitBtn">Submit</button>
    <div id="result"></div>

    <script src="ai.js"></script>
</body>

</html>
```

### public/ai.js

```javascript

async function queryOpenAI(userInput) {
    try {
        const response = await fetch('/api/credit-check', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ userInput })
        });

        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }

        const data = await response.json();
        console.log('Creditworthiness result:', data.result);

        document.getElementById('result').innerText = data.result;
    } catch (error) {
        console.error('Error:', error);
        document.getElementById('result').innerText = 'Error occurred while fetching data';
    }
}

document.getElementById('submitBtn').addEventListener('click', () => {
    const userInput = document.getElementById('userInput').value; git
    queryOpenAI(userInput);
});
```