A feature for a digital marketplace that allows users to gift vouchers to recipients via email or wallet address. The system uses a queue-based architecture for reliable asynchronous processing with robust retry and error handling.
- Gift vouchers via email or wallet address
- Asynchronous processing with AWS SQS
- Persistent storage with AWS DynamoDB
- Retry handling and dead-letter queue (DLQ) logic
- Detailed monitoring and metrics
- React frontend with form validation
- Comprehensive test suite using Vitest
- Comprehensive Logging on the backend
- Rate Limiting: Prevents abuse by limiting requests per IP address, with stricter limits for high-value transactions
- Amount Limits: Maximum voucher amount enforced through validation
- High-Value Confirmation: Additional confirmation required for high-value vouchers
- Idempotency: Prevents duplicate voucher creation through idempotency keys
- Input Validation: Strict validation using Zod schema
- Node.js with TypeScript
- Express.js for API endpoints
- AWS SDK v3 for SQS and DynamoDB
- Zod for input validation
- Vitest for unit testing
- Serverless architecture (Lambda-style handlers)
- React with TypeScript
- Bootstrap for UI components
- Axios for API requests
- React Testing Library for component tests
- Vitest for unit testing
- Docker and Docker Compose for local AWS emulation
- LocalStack for AWS services emulation
- Concurrently for running multiple services
- Git for version control
gift-a-voucher/
├── api/ # Backend API
│ ├── config/ # AWS configuration
│ ├── handlers/ # API and Lambda handlers
│ ├── models/ # Data models and validation
│ ├── services/ # Services for SQS and DynamoDB
│ ├── tests/ # Backend unit tests
│ │ ├── handlers/ # Handler tests
│ │ └── services/ # Service tests
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ ├── index.ts # Main Express server
│ ├── package.json # Backend dependencies
│ └── tsconfig.json # Backend TypeScript config
├── frontend/ # React frontend
│ ├── public/ # Static assets
│ ├── src/ # Source code
│ │ ├── components/ # React components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── services/ # API services
│ │ └── tests/ # Frontend unit tests
│ ├── package.json # Frontend dependencies
│ └── vite.config.ts # Vite configuration
├── public/ # Public assets
├── .env # Environment variables
├── docker-compose.yml # Docker configuration
├── init-aws-resources.sh # AWS resources setup script
├── package.json # Root package.json for monorepo
├── start.sh # Project startup script
├── tsconfig.json # TypeScript configuration
└── vitest.config.ts # Vitest configuration
The easiest way to set up and run the project is using the provided start script:
./start.shThis script will:
- Install all dependencies for both backend and frontend
- Start LocalStack using Docker Compose
- Initialize AWS resources (SQS queue and DynamoDB table)
- Start both the API and frontend concurrently
-
Install root dependencies:
npm install
-
Install API and frontend dependencies:
cd api && npm install cd ../frontend && npm install cd ..
-
Start LocalStack using Docker Compose:
npm run docker:up
-
Initialize AWS resources:
./init-aws-resources.sh
-
Start the backend and frontend:
# Start both concurrently npm run dev:all # Or start them individually npm run dev:api # Backend only npm run dev:frontend # Frontend only
- URL:
/api/vouchers/gift - Method:
POST - Request Body:
{ "recipientEmail": "recipient@example.com", // Optional if walletAddress is provided "walletAddress": "0x123...", // Optional if recipientEmail is provided "amount": 100, "message": "Happy Birthday!" // Optional } - Response:
{ "success": true, "data": { "id": "voucher-uuid", "status": "PENDING" } }
- URL:
/api/simulate/process-voucher - Method:
POST - Request Body: Same as the voucher gift message
- Response:
{ "success": true, "message": "Voucher processed successfully" }
The project includes comprehensive test suites for both the backend and frontend using Vitest.
From the root directory, you can run all tests:
npm testOr run tests for specific parts of the application:
# Backend tests only
npm run test:api
# Frontend tests only
npm run test:frontendTo generate test coverage reports:
npm run test:coverageBackend tests cover:
- DynamoDB service operations (save, get, update voucher records)
- SQS service message sending
- Voucher processing logic including retry and DLQ handling
- API handlers for voucher gifting
Frontend tests cover:
- React components (VoucherForm)
- API service module
- Form validation and submission
- Success/error modals
The API includes validation and error handling for:
- Missing required fields
- Invalid email format
- Non-positive amount values
- AWS service errors
- Retry logic for transient failures
- Dead-letter queue (DLQ) for persistent failures
The application includes monitoring capabilities:
- Structured logging with [MONITOR] and [METRICS] prefixes
- Tracking of processed, failed, retried, and DLQ messages
- Processing time measurements
For production deployment, configure the appropriate AWS credentials and environment variables for your serverless environment. The application is designed to work with AWS Lambda, SQS, and DynamoDB.