How amarnaath05/the-bookshelf works
Project type and purpose
• This is a full-stack e-commerce bookstore web application.
• Frontend: React.js SPA styled with Tailwind CSS and React Router for navigation.
• Backend: A mock API server implemented with MirageJS (controllers, in-memory “db”).
• Purpose: allow users to browse books by category, search, authenticate, add to wishlist/cart, checkout.
High-level file-structure analysis
• public/: static HTML and manifest.
• src/
• backend/: MirageJS mock-server
– db/: in-memory data sets (users, products, categories)
– controllers/: REST handlers (AuthController, ProductController, CartController, etc.)
– utils/: authentication helpers (JWT validation, token utilities)
• services/: client-side wrappers for API & localStorage interactions (auth-service, cart-service, etc.)
• contexts/: React Context providers and reducers for global state (Auth, Books, Filters, Address)
• components/: reusable UI pieces (product cards, buttons, loader, navbar, route guards)
• pages/: route-level containers (Home, Login, Products, Cart, Checkout, Thank You, etc.)
• layouts/: top-level layouts (RootLayout, ProductLayout)
• App.js + index.js: application entrypoint and router setup
Key insights from README
• Uses JWT-based token authentication.
• MirageJS simulates API endpoints for all CRUD operations.
• State flows through Context + Reducer + Services pattern.
• Tailwind CSS ensures responsive design.
• React Router DOM enforces protected routes via CanActivate.
Components
A. Frontend Layer
1. Browser / Client Application
– React SPA (App.js)
– React Router (public & protected routes)
2. UI Components & Layouts
– components/ & pages/
3. State Management
– Context Providers (AuthProvider, BooksProvider, AddressProvider)
– Reducers (Books, Filters)
4. Services Layer (API clients)
– auth-service.js, products-service.js, cart-service.js, wishlist-service.js, etc.
5. Local Storage Adapter
– localstorage-service.js
B. Backend (Mock API) Layer
1. MirageJS Server (initialized in src/server.js)
2. Controllers
– AuthController (login, signup, token management)
– ProductController (fetch, filter, search)
– CategoryController
– CartController
– WishlistController
3. In-Memory DB
– Collections: users, products, categories
C. External Dependencies
– JWT Decode
– UUID (for ID generation)
– Day.js (date formatting)
– React Hot Toast (notifications)
Relationships & Data Flows
1. User → Browser: interacts with UI (clicks, form submissions).
2. UI Component → Service: calls service method (e.g., productsService.getProducts()).
3. Service → MirageJS API: issues HTTP request.
4. Mirage Controller → Database: CRUD on in-memory collections.
5. Controller → Service: returns JSON payload.
6. Service → Context Reducer: dispatches action to update global state.
7. State → UI: components re-render with new data.
8. For protected routes: React Router → CanActivate → checks AuthContext token validity → allow/redirect.
Architectural patterns & principles
• Component-based UI (React)
• Context + Reducer for centralized state
• Service layer abstracts API calls
• MVC-style structure in mock backend (controllers + db)
• Clear separation of concerns
• Single-page application model with client-side routing
Detailed elements to capture
• Entrypoint: index.js → App.js
• Router configuration with protected route guard.
• Context providers wrapping App.
• Key pages (Home, ProductOverview, Cart, Checkout, Login/Signup).
• Service calls and corresponding controllers.
• In-memory DB schemas (collections).
• Utility modules (authUtils, localstorage-service).
• External libraries that impact architecture (MirageJS, JWT Decode).