This document outlines the high-level architecture and implementation plan for the Bookstore API frontend, designed to meet enterprise standards for performance, scalability, and premium user experience.
| Layer | Technology | Rationale |
|---|---|---|
| Core Framework | Next.js 15 (App Router) | Server-Side Rendering (SSR) for SEO, Static Site Generation (SSG) for book pages, and optimized performance. |
| Language | TypeScript | Type safety across the boundary (shared DTO contracts with backend). |
| Styling | Tailwind CSS + Shadcn UI | Rapid development with a consistent, accessible, and premium design system. |
| State Management | TanStack Query (React Query) | Robust server state management, caching, and optimistic UI updates for carts and wishlists. |
| Forms/Validation | React Hook Form + Zod | Type-safe form validation matching backend domain constraints. |
| Auth | NextAuth.js / Auth.js | Seamless JWT integration with the existing .NET identity flow. |
| Icons | Lucide React | Clean, consistent iconography. |
We will follow a Feature-Based Module structure to ensure maintainability as the application grows.
src/
├── app/ # Next.js App Router (Pages & Layouts)
├── components/ # Shared UI components (Atomic Design)
│ ├── ui/ # Base Shadcn components
│ └── shared/ # Business-agnostic shared components (Header, Footer, Button)
├── features/ # Business Logic & Feature-specific components
│ ├── auth/ # Login, Register, Profile logic
│ ├── books/ # Catalog, Search, Book Detail, Admin Management
│ ├── cart/ # Shopping Cart drawer, logic, and persistence
│ ├── orders/ # Checkout flow, order history
│ └── wishlist/ # Wishlist toggles and management
├── hooks/ # Global reusable hooks
├── lib/ # Service clients (Axios/Fetch with JWT interceptors)
├── store/ # Unified state management (Zustand for client state)
└── types/ # TypeScript interfaces mapped from C# DTOs
- Action: Adding a book to the cart or wishlist.
- Frontend Strategy: Immediately update the UI state locally using TanStack Query, then sync with the API. Roll back only if the server returns an error. No "waiting" spinners for simple actions.
- Multi-dimensional filters (Category, Price Range, Author).
- Real-time debounced search using the
/api/books/search/{title}endpoint. - Infinite scroll or smart pagination for the book catalog.
- Validation: Real-time stock check before payment.
- Persistence: Cart recovery via database sync (logged-in) or local storage (guest).
- Security: Strict route protection via Next.js Middleware.
- Inventory Management: File upload integration for book covers using the
POST /api/books/{id:guid}/covermultipart endpoint. - Analytics: Visualization of recent order status and inventory alerts.
- Set up Next.js project with strict TypeScript.
- Implementation of the Global Design System (HSL colors, Glassmorphism, premium typography like Inter or Outfit).
- Configure Axios Interceptors to automatically attach JWT Bearer tokens from
localStorage/cookies.
- Map all C# DTOs into TypeScript Interfaces.
- Example:
export interface BookResponseDto { id: string; title: string; isbn: string; price: number; stockQuantity: number; coverImageUrl?: string; categoryName: string; }
- Authentication: Register/Login logic with role-based routing (Admin vs User).
- Catalog: Book listing with server-side pagination.
- Cart & Wishlist: Context-aware UI items (badges, side drawers).
- Reviews: Interactive rating system leveraging the
api/books/{id}/reviewsendpoints.
- Image Optimization: Using
next/imagewith blur-up placeholders for book covers. - Prefetching: Prefetching book details on hover for "instant" navigation.
- Caching: 60-second SWR (Stale-While-Revalidate) for public catalog pages.
- Unit Tests: Vitest + React Testing Library for core business logic.
- E2E Tests: Playwright for the critical "Happy Path" (Search -> Add to Cart -> Checkout).
- Compliance: Lighthouse score targets: 95+ on Accessibility, Best Practices, and SEO.
- Platform: Vercel (recommended) or Dockerized on AWS/Azure.
- Environment Management:
.env.productionpointing to the .NET APIhttps://api.bookstore.com. - CI/CD: Automatic branch previews and Vercel edge-caching configuration.
Prepared By: Senior Frontend Lead
Status: Architecture Approved
Alignment: Fully synced with Bookstore API v1.0.0