A full-stack bookstore platform with authentication, admin document ingestion, and a Retrieval-Augmented Generation (RAG) assistant for contextual Q&A.
- Overview
- Features
- Tech Stack
- Architecture
- Getting Started
- Configuration
- Running the Apps
- Docker Workflow
- API Endpoints
- Usage Examples
- Folder Structure
- Contribution
- License
Mega Book Store combines a modern React frontend with an Express + MongoDB backend and a RAG-powered chat flow. Admin users can upload PDF/DOCX content to build a searchable knowledge base, and authenticated users can ask questions that are answered from retrieved context.
- Authentication with role-based authorization (
admin,user) - Book catalog browsing and pricing display in ETB
- Admin knowledge-base ingestion pipeline (PDF/DOCX)
- Text extraction, chunking, embedding, and vector retrieval
- RAG chat API with SSE streaming support
- Graceful maintenance response when provider quota/rate limits are hit
- React 19
- TypeScript
- Vite 6
- Tailwind CSS
- Zustand
- React Router
- Node.js (ESM)
- Express 5
- MongoDB + Mongoose
- JWT authentication
- OAuth 2.0 (Google)
- Multer for uploads
- Gemini (
@google/genai) for answer generation - Voyage AI or Gemini embeddings (configurable)
- MongoDB vector search over chunk embeddings
- Admin uploads documents via
/api/admin/documents. - Server extracts and cleans text.
- Text is chunked and embedded.
- Chunks are stored in
rag_chunkswith metadata. - Chat query is embedded and matched using vector search.
- Retrieved context is passed to Gemini for final response.
- Clone the repository.
- Install dependencies for both apps.
- Configure environment variables.
- Start server and client.
Create these files:
client/.envserver/.env
You can start from the included templates:
cp client/.env.example client/.env
cp server/.env.example server/.envExample values:
# client/.env
VITE_API_BASE_URL=# server/.env
PORT=4000
CLIENT_ORIGIN=http://localhost:5173
MONGODB_URI=<your-mongodb-uri>
JWT_SECRET=<your-jwt-secret>
GEMINI_API_KEY=<your-gemini-api-key>
VOYAGE_API_KEY=<your-voyage-api-key>
EMBEDDING_PROVIDER=voyage# terminal 1
cd server
npm run dev# terminal 2
cd client
npm run devFrontend: http://localhost:5173
Run this from the project root to start everything in development mode:
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --buildTo stop it:
docker compose -f docker-compose.yml -f docker-compose.dev.yml downThis repository includes Docker support for both development and production:
docker-compose.yml(shared/base config)docker-compose.dev.yml(hot-reload development stack)docker-compose.prod.yml(optimized production stack)
- Docker Engine + Docker Compose plugin installed.
- External MongoDB connection string configured in
server/.env(MONGODB_URI).
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build- Frontend:
http://localhost:5173 - Backend:
http://localhost:4000
The dev stack uses Vite proxying (/api, /uploads) to the server container.
docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d- Frontend (Nginx):
http://localhost - Backend (direct):
http://localhost:4000
Nginx serves the frontend and reverse-proxies /api and /uploads to the backend service.
docker compose -f docker-compose.yml -f docker-compose.dev.yml down
docker compose -f docker-compose.yml -f docker-compose.prod.yml downdocker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm server npm run seed:books
docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm server npm run seed:usersPOST /api/auth/signupPOST /api/auth/loginPOST /api/auth/googleGET /api/auth/me
GET /api/books
POST /api/admin/documentsGET /api/admin/documentsDELETE /api/admin/documents/:id
POST /api/chatGET /api/chat/streamGET /api/chat/sessionsGET /api/chat/sessions/:id
Use multipart form data with field name file to upload PDF or DOCX content.
Send POST /api/chat
- Frontend: http://localhost:5173
- Backend: http://localhost:4000
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build- Frontend (Nginx): http://localhost
- Backend: http://localhost:4000
docker compose -f docker-compose.yml -f docker-compose.dev.yml down
docker compose -f docker-compose.yml -f docker-compose.prod.yml downdocker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm server npm run seed:books
docker compose -f docker-compose.yml -f docker-compose.dev.yml run --rm server npm run seed:users- Default ports: 5173 (frontend), 4000 (backend)
- Nginx reverse proxies
/apiand/uploadsin production - Ensure secrets are never committed; use
.envfiles only - MongoDB must be accessible from Docker containers
Frontend:
- React 19, TypeScript, Vite 6, Tailwind CSS, Zustand, React Router
Backend:
- Node.js (ESM), Express 5, MongoDB + Mongoose, JWT, OAuth 2.0 (Google), Multer
AI / RAG:
- Gemini (
@google/genai), Voyage AI (embeddings), MongoDB Atlas Vector Search
DevOps:
- Docker, Docker Compose, Nginx (prod)
flowchart TD
A[Admin Uploads Document] --> B[Text Extraction & Cleaning]
B --> C[Chunking & Embedding]
C --> D[Store Chunks in MongoDB]
E[User Sends Chat Query] --> F[Embed Query]
F --> G[Vector Search]
G --> H[Retrieve Top Chunks]
H --> I[Gemini LLM Generates Answer]
I --> J[Stream Response to User]
Auth Flow:
- JWT for session, Google OAuth for SSO
- Role-based access for admin endpoints
Frontend/Backend Interaction:
- REST API for CRUD, SSE for chat streaming
- Vite dev proxy in development, Nginx in production
- JWT login/signup, Google OAuth
/api/auth/signup,/api/auth/login,/api/auth/google,/api/auth/me
/api/books(search, filter, pagination)
/api/admin/documents(upload/list/delete)- PDF/DOCX ingestion, chunking, embedding
/api/chat(Q&A),/api/chat/stream(SSE)/api/chat/sessions,/api/chat/sessions/:id- Contextual retrieval, Gemini answer generation
- SSE for chat responses
oak-&-ink-bookstore/
client/ # React frontend
components/
pages/
services/
store/
...
server/ # Express API + RAG
config/
middleware/
models/
routes/
scripts/
services/
uploads/
...
docker-compose.yml
docker-compose.dev.yml
docker-compose.prod.yml
README.md
LICENSE
# Set to empty to use Vite/Nginx proxy routes (/api, /uploads)
VITE_API_BASE_URL=
# Optional, used by Vite dev proxy inside Docker dev stack
VITE_DEV_PROXY_TARGET=http://server:4000
# Optional direct key injection used by existing app config
GEMINI_API_KEY=PORT=4000
CLIENT_ORIGIN=http://localhost:5173,http://localhost
MONGODB_URI=<your-mongodb-uri>
MONGODB_DB_NAME=mega_book_store_chat
JWT_SECRET=<your-jwt-secret>
GEMINI_API_KEY=<your-gemini-api-key>
VOYAGE_API_KEY=<your-voyage-api-key>
EMBEDDING_PROVIDER=voyage
VECTOR_INDEX_NAME=chunk_vector_index
EMBEDDING_DIMENSIONS=1024
GOOGLE_CLIENT_ID=<your-google-client-id>
LOG_MEMORY=false
SEED_ADMIN_EMAIL=admin@megabookstore.com
SEED_ADMIN_PASSWORD=Admin@12345# 1. Clone the repository
git clone <repo-url>
cd oak-&-ink-bookstore
# 2. Install dependencies
cd server && npm install && cd ../client && npm install
# 3. Configure environment variables
cp ../server/.env.example ../server/.env
cp ../client/.env.example ../client/.env
# Edit .env files as needed
# 4. Start development servers
cd ../server && npm run dev
# In another terminal:
cd ../client && npm run devPOST /api/auth/signup— Register new userPOST /api/auth/login— Login with email/passwordPOST /api/auth/google— Google OAuthGET /api/auth/me— Get current user
GET /api/books— List/search books
POST /api/admin/documents— Upload document (admin)GET /api/admin/documents— List documentsDELETE /api/admin/documents/:id— Delete document
POST /api/chat— Ask question (RAG)GET /api/chat/stream— SSE chat streamGET /api/chat/sessions— List chat sessionsGET /api/chat/sessions/:id— Get session details
- REST: Standard JSON request/response
- SSE: Server-Sent Events for streaming chat answers
- User profile management
- Book purchasing & order history
- Admin analytics dashboard
- Multi-language support
- Enhanced document ingestion (more formats)
- Rate limiting & abuse prevention
- CI/CD pipeline & test coverage
License: MIT — see LICENSE
Author: Fuad Sano Contact: [conatacts.fuad@gmail.com]
