How kshitijomkar/lilgiftstore works
Purpose and Deployable Surfaces
The Lil Gift Corner is a gift-commerce system: catalog discovery, customer accounts, carts/wishlists, coupons, Stripe checkout, orders, reviews, contacts, custom-gift requests, and admin operations. The repository contains two application generations: a React + FastAPI stack and a fuller Next.js application with colocated API routes. Treat nextjs-app as a distinct/full-stack runtime unless deployment confirms otherwise.
• FastAPI entry point: backend/server.py
• React entry point: frontend/src/index.js, frontend/src/App.js
• Next.js application shell: nextjs-app/src/app/layout.tsx, nextjs-app/src/app/(site)/page.tsx
Legacy/Separate FastAPI API Layer
The Python backend exposes domain HTTP routes, applies dependency/configuration and middleware boundaries, then delegates persistence and selected business logic. It uses async MongoDB via Motor, Pydantic schemas, JWT/bcrypt authentication, CORS, and Stripe.
• API composition/configuration: backend/server.py, backend/api/config/settings.py, backend/api/config/database.py
• Route boundaries: backend/api/routes/auth.py, backend/api/routes/products.py, backend/api/routes/payments.py
• Cross-cutting error/logging: backend/api/middleware/error_handler.py, backend/api/middleware/logging_middleware.py
Domain Persistence and Services
Both backends model core commerce entities through repositories: products, users, carts, orders, coupons, reviews, and wishlists. Services concentrate higher-order workflows rather than putting all logic in route handlers.
• Python repositories: backend/api/repositories/product_repository.py, backend/api/repositories/order_repository.py, backend/api/repositories/cart_repository.py
• Python services: backend/api/services/auth_service.py, backend/api/services/order_service.py, backend/api/services/payment_service.py
• Next.js repositories/services: nextjs-app/src/lib/repositories/product.repository.ts, nextjs-app/src/lib/services/order.service.ts, nextjs-app/src/lib/db.ts
Next.js Full-Stack Application
The App Router serves customer and admin pages alongside server-side route handlers. Pages/components call internal /api endpoints; route handlers should enforce validation, authentication/role boundaries, service orchestration, and standardized responses before repositories access MongoDB.
• Customer storefront flows: nextjs-app/src/app/shop/page.tsx, nextjs-app/src/app/product/[id]/page.tsx, nextjs-app/src/app/cart/page.tsx
• Route-handler entry points: nextjs-app/src/app/api/products/route.ts, nextjs-app/src/app/api/cart/route.ts, nextjs-app/src/app/api/orders/route.ts
• Shared server boundaries: nextjs-app/src/lib/auth.ts, nextjs-app/src/lib/middleware/auth.ts, nextjs-app/src/lib/api-response.ts
Identity and Customer State Flow
Registration/login establishes JWT/session-based identity; protected account, cart, wishlist, order, and admin requests derive authorization from shared auth middleware/helpers. Cart handling includes anonymous-to-account merge, while wishlist and addresses remain user-scoped.
• Auth endpoints: nextjs-app/src/app/api/auth/login/route.ts, nextjs-app/src/app/api/auth/refresh/route.ts, nextjs-app/src/app/api/auth/me/route.ts
• Customer state endpoints: nextjs-app/src/app/api/cart/merge/route.ts, nextjs-app/src/app/api/wishlist/route.ts, nextjs-app/src/app/api/user/addresses/route.ts
• UI auth/session consumers: nextjs-app/src/components/auth/AuthModal.tsx, frontend/src/utils/auth.js
Checkout, Payment, and Fulfillment Flow
Checkout validates cart/items and coupon state, creates a Stripe payment/checkout session, then receives payment status or webhook events to drive payment history and order status. Refund and retry paths are explicit. Order tracking exposes fulfillment state to customers; admin users update orders and inspect analytics.
• Checkout/payment boundary: nextjs-app/src/app/api/checkout/session/route.ts, nextjs-app/src/app/api/payments/webhook/route.ts, nextjs-app/src/lib/services/payment.service.ts
• Order lifecycle: nextjs-app/src/app/api/orders/route.ts, nextjs-app/src/app/api/orders/track/[id]/route.ts, nextjs-app/src/app/api/admin/orders/status/route.ts
• Admin operations: nextjs-app/src/app/admin/page.tsx, nextjs-app/src/app/api/admin/dashboard/route.ts, nextjs-app/src/app/api/admin/analytics/route.ts
Infrastructure and Operational Dependencies
Primary runtimes are Python 3.11/FastAPI and Node.js/React or Next.js/TypeScript. MongoDB is the system of record (local or Atlas); Stripe is the external payment provider. The README describes Vercel frontend and Render FastAPI deployment, while the Next.js app has its own environment template and seed scripts.
• Environment/runtime setup: backend/requirements.txt, nextjs-app/package.json, nextjs-app/.env.example
• Data bootstrap: backend/seed_products.py, nextjs-app/scripts/seed.js, nextjs-app/scripts/seed-admin.js
• CI/CD: .github/workflows/ci_cd.yml
Main entry points: route.ts API route handlers · order.service.ts Commerce services · ci_cd.yml CI/CD · order_service.py Commerce services
Components 18
FastAPI stack
Separate Python API and React client.
- React client
frontend/src/App.js - FastAPI server · Composes routes, configuration, and middleware.
backend/server.py - Commerce routes
backend/api/routes/products.py - Commerce services
backend/api/services/order_service.py - Python repositories
backend/api/repositories/order_repository.py
Next.js full-stack
App Router storefront, APIs, and admin.
- Storefront pages · Customer catalog, product, and cart experiences.
nextjs-app/src/app/(site)/page.tsx - Admin pages
nextjs-app/src/app/admin/page.tsx - API route handlers · Validates requests and standardizes responses.
nextjs-app/src/app/api/products/route.ts - Auth boundary · Establishes identity and enforces user or role access.
nextjs-app/src/lib/middleware/auth.ts - Commerce services · Orchestrates orders and payment workflows.
nextjs-app/src/lib/services/order.service.ts - Next repositories
nextjs-app/src/lib/repositories/product.repository.ts - Checkout session · Validates cart and creates Stripe checkout sessions.
nextjs-app/src/app/api/checkout/session/route.ts - Payment webhook · Applies Stripe payment events to order state.
nextjs-app/src/app/api/payments/webhook/route.ts - Order tracking
nextjs-app/src/app/api/orders/track/[id]/route.ts
Data & payments
- MongoDB · Stores commerce entities and customer state.
nextjs-app/src/lib/db.ts - Stripe
Other components
- Data bootstrap · Seeds catalog and administrator data.
nextjs-app/scripts/seed.js - CI/CD
.github/workflows/ci_cd.yml
Connections 22
- React client → FastAPI server: HTTP API
- FastAPI server → Commerce routes: mounts
- Commerce routes → Commerce services: delegates
- Commerce services → Python repositories: uses
- Python repositories → MongoDB: persists
- Commerce services → Stripe: payments
- Storefront pages → API route handlers: internal /api
- Admin pages → API route handlers: admin /api
- API route handlers → Auth boundary: protects requests
- API route handlers → Commerce services: orchestrates
- Commerce services → Next repositories: uses
- Next repositories → MongoDB: persists
- API route handlers → Checkout session: checkout flow
- Checkout session → Stripe: creates session
- Stripe → Payment webhook: payment events
- Payment webhook → Commerce services: updates payment and order
- Storefront pages → Order tracking: order status
- Order tracking → Commerce services: reads lifecycle
- Data bootstrap → MongoDB: initial data
- CI/CD → React client: builds/deploys
- CI/CD → FastAPI server: builds/deploys
- CI/CD → Storefront pages: builds/deploys