Receipt Processor is a lightweight API backend built in Go that processes retail receipts to calculate reward points based on a set of business rules. The project is designed using an n‑tier architecture with separate layers for API handling, business logic, persistence, and middleware.
- Process Receipts: Accepts a JSON payload of receipt data, validates it, and calculates reward points according to specific rules (e.g., points per alphanumeric character in the retailer name, bonus points for round totals, etc.).
- Retrieve Points: Provides an endpoint to look up the points awarded for a processed receipt via its unique ID.
- Duplicate Prevention: Uses a hash of the receipt data to prevent storing duplicate receipts.
- Rate Limiting: Implements a sliding window rate limiter (using Redis) to throttle incoming requests.
- Logging with Context: All logs include a unique request ID, making it easier to trace requests through the system.
This project includes a Dockerfile and a Docker Compose configuration to simplify deployment. The Docker setup creates two services:
- receipt_processor: The Go API service.
- redis: A Redis service used for the rate limiter.
To run the application in Docker, use the following Makefile command:
make docker-run
This command will:
- Tear down any existing Docker Compose stack (removing images if necessary).
- Build and start the containers in detached mode.
- You can then access the API at
http://localhost:8080
Warning: Make sure both ports (8080 and 6379) are not in use.
The project includes a comprehensive set of unit and integration tests for the API, middleware, repository, and service layers. To run all tests, use:
make test
For a test coverage report (which generates a coverage.out
file and an HTML report), run:
make test-coverage
The provided Makefile includes the following targets:
-
test
Runs all tests in the project:
make test
-
Coverage
Runs tests with coverage and generates a coverage HTML report:
make test-coverage
-
Run
Builds and runs the Docker containers using Docker Compose:
make docker-run