A full-stack TypeScript application demonstrating collaborative editing with Eclipse Open Collaboration Tools (OCT)
This application provides a comprehensive discount calculation system for an e-commerce platform. It enables businesses to offer tiered discounts based on customer loyalty levels, helping to reward repeat customers and VIP members.
The application is specifically designed to showcase OCT's collaborative editing capabilities across code, documentation, and configuration files.
- Node.js 18 or higher
- npm (comes with Node.js)
# 1. Install all dependencies (uses npm workspaces)
cd app
npm install
# 2. Start backend (Terminal 1)
npm run dev:backend
# ✅ Backend running on http://localhost:3001
# 3. Start frontend (Terminal 2)
npm run dev:frontend
# ✅ Frontend running on http://localhost:3000
# Or run both concurrently
npm run devOpen http://localhost:3000 in your browser and test the discount calculator.
Test via API:
curl -X POST http://localhost:3001/api/calculate-discount \
-H "Content-Type: application/json" \
-d '{"customerType": "VIP", "amount": 100}'
# Expected: {"originalAmount":100,"discountedAmount":90,"discountPercentage":10,"customerType":"VIP"}app/
├── backend/ # Express.js API server
│ ├── src/
│ │ ├── server.ts # Main server entry point
│ │ ├── discount-rules.ts # Core business logic (Act 1)
│ │ └── types.ts # TypeScript type definitions
│ ├── package.json
│ └── tsconfig.json
│
├── frontend/ # React frontend application
│ ├── src/
│ │ ├── App.tsx # Main React component
│ │ ├── App.css # Application styles
│ │ ├── main.tsx # React entry point
│ │ └── types.ts # TypeScript type definitions
│ ├── index.html
│ ├── package.json
│ ├── tsconfig.json
│ └── vite.config.ts
│
├── discount-rules.ts # Complex business logic with tiered discounts (Act 1) ⭐
├── validation-rules.ts # Business validation and edge cases (Act 4) ⭐
├── config.json # Complex nested configuration (Act 3) ⭐
├── README.md # This file with detailed examples (Act 2) ⭐
├── package.json # Root workspace configuration
└── package-lock.json # Single lock file for all dependencies
⭐ = Key files for OCT demo scenario
The system supports four customer types with sophisticated discount rules combining base discounts, tiered bonuses, and seasonal multipliers:
| Type | Base Discount | Tier Bonuses | Seasonal Multiplier | Max Total Discount | Minimum Order |
|---|---|---|---|---|---|
| REGULAR | 0% | Yes | Yes | 40% | None |
| LOYALTY | 5% | Yes | Yes | 50% | None |
| VIP | 10% | Yes | Yes | 60% | None |
| ENTERPRISE | 15% | Yes | Yes | No cap | $5,000 |
Tier bonuses are automatically applied based on order amount:
TODO
During promotional periods, base discounts are multiplied:
- Black Friday (Nov 29): 2x multiplier
- Cyber Monday (Dec 2): 2x multiplier
- Holiday Season (Dec 15-31): 1.5x multiplier
Note: Orders under $100 do not qualify for seasonal multipliers during promotional periods.
The discount system uses a sophisticated formula that combines multiple factors:
totalDiscount = (baseDiscount × seasonalMultiplier) + tierBonus
finalDiscount = min(totalDiscount, maxDiscountForCustomerType)
finalAmount = originalAmount × (1 - finalDiscount)
Key Points:
- Seasonal multiplier applies ONLY to base discount, not tier bonuses
- Tier bonuses are added after seasonal multiplication
- Final discount is capped at the maximum for each customer type
- ENTERPRISE customers have no cap
Example 1: VIP customer spending $1000 during Black Friday
- Base discount: 10%
- Seasonal multiplier: 2x (Black Friday)
- Seasonal discount: 10% × 2 = 20%
- Tier bonus: 10% (for $1000+ order)
- Total discount: 20% + 10% = 30%
- Final discount: 30% (under 60% VIP cap) ✓
- Final amount: $700 (saved $300)
Example 2: LOYALTY customer spending $1000 during Black Friday
- Base discount: 5%
- Seasonal multiplier: 2x (Black Friday)
- Seasonal discount: 5% × 2 = 10%
- Tier bonus: 10% (for $1000+ order)
- Total discount: 10% + 10% = 20%
- Final discount: 20% (under 50% LOYALTY cap) ✓
- Final amount: $800 (saved $200)
Example 3: REGULAR customer spending $1000 during Black Friday
- Base discount: 0%
- Seasonal multiplier: 2x (Black Friday)
- Seasonal discount: 0% × 2 = 0%
- Tier bonus: 10% (for $1000+ order)
- Total discount: 0% + 10% = 10%
- Final discount: 10% (under 40% REGULAR cap) ✓
- Final amount: $900 (saved $100)
Example 4: ENTERPRISE customer spending $10,000 during Holiday Season
- Base discount: 15%
- Seasonal multiplier: 1.5x (Holiday Season)
- Seasonal discount: 15% × 1.5 = 22.5%
- Tier bonus: 10% (for $1000+ order)
- Total discount: 22.5% + 10% = 32.5%
- Final discount: 32.5% (no cap for ENTERPRISE) ✓
- Final amount: $6,750 (saved $3,250)
Example 5: VIP customer spending $600 (no promotional period)
- Base discount: 10%
- Seasonal multiplier: 1x (no promotion)
- Seasonal discount: 10% × 1 = 10%
- Tier bonus: 5% (for $500-$999 order)
- Total discount: 10% + 5% = 15%
- Final discount: 15% (under 60% VIP cap) ✓
- Final amount: $510 (saved $90)
All calculations are performed server-side to ensure consistency and security.
The application includes a comprehensive promotional code system that works alongside tier discounts:
Available Promo Codes:
- WELCOME10: 10% off orders over $50
- SAVE20: $20 off orders over $100
- VIP25: 25% off for VIP/Enterprise customers (disables tier bonuses)
- BULK50: $50 off orders over $500
- FREESHIP: $15 off orders over $75 (free shipping equivalent)
Promo Code Features:
- Percentage or fixed amount discounts
- Minimum order requirements
- Customer type restrictions
- Usage limits
- Expiration dates
- Configurable stacking with tier bonuses and seasonal multipliers
Browse a comprehensive product catalog with category-based discounts:
Product Categories:
- Electronics: 5% category discount (Tech sale)
- Clothing: 10% category discount (Fashion week)
- Books: 15% category discount (Reading promotion)
- Sports: 8% category discount (Fitness month)
- Home: Standard pricing
- Toys: Standard pricing
Catalog Features:
- 10+ sample products across all categories
- Real-time stock tracking
- Category-based automatic discounts
- Product search functionality
- Price calculation with category discounts
Full-featured shopping cart with bulk discount calculations:
Cart Features:
- Add multiple products with quantities
- Automatic category discount application
- Real-time cart summary with all discounts
- Update quantities or remove items
- Persistent cart per customer
- Bulk discount calculations
Cart Summary Includes:
- Item count and subtotal
- Category discounts breakdown
- Tier bonus discounts
- Promo code discounts
- Final total with all savings
Track all customer orders with detailed information:
Order Tracking:
- Complete order history per customer
- Order date and time stamps
- Discount breakdown per order
- Savings calculation
- Promo code usage tracking
- Customer type at time of purchase
Real-time analytics showing discount system performance:
Analytics Metrics:
- Total orders processed
- Total revenue generated
- Total customer savings
- Average order value
- Average discount percentage
- Orders breakdown by customer type
Business Insights:
- Track discount effectiveness
- Monitor customer type distribution
- Analyze savings patterns
- Optimize discount strategies
Comprehensive customer profile management:
Customer Features:
- Create and manage customer profiles
- Track customer type (REGULAR, LOYALTY, VIP, ENTERPRISE)
- Lifetime statistics (total orders, total spent, lifetime savings)
- Customer search functionality
- Email-based customer lookup
- Customer notes and metadata
Discount rules are highly configurable through the config.json file, allowing business administrators to:
- Define base discounts and caps for each customer type
- Configure tier bonus thresholds and amounts
- Set up promotional periods with seasonal multipliers
- Enable/disable specific promotions without deleting configuration
- Adjust business rules for discount stacking and validation
- Set minimum order amounts for customer types
- Configure fraud prevention thresholds
The system includes comprehensive validation to ensure business policy compliance:
- Order Amount Validation: Orders must have positive amounts
- Customer Type Validation: Only valid customer types are accepted
- ENTERPRISE Minimum: Orders below $5,000 are automatically downgraded to VIP pricing
- Promotional Minimums: Orders under $100 don't qualify for seasonal multipliers
- Large Order Review: Orders over $50,000 are flagged for manual review
- Discount Stacking: Rules for combining promotional codes with tier discounts
Built with Node.js and Express, providing comprehensive RESTful endpoints:
- POST /api/calculate-discount - Calculate discount with optional promo code
Request: { "customerType": "VIP", "amount": 100, "customerId": "CUST-001", "saveToHistory": true, "promoCode": "WELCOME10" } Response: { "originalAmount": 100, "discountedAmount": 81, "discountPercentage": 19, "customerType": "VIP", "promoCodeDiscount": {...}, "warnings": [] }
- POST /api/customers - Create new customer
- GET /api/customers - List all customers (supports ?type= and ?search= filters)
- GET /api/customers/:id - Get customer details
- PUT /api/customers/:id - Update customer
- DELETE /api/customers/:id - Delete customer
- GET /api/orders - Get all orders (supports ?customerId= and ?limit= filters)
- GET /api/orders/:id - Get specific order
- DELETE /api/orders/:id - Delete order
- GET /api/stats - Get comprehensive order statistics
Response: { "totalOrders": 42, "totalRevenue": 5234.50, "totalSavings": 892.30, "averageOrderValue": 124.63, "averageDiscount": 14.2, "ordersByCustomerType": {...} }
- GET /api/promo-codes - Get all active promo codes
- POST /api/promo-codes/validate - Validate a promo code
- GET /api/products - List all products (supports ?category= and ?search= filters)
- GET /api/products/:id - Get product details
- GET /api/category-discounts - Get all category discounts
- POST /api/products/:id/calculate-price - Calculate product price with discounts
- POST /api/cart - Create or get cart for customer
- GET /api/cart/:id - Get cart details
- POST /api/cart/:id/items - Add item to cart
- PUT /api/cart/:id/items/:productId - Update item quantity
- DELETE /api/cart/:id/items/:productId - Remove item from cart
- GET /api/cart/:id/summary - Get cart summary with all discounts
- DELETE /api/cart/:id - Clear cart
- GET /health - Health check endpoint
- GET /api/customer-types - Get supported customer types
React-based single-page application with multiple views:
Calculator View:
- Intuitive discount calculator interface
- Real-time discount calculation
- Promo code input and validation
- Visual representation of discount tiers
- Responsive design for all devices
Order History View:
- Complete order history display
- Order details with discount breakdown
- Promo code usage tracking
- Chronological order listing
Promo Codes View:
- Browse all available promo codes
- View promo code details and requirements
- Copy codes for easy use
- See discount values and minimums
Analytics View:
- Real-time statistics dashboard
- Visual metrics cards
- Customer type breakdown
- Revenue and savings tracking
The core discount calculation logic is implemented in discount-rules.ts, which:
- Validates customer types
- Applies appropriate discount rates
- Handles edge cases and error conditions
- Ensures consistent discount application
Backend:
- Node.js 20
- Express.js
- TypeScript
- ts-node for development
Frontend:
- React 18
- TypeScript
- Vite (build tool)
- CSS3
Monorepo:
- npm workspaces
- Single package-lock.json
- Shared dependencies
This application is designed to demonstrate Eclipse Open Collaboration Tools through a realistic stakeholder-developer collaboration scenario.
File: discount-rules.ts
During the demo:
- Dev opens
discount-rules.tswith simple discount logic - Sta sees it instantly and discusses complex requirements over the call
- Both discuss tiered discounts, seasonal multipliers, and stacking rules
- Dev refactors the code while Sta validates business logic in real-time
- They collaboratively design the discount calculation formula
- Sta catches edge cases (ENTERPRISE customers, discount caps)
Key complexity points:
- Formula design: Should discounts add or multiply? Where do caps apply?
- Seasonal multipliers: Apply to base only or include tier bonuses?
- Customer type hierarchy: What happens when ENTERPRISE orders are too small?
- Performance considerations: Multiple calculations per order
Value demonstrated:
- Complex business logic requires immediate clarification
- Both parties contribute domain knowledge (business + technical)
- Comments become conversation medium within code
- Synchronous editing prevents misunderstandings about calculation logic
- Questions answered immediately, preventing costly rework
File: README.md (this file)
During the demo:
- Dev switches to
README.md- Sta's view follows automatically - Both create comprehensive discount matrix table with 4 customer types
- Sta adds calculation formula with multiple examples
- Dev validates technical accuracy of formulas
- They add examples that demonstrate both normal cases and cap scenarios
- Discussion about whether regular customers should get tier bonuses
Key complexity points:
- Discount matrix with multiple dimensions (base, tier, seasonal, caps)
- Calculation formula needs to be clear for non-technical readers
- Examples must cover edge cases (hitting caps, no base discount, etc.)
- Customer-facing language must be accurate and clear
Value demonstrated:
- Complex business rules require detailed documentation
- Both parties validate documentation matches implementation
- Real-time discussion catches potential misunderstandings
- Examples refined collaboratively to cover edge cases
- Stakeholder ensures customer-facing language is clear
- Developer ensures technical accuracy
File: config.json
During the demo:
- Dev switches to
config.json- Sta's view follows - Both realize simple config won't support complex requirements
- Dev restructures into nested configuration with customer types, tier bonuses, promotional periods
- Sta proposes ENTERPRISE customer type with no cap
- They add promotional period definitions (Black Friday, Cyber Monday, Holiday Season)
- Discussion about enable/disable flags vs deleting config entries
- Business rules section makes policies explicit
Key complexity points:
- Nested structure with multiple configuration sections
- Null values for "no cap" on ENTERPRISE customers
- Array of tier bonuses with thresholds
- Promotional periods with date ranges and multipliers
- Enable/disable flags for operational flexibility
- Business rules that affect calculation behavior
Value demonstrated:
- Complex nested configuration requires careful structuring
- Stakeholder proposes requirements, developer implements valid JSON
- Real-time validation prevents syntax errors
- Configuration matches code implementation
- Edge cases discussed and resolved (null for no cap, enabled flags)
- Business rules made explicit and configurable
File: validation-rules.ts (new file created during session)
During the demo:
- Dev proposes adding validation file for business rule enforcement
- Dev creates new file - Sta's view switches to it automatically
- Sta discusses validation rules over the call
- Dev implements validation logic
- Discussion about error vs warning for ENTERPRISE minimum order
- They decide to downgrade to VIP pricing instead of blocking sale
- Add fraud prevention for large orders over $50,000
- Document interaction with promotional code system
Key complexity points:
- Distinction between blocking errors and informational warnings
- Business decision: downgrade vs reject for ENTERPRISE minimum
- Fraud prevention thresholds
- Promotional period minimum order amounts
- Documentation of cross-system interactions (promo codes)
Value demonstrated:
- New file creation synchronized across participants
- Complex validation rules require discussion of edge cases
- Real-time discussion resolves ambiguities (error vs warning)
- Both parties ensure all marketing requirements covered
- Inline documentation clarifies complex interactions
Complete collaboration workflow:
- ✅ Complex tiered discount logic designed together (
discount-rules.ts) - ✅ Comprehensive documentation with examples (
README.md) - ✅ Sophisticated nested configuration (
config.json) - ✅ Business validation rules and edge cases (
validation-rules.ts) - ✅ No IDE setup required for stakeholder
- ✅ Real collaboration across 4 files with synchronized navigation
- ✅ Complex requirements finalized in one session vs days of back-and-forth
Edit config.json to customize discount rules. The configuration supports:
Define base discounts, maximum caps, and minimum order amounts for each customer type:
- REGULAR: 0% base, 40% cap
- LOYALTY: 5% base, 50% cap
- VIP: 10% base, 60% cap
- ENTERPRISE: 15% base, no cap, $5000 minimum
Configure order amount thresholds and bonus percentages:
- $500-$999: 5% bonus
- $1000+: 10% bonus
Set up seasonal promotions with date ranges and multipliers:
- Black Friday: 2x multiplier
- Cyber Monday: 2x multiplier
- Holiday Season: 1.5x multiplier
Each promotion can be enabled/disabled without deleting the configuration.
Control system behavior:
allowDiscountStacking: Enable/disable combining multiple discountsapplySeasonalToBaseOnly: Seasonal multiplier applies only to base discountlargeOrderThreshold: Amount that triggers manual reviewrequireMinimumForTierBonus: Whether tier bonuses require minimum order
# Install dependencies
npm install
# Run backend only
npm run dev:backend
# Run frontend only
npm run dev:frontend
# Run both concurrently
npm run dev
# Build both projects
npm run build
# Build specific workspace
npm run build --workspace=backend
npm run build --workspace=frontendThe system helps businesses build customer loyalty by offering automatic discounts to repeat customers. Loyalty card holders automatically get 5% off all purchases, encouraging continued engagement with the brand.
VIP customers receive premium treatment with a 10% discount, making them feel valued and incentivizing higher-tier membership.
The configurable nature of the discount system allows businesses to:
- Run promotional campaigns by adjusting discount rates
- Test different discount strategies
- Adapt to market conditions
- Maintain competitive pricing
# Kill process on port 3001 (backend)
lsof -ti:3001 | xargs kill -9
# Kill process on port 3000 (frontend)
lsof -ti:3000 | xargs kill -9# Clear npm cache
npm cache clean --force
# Remove node_modules and reinstall
rm -rf node_modules backend/node_modules frontend/node_modules
npm install# Rebuild backend
cd backend && npm run build
# Rebuild frontend
cd frontend && npm run build- Backend starts without errors
- Frontend starts without errors
- Can access UI at http://localhost:3000
- Can calculate discount for REGULAR customer
- Can calculate discount for LOYALTY customer
- Can calculate discount for VIP customer
- Can calculate discount for ENTERPRISE customer
- Tier bonuses apply correctly ($500 and $1000 thresholds)
- Seasonal multipliers work during promotional periods
- Discount caps are enforced per customer type
- ENTERPRISE customers below $5000 get VIP pricing
- Promo codes can be applied to orders
- Promo code validation works correctly
- Order history displays past orders
- Analytics dashboard shows statistics
- Product catalog displays all products
- Category discounts apply automatically
- Shopping cart can add/remove items
- Cart summary calculates all discounts
- Customer management CRUD operations work
- All four key files exist and are editable
- discount-rules.ts contains complex business logic
- validation-rules.ts has edge case handling
- config.json has nested configuration
- README.md has comprehensive documentation
- Documentation matches implementation
curl -X POST http://localhost:3001/api/calculate-discount \
-H "Content-Type: application/json" \
-d '{
"customerType": "VIP",
"amount": 150,
"customerId": "DEMO-USER-001",
"saveToHistory": true,
"promoCode": "WELCOME10"
}'curl http://localhost:3001/api/orders?customerId=DEMO-USER-001curl http://localhost:3001/api/statscurl http://localhost:3001/api/products?category=ELECTRONICScurl -X POST http://localhost:3001/api/cart \
-H "Content-Type: application/json" \
-d '{"customerId": "DEMO-USER-001", "customerType": "VIP"}'The application follows a modern full-stack architecture:
┌─────────────────────────────────────────────────────────┐
│ Frontend (React) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────┐ │
│ │Calculator│ │ Order │ │ Promo │ │Analytics│ │
│ │ View │ │ History │ │ Codes │ │Dashboard│ │
│ └──────────┘ └──────────┘ └──────────┘ └─────────┘ │
└─────────────────────────────────────────────────────────┘
│
REST API (JSON)
│
┌─────────────────────────────────────────────────────────┐
│ Backend (Express.js) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Discount │ │ Customer │ │ Order │ │
│ │ Rules │ │ Management │ │ History │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Promo Code │ │ Product │ │ Shopping │ │
│ │ Rules │ │ Catalog │ │ Cart │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────┘
│
In-Memory Storage
(Production: Database)
Potential improvements to the system include:
- Database integration (PostgreSQL/MongoDB)
- User authentication and authorization
- Payment gateway integration
- Email notifications for orders
- Advanced analytics with charts and graphs
- Export functionality for reports
- Multi-currency support
- Internationalization (i18n)
- Mobile app version
- Admin dashboard for managing discounts
- A/B testing for discount strategies
- Machine learning for personalized discounts
Potential improvements to the system include:
- Product-category-specific discounts
- Cumulative discount rules based on customer lifetime value
- Integration with inventory management
- Analytics and reporting dashboard for discount effectiveness
- Multi-currency support with exchange rates
- User authentication and authorization
- Admin panel for real-time discount management
- A/B testing for discount strategies
- Machine learning for personalized discount recommendations
- Integration with promotional code system
- Customer upgrade recommendations (e.g., LOYALTY → VIP)
- Real-time fraud detection for large orders
- ../IMPLEMENTATION-SUMMARY.md - Complete project overview at repository root
MIT
For questions or issues, please contact the development team or refer to the technical documentation in the codebase.