The Snack Safari backend is a Node.js/Express server that powers an e-commerce platform specializing in international snacks. It provides APIs for user authentication, product management, order processing, and payment integration with Stripe.
- Firebase Authentication integration
- Stripe payment processing
- Order management system
- Product catalog with search
- Redis caching for performance
- RAG (Retrieval Augmented Generation) for product search
- PostgreSQL database with Prisma ORM
- Cloudinary integration for image storage
- Node.js/Express
- PostgreSQL
- Neon (Serverless Postgres)
- Prisma ORM
- Firebase
- Stripe
- Redis
- TypeScript
- Docker
- Cloudinary
- OpenAI
backend/
├── controllers/ # API route handlers
│ ├── stripe/ # Stripe-related controllers
│ └── ... # Other controllers
├── services/ # Business logic layer
├── prisma/ # Database schema and client
├── firebase/ # Firebase configuration & middleware
├── redis/ # Redis client setup
├── types/ # TypeScript type definitions
├── utils/ # Utility functions
├── notifications/ # Email and notification services
├── rag/ # RAG implementation
└── db_test/ # Database test data
server.ts
- Application entry pointprisma/schema.prisma
- Database schema definitionfirebase/firebaseMiddleware.ts
- Auth middlewarecontrollers/stripe/controllersPaymentIntent.ts
- Payment processingdocker-compose.yaml
- Docker services configuration.env.template
- Environment variables template
- Node.js 16+
- PostgreSQL 13+ (for local development)
- Neon Account (for production/dev database)
- Redis
- Firebase Account
- Stripe Account
- Cloudinary Account
- OpenAI API Key
- Docker (optional)
- Clone the repository
git clone <repository-url>
cd backend
- Install dependencies
npm install
# or
bun install
- Set up environment variables
cp .env.template .env
- Configure environment variables:
# Firebase
FIREBASE_TYPE=
FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_CLIENT_ID=
FIREBASE_AUTH_URI=
FIREBASE_TOKEN_URI=
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=
FIREBASE_CLIENT_X509_CERT_URL=
# Database
DATABASE_URL= # Neon production database URL
DATABASE_URL_DEV= # Local development database URL
# Cloudinary
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
# Stripe
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
# OpenAI
OPENAI_KEY=
- Start local services (optional)
# Start PostgreSQL
docker-compose -f docker-compose-db.yaml up -d
# Start Redis
docker-compose -f docker-compose-redis.yaml up -d
- Run database migrations
npx prisma generate
npx prisma migrate dev
- Start the development server
npm run dev
# or
bun run dev
# Generate Prisma Client
npx prisma generate
# Run migrations
npx prisma migrate dev
# Reset database
npx prisma migrate reset
# Open Prisma Studio
npx prisma studio
POST /auth/signup
- User registrationPOST /auth/login
- User login
POST /product/getAllProducts
- Get all productsPOST /product/getProduct
- Get single productPOST /product/getProductsFromCountry
- Get products by country
POST /order/getAllOrders
- Get all ordersPOST /order/getOrder
- Get single orderPOST /order/addOrder
- Create new orderPOST /order/updateOrder
- Update orderPOST /order/deleteOrder
- Delete order
POST /stripe/create-payment-intent
- Create payment intent
Common issues and their solutions:
-
Database connection issues:
- Check Neon connection string
- Verify network access
-
Redis connection errors:
- Ensure Redis is running
- Check Redis URL
-
Firebase authentication issues:
- Verify Firebase credentials
- Check service account configuration