# kshitijomkar/lilgiftstore architecture

> Architecture diagram of the GitHub repository kshitijomkar/lilgiftstore, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kshitijomkar/lilgiftstore
- Repository: https://github.com/kshitijomkar/lilgiftstore

## Overview

#### 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: [`nextjs-app/src/app/api/products/route.ts`](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/products/route.ts) (API route handlers), [`nextjs-app/src/lib/services/order.service.ts`](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/services/order.service.ts) (Commerce services), [`.github/workflows/ci_cd.yml`](https://github.com/kshitijomkar/lilgiftstore/blob/main/.github/workflows/ci_cd.yml) (CI/CD), [`backend/api/services/order_service.py`](https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/services/order_service.py) (Commerce services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_legacy["FastAPI stack"]
  node_react["React client<br/>SPA<br/>[App.js]"]
  node_fastapi["FastAPI server<br/>HTTP API<br/>[server.py]"]
  node_py_routes["Commerce routes<br/>route layer<br/>[products.py]"]
  node_py_services["Commerce services<br/>service layer<br/>[order_service.py]"]
  node_py_repos["Python repositories<br/>repository layer"]
end

subgraph group_next["Next.js full-stack"]
  node_next_pages["Storefront pages<br/>App Router pages<br/>[page.tsx]"]
  node_admin["Admin pages<br/>admin UI<br/>[page.tsx]"]
  node_next_api["API route handlers<br/>server API<br/>[route.ts]"]
  node_auth["Auth boundary<br/>identity middleware<br/>[auth.ts]"]
  node_next_services["Commerce services<br/>service layer<br/>[order.service.ts]"]
  node_next_repos["Next repositories<br/>repository layer"]
  node_checkout["Checkout session<br/>payment endpoint<br/>[route.ts]"]
  node_webhook["Payment webhook<br/>payment endpoint<br/>[route.ts]"]
  node_tracking["Order tracking<br/>customer endpoint<br/>[route.ts]"]
end

subgraph group_external["Data &amp; payments"]
  node_mongodb[("MongoDB<br/>system of record<br/>[db.ts]")]
  node_stripe{{"Stripe<br/>payment provider"}}
end

node_seed["Data bootstrap<br/>seed script<br/>[seed.js]"]
node_ci["CI/CD<br/>deployment workflow<br/>[ci_cd.yml]"]

node_react -->|"HTTP API"| node_fastapi
node_fastapi -->|"mounts"| node_py_routes
node_py_routes -->|"delegates"| node_py_services
node_py_services -->|"uses"| node_py_repos
node_py_repos -->|"persists"| node_mongodb
node_py_services -->|"payments"| node_stripe
node_next_pages -->|"internal /api"| node_next_api
node_admin -->|"admin /api"| node_next_api
node_next_api -->|"protects requests"| node_auth
node_next_api -->|"orchestrates"| node_next_services
node_next_services -->|"uses"| node_next_repos
node_next_repos -->|"persists"| node_mongodb
node_next_api -->|"checkout flow"| node_checkout
node_checkout -->|"creates session"| node_stripe
node_stripe -.->|"payment events"| node_webhook
node_webhook -->|"updates payment and order"| node_next_services
node_next_pages -->|"order status"| node_tracking
node_tracking -->|"reads lifecycle"| node_next_services
node_seed -.->|"initial data"| node_mongodb
node_ci -.->|"builds/deploys"| node_react
node_ci -.->|"builds/deploys"| node_fastapi
node_ci -.->|"builds/deploys"| node_next_pages

click node_react "https://github.com/kshitijomkar/lilgiftstore/blob/main/frontend/src/App.js"
click node_fastapi "https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/server.py"
click node_py_routes "https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/routes/products.py"
click node_py_services "https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/services/order_service.py"
click node_py_repos "https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/repositories/order_repository.py"
click node_next_pages "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/(site)/page.tsx"
click node_admin "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/admin/page.tsx"
click node_next_api "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/products/route.ts"
click node_auth "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/middleware/auth.ts"
click node_next_services "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/services/order.service.ts"
click node_next_repos "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/repositories/product.repository.ts"
click node_checkout "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/checkout/session/route.ts"
click node_webhook "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/payments/webhook/route.ts"
click node_tracking "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/orders/track/%5Bid%5D/route.ts"
click node_mongodb "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/db.ts"
click node_seed "https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/scripts/seed.js"
click node_ci "https://github.com/kshitijomkar/lilgiftstore/blob/main/.github/workflows/ci_cd.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_react,node_fastapi,node_py_routes,node_py_services,node_py_repos toneBlue
class node_next_pages,node_admin,node_next_api,node_auth,node_next_services,node_next_repos,node_checkout,node_webhook,node_tracking toneAmber
class node_mongodb,node_stripe toneMint
class node_seed,node_ci toneNeutral
```

## Components

### FastAPI stack

Separate Python API and React client.

- [React client](https://github.com/kshitijomkar/lilgiftstore/blob/main/frontend/src/App.js): SPA · `frontend/src/App.js`
- [FastAPI server](https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/server.py): HTTP API · Composes routes, configuration, and middleware. · `backend/server.py`
- [Commerce routes](https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/routes/products.py): route layer · `backend/api/routes/products.py`
- [Commerce services](https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/services/order_service.py): service layer · `backend/api/services/order_service.py`
- [Python repositories](https://github.com/kshitijomkar/lilgiftstore/blob/main/backend/api/repositories/order_repository.py): repository layer · `backend/api/repositories/order_repository.py`

### Next.js full-stack

App Router storefront, APIs, and admin.

- [Storefront pages](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/(site)/page.tsx): App Router pages · Customer catalog, product, and cart experiences. · `nextjs-app/src/app/(site)/page.tsx`
- [Admin pages](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/admin/page.tsx): admin UI · `nextjs-app/src/app/admin/page.tsx`
- [API route handlers](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/products/route.ts): server API · Validates requests and standardizes responses. · `nextjs-app/src/app/api/products/route.ts`
- [Auth boundary](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/middleware/auth.ts): identity middleware · Establishes identity and enforces user or role access. · `nextjs-app/src/lib/middleware/auth.ts`
- [Commerce services](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/services/order.service.ts): service layer · Orchestrates orders and payment workflows. · `nextjs-app/src/lib/services/order.service.ts`
- [Next repositories](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/repositories/product.repository.ts): repository layer · `nextjs-app/src/lib/repositories/product.repository.ts`
- [Checkout session](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/checkout/session/route.ts): payment endpoint · Validates cart and creates Stripe checkout sessions. · `nextjs-app/src/app/api/checkout/session/route.ts`
- [Payment webhook](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/payments/webhook/route.ts): payment endpoint · Applies Stripe payment events to order state. · `nextjs-app/src/app/api/payments/webhook/route.ts`
- [Order tracking](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/app/api/orders/track/%5Bid%5D/route.ts): customer endpoint · `nextjs-app/src/app/api/orders/track/[id]/route.ts`

### Data & payments

- [MongoDB](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/src/lib/db.ts): system of record · Stores commerce entities and customer state. · `nextjs-app/src/lib/db.ts`
- **Stripe**: payment provider

### Other components

- [Data bootstrap](https://github.com/kshitijomkar/lilgiftstore/blob/main/nextjs-app/scripts/seed.js): seed script · Seeds catalog and administrator data. · `nextjs-app/scripts/seed.js`
- [CI/CD](https://github.com/kshitijomkar/lilgiftstore/blob/main/.github/workflows/ci_cd.yml): deployment workflow · `.github/workflows/ci_cd.yml`

## Connections

- 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
