Empowering Knowledge, Transforming Reading Experiences
- ๐ฏ Overview
- โจ Features
- ๐๏ธ Architecture
- ๐ Getting Started
- ๐ฆ Installation
- ๐ง Configuration
- ๐ณ Docker Deployment
- ๐ Project Structure
- ๐ Authentication
- ๐ก๏ธ Protected Routes
- ๐ง State Management
- ๐จ UI Components
- ๐ฑ Responsive Design
- ๐ Development Tools
- ๐ Scripts
- ๐ค Contributing
- ๐ License
Knowledge Store is a modern, full-stack book rental platform built with React and Vite. It offers an intuitive user experience for browsing, renting, and managing books with robust authentication, state management, and responsive design.
This project demonstrates best practices in modern web development with:
- Scalable Architecture: Modular component structure with clear separation of concerns
- Advanced Authentication: Google OAuth integration with cookie-based sessions
- State Management: Hybrid approach using Redux Toolkit and Context API
- Modern UI: Responsive design with Tailwind CSS and NextUI components
- Developer Experience: Hot reload, ESLint, and containerized deployment
- Google OAuth Integration - Seamless social login
- Email/Password Authentication - Traditional login system
- Cookie-based Sessions - Secure session management
- Protected Routes - Role-based access control
- Onboarding Flow - New user setup process
- Browse Books - Categorized book listings
- Search Functionality - Find books by title, author, or genre
- Book Preview - Detailed book information
- Wishlist - Save favorite books
- Shopping Cart - Manage book rentals
- Order Management - Track rental history
- Responsive Design - Mobile-first approach
- Dark/Light Mode - Theme switching capability
- Loading States - Smooth transitions and feedback
- Toast Notifications - Real-time user feedback
- Animated Interactions - Framer Motion animations
- Finance
- Biography
- Fictional
- Santana-Dharma
- Self-Help
- Skill-based
โโโ Redux Store (Global State)
โ โโโ Alert Slice - Notification management
โ โโโ Book Details Slice - Book data & async operations
โ
โโโ Context API (Auth & Loading)
โ โโโ AuthContext - User authentication state
โ โโโ LoadingContext - Global loading states
โ
โโโ Local State - Component-specific data
src/
โโโ Components/
โ โโโ Categories/ # Book category components
โ โโโ Features/ # Core functionality
โ โ โโโ Account/ # User profile & settings
โ โ โโโ Forms/ # Authentication forms
โ โ โโโ orders/ # Order management
โ โโโ Home/ # Landing page components
โ โโโ Navbar/ # Navigation components
โ โโโ utils/ # Shared utilities
โ
โโโ context/ # React Context providers
โโโ hooks/ # Custom React hooks
โโโ Store/ # Redux store configuration
Ensure you have the following installed:
- Node.js (v18 or higher)
- npm (v9 or higher)
- Docker (for containerized deployment)
- OS: Windows, macOS, or Linux
- Memory: 4GB RAM minimum
- Storage: 1GB free space
git clone https://github.com/lakshay2425/KnowledgeStore
cd KnowledgeStore/frontendnpm install# Copy environment template
cp .env.sample .env
# Edit .env file with your configuration
nano .envnpm run devThe application will be available at http://localhost:4000
Create a .env file in the root directory with the following variables:
# Backend API Configuration
VITE_BACKEND_URL=http://localhost:5000/api
VITE_AUTH_URL=http://localhost:5000/auth
# Frontend Configuration
VITE_FRONTEND_URL=http://localhost:4000
# Google OAuth Configuration
VITE_GOOGLE_CLIENT_ID=your_google_client_id_here
# Development Settings
VITE_DEV_MODE=false| Variable | Description | Required |
|---|---|---|
VITE_BACKEND_URL |
Main API endpoint | โ |
VITE_AUTH_URL |
Authentication service URL | โ |
VITE_FRONTEND_URL |
Frontend application URL | โ |
VITE_GOOGLE_CLIENT_ID |
Google OAuth client ID | โ |
VITE_DEV_MODE |
Skip authentication in dev | โ |
# Build production image
docker build -f Docker/Dockerfile -t knowledge-store-frontend .
# Run container
docker run -p 3000:3000 knowledge-store-frontend# Build development image
docker build -f Docker/Dockerfile.dev -t knowledge-store-dev .
# Run development container
docker run -p 4000:4000 knowledge-store-dev- Optimized Size: Production image excludes development dependencies
- Security: Non-root user execution
- Performance: Nginx serving static files
- Caching: Efficient Docker layer caching
frontend/
โโโ ๐ public/ # Static assets
โโโ ๐ src/
โ โโโ ๐ App.jsx # Main application component
โ โโโ ๐ main.jsx # Application entry point
โ โโโ ๐ index.css # Global styles
โ โโโ ๐ Components/
โ โ โโโ ๐ Categories/ # Book category components
โ โ โ โโโ BestSellers.jsx
โ โ โ โโโ Category.jsx
โ โ โ โโโ Recommended.jsx
โ โ โโโ ๐ Features/ # Core functionality
โ โ โ โโโ ๐ Account/ # User account management
โ โ โ โโโ ๐ Forms/ # Authentication forms
โ โ โ โโโ ๐ orders/ # Order management
โ โ โ โโโ BookPreview.jsx
โ โ โ โโโ Cart.jsx
โ โ โ โโโ Wishlist.jsx
โ โ โโโ ๐ Home/ # Landing page
โ โ โโโ ๐ Navbar/ # Navigation
โ โ โโโ ๐ utils/ # Utilities & helpers
โ โโโ ๐ context/ # React Context
โ โ โโโ AuthContext.jsx
โ โ โโโ LoadingContext.jsx
โ โโโ ๐ hooks/ # Custom hooks
โโโ ๐ Store/ # Redux configuration
โ โโโ store.jsx
โโโ ๐ features/ # Redux slices
โ โโโ alertSlice.js
โ โโโ bookDetailsSlice.js
โโโ ๐ Docker/ # Docker configuration
โ โโโ Dockerfile
โ โโโ Dockerfile.dev
โ โโโ .dockerignore
โโโ ๐ package.json # Dependencies & scripts
โโโ ๐ vite.config.js # Vite configuration
โโโ ๐ tailwind.config.js # Tailwind CSS config
โโโ ๐ .eslintrc.cjs # ESLint configuration
โโโ ๐ README.md # Project documentation
-
Login Options
- Email/password authentication
- Google OAuth integration
-
Session Management
- Cookie-based session storage
- Automatic session validation
- Secure token handling
-
User Onboarding
- New user profile completion
- Required information collection
- Onboarding status tracking
const AuthContext = {
isAuthenticated: boolean,
isLoading: boolean,
gmail: string,
onBoarded: boolean,
setIsAuthenticated: (boolean) => void,
setGmail: (string) => void,
setOnBoarded: (boolean) => void
}// Google Login Configuration
const handleGoogleLogin = useGoogleLogin({
onSuccess: googleResponse,
onError: handleGoogleError,
flow: "auth-code",
});The application implements a sophisticated route protection system:
const protectedRoutes = [
{
path: '/Cart',
protected: true,
requiresOnboarding: true,
fallback: '/Login',
errorMessage: "You need to login to access your Cart"
},
{
path: '/Profile',
protected: true,
requiresOnboarding: true,
fallback: '/Login',
errorMessage: "You need to login to access your profile"
}
];-
Public Routes - Accessible to all users
- Home (
/) - Category pages (
/Finance,/Biography, etc.) - Book preview (
/:bookName)
- Home (
-
Protected Routes - Require authentication
- Shopping Cart (
/Cart) - Wishlist (
/Wishlist) - User Profile (
/Profile)
- Shopping Cart (
-
Onboarding Required - Need completed user profile
- Contact Form (
/Contact) - Feedback Form (
/Feedback) - Suggestion Form (
/Suggestion)
- Contact Form (
// Skip authentication in development
if (devMode) {
return <div>{renderPage}</div>;
}store = {
alert: {
type: string,
message: string,
isVisible: boolean
},
book: {
booksInfo: Array,
genreBookInfo: Array,
recommendedBooksInfo: Array,
bookFetched: boolean,
loading: boolean
}
}// Set alert notification
dispatch(setAlert({
type: 'success',
message: 'Operation completed successfully'
}));
// Clear alert
dispatch(clearAlert());// Fetch all books
dispatch(fetchBooks());
// Filter books by genre
dispatch(filterBooks('Fiction'));
// Fetch recommended books
dispatch(fetchRecommendedBooks());AuthContext - Manages user authentication state LoadingContext - Controls global loading states
- Framework: Tailwind CSS for utility-first styling
- Component Library: NextUI for consistent UI components
- Icons: Lucide React for modern iconography
- Animations: Framer Motion for smooth interactions
{
"@nextui-org/react": "^2.4.8",
"@headlessui/react": "^1.7.18",
"@radix-ui/themes": "^3.1.4",
"framer-motion": "^11.11.11",
"lucide-react": "^0.462.0",
"react-icons": "^5.2.1"
}// Tailwind Configuration
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
"./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}"
],
theme: {
extend: {},
},
darkMode: "class",
plugins: [nextui()]
}- Mobile First: Base styles target mobile devices
- Progressive Enhancement: Larger screens add complexity
- Flexible Grid: CSS Grid and Flexbox for layouts
- Responsive Typography: Fluid text scaling
<div className="min-h-screen bg-gray-50 flex items-center justify-center p-2 sm:p-4">
<div className="bg-white rounded-xl sm:rounded-2xl p-4 sm:p-6 md:p-8 w-full max-w-[320px] sm:max-w-md shadow-lg sm:shadow-2xl">
<h2 className="text-xl sm:text-2xl font-bold text-black font-serif">
Welcome back
</h2>
</div>
</div>ESLint Configuration
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
settings: { react: { version: '18.2' } },
plugins: ['react-refresh']
}- Hot Module Replacement - Instant updates during development
- TypeScript Support - Type checking for better code quality
- Auto-formatting - Consistent code style
- Import Optimization - Automatic import organization
- Redux DevTools - State debugging
- React DevTools - Component inspection
- Vite DevTools - Build analysis
{
"dev": "vite --host --port 4000",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0"
}| Command | Description | Usage |
|---|---|---|
npm run dev |
Start development server | Development |
npm run build |
Build for production | Deployment |
npm run preview |
Preview production build | Testing |
npm run lint |
Run ESLint checks | Code quality |
# 1. Start development environment
npm run dev
# 2. Run linting (in separate terminal)
npm run lint
# 3. Build for production testing
npm run build
npm run preview
# 4. Docker development
docker-compose up -f docker-compose.dev.ymlconst [user, setUser] = useLocalStorageState("userInfo", null);const { handleSuccess, handleError } = useAlert();// Automatic credential inclusion
axios.defaults.withCredentials = true;
// Custom axios instance with interceptors
const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_BACKEND_URL,
withCredentials: true
});- CSRF Protection - Cookie-based authentication
- Input Sanitization - XSS prevention
- Route Protection - Unauthorized access prevention
- Environment Variables - Sensitive data protection
// Global error handling with toast notifications
const { handleError } = useAlert();
try {
// API operations
} catch (error) {
if (error.response?.status === 429) {
handleError("Rate limit exceeded. Please try again later.");
} else if (error.response?.status === 404) {
handleError("Resource not found");
} else {
handleError("An unexpected error occurred");
}
}- Network Errors - Connection issues
- Authentication Errors - Invalid credentials
- Authorization Errors - Insufficient permissions
- Validation Errors - Form input errors
- Rate Limiting - API throttling
- Unit Testing - Individual component testing
- Integration Testing - Component interaction testing
- E2E Testing - Full user workflow testing
- Code Splitting - Lazy loading with React.lazy()
- Bundle Optimization - Vite's efficient bundling
- Image Optimization - WebP format support
- Caching Strategy - Service worker ready
const components = {
BookPreview: lazy(() => import('./Components/Features/BookPreview')),
Home: lazy(() => import('./Components/Home/Home')),
Category: lazy(() => import('./Components/Categories/Category')),
// ... more components
};- First Contentful Paint - Initial render speed
- Largest Contentful Paint - Main content load
- Cumulative Layout Shift - Layout stability
- Time to Interactive - User interaction readiness
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Run tests and linting
npm run lint npm run test # when implemented
- Commit your changes
git commit -m 'Add some amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- Follow ESLint configuration
- Write meaningful commit messages
- Add comments for complex logic
- Maintain consistent naming conventions
- Update documentation when needed
When reporting issues, please include:
- Environment details (OS, Node version, browser)
- Steps to reproduce the issue
- Expected behavior vs actual behavior
- Screenshots if applicable
- Error messages or console logs
This project is licensed under the MIT License - see the LICENSE file for details.
- React Team - For the amazing framework
- Vite Team - For the lightning-fast build tool
- NextUI - For beautiful UI components
- Tailwind CSS - For utility-first CSS framework
- Community Contributors - For ongoing support and feedback
Built with โค๏ธ by Lakshay