Skip to content

Latest commit

 

History

History
104 lines (84 loc) · 4.41 KB

README.md

File metadata and controls

104 lines (84 loc) · 4.41 KB

Ki_Data Web Application

Dragon Ball Character

Overview

Ki_Data is my first real web application, it's designed to manage and display information about Dragon Ball characters, like a sort of Wiki. The application provides RESTful endpoints to create, read, and delete character data. It is built using Java and frameworks to ensure a robust, secure, and maintainable codebase.

Technologies Used

Backend

  • Spring Boot: Framework for building the application.
  • Spring Security: For securing the application endpoints with role-based access control, using JWT token authentication logic.
  • Spring Data JPA: For data persistence and interaction with the Postgres database.
  • Hibernate: ORM framework used with Spring Data JPA.
  • Postgres Database: Relational database for storing character data.
  • Lombok: Library to reduce boilerplate code by generating getters, setters, and constructors.
  • ModelMapper: Library for mapping between DTOs and entities.
  • JWT Token: For secure token-based authentication.
  • Jakarta Persistence API (JPA): For ORM mapping and database interaction.
  • Spring AI: For integration with AI services.
  • Mistral AI: AI service used for chatbot functionality.

Project Structure

The project is organized into several packages, each serving a distinct purpose:

  • controller: Contains REST controllers to handle HTTP requests.
  • dto: Data Transfer Objects used for transferring data between layers.
  • model: Entity classes representing the database schema.
  • repository: Spring Data JPA repositories for data access.
  • service: Service layer containing business logic.
  • security: Configuration classes for application security.
  • ai: Contains AI-related classes and services.

Endpoints

The application exposes the following endpoints:

  • GET /kiData/characters: Retrieve all characters.
  • GET /kiData/characters/{id}: Retrieve a character by ID.
  • POST /kiData/characters: Create a new character (Admin only).
  • DELETE /kiData/characters/{id}: Delete a character by ID (Admin only).
  • GET /kiData/ai/dendechat: Chat with AI Dende bot.

Setup and Running the Application

Prerequisites

  • Java 11 or higher
  • Maven

Steps

  1. Clone the repository:
    git clone <repository-url>
    cd Ki_Data
    
  2. Build the project:
    mvn clean install
  3. Run the application:
    mvn spring-boot:run
    

Security

The application uses JWT (JSON Web Token) for authentication and authorization to ensure secure access to its endpoints.

User Registration and Authentication

  • User: user, Role: USER/ADMIN

Endpoints

  • Register a User: POST /kiData/auth/registrationUsrOnly

    • This endpoint allows new users to register by providing their details in a JSON body.
    • Request Body Example:
      {
        "name" : "name",
        "last_name" : "last_name", 
        "email": "[email protected]",
        "password": "newpassword"
      }
  • Authenticate a User: POST /kiData/auth/authentication

    • This endpoint is used to authenticate a user. It requires the user's credentials (email and password) to be provided in a JSON body. Upon successful authentication, a JWT token is returned.
    • Request Body Example:
      {
        "email": "[email protected]",
        "password": "password"
      }
    • Response Example:
      {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
      }

Role-based Access Control

Role-based access control is enforced to restrict access to certain endpoints based on the user's role. Only users with the ADMIN role have permission to create or delete characters.

  • Endpoints accessible by ADMIN only:
    • POST /kiData/characters: Create a new character.
    • DELETE /kiData/characters/{id}: Delete a character by ID.