How adrianhajdin/ecommerce works
Main Components
• Frontend Application – Built with Next.js 14:
• This includes the user-facing pages under the src/app/(pages) directory such as account management, products, cart, checkout, login/logout, and order confirmation.
• Backend API & CMS (Payload):
• The payload folder contains collections, fields, endpoints, hooks, globals, and payload configuration files that define the CMS and e-commerce logic.
• This is where the admin dashboard and content management functionality is implemented.
• Payment Processing – Stripe Integration:
• Notice the presence of Stripe webhooks in src/payload/stripe/webhooks. These are used to update product prices, handle payment events, and sync with the ordering process.
• API Endpoints:
• Within both src/app/api and parts of the payload directory, API routes (like for preview and revalidation) are defined. These endpoints bridge the frontend with backend processing.
• External Services:
Relationships & Interactions
• Data Flow from Frontend to Backend:
• Users interact with the Next.js pages, which then communicate with internal API routes (_api) for tasks like fetching products, placing orders, or managing accounts.
• Content Management & Admin Dashboard:
• The Payload CMS is responsible for content blocks, collections (e.g., Products, Orders, Users), and is integrated with the frontend to dynamically serve page data and support an admin interface.
• Payment Processing Flow:
• The integration with Stripe ensures that when a user checks out, payment intents are created, and subsequent webhook calls update the system (e.g., update product status, order completion).
• Shared Utilities & Providers:
Important Architectural Patterns & Design Principles
• Separation of Concerns:
• Clearly separate the presentation layer (Next.js frontend/UI components) from the backend CMS logic (Payload).
• API-Driven Architecture:
• How the custom API endpoints serve as a bridge between the client UI and the backend services.
• Component-based Architecture:
• The extensive _components, _blocks, and _providers directories showcase a modular design that emphasizes reusability and maintainability.
• Microservice-Like Structure with Docker:
• With Dockerfile and docker-compose.yml provided, show containerization as part of the deployment strategy (especially for isolating environment dependencies, such as the web server, CMS backend, and potentially a database).
• A user interacts with the Next.js frontend which calls API endpoints.
• The API layer queries or updates the CMS (Payload) which in turn writes to the database.
• The checkout page communicates with Stripe for payment processing, and webhooks update both the CMS and order management systems.
• Annotations or notes that call out design patterns such as modular components, provider patterns for state management, and containerization.