Copyright (c) 2025 Software Tree
Automated e-commerce microservice with PostgreSQL integration and Docker deployment
This repository contains a complete e-commerce microservice built with Gilhari ORM, featuring automatic environment detection for seamless local development and Docker deployment. The system automatically handles database connectivity across different environments without manual configuration.
- π Automated Environment Detection: Automatically switches between local and Docker configurations
- π³ Docker-Ready: Complete containerization with proper networking
- π PostgreSQL Integration: Full CRUD operations with complex business relationships
- π One-Command Build: Complete automation from reverse engineering to deployment
- π€ ORMCP Compatible: Ready for AI-powered database interactions
- π Business Intelligence: Advanced queries and aggregations
The microservice provides RESTful APIs for six core e-commerce entities with sophisticated business relationships. This example uses a sophisticated object model found in a typical eCommerce application. For example:
- Supplier has a 1-many relationship with Product
- Customer has a 1-many relationship with CustomerOrder. Customer also has a 1-many relationship with Address
- CustomerOrder has a 1-many relationship with OrderItem
- Product has a 1-many relationship with OrderItem
The above model was automatically inferred from an existing database schema by the reverse-engineering tool shipped with the Gilhari SDK. Please see REVERSE_ENGINEERING.md to learn how you can easily work with an existing relational schema and use its data in an intuitive object-oriented way without writing any SQL code.
- Supplier: Company information with contact details and ratings
- Product: Product catalog with SKU, pricing, inventory, and supplier relationships
- Customer: Customer information with loyalty tiers and spending history
- Address: Customer addresses for shipping and billing
- CustomerOrder: Order information with status tracking
- OrderItem: Individual items within orders with pricing and discounts
gilhari_ecommerce/
βββ src/ # Generated Java model classes
β βββ com/acme/ecommerce/model/ # Package structure
βββ config/ # Configuration files
β βββ ecommerce_template_postgres.config # Local development config
β βββ ecommerce_template_postgres_docker.config # Docker config
β βββ ecommerce_template_postgres.config.revjdx # Local ORM spec
β βββ ecommerce_template_postgres_docker.config.revjdx # Docker ORM spec
β βββ classnames_map_ecommerce.js # Class name mappings
β βββ postgresql-XX.X.X.jar # PostgreSQL JDBC driver (download from official source)
βββ database/ # Database setup files
β βββ schema.sql # PostgreSQL schema definition
β βββ sample_data.sql # Sample data for testing
βββ bin/ # Compiled .class files
βββ logs/ # Build and runtime logs (gitignored)
βββ Dockerfile # Docker image definition
βββ gilhari_service.config # Service configuration
βββ setEnvironment.sh / setEnvironment.cmd # Environment setup (Unix/Windows)
βββ smart_reverse_engineer.sh / .cmd # Automated reverse engineering
βββ reverse_engineer.sh / .cmd # Environment-aware reverse engineering
βββ compile.sh / compile.cmd # Java compilation
βββ build_all.sh / build_all.cmd # Complete automated build
βββ populate_database.sh / .cmd # Database setup and population scripts
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ REVERSE_ENGINEERING.md # Reverse engineering guide
Follow these steps in order to get the e-commerce microservice up and running:
Ensure you have the following installed:
- Docker installed and running
- PostgreSQL Database: A running PostgreSQL instance
- Default connection:
localhost:5432 - Credentials:
postgres/<password>
- Default connection:
- Java Development Kit (JDK) 8 or higher
- Gilhari SDK installed and accessible
Windows Users: Before running any scripts, edit setEnvironment.cmd and update the JX_HOME variable to point to your Gilhari SDK installation path.
Download the PostgreSQL JDBC driver from one of these sources:
Place the JAR file (e.g., postgresql-42.7.8.jar) in the config/ directory.
Create the database and populate it with schema and sample data:
macOS/Linux/Unix:
# Create the database (if it doesn't exist)
createdb -h localhost -p 5432 -U postgres ecommerce
# Run the population script to create schema and sample data
./populate_database.shWindows:
REM Create the database (if it doesn't exist)
createdb -h localhost -p 5432 -U postgres ecommerce
REM Run the population script to create schema and sample data
populate_database.cmdCustom Connection Parameters: If your database uses different connection settings, set environment variables:
export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=ecommerce
export DB_USER=postgres
export DB_PASSWORD=your_password
./populate_database.shThis will:
- β
Create all database tables (
supplier,product,customer,address,customerorder,orderitem) - β Set up foreign key relationships
- β Create indexes for optimal performance
- β Populate database with realistic sample data (4 suppliers, 8 products, 7 customers, 9 orders, etc.)
Option A: One-Command Build (Recommended)
macOS/Linux/Unix:
cd gilhari_ecommerce
./build_all.shWindows:
cd gilhari_ecommerce
build_all.cmdThis single command handles:
- β Smart reverse engineering (analyzes database and generates Java classes)
- β Java compilation
- β Docker image build
- β Container deployment
- β Service testing
Option B: Manual Steps
macOS/Linux/Unix:
# 1. Smart reverse engineering
./smart_reverse_engineer.sh
# 2. Compile Java classes
./compile.sh
# 3. Build Docker image
docker build -t gilhari_ecommerce:1.0 .
# 4. Run container
docker run -d --name gilhari_ecommerce_container -p 8081:8081 gilhari_ecommerce:1.0Windows:
REM 1. Smart reverse engineering
smart_reverse_engineer.cmd
REM 2. Compile Java classes
compile.cmd
REM 3. Build Docker image
docker build -t gilhari_ecommerce:1.0 .
REM 4. Run container
docker run -d --name gilhari_ecommerce_container -p 8081:8081 gilhari_ecommerce:1.0Test that the microservice is running:
# Check container status
docker ps | grep gilhari_ecommerce
# Test the microservice endpoint
curl -i http://localhost:8081/gilhari/v1/getObjectModelSummary/now
# View container logs if needed
docker logs gilhari_ecommerce_containerSuccess! π Your microservice should now be running at http://localhost:8081/gilhari/v1/
The system automatically detects the environment and uses appropriate configurations:
Local Development:
JDX_DATABASE JDX:jdbc:postgresql://127.0.0.1:5432/ecommerceDocker Container:
JDX_DATABASE JDX:jdbc:postgresql://host.docker.internal:5432/ecommerceecommerce_template_postgres.config- Local development configecommerce_template_postgres_docker.config- Docker configecommerce_template_postgres.config.revjdx- Generated local ORM spececommerce_template_postgres_docker.config.revjdx- Generated Docker ORM spec
macOS/Linux/Unix:
smart_reverse_engineer.sh- Handles environment detection and creates both configsbuild_all.sh- Complete automated build pipelinereverse_engineer.sh- Environment-aware reverse engineeringcompile.sh- Java compilation with proper classpathsetEnvironment.sh- Environment setup script
Windows:
smart_reverse_engineer.cmd- Handles environment detection and creates both configsbuild_all.cmd- Complete automated build pipelinereverse_engineer.cmd- Environment-aware reverse engineeringcompile.cmd- Java compilation with proper classpathsetEnvironment.cmd- Environment setup script (updateJX_HOMEpath in file)
Once running, access the microservice at:
Base URL: http://localhost:8081/gilhari/v1/
GET /gilhari/v1/getObjectModelSummary/now # Object model overview
GET /gilhari/v1/Supplier # Supplier operations
GET /gilhari/v1/Product # Product operations
GET /gilhari/v1/Customer # Customer operations
GET /gilhari/v1/Address # Address operations
GET /gilhari/v1/CustomerOrder # Order operations
GET /gilhari/v1/OrderItem # Order item operations
| Method | Purpose | Example |
|---|---|---|
| GET | Retrieve objects | GET /gilhari/v1/Product |
| POST | Create objects | POST /gilhari/v1/Product |
| PUT | Update objects | PUT /gilhari/v1/Product |
| PATCH | Partial update | PATCH /gilhari/v1/Product |
| DELETE | Delete objects | DELETE /gilhari/v1/Product |
curl -X GET "http://localhost:8081/gilhari/v1/getObjectModelSummary/now"curl -X POST http://localhost:8081/gilhari/v1/Product \
-H "Content-Type: application/json" \
-d '{
"entity": {
"id": 1,
"sku": "LAPTOP-001",
"name": "UltraBook Pro 15",
"description": "High-performance laptop",
"category": "Electronics",
"price": 1299.99,
"stockQuantity": 45,
"supplierId": 1,
"isActive": true
}
}'curl -X GET "http://localhost:8081/gilhari/v1/Product?filter=category='Electronics'" \
-H "Content-Type: application/json"curl -X GET "http://localhost:8081/gilhari/v1/Product/getAggregate?attribute=price&aggregateType=AVG" \
-H "Content-Type: application/json"This microservice is designed to work seamlessly with the ORMCP Server for AI-powered database interactions. The object-oriented nature of the tools and the availability of the getObjectModelSummary tool help LLMs make optimized MCP tool calls.
- ORMCP Server: Running on
https://1a81a816d1d4.ngrok-free.app/mcp - Ecommerce Microservice: Running on
http://localhost:8081 - Database: PostgreSQL with complete e-commerce schema
- Object Model Summary: The
getObjectModelSummarytool provides LLMs with complete entity and relationship information - Natural Language Queries: LLMs can perform complex operations without SQL knowledge
- SQL Debugging: Set
DEBUG_LEVEL=3to monitor SQL statements generated by Gilhari/JDX - Object Navigation: Intuitive relationship traversal using generated navigation methods
The ORMCP Server can perform natural language queries like:
- "Show me all products in the Electronics category"
- "What's the average price of products from TechSupply Inc?"
- "Find all customers with Gold tier status"
- "Calculate total revenue from delivered orders"
- "Add a new product with SKU LAPTOP-002"
- Base Image:
softwaretree/gilhari - Working Directory:
/opt/gilhari_ecommerce - Port:
8081 - Environment:
GILHARI_DOCKER_MODE=1
- Local Development:
127.0.0.1:5432/ecommerce - Docker Container:
host.docker.internal:5432/ecommerce
# View running containers
docker ps
# View container logs
docker logs gilhari_ecommerce_container
# Stop container
docker stop gilhari_ecommerce_container
# Remove container
docker rm gilhari_ecommerce_containercom.acme.ecommerce.model/
βββ Address.class
βββ Customer.class
βββ CustomerOrder.class
βββ OrderItem.class
βββ Product.class
βββ Supplier.class
- ORM Specifications:
.revjdxfiles with database mappings - Service Config:
gilhari_service.config(JSON) - Class Mapping:
classnames_map_ecommerce.js
The microservice works with these PostgreSQL tables:
supplier- Product suppliersproduct- Product catalogcustomer- Customer informationaddress- Customer addressescustomerorder- Customer ordersorderitem- Order line items
Note: This section provides detailed information about database setup. For a quick start, follow Step 3: Set Up Database in the Quick Start guide above.
The easiest way to set up the database is using the provided population scripts:
macOS/Linux/Unix:
# 1. Create the database (if it doesn't exist)
createdb -h localhost -p 5432 -U postgres ecommerce
# 2. Run the population script
./populate_database.shWindows:
REM 1. Create the database (if it doesn't exist)
createdb -h localhost -p 5432 -U postgres ecommerce
REM 2. Run the population script
populate_database.cmdIf you prefer to run the SQL files manually:
-
Create database:
createdb -h localhost -p 5432 -U postgres ecommerce
-
Run schema:
psql -h localhost -p 5432 -U postgres -d ecommerce -f database/schema.sql
-
Populate sample data:
psql -h localhost -p 5432 -U postgres -d ecommerce -f database/sample_data.sql
-
Verify connection:
psql -h localhost -p 5432 -U postgres -d ecommerce
The repository includes automated scripts to set up and populate the database:
populate_database.sh(macOS/Linux/Unix) - Automated database setup scriptpopulate_database.cmd(Windows) - Automated database setup scriptdatabase/schema.sql- PostgreSQL schema definition with all tables, indexes, and triggersdatabase/sample_data.sql- Sample data including suppliers, products, customers, addresses, orders, and order items
Script Features:
- β Automatically creates all database tables
- β Sets up foreign key relationships
- β Creates indexes for optimal performance
- β Populates database with realistic sample data
- β Verifies data insertion
- β Compatible with the reverse-engineered ORM model
Custom Connection Parameters: You can customize the database connection by setting environment variables:
export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=ecommerce
export DB_USER=postgres
export DB_PASSWORD=your_password
./populate_database.shSample Data Includes:
- 4 Suppliers (TechSupply Inc, Global Electronics, Premium Goods Ltd, FastShip Distributors)
- 8 Products (Laptops, Phones, Headphones, Watches, Tablets, Mice, Keyboards, Monitors)
- 7 Customers (various tiers: Bronze, Silver, Gold, Platinum)
- 7 Addresses (one per customer)
- 9 Orders (various statuses: Pending, Processing, Shipped, Delivered)
- 17 Order Items (demonstrating complex order relationships)
macOS/Linux/Unix:
# Set up environment variables
source setEnvironment.sh
# Verify PostgreSQL connection
psql -h localhost -p 5432 -U postgres -d ecommerce -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"Windows:
REM Set up environment variables
REM Note: Edit setEnvironment.cmd to set your JX_HOME path first
call setEnvironment.cmd
REM Verify PostgreSQL connection
psql -h localhost -p 5432 -U postgres -d ecommerce -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"macOS/Linux/Unix:
# Complete rebuild
./build_all.sh
# Individual steps
./smart_reverse_engineer.sh # Auto-detects environment
./compile.sh # Compiles Java classes
docker build -t gilhari_ecommerce:1.0 . # Builds imageWindows:
REM Complete rebuild
build_all.cmd
REM Individual steps
smart_reverse_engineer.cmd REM Auto-detects environment
compile.cmd REM Compiles Java classes
docker build -t gilhari_ecommerce:1.0 . REM Builds image# Test microservice health
curl -i http://localhost:8081/gilhari/v1/getObjectModelSummary/now
# Test ORMCP server
curl -i https://1a81a816d1d4.ngrok-free.app/mcpβ
Zero Manual Configuration: No more editing database URLs
β
Environment Agnostic: Works locally and in Docker
β
One Command Build: Complete automation
β
Future Proof: Handles any environment changes
β
Error Prevention: Eliminates manual configuration mistakes
β
Docker Ready: Seamless containerization
β
ORMCP Compatible: AI-powered database interactions
Problem: Microservice fails to start
- Solution: Check container logs:
docker logs gilhari_ecommerce_container - Check: Database connectivity and credentials
Problem: Database connection errors
- Solution: Verify PostgreSQL is running and accessible
- Check: Database URL in configuration files
- Check: Ensure PostgreSQL JDBC driver JAR file is present in
config/directory- Download from PostgreSQL JDBC Downloads if missing
Problem: Build fails
- Solution: Ensure all prerequisites are installed
- Check: Environment variables and file permissions
- Check: PostgreSQL JDBC driver JAR file is in
config/directory
Problem: ORMCP Server cannot connect
- Solution: Verify microservice is running and accessible
- Check:
getObjectModelSummaryendpoint
macOS/Linux/Unix:
# Check container status
docker ps | grep gilhari_ecommerce
# View container logs
docker logs gilhari_ecommerce_container
# Test database connection
psql -h localhost -p 5432 -U postgres -d ecommerce -c "SELECT 1;"
# Test microservice endpoint
curl -i http://localhost:8081/gilhari/v1/getObjectModelSummary/now
# Enable SQL debugging (add to config file)
echo "JDX_DEBUG_LEVEL 3" >> config/ecommerce_template_postgres.configWindows:
REM Check container status
docker ps | findstr gilhari_ecommerce
REM View container logs
docker logs gilhari_ecommerce_container
REM Test database connection
psql -h localhost -p 5432 -U postgres -d ecommerce -c "SELECT 1;"
REM Test microservice endpoint
curl -i http://localhost:8081/gilhari/v1/getObjectModelSummary/now
REM Enable SQL debugging (add to config file)
echo JDX_DEBUG_LEVEL 3 >> config\ecommerce_template_postgres.configTo see how LLM queries translate to SQL statements:
- Set
DEBUG_LEVEL=3in your configuration file - Monitor the logs to see generated SQL
- This helps understand how object operations become database queries
- Reverse Engineering Guide: REVERSE_ENGINEERING.md - Detailed guide to automatic database-to-object mapping
- Gilhari SDK: Download from https://softwaretree.com
- ORMCP Server: https://github.com/SoftwareTree/ormcp-server
- PostgreSQL Documentation: https://www.postgresql.org/docs/
- Docker Documentation: https://docs.docker.com/
Ready to try it? Start with the Quick Start section above!
The automated build system ensures you can get up and running with a single command, handling all the complexity of environment detection, configuration management, and deployment automatically.
No more manual database URL changes needed! The system automatically handles:
- β
Local development (
127.0.0.1:5432) - β
Docker containers (
host.docker.internal:5432) - β Environment detection
- β Configuration management
- β Service deployment
The JDX_DATABASE configuration is now fully automated! π