How hiteshchoudhary/image-ecommerce works
Project’s Purpose and Type
• This is a full-stack image selling application built with Next.js and React.
• It integrates with external services such as ImageKit (for image uploads), Razorpay (for payment processing), and NextAuth (for user authentication).
• It supports CRUD operations for products, user orders, and includes a component-based frontend alongside API endpoints.
File Structure
• The top-level directories and files set up configuration (e.g., .env, next.config.ts, tailwind.config.ts), and source code.
• The "app" directory contains the core Next.js pages and API endpoints. It is organized into:
• Pages for standard UI routes (e.g., “/login”, “/register”, “/products”, “/orders”, “/admin”).
• Dedicated API folders for authentication (/api/auth), image handling (/api/imagekit-auth), orders (/api/orders), products (/api/products), and Razorpay webhook (/api/webhook/razorpay).
• The "lib" directory includes utility functions and modules for API clients, authentication logic, and database access.
• The "models" directory defines the data models (User, Product, Order) that connect with the business logic.
• Additional directories such as “components” (for UI elements), “public” (static resources), and "scripts" (for database seeding and mail testing) further clarify separation of concerns.
Key Components
a. Frontend (Client Side)
• Next.js UI pages in "app" (e.g., homepage, login, register, products detail page, orders, admin).
• Reusable React components (e.g., Header, ProductCard, Notification, FileUpload, ImageGallery).
• Global styling with Tailwind CSS.
• Layout and Providers used to maintain state and handle session data via NextAuth.
b. Backend API Layer
• API endpoints handling user authentication, registration, product CRUD operations, order processing, image uploads, and payment webhook processing.
• These endpoints in the "app/api" folder handle requests and business logic.
c. External Service Integrations
• NextAuth for authentication (configured under /api/auth).
• ImageKit for image hosting and manipulation (/api/imagekit-auth).
• Razorpay to process payments and handle webhook callbacks (/api/webhook/razorpay).
d. Data and Persistence
• Database operations managed through utility functions in "lib/db" and defined models in "models".
• The models (User, Product, Order) capture the essential business entities.
Relationships and Interactions
• Frontend interacts with the backend API endpoints for data operations (authentication, product display/management, order processing).
• API endpoints communicate with the database (using models and utility functions in "lib/db") to perform CRUD operations.
• API endpoints also connect to external services:
• NextAuth for secure authentication flows.
• ImageKit for handling image uploads.
• Razorpay for payment processing and via webhook for asynchronous event handling.
• The routing structure indicates clear separation between the API layer and the component-based UI layer managed by Next.js.
Architectural Patterns and Design Principles
• Separation of concerns: UI, API, and integration layers are kept distinct.
• Modularization: Components are reusable and the API routes follow Next.js’s file-based routing.
• Security and scalability: Using middleware, environment configurations (.env files) and clear separation of public vs. private elements.