DarshanCode2005/Pinch-Assignment

★ 0Forks 0JavaScriptGitHub ↗Compare

README

Ecommerce MVP

A simple mobile app where you can browse products, add them to a cart, and see your total. Built with React Native (Expo), Express, Apollo Server, GraphQL, and PostgreSQL.

What's in the repo

  • server/ - GraphQL API
  • mobile/ - React Native app (Expo Go)

What you need

  • Node.js 18 or newer
  • PostgreSQL
  • Expo Go on your phone, or an emulator

Server setup

Create the database and tables:

createdb ecommerce_mvp
psql -d ecommerce_mvp -f server/schema.sql

Copy the env file and fill in your database details:

cp server/.env.example server/.env

If you're running Postgres locally on Linux with peer auth, leave DATABASE_URL empty and use something like:

PGUSER=your_username
PGDATABASE=ecommerce_mvp
PGHOST=/var/run/postgresql

If port 4000 is taken, set PORT=4001 and update the mobile app's GraphQL URL to match.

Install, seed, and start:

cd server
npm install
npm run seed
npm start

The API will be at http://localhost:4000/graphql.

Mobile setup

Get your machine's LAN IP:

hostname -I | awk '{print $1}'

Set up the GraphQL endpoint:

cp mobile/.env.example mobile/.env

Put your LAN IP in EXPO_PUBLIC_GRAPHQL_URI, for example:

EXPO_PUBLIC_GRAPHQL_URI=http://192.168.1.11:4000/graphql

Use your LAN IP, not localhost. Your phone is a different device and can't reach localhost on your laptop.

Start the app:

cd mobile
npm install
npx expo start

Scan the QR code with Expo Go.

How the app works

  1. Open the Shop tab to see all products
  2. Tap a product to view details
  3. Tap Add to Cart to add it (no login needed)
  4. Open the Cart tab to see your items and total

Stock goes down when you add to cart and goes back up when you remove an item.

GraphQL API

  • products - list all products
  • product(id) - get one product
  • cart(sessionId) - get cart for a session
  • addToCart - add or update quantity
  • removeFromCart - remove an item

Sessions

On first launch the app creates a random ID and saves it in AsyncStorage. That ID is used as your cart session. No sign-in required.

Not included yet

Auth, payments, orders, search, product variants, push notifications, and an admin panel.

Contributors

DarshanCode2005

Issues