Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:
  • Java 1.8 or higher
  • Maven 3.6+ for dependency management
  • MySQL 8.0 or higher
  • Git for cloning the repository

Setup Instructions

1

Clone the Repository

Clone the InvestGo source code to your local machine:
git clone <repository-url>
cd sistema-factoring-backend
2

Create MySQL Database

Create the InvestGo database in MySQL:
CREATE DATABASE InvestGo;
The application uses spring.jpa.hibernate.ddl-auto=update, so tables will be created automatically on first run.
3

Configure Database Connection

Update src/main/resources/application.properties with your MySQL credentials:
# Server Configuration
server.port=8091

# Database Configuration
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/InvestGo
spring.datasource.username=root
spring.datasource.password=1234

# Hibernate Configuration
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
Replace spring.datasource.username and spring.datasource.password with your MySQL credentials.
4

Install Dependencies

Use Maven to download all required dependencies:
mvn clean install
This will install:
  • Spring Boot 2.7.5 (Web, JPA, Security, Validation)
  • MySQL Connector
  • JJWT 0.9.1 for JWT authentication
  • BCrypt for password encryption
5

Run the Application

Start the Spring Boot application:
mvn spring-boot:run
Or run the compiled JAR:
mvn package
java -jar target/sistema-factoring-backend-0.0.1-SNAPSHOT.jar
The application will start on port 8091.
6

Verify Startup

Check the console output for successful initialization:
Roles registrado con exito!
USUARIO registrado con exito!
Tipos registrado con exito!
Se registro el banco: Banco continental BBVA
Se registro el banco: Banco de credito BCP
...
Se registro la moneda: PEN
Se registro la moneda: USD
Se registro el riesgo: A
Se registro el riesgo: B
Se registro el riesgo: C
On first run, InvestGo automatically seeds the database with:
  • Two roles: INVERSIONISTA and ADMIN
  • Default admin user with credentials
  • Transaction types: Deposito and Retiro
  • Supported banks (BBVA, BCP, Scotiabank, Interbank, etc.)
  • Currencies: PEN (S/.) and USD ($)
  • Risk levels: A, B, C with descriptions

Authentication

InvestGo uses JWT-based authentication. To access protected endpoints, you must first obtain a token.

Default Admin Credentials

The application creates a default admin user on first run:
{
  "username": "jamie",
  "password": "Admin12345"
}
The admin user has the following details:
  • Name: Jeimy Apolaya Jurado
  • Email: [email protected]
  • Phone: 938311721
  • DNI: 77454558
  • Role: ADMIN (idTipoUsu: 2)
  • Initial Wallet Balance: 10,000,000

Get JWT Token

Make a POST request to the authentication endpoint:
curl -X POST http://localhost:8091/generate-token \
  -H "Content-Type: application/json" \
  -d '{
    "username": "jamie",
    "password": "Admin12345"
  }'
Response:
{
  "token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJqYW1pZSIsImV4cCI6MTcwOTU2NzgwMCwiaWF0IjoxNzA5NTMxODAwfQ..."
}
JWT tokens expire after a certain period. If you receive a 401 Unauthorized error, generate a new token.

Use Token in Requests

Include the token in the Authorization header with the Bearer prefix:
curl -X GET http://localhost:8091/api/user/listarOportunidadInversion \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Making Your First API Call

Let’s retrieve the list of active investment opportunities.

List Investment Opportunities

curl -X GET http://localhost:8091/api/user/listarOportunidadInversion \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json"
Response:
[
  {
    "idOportunidad": 1,
    "rendimiento": 12.5,
    "tir": 15.3,
    "monto": 50000.0,
    "montoRecaudado": 20000.0,
    "fechaCaducidad": "2024-06-30",
    "fechaRegistro": "2024-03-05",
    "fechaPago": "2024-04-30",
    "enable": "Activo",
    "empresa": {
      "idEmpresa": 1,
      "nomEmpresa": "Tech Solutions SAC",
      "ruc": "20123456789",
      "sector": "Tecnología",
      "riesgo": {
        "rango": "A",
        "descripcion": "El riesgo de inversion es nulo!"
      }
    }
  }
]

Get Current User Details

Retrieve the authenticated user’s information:
curl -X GET http://localhost:8091/actual-usuario \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
Response:
{
  "id": 1,
  "nombre": "Jeimy",
  "apellidoPa": "Apolaya",
  "apellidoMa": "Jurado",
  "correo": "[email protected]",
  "username": "jamie",
  "telefono": "938311721",
  "dni": "77454558",
  "enable": "Activo",
  "idTipoUsu": 2,
  "tiporol": {
    "tipo": "ADMIN"
  }
}

Key API Endpoints

Here are the main endpoints you’ll use:
# Generate JWT token
POST /generate-token

# Get current user
GET /actual-usuario

Application Architecture

InvestGo follows a layered architecture pattern:
┌─────────────────┐
│   Controllers   │  <- REST endpoints (@RestController)
└────────┬────────┘

┌────────▼────────┐
│    Services     │  <- Business logic (@Service)
└────────┬────────┘

┌────────▼────────┐
│  Repositories   │  <- Data access (@Repository)
└────────┬────────┘

┌────────▼────────┐
│    Entities     │  <- JPA entities (@Entity)
└────────┬────────┘

┌────────▼────────┐
│  MySQL Database │  <- InvestGo schema
└─────────────────┘

Common Issues

Error: Communications link failureSolution:
  • Verify MySQL is running: sudo service mysql status
  • Check credentials in application.properties
  • Ensure database InvestGo exists
  • Verify port 3306 is accessible
Error: Port 8091 was already in useSolution:
  • Change the port in application.properties: server.port=8092
  • Or stop the process using port 8091:
    lsof -ti:8091 | xargs kill -9
    
Error: 401 Unauthorized or “El token ha expirado”Solution:
  • Generate a new token using /generate-token endpoint
  • Tokens expire after a configured duration
Error: Dependency resolution errorsSolution:
# Clear Maven cache and rebuild
mvn clean
rm -rf ~/.m2/repository
mvn install

Next Steps

Now that you have InvestGo running:

Explore the Architecture

Learn about entities, relationships, and design patterns

API Reference

Comprehensive endpoint documentation
Development Tips:
  • Enable spring.jpa.show-sql=true to see generated SQL queries
  • Use Spring DevTools for automatic restarts during development
  • All dates use timezone America/Lima - ensure consistency
  • CORS is configured to allow all origins (*) - restrict in production

Build docs developers (and LLMs) love