Your daily dose of purrfect facts.
Built with the tools and technologies:
CatFactsDaily is a secure, user-friendly web application where users can store and share their favorite cat facts. It features user authentication, data persistence, and a clean REST API, all packaged for easy deployment using Docker. Perfect for cat lovers who want a simple, reliable way to manage their feline-themed wisdom.
API documentation on catfactsdaily.onrender.com/swagger-ui/index.html
Uptime and status on stats.uptimerobot.com/cxdTXPQLeA
| Feature | Summary | |
|---|---|---|
| βοΈ | Architecture |
|
| π© | Code Quality |
|
| π | Documentation |
|
| π | Integrations |
|
| π§© | Modularity |
|
βββ render-slot-catfactsdaily/
βββ Dockerfile
βββ mvnw
βββ mvnw.cmd
βββ pom.xml
βββ README.md
βββ src
βββ main
βββ testRENDER-SLOT-CATFACTSDAILY/
__root__
Dockerfile - The Dockerfile automates the building and deployment of a Java Spring Boot application
- It leverages a multi-stage build process: first compiling the application using Maven, running tests, and packaging it; then, deploying the resulting JAR into a minimal runtime environment
- The final image exposes port 8080 for the application's HTTP service.mvnw - The mvnw script bootstraps Apache Maven, a build automation tool
- It downloads and installs a Maven distribution if one is not already present, verifying its integrity
- The script then executes Maven commands, providing a consistent build environment across different systems and ensuring the correct Maven version is used for the project
- This simplifies project setup and dependency management.mvnw.cmd - mvnw.cmd acts as a wrapper script for Apache Maven, automating its download and setup if not already present
- It leverages PowerShell to download the correct Maven distribution based on configuration, verifies its integrity, and sets up the necessary environment variables, enabling execution of Maven commands via mvnw
- This streamlines the build process by ensuring a consistent Maven version across different environments.
src
main
java
com
example
catfactsdaily
CatfactsdailyApplication.java - CatfactsdailyApplication serves as the main application entry point for the Spring Boot application
- It enables scheduled tasks, initiating the application's core functionality
- The class bootstraps the Spring context, allowing other components to function, ultimately delivering daily cat facts.config
ApplicationConfiguration.java - ApplicationConfiguration configures Spring Security for the CatFactsDaily application
- It defines beans for user details service, password encoding (using BCrypt), authentication manager, and authentication provider
- These beans integrate user data from the UserRepository to enable secure user authentication within the application's architecture.JacksonConfig.java - JacksonConfig customizes Jackson's ObjectMapper for the CatFactsDaily application
- It configures the ObjectMapper to handle Java 8 date and time objects, exclude null values from JSON output, and format dates in a specific pattern
- This ensures consistent and optimized JSON serialization and deserialization throughout the application, improving data handling efficiency.JwtAuthenticationFilter.java - JwtAuthenticationFilter intercepts incoming requests, validating JSON Web Tokens (JWTs) present in Authorization headers
- It extracts user information from verified tokens, authenticating the user and populating Spring Security's context
- Upon successful authentication, the filter allows the request to proceed; otherwise, it handles exceptions gracefully
- This ensures secure access to protected resources within the CatFactsDaily application.OpenApiConfig.java - OpenApiConfig configures the Spring Boot application's OpenAPI (Swagger) documentation
- It defines the API title, version, and security scheme using JWT bearer tokens
- This enables automatic generation of interactive API documentation, improving developer experience and facilitating API consumption by external clients
- The configuration enhances the CatFactsDaily application's discoverability and usability.SecurityConfig.java - SecurityConfig secures the CatFactsDaily application
- It configures Spring Security, enabling JWT authentication and authorization
- Specifically, it defines security rules, allowing access to specific endpoints like Swagger and authentication routes while requiring authentication for others
- CORS configuration is also established to handle cross-origin requests
- The configuration uses a stateless session management approach for enhanced security.controller
AuthenticationController.java - AuthenticationController manages user registration and login within the CatFactsDaily application
- It receives user credentials, interacts with an authentication service to verify them, and generates JSON Web Tokens (JWTs) for successful logins
- The controller returns user information and JWTs to the client, enabling secure access to application resources.CatFactsController.java - CatFactsController manages user interactions with cat facts
- It provides REST endpoints for adding, retrieving, updating, and deleting cat facts, secured using JWT authentication
- The controller interacts with a CatFactsService for data persistence and a JwtService for authentication, ensuring only authorized users can modify their data
- Responses are appropriately formatted and include logging for security and debugging.LoggedInController.java - LoggedInController manages user logout within the CatFactsDaily application
- It utilizes a JWT service to verify user identity and authorization before invalidating the provided token
- This ensures only authenticated users can log out and prevents unauthorized access
- The controller returns appropriate HTTP responses indicating success or unauthorized attempts.dto
CatFactDTO.java - CatFactDTO defines a data transfer object within the CatFactsDaily application
- It encapsulates cat fact data, specifically a single string representing the fact itself, for efficient data exchange between different application layers
- This facilitates clean separation of concerns and improves code maintainability within the broader project architecture.UserDTO.java - UserDTO defines a data transfer object for user information within the CatFactsDaily application
- It encapsulates user name and password, facilitating data exchange between different layers of the application, likely serving as a model for user registration or login processes
- This promotes clean separation of concerns and improves code maintainability.entity
CatFact.java - CatFact defines the data structure for storing cat facts within the CatFactsDaily application
- It represents a single cat fact entry, including its unique identifier, user association, the fact itself, timestamps for creation and modification, and an active status flag
- This entity facilitates database persistence and interaction with the application's core functionality.TokenBlacklisted.java - TokenBlacklisted.java defines an entity for managing blacklisted authentication tokens within the CatFactsDaily application
- It stores blacklisted tokens, their expiration dates, and ensures uniqueness for efficient revocation
- This entity contributes to the application's security by preventing unauthorized access using invalidated tokens, enhancing overall system robustness.User.java - User.java defines the User entity for the CatFactsDaily application
- It represents a user within the system, managing user authentication and authorization details
- The entity includes a unique username, password, and implements Spring Security's UserDetails interface for integration with the application's security framework
- This enables user management and access control features.repository
CatFactRepository.java - CatFactRepository manages persistent storage of cat facts within the CatFactsDaily application
- It leverages Spring Data JPA to provide data access functionality, specifically enabling retrieval of cat facts based on user ID
- This repository facilitates database interactions, simplifying data management for the application's core functionality.TokenBlacklistedRepository.java - TokenBlacklistedRepository manages blacklisted authentication tokens within the CatFactsDaily application
- It provides database access for storing and retrieving blacklisted tokens, enabling efficient checking of token validity and automated removal of expired tokens
- This ensures application security by preventing unauthorized access.UserRepository.java - UserRepository manages persistent storage of User entities within the CatFactsDaily application
- Leveraging Spring Data JPA, it provides database interaction, enabling retrieval of users by name and standard CRUD operations
- This repository component facilitates user authentication and data management within the broader application architecture.response
CatFactResponse.java - CatFactResponse defines a data structure representing a cat fact within the CatFactsDaily application
- It encapsulates essential attributes: a unique identifier, the cat fact itself, and timestamps indicating creation and modification times
- This class facilitates the consistent handling and transmission of cat fact data throughout the application's response mechanisms.LoginResponse.java - LoginResponse defines a data structure for successful user logins within the CatFactsDaily application
- It encapsulates user information, specifically the user's name, a security token, and the token's expiration time
- This class facilitates the communication of authentication results from the application's backend to the client, enabling secure session management.SignupResponse.java - SignupResponse defines a data structure for user registration responses within the CatFactsDaily application
- It encapsulates user name information, facilitating communication between the application's signup functionality and other components
- This class plays a role in returning user details after successful registration, contributing to the overall user management system.service
AuthenticationService.java - AuthenticationService handles user registration and login within the CatFactsDaily application
- It uses Spring Security's AuthenticationManager for authentication and encrypts passwords using a PasswordEncoder
- The service interacts with a UserRepository to persist and retrieve user data, ensuring data integrity through transactional management
- It facilitates secure user access to the application.CatFactsService.java - CatFactsService manages user cat facts within the CatFactsDaily application
- It provides functionalities for adding, retrieving, updating, and deleting user-specific cat facts, ensuring data integrity through transactional control
- The service interacts with a repository to persist data and uses DTOs and response objects for data transfer and presentation
- Unauthorized access is prevented through user ID verification.JwtService.java - JwtService manages JSON Web Tokens (JWTs) for authentication within the CatFactsDaily application
- It generates, validates, and invalidates JWTs, extracting user information and checking for token expiration or blacklisting
- The service interacts with a token blacklist repository to ensure security
- Integration with Spring Security is evident through UserDetails and UsernamePasswordAuthenticationToken usage.TokenCleanupService.java - TokenCleanupService periodically removes expired blacklisted tokens from the CatFactsDaily application's database
- Operating as a scheduled Spring service, it identifies and deletes entries with past expiration dates, maintaining database integrity and efficiency by removing obsolete data
- The service uses a transactional approach to ensure data consistency.test
java
com
example
catfactsdaily
CatfactsdailyApplicationTests.java - CatfactsdailyApplicationTests provides a Spring Boot test suite for the Catfactsdaily application
- The file's role within the project is to ensure the application's core functionality works correctly, contributing to overall application quality and stability.controller
CatFactsControllerTest.java - Unit tests verify the `CatFactsController`
- These tests cover various scenarios for creating, reading, updating, and deleting cat facts, including authorization checks and handling of edge cases like nonexistent records
- The tests utilize mock objects to isolate the controller's logic and ensure its proper interaction with the `CatFactsService` and `JwtService` within the application's architecture.
Before getting started with render-slot-catfactsdaily, ensure your runtime environment meets the following requirements:
- Programming Language: Java
- Container Runtime: Docker
Install render-slot-catfactsdaily using the following method:
- Clone the render-slot-catfactsdaily repository:
git clone https://github.com/Eyelor/render-slot-catfactsdaily- Navigate to the project directory:
cd render-slot-catfactsdaily- Install the project dependencies:
Using docker
docker build -t CatFactsDaily .Run render-slot-catfactsdaily using the following command:
Using docker
docker run -p 8080:8080 CatFactsDailyRun the test suite using the following command:
mvn clean testThis command runs before the build process in the dockerfile, but you can do this too in your IDE. For example in the IntelliJ IDEA if you have access to mvn in your terminal.
This project is protected under the Apache 2.0 License. For more details, refer to the LICENSE file.
Authors:

