Skip to content

Azure-Samples/java-ai

Repository files navigation

Java AI - AI Shop

This is a simple AI Shop application that demonstrates how to use Azure OpenAI with Java to create a sample second hand shop. It uses the multi-modal capabilities of the OpenAI API to generate a description of the product based on an image. Instead of filling out a form, the users can simply upload an image of the product they want to sell and the AI will generate all the necessary information and fill the form for them.

The functional architecture of the application is as follows:

  • src/ai-shop-ui: The user interface of the application. It is a simple React application that allows the user to upload an image and see the generated information in a form.
  • src/api-gateway: The API Gateway of the application. It is a Spring Boot application that orchestrates the calls to the other services. It uses Spring Cloud Eureka Server for service discovery.
  • src/eureka-server: The Eureka Server of the application. It is simple Eureka Server that is only required for local development.
  • src/ai-image-processing-service: The AI Image Processing Service of the application. It is a Spring Boot application that uses Spring AI to generate the product information based on the image.
  • src/blob-storage-service: The Blob Storage Service of the application. It is a Spring Boot application that uses Spring Cloud Azure to store the images in Azure Blob Storage. It also provide the generation of the image URL with a SAS token for the ai-image-processing-service.
  • src/item-category-service: The Item Category Service of the application. It is a Spring Boot application that provides the categories of the items that can be sold in the shop. It uses Spring Data JPA to store the categories in a H2 database. It is infused with AI and uses LangChain4j to generate the categories based on the product description.
  • src/java-ai-common: A common module that is used by all the services. It contains the common DTOs.

Functional Architecture

Features

This AI Shop application demonstrates several key features:

  • Multi-modal AI Integration: Uses Azure OpenAI's vision capabilities to analyze product images and generate comprehensive product information automatically
  • Microservices Architecture: Built with Spring Boot microservices including API Gateway, Eureka service discovery, and specialized services for different functions
  • Cloud-Native Deployment: Fully containerized application deployable to Azure Container Apps with Azure Developer CLI (azd)
  • AI-Powered Categorization: Intelligent product categorization using LangChain4j for enhanced product organization
  • Secure Blob Storage: Azure Blob Storage integration with SAS token generation for secure image handling
  • Modern React UI: Clean, responsive user interface for easy product upload and management
  • Enterprise Security: Entra ID authentication and role-based access control for production readiness

Getting Started

Quick Start with Azure

The fastest way to get started is to deploy directly to Azure:

  1. Fork this repository to your GitHub account
  2. Open in GitHub Codespace (recommended) or clone locally
  3. Login to Azure and run deployment:
    azd auth login
    azd up
  4. Access your application at the provided endpoint after deployment completes

Local Development

For local development and testing:

  1. Prerequisites: Ensure you have Java 17+, Azure CLI, azd, and Docker installed
  2. Build the common module: Follow instructions in src/java-ai-common/common/README.md
  3. Start services in order: Follow the detailed steps in the "Run locally" section below
  4. Access the application at http://localhost:3000

Guidance

Architecture Decisions

This application follows several architectural patterns:

  • Microservices Pattern: Each service has a single responsibility and can be deployed independently
  • API Gateway Pattern: Centralized entry point for all client requests with service orchestration
  • Service Discovery: Uses Eureka for dynamic service registration and discovery in local development
  • Event-Driven Architecture: Services communicate through well-defined APIs and events
  • Cloud-First Design: Built specifically for Azure Container Apps with proper scaling and monitoring

Best Practices Implemented

  • Security: Entra ID authentication, managed identities, and secure secret management
  • Monitoring: Azure Log Analytics integration for comprehensive observability
  • Scalability: Container Apps auto-scaling based on demand
  • Reliability: Health checks, graceful degradation, and proper error handling
  • Performance: Optimized container images and efficient resource utilization

Customization Guidelines

To adapt this application for your use case:

  1. Model Configuration: Update AI model deployments in infra/bicep/deploy.bicep
  2. Service Logic: Modify business logic in individual service modules
  3. UI Customization: Update React components in src/ai-shop-ui
  4. Data Models: Extend DTOs in src/java-ai-common for additional fields
  5. Infrastructure: Adjust Azure resources in bicep templates as needed

Resources

Documentation

Learning Resources

Sample Code and Templates

Community and Support

Prerequisites

Easiest way to start is to Fork and open the repository in a GitHub Codespace as it contains all the prerequisites.

If you develop locally, you need to have the following installed:

Run locally

To run the AI Shop locally, you need first to build the common module and then start the services. Follow the instructions below in the order they are presented:

  1. Build the common module
  2. Start the Eureka Server
  3. Start the Blob Storage Service
  4. Start the AI Image Processing Service
  5. Start the Item Category Service
  6. Start the API Gateway
  7. Start the AI Shop UI

Deploy to Azure

The following resources will be created as represented in the diagram below:

Azure Architecture

Quick start

To deploy the AI Shop to Azure, you need only to run the azd up command. The Azure Developer CLI (azd) will create all the necessary resources in Azure and deploy the services to Azure Container Apps. Please login first, then choose a name for the resource group, a subscription and region.

azd auth login
azd up

After up to 15 minutes all resources will be deployed. Please call the printed endpoint of the ai-shop-ui of the terminal in a browser. You should see the start page of The AI Shop:

alt text

Just upload a product picture to generate name, brand, model, price, description, categories via OpenAI.

alt text

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

About

Use Java and AI for production ready use cases

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 9