> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Yurben-bit/Sistema-de-Administraci-n-Escolar-Backend/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get EduTec Backend up and running in minutes

## Prerequisites

Before you begin, ensure you have the following installed on your system:

<CardGroup cols={3}>
  <Card title="Java 8+" icon="mug-hot">
    JDK 8 or higher required
  </Card>

  <Card title="Maven 3.x" icon="box">
    For dependency management
  </Card>

  <Card title="MySQL 8.0+" icon="database">
    Database server running
  </Card>
</CardGroup>

<Note>
  You'll also need Git to clone the repository.
</Note>

## Quick Installation

<Steps>
  <Step title="Clone the Repository">
    Clone the EduTec Backend repository to your local machine:

    ```bash theme={null}
    git clone <repository-url>
    cd edutec-backend
    ```
  </Step>

  <Step title="Set Up MySQL Database">
    Create a new MySQL database for the application:

    ```sql theme={null}
    CREATE DATABASE edutec_db;
    CREATE USER 'edutec_user'@'localhost' IDENTIFIED BY 'your_password';
    GRANT ALL PRIVILEGES ON edutec_db.* TO 'edutec_user'@'localhost';
    FLUSH PRIVILEGES;
    ```

    <Warning>
      Make sure to replace `your_password` with a secure password of your choice.
    </Warning>
  </Step>

  <Step title="Configure Database Connection">
    Update the `src/main/resources/application.properties` file with your database credentials:

    ```properties theme={null}
    spring.application.name=edutec

    # Database Configuration
    spring.datasource.url=jdbc:mysql://localhost:3306/edutec_db
    spring.datasource.username=edutec_user
    spring.datasource.password=your_password
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

    # JPA Configuration
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.show-sql=true
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

    # Server Configuration
    server.port=8080
    ```
  </Step>

  <Step title="Install Dependencies">
    Use Maven to download all required dependencies:

    <CodeGroup>
      ```bash Maven Wrapper (Recommended) theme={null}
      ./mvnw clean install
      ```

      ```bash Maven theme={null}
      mvn clean install
      ```
    </CodeGroup>

    <Note>
      The Maven wrapper (`./mvnw`) is included in the project and doesn't require Maven to be installed globally.
    </Note>
  </Step>

  <Step title="Run the Application">
    Start the Spring Boot application:

    <CodeGroup>
      ```bash Maven Wrapper theme={null}
      ./mvnw spring-boot:run
      ```

      ```bash Maven theme={null}
      mvn spring-boot:run
      ```

      ```bash Java JAR theme={null}
      java -jar target/com.escolar-0.0.1-SNAPSHOT.jar
      ```
    </CodeGroup>

    The application will start on `http://localhost:8080`

    You should see output similar to:

    ```
    Started EdutecApplication in X.XXX seconds
    ```
  </Step>
</Steps>

## Verify Installation

Once the application is running, verify that everything is working correctly.

### Check Application Health

Test the application by making a request to the login endpoint:

```bash theme={null}
curl -X POST http://localhost:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "testpass"
  }'
```

<Note>
  Since this is a development build without full authentication validation, the endpoint will generate a JWT token for any username provided.
</Note>

### Expected Response

You should receive a JWT token response:

```
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0dXNlciIsImlhdCI6MTY4MDE1MzYwMCwiZXhwIjoxNjgwMTg5NjAwfQ.xxxxxxxxxxxxxxxxxxxxx
```

This token is valid for 10 hours and can be used for authenticated requests (once authentication middleware is implemented).

## Understanding the Code

Now that you have the application running, let's understand the key components:

### Main Application Class

The entry point of the application is defined in `EdutecApplication.java`:

```java src/main/java/com/tecmilenio/edutec/EdutecApplication.java theme={null}
package com.tecmilenio.edutec;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class EdutecApplication {

	public static void main(String[] args) {
		SpringApplication.run(EdutecApplication.class, args);
	}

}
```

### Authentication Controller

The `AuthController` handles login requests at `/auth/login`:

```java src/main/java/com/tecmilenio/edutec/controller/AuthController.java theme={null}
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private JwtService jwtService;

    @PostMapping("/login")
    public String login(@RequestBody LoginRequest loginRequest) {
        System.out.println("El usuario " + loginRequest.getUsername() + " está intentando entrar");
        return jwtService.generateToken(loginRequest.getUsername());
    }
}
```

### JWT Service

The `JwtService` generates secure JWT tokens for authenticated users:

```java src/main/java/com/tecmilenio/edutec/security/JwtService.java theme={null}
@Service
public class JwtService {
    private static final String SECRET_KEY = "12345678910111213141516171819200";
    private static final Key KEY = Keys.hmacShaKeyFor(SECRET_KEY.getBytes());

    public String generateToken(String username) {
        return Jwts.builder()
                .setSubject(username)
                .setIssuedAt(new Date(System.currentTimeMillis()))
                .setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 10))
                .signWith(KEY, SignatureAlgorithm.HS256)
                .compact();
    }
}
```

<Warning>
  The current JWT secret key is hardcoded for development purposes. In production, this should be moved to environment variables or a secure configuration service.
</Warning>

### User Model

The `User` entity represents users in the database:

```java src/main/java/com/tecmilenio/edutec/model/User.java theme={null}
@Entity
@Table(name = "usuarios")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, unique = true)
    private String username;

    @Column(nullable = false)
    private String password;
}
```

### Login Request DTO

The `LoginRequest` DTO handles incoming login data:

```java src/main/java/com/tecmilenio/edutec/dto/LoginRequest.java theme={null}
public class LoginRequest {
    private String username;
    private String password;

    public LoginRequest() {}

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
```

## Development Workflow

### Running in Development Mode

Spring Boot DevTools is included in the project, enabling automatic restart when code changes:

```bash theme={null}
./mvnw spring-boot:run
```

Any changes to Java files will trigger an automatic application restart.

### Database Schema Management

The application uses JPA's `ddl-auto=update` setting, which automatically creates and updates database tables based on your entity classes.

<Note>
  For production deployments, consider using a migration tool like Flyway or Liquibase instead of automatic schema generation.
</Note>

### Common Issues

<AccordionGroup>
  <Accordion title="MySQL Connection Refused">
    Ensure MySQL is running and accessible:

    ```bash theme={null}
    sudo systemctl status mysql
    ```

    Check that the port 3306 is not blocked by a firewall.
  </Accordion>

  <Accordion title="Port 8080 Already in Use">
    Change the server port in `application.properties`:

    ```properties theme={null}
    server.port=8081
    ```
  </Accordion>

  <Accordion title="Maven Build Failures">
    Clear the Maven cache and rebuild:

    ```bash theme={null}
    ./mvnw clean install -U
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

Now that you have EduTec Backend running locally, you can:

* Explore the [API Reference](/api/auth/login) to learn about available endpoints
* Read about [Authentication](/authentication) to understand the JWT implementation
* Check the [Database Schema](/database) to see the data structure
* Review the [Configuration Guide](/configuration) for production settings

<Card title="Need Help?" icon="question" href="https://github.com/Yurben-bit/Sistema-de-Administraci-n-Escolar-Backend/issues">
  If you encounter any issues, please open an issue on GitHub.
</Card>
