diff --git a/README.md b/README.md index 637fc2e..5e57036 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,132 @@ -# Simple E-commerce REST API +# 🌟 Simple E-commerce REST API [![Build and Test](https://github.com/syedabdullahrahman/e-commerce/actions/workflows/maven.yml/badge.svg)](https://github.com/syedabdullahrahman/e-commerce/actions/workflows/maven.yml) +--- + +## πŸ“š Table of Contents +- [Technologies Used](#technologies-used) +- [Features](#features) +- [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Database Schema](#database-schema) +- [Screenshots](#screenshots) +- [Contributing](#contributing) +- [License](#license) + +--- + +## πŸ› οΈ Technologies Used + +This project leverages a variety of powerful technologies to create a seamless e-commerce experience: + +- **Java 17** +- **Spring Boot 3.2.2** +- **Spring Data JPA** +- **Hibernate** +- **MySQL** +- **PostgreSQL** +- **Maven** +- **Liquibase** +- **OpenAPI** +- **Docker** +- **Spring Data REST** +- **Test Containers** +- **Prometheus** +- **Grafana** +- **Tempo** + +--- + +## πŸš€ Features + +Discover the robust features of this e-commerce API: + +- **Customer Wish List**: Easily retrieve and manage customer wish lists. +- **Sales Insights**: Get total sales for the current day and identify peak sales days. +- **Top Selling Items**: Fetch top N selling items of all time and for the last month based on sales metrics. +- **Integration Testing**: Robust integration testing using Test Containers for both MySQL and PostgreSQL databases, ensuring quality across different environments. +- **Observability**: Monitor application performance with Prometheus, Grafana, and Tempo. + +--- -# Table of Contents - - [Technologies Used](#technologies-used) - - [Features](#features) - - [Getting Started](#getting-started) - - [Prerequisites](#prerequisites) - - [Installation](#installation) - - [Database Schema](#database-schema) - - [Screenshots](#screenshots) - -# Technologies Used - - - Java 17 - - Spring Boot 3.2.2 - - Spring Data JPA - - Hibernate - - MySQL - - Maven - - Liquibase - - OpenAPI - - Docker - - Spring Data REST - - Test Containers - - Prometheus - - Grafana - - Tempo - -# Features - - - Retrieve a customer's wish list. - - Get the total sales amount for the current day. - - Determine the maximum sales day within a specified time range. - - Fetch the top N selling items of all time based on total sales amount. - - Get the top N selling items of the last month based on the number of sales. - - **Integration Testing**: Utilizes Test Containers for robust integration testing. - - **Observability**: Integrated with Prometheus, Grafana, and Tempo for monitoring and observability of the application. - -# Getting Started - -## Prerequisites - -Ensure you have the following installed: +## 🏁 Getting Started + +### Prerequisites + +Before you begin, ensure you have the following installed: - **Java 17+** - **Docker** -## Installation +### Installation -Follow these steps to install and configure the project: +Follow these steps to get your local environment up and running: -1. Clone the repository. +1. **Clone the repository**: ```bash git clone https://github.com/syedabdullahrahman/e-commerce.git ``` -2. Navigate to the project directory. +2. **Navigate to the project directory**: + ```bash + cd e-commerce + ``` +3. **Build the project using Maven**: + ```bash + mvn clean install + ``` +4. **Run the application**: + ```bash + java -jar target/demo-0.0.1-SNAPSHOT.jar + ``` -3. Build the project using Maven. -```bash -mvn clean install -``` -4. Run the application +### OR + +**Run the application using Docker Compose**: ```bash -java -jar target/demo-0.0.1-SNAPSHOT.jar +docker-compose up ``` -### OR +--- + +## πŸ“Έ Screenshots + +Here’s a glimpse of the application in action: + +- **OpenAPI / Swagger UI for API testing** + ![OpenAPI](screenshots/swagger-ui.PNG) + +- **Application HTTP requests metrics** + ![HTTP Metrics](screenshots/grafana-ecommerce-app-stat.PNG) -**Run the application using Docker Compose:** - ```bash - docker-compose up - ``` +- **Overall application metrics** + ![Overall Metrics](screenshots/grafana-spring-boot-stat.PNG) -# Screenshots +### πŸ“Š Database Schema -- *OpenAPI or Swagger UI for testing API* +The database schema is derived from the [MySQL Sample Database](https://www.mysqltutorial.org/getting-started-with-mysql/mysql-sample-database/). Here’s the schema diagram: -![Screenshot 1](screenshots/swagger-ui.PNG) +![Database Schema](mysql-sample-database.png) -- *Application HTTP requests metrics* +--- -![Screenshot 2](screenshots/grafana-ecommerce-app-stat.PNG) +## 🀝 Contributing +We welcome contributions! If you'd like to contribute, please follow these steps: -- *Application overall metrics* +1. Fork the repository. +2. Create a new branch (`git checkout -b feature/YourFeature`). +3. Make your changes and commit them (`git commit -m 'Add some feature'`). +4. Push to the branch (`git push origin feature/YourFeature`). +5. Open a pull request. -![Screenshot 3](screenshots/grafana-spring-boot-stat.PNG) +--- +## πŸ“ License -### Database Schema -The database schema is from [MySQL Sample Database](https://www.mysqltutorial.org/getting-started-with-mysql/mysql-sample-database/) +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. -Here is the schema diagram: +--- -![schema](mysql-sample-database.png) \ No newline at end of file +Feel free to reach out if you have any questions or suggestions! diff --git a/src/main/resources/application-postgresdb.properties b/src/main/resources/application-postgresdb.properties index c08fa6f..304a054 100644 --- a/src/main/resources/application-postgresdb.properties +++ b/src/main/resources/application-postgresdb.properties @@ -9,8 +9,21 @@ spring.datasource.url=jdbc:tc:pgvector/pgvector:pg16:///ecommerce spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=none spring.sql.init.data-locations=classpath:postgresdb-schema-with-data.sql + +# Turn on statistics +spring.jpa.properties.hibernate.generate_statistics=true +logging.level.org.hibernate.stat=debug + +# Show all queries +spring.jpa.show-sql=true spring.jpa.properties.hibernate.show_sql=true +# Don't enable formatting on PROD +spring.jpa.properties.hibernate.format_sql=true + +#Show parameters of SQL logging.level.org.hibernate.orm.jdbc.bind=trace +logging.level.org.hibernate.type=debug + ## Disable liquibase as it contains MySQL schema files spring.liquibase.enabled=false \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 96077e9..198bb7d 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -9,8 +9,21 @@ spring.datasource.url=jdbc:tc:mysql:latest:///ecommerce spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect spring.jpa.hibernate.ddl-auto=none spring.sql.init.data-locations=classpath:test-dataset.sql + + +# Turn on statistics +spring.jpa.properties.hibernate.generate_statistics=true +logging.level.org.hibernate.stat=debug + +# Show all queries +spring.jpa.show-sql=true spring.jpa.properties.hibernate.show_sql=true +# Don't enable formatting on PROD +spring.jpa.properties.hibernate.format_sql=true + +#Show parameters of SQL logging.level.org.hibernate.orm.jdbc.bind=trace +logging.level.org.hibernate.type=debug spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.maxLifetime=1800000