Cartify is a production-grade REST API designed to manage e-commerce order lifecycles and real-time inventory tracking. Built with a focus on data consistency and concurrency control in a high-traffic environment.
- Order State Machine — Strict enforcement of transitions:
PENDING→CONFIRMED→SHIPPED→DELIVERED. - Race Condition Prevention — Utilizes Pessimistic Locking to ensure stock integrity during high-concurrency checkout operations.
- Secure by Design — Stateless JWT authentication with Role-Based Access Control (RBAC) for Users and Admins.
- Audit-Ready Persistence — Soft-delete mechanism for products to maintain referential integrity in historical orders.
- Automated Inventory Sync — Real-time stock restoration on order cancellations or failures.
- Interactive API Docs — Comprehensive documentation with Swagger/OpenAPI 3.
| Layer | Technology |
|---|---|
| Backend | Java 21 (LTS), Spring Boot 3.3, Spring Security |
| Database | PostgreSQL 17, Spring Data JPA (Hibernate) |
| Testing | JUnit 5, Mockito, Testcontainers |
| Containerization | Docker & Docker Compose |
| Documentation | Swagger UI |
- Concurrency Guard: Why Pessimistic Locking? In a real-world scenario, multiple users might buy the last item simultaneously. I implemented database-level locking on the Product entity to prevent overselling.
- Data Integrity: Why Soft Deletes? Deleting a product from the database would orphan old order records. I used an
activeflag to preserve the business history while removing it from the storefront. - Reliable Testing: Why Testcontainers? Instead of H2 (which behaves differently than Postgres), I used Testcontainers to run integration tests against a real PostgreSQL instance inside Docker.
- Docker & Docker Compose installed.
git clone [https://github.com/ulasdursun/cartify.git](https://github.com/ulasdursun/cartify.git)
cd cartify
docker-compose up --build