A full-stack e-commerce web application built with Spring Boot, Thymeleaf, and HTMX. This project combines backend services and frontend presentation in a single monolithic application, providing a seamless user experience without the need for a separate frontend application.
This project is based on the original G-commerce backend api and G-commerce frontend projects, combining them into a unified application.
-
User Management
- User registration and authentication with Spring Security
- Role-based authorization (ADMIN, USER)
- Profile management and password updates
- Paginated user listing for administrators
-
Product Management
- Product creation, update, delete, and list operations
- Product status management (active/inactive)
- Text search across product name and description fields
- Responsive product grid display
-
Shopping Cart
- Client-side cart functionality with JavaScript
- Add/remove products with real-time updates
- Cart persistence during session
- Automatic total calculations
-
Purchase System
- Checkout process
- Purchase history tracking with pagination
- Role-specific purchase restrictions
-
Responsive UI with Thymeleaf & HTMX
- Server-side rendering with Thymeleaf templates
- HTMX for dynamic content loading without page refreshes
- Thymeleaf fragments for component reusability
- Light/dark theme support
- Bootstrap 5 for responsive layouts
-
Security Features
- Spring Security integration
- Form-Based authentication
- CSRF protection
- Input validation
- User role enforcement
-
Advanced Logging System
- Comprehensive Logback configuration optimized for containers
- Multiple specialized log files (application, error, security, performance)
- Async logging for improved performance
-
Code Quality Tools
- Checkstyle for enforcing coding standards
- PMD for static code analysis
- Automated checks during build process
-
Backend
- Java 21
- Spring Boot 3.4.7
- Spring Security
- Spring Data JPA
- MySQL 9
- H2 Database (for testing)
-
Frontend
- Thymeleaf
- HTMX
- Bootstrap 5
- JavaScript (ES6+)
- CSS3
-
DevOps & Tools
- Docker & Docker Compose
- Maven
- GitHub Actions for CI/CD
- Lombok
- JUnit 5 & Mockito
- Checkstyle 10.14.2
- PMD 7.1.0
- Logback for advanced logging
- Java 21 or higher
- Docker and Docker Compose
- Maven
- Git
-
Clone the repository:
git clone https://github.com/gussttaav/g-commerce-thymeleaf.git cd g-commerce-thymeleaf -
Create a
.envfile in the root directory with the following variables:MYSQL_ROOT_PASSWORD=your_root_password MYSQL_USER=your_database_user MYSQL_PASSWORD=your_database_password ADMIN_EMAIL=admin@example.com ADMIN_PASSWORD=your_admin_password
-
Set up the database using one of these two options:
Option A: Using Docker Compose (Recommended)
docker-compose -f docker-compose.db.yml up -d
This will start the MySQL database container with the pre-configured schema.
Option B: Using the SQL script directly
- Set up your MySQL database server
- Run the initialization script ./mysql-init/shopping_db.sql
- Update the application.yml file with your database connection details
-
Build and run the application:
mvn clean install mvn spring-boot:run
The application will be available at http://localhost:8080.
The application includes a comprehensive logging system designed for production environments and containerized deployments.
g-commerce.log- Main application logsg-commerce-error.log- Error-level logs only for quick troubleshootingg-commerce-security.log- Security-related events and audit trailg-commerce-performance.log- Performance monitoring logs
- Automatic Log Rotation: Configure log rotation to archive old logs and prevent disk space issues
- Compression: Old logs are automatically compressed to save disk space
- Profile-Specific Configuration: Different log levels for development, testing, and production
- Async Logging: Improved application performance through asynchronous log writing
- Colored Console Output: Enhanced readability during development
| Variable | Description | Default |
|---|---|---|
LOG_PATH |
Directory for log files | logs |
LOG_ARCHIVE |
Directory for archived logs | logs/archive |
LOG_MAX_FILE_SIZE |
Maximum size per log file | 100MB |
LOG_MAX_HISTORY |
Days to keep archived logs | 30 |
LOG_TOTAL_SIZE_CAP |
Total size limit for all logs | 1GB |
The application is deployed using two Docker images:
-
G-Commerce Application (This repository)
- Combines Spring Boot backend and Thymeleaf frontend
- Available at
gussttaav/g-commerce-thymeleaf:latest
-
Database (Reusing existing image)
- MySQL 9 with pre-configured schema
- Available at
gussttaav/g-commerce-mysql:latest
The project follows a standard Spring Boot structure with Thymeleaf templates:
src/
βββ main/
β βββ java/
β β βββ com/gplanet/commerce/
β β βββ controllers/ # MVC Controllers
β β βββ dtos/ # Data Transfer Objects
β β βββ entities/ # JPA Entities
β β βββ exceptions/ # Custom Exceptions
β β βββ repositories/ # Spring Data Repositories
β β βββ security/ # Security Configuration
β β βββ services/ # Business Logic
β β βββ utilities/ # Helper Classes
β βββ resources/
β βββ static/ # Static Assets
β β βββ css/ # Stylesheets
β β βββ img/ # Images
β β βββ js/ # JavaScript Files
β βββ templates/ # Thymeleaf Templates
β βββ compras/ # Purchase-related Templates
β βββ productos/ # Product-related Templates
β βββ usuarios/ # User-related Templates
βββ test/
β βββ java/
β β βββ com/gplanet/commerce/
β β βββ controllers/ # Controllers Tests
β β βββ integration/ # Integration Tests
β β βββ repositories/ # Spring Data Repositories Tests
β β βββ security/ # Security Configuration Tests
β β βββ services/ # JUnit services tests
β βββ resources/
βββ docker-compose.db.yml # Docker Compose for Database
This application differs from the previous version in several key ways:
-
Monolithic Architecture: Frontend and backend are integrated into a single application, simplifying deployment and development.
-
Server-Side Rendering: Uses Thymeleaf templates rendered on the server rather than a separate client-side application.
-
HTMX Integration: Leverages HTMX for dynamic content loading without full page refreshes, providing a SPA-like experience.
-
Template Fragments: Uses Thymeleaf fragments for component reusability and consistency across pages.
-
Simplified Deployment: Requires only two Docker images (application and database) instead of three.
-
Reduced Network Overhead: Eliminates API calls between separate frontend and backend services.
The application uses Thymeleaf for server-side rendering, with templates organized by domain:
templates/layout.html: Main layout template with common elementstemplates/productos/: Product-related templatestemplates/usuarios/: User-related templatestemplates/compras/: Purchase-related templates
HTMX is used to provide a modern, dynamic user experience without the complexity of a full SPA framework:
- Dynamic content loading
- Form submissions without page refreshes
- Partial page updates
- Server-sent events
- Bootstrap 5 for responsive layouts
- Custom CSS for theme customization
- Client-side JavaScript cart logic
- Theme switching between light and dark modes
The application includes comprehensive tests for all layers:
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=UsuarioControllerTest
# Run tests with coverage report
mvn verifyThe project enforces strict code quality standards using the following tools:
Checkstyle is configured to enforce consistent coding conventions and best practices:
# Run Checkstyle checks
mvn checkstyle:checkKey Checkstyle rules include:
- Line length limit (120 characters)
- Import organization rules (no wildcard imports)
- Naming conventions for all code elements
- Code block organization (braces, whitespace)
- Method size limits (50 lines max)
- Parameter number limits (7 max)
- Class design rules (final classes, utility class constructors)
- Code complexity rules (cyclomatic complexity)
PMD performs static code analysis to detect potential bugs and code smells:
# Run PMD checks
mvn pmd:checkPMD is configured to focus on:
- Best practices for Java development
- Error-prone patterns
- Code duplication detection
Both Checkstyle and PMD are integrated into the Maven build lifecycle and will cause the build to fail if any violations are detected. This ensures consistent code quality throughout the project.
- Form-based authentication with Spring Security
- Role-based access control (ADMIN, USER)
- CSRF protection for form submissions
- Input validation
- Secure password storage with BCrypt
A live demo of this application is available at:
π G-Commerce Thymeleaf Demo on Render
This demo is hosted on a free Render.com plan, which means the server spins down after periods of inactivity. The first request after a while might take up to a minute or more to load as the server starts up again. Be patient β itβs worth the wait!
This project is licensed under the MIT License - see the LICENSE file for details.