How nguyenthanhcong03/e-commerce works
Main Components
• Frontend (Client):
• Built using ReactJS with Vite, Tailwind CSS, and Redux for state management.
• Contains components for user interface elements (e.g., Auth, Breadcrumb, Button, Layout components like Header, Footer, SideBar, etc.).
• Organized into pages for both customer and admin functionalities (e.g., HomePage, DetailProduct, Admin Dashboard, ManageUser, etc.).
• Uses hooks and utility functions for custom behaviors (e.g., useScrollHandling, useTranslateXImage).
• Routing layer (client/src/routes) to manage navigation between pages.
• Backend (Server):
• Implements a RESTful API using Node.js.
• Follows an MVC-like pattern with separate folders for controllers, models, routes, services, middleware, and configuration.
• Controllers manage business logic for different aspects (authentication, products, customers, users).
• Models define the data schemas (e.g., product.js, user.js, customer.js) used by the database.
• Middleware handles authentication (JWT, verifyToken), error handling, validation, etc.
• Service layer for additional business logic and integrations (e.g., authService, customerService, emailService).
• Config folder contains settings for database connections (dbconnect) and mailing (mailer).
• Public folder for static assets like image uploads.
• External Services and Dependencies:
• Database: Although not explicitly named in the files, the presence of dbconnect.js suggests a connection to a database (likely MongoDB or SQL).
• Email Service: Configurations for mailing indicate integration with an email service.
• File Upload and Storage: Handled through specific routes for uploading files.
Relationships and Interactions
• Middleware processes within the server (e.g., authentication, validation, error handling) which intercept incoming requests and outgoing responses.
• Integration points such as the Email Service when a specific action (e.g., user registration or order confirmation) triggers an outgoing email.
Architectural Patterns and Principles
• Client-Side: Uses a component-based structure with separation between presentation components (UI components, pages) and state management (Redux store, slices for account, cart, etc.).
• Server-Side: Exhibits an MVC-like pattern (routes delegate to controllers, which then interact with models), with a layered approach (middleware → controllers → services/models).
• Separation of concerns, where each layer handles its specific role ensuring modularity and maintainability.