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.
- 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.
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.
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.
- Java 11 or higher
- Maven
- Clone the repository:
git clone <repository-url> cd Ki_Data
- Build the project:
mvn clean install
- Run the application:
mvn spring-boot:run
The application uses JWT (JSON Web Token) for authentication and authorization to ensure secure access to its endpoints.
- User:
user
, Role:USER
/ADMIN
-
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 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.