Inside `Rathi5625/AI-Grocery-Delivery`: The Grocery Clone That Prices Carbon, Not Just Cart Total

A Spring Boot and React quick-commerce build where checkout, inventory, and delivery fees are familiar, but sustainability data is treated as core product state.

8 min read • View on GitHub • More from Rathi5625

A grocery checkout counter rendered as a split mechanical ledger, with produce, detergent, and cartons moving through a scanner on one side and a second line tallying carbon impact on the other. The image explains that this project treats sustainability as something recorded during checkout, not added after the fact.
The surprise is not that this is a grocery app. It is that the receipt has two ledgers: money and impact.
Key Takeaways

The Grocery App That Also Keeps Score on Carbon

Most grocery clones chase the same three things: speed, convenience, and conversion. `Rathi5625/AI-Grocery-Delivery` does that too, but it adds a second ledger. Products carry sustainability metadata, orders preserve it, and checkout rolls it up into a `carbonSaved` metric alongside price, stock checks, and delivery fees.

The core idea is dual accounting. Money flows through one lane, impact through another, and the order keeps both intact.

What FreshAI Is, and Why It Exists

Its an AI based grocery delivery web application.

Naveen Rathi, Project Author · Rathi5625/AI-Grocery-Delivery README

This is a personal portfolio project, not a large open-source commerce platform. That matters because it changes how you read the code. The goal is not market dominance. The goal is to show full-stack range, product thinking, and a willingness to make the data model do real work.

The Data Model Makes the Thesis Real

The interesting move is not a label in the UI. It is the schema. `Product` carries fields like `sustainability_score`, `carbon_footprint`, and `freshness_days`, which means the app can treat environmental cost as durable product state instead of a one-off calculation at the end.

@Entity
public class Product {
    private String name;
    private BigDecimal price;
    private Integer stockQuantity;
    private Double sustainabilityScore;
    private Double carbonFootprint;
    private Integer freshnessDays;

    @PrePersist
    public void generateSlug() {
        this.slug = name.toLowerCase().replaceAll("[^a-z0-9]+", "-") + "-" + System.currentTimeMillis();
    }
}
A close-up ledger handoff where a product card labeled with price, stock, freshness, and carbon data slides into an order envelope. A second path branches toward delivery fee logic and impact rollup. The image explains that sustainability metadata is carried forward with the order instead of being recalculated after checkout.
The key engineering choice is simple. Preserve the fields, do not recreate them later.

Checkout as a Transaction, Not a Button Click

`OrderService` is the center of gravity. It validates stock, calculates subtotal, applies a flat delivery fee of ₹49, waives it past a ₹500 threshold, and aggregates item-level carbon footprint into the order. That is a cleaner story than a cart total in a modal. It is a transaction that decides what can ship, what it costs, and what impact it carries forward.

public Order createOrder(Long userId, List<OrderItemRequest> items) {
    validateStock(items);
    BigDecimal subtotal = calculateSubtotal(items);
    BigDecimal deliveryFee = subtotal.compareTo(new BigDecimal("500.00")) >= 0
            ? BigDecimal.ZERO
            : new BigDecimal("49.00");
    Double carbonSaved = calculateCarbonSaved(items);

    Order order = new Order();
    order.setSubtotal(subtotal);
    order.setDeliveryFee(deliveryFee);
    order.setCarbonSaved(carbonSaved);
    return orderRepository.save(order);
}

This is where the project stops being a standard cart demo. A normal clone would stop at money movement and inventory checks. Here the order object also remembers that impact exists.

Cart Sync Is the Quietly Important Part

The cart logic is stateful, and that is a good sign. Instead of letting totals drift until checkout, the app uses a `recalculateTotal()` pattern so the cart stays aligned with its child items. That reduces the chance that the final invoice becomes the first moment the app discovers a mismatch.

public void recalculateTotal(Cart cart) {
    BigDecimal total = cart.getItems().stream()
            .map(item -> item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity())))
            .reduce(BigDecimal.ZERO, BigDecimal::add);
    cart.setTotalAmount(total);
}

That detail sounds small, but it shapes the whole experience. It means the app treats cart state as living data, not a bag of numbers to be recomputed only when the user clicks checkout.

Security Is Built Like a Real App

The auth layer is practical: JWT access and refresh tokens, email-based identity, and Spring Security wiring. It is not the main attraction, but it signals that this is more than a front-end mock with fake persistence. The project is trying to behave like software that could survive real users, even if it is still clearly an early-stage build.

Token roleWhat it doesWhy it matters
Access tokenCarries user identity and rolesKeeps request authorization fast
Refresh tokenLets the session continue safelyReduces repeated logins
Email identityUses email instead of usernameFits consumer commerce better

The Stack Choice Signals the Intended Audience

The repo is a monorepo with a Spring Boot backend, a React frontend, Vite, vanilla CSS, MySQL, Maven, and npm. That combination says a lot. It is optimized for clarity and learning, not for framework fashion. You can read the flow without decoding a pile of abstraction layers.

DimensionFreshAITypical grocery cloneMature commerce platform
Product focusImpact-aware quick commerceSpeed and conversionScale, extensibility, and ops
Data modelTracks carbon and freshnessTracks price and stockUsually richer but more complex
Checkout logicFees plus carbon rollupFees and inventory onlyDeeply configurable workflows
AudienceStudent project and portfolioDemo or prototypeProduction teams
Stack shapeSpring Boot and React monorepoVaries widelyUsually enterprise-heavy

How It Compares to Real Grocery Platforms

Against Instacart, Amazon Fresh, or Walmart Grocery, this repo is obviously smaller and less mature. That is not the point. Its value is in showing how a familiar commerce flow can be re-authored around a different principle: preserve impact data as carefully as you preserve price.

Against mature open-source commerce systems like WooCommerce or Reaction Commerce, it is much narrower. But it is also much easier to understand. It demonstrates one strong idea cleanly, which is often more useful than a sprawling feature list.

What This Repo Is Really Teaching

The lesson is not “build a grocery app.” The lesson is that product philosophy can be encoded in the schema, then protected through checkout, auth, cart state, and order creation. Once that happens, carbon is no longer a dashboard afterthought. It is part of the transaction.