How macrozheng/mall-app-web works
Project Type & Purpose
• This is the front-end portion of a full-stack e-commerce system “mall” designed for mobile platforms, built on the uni-app framework.
• The project implements various e-commerce functionalities such as homepage, product listings, shopping cart, orders, member center, and more.
• It leverages Vue for UI rendering, Vuex for state management, and luch-request for HTTP communications with the back-end service.
File Structure Insights
• Top-level Files:
• App.vue, main.js, manifest.json, pages.json: Entry point and configuration files for the uni-app mobile application.
• Key Directories:
• api: Contains JavaScript files that define HTTP requests for various e-commerce operations (e.g., products, orders, member actions). This forms the abstraction layer over the back-end API (mall-portal in the corresponding back-end project).
• pages: Contains the various view layers for different sections (address management, cart, product details, user profile, etc.). This directory mirrors the different “screens” in the mobile application.
• store: Implements global state management using Vuex for maintaining shared states (e.g., shopping cart, user session, etc.).
• utils: Contains helper functions such as app configuration, date utilities, and request utilities (supporting the API interactions).
• js_sdk: Third-party SDKs that are bundled (e.g., luch-request) and integrated to handle network requests.
Architectural Components
a. Frontend Application (uni-app based)
• This is the main container that integrates the various layers.
b. UI/Presentation Layer
• Pages (e.g., index, product, cart, order, user, etc.)
• Reusable Components (from the components directory)
c. State Management Layer
• Vuex Store (manages the global state and interactions across pages)
d. Service/API Layer
• API definitions (in the api directory) that wrap the HTTP calls to the back-end.
• Integration with luch-request (from js_sdk) for network communications
e. Utility & Configuration Layer
• Common utilities (date functions, configurations, request utilities) that support the other layers.
f. Static Assets
• Resources such as images (from the static directory) and additional styling in uni.scss.
Relationships & Data Flow
• User Interaction → Pages:
• Users interact with various pages (e.g., browsing products, managing the cart). Pages are built using a combination of Vue components.
• Pages ↔ Components:
• Individual pages are composed of sub-components which encapsulate UI elements (like loading spinners, input fields, etc.).
• Pages ↔ Vuex Store:
• The pages interact with the Vuex store to get or update the global application state (e.g., cart contents, user login state).
• Pages/Components → API Layer:
• When data is needed from the back-end (such as fetching products or creating an order), pages and components call the functions defined in the api directory.
• API Layer → luch-request:
• The API calls are implemented using luch-request, handling HTTP requests and responses.
• API Layer → Backend (External):
• The API requests ultimately communicate with the separate mall back-end service. Although the back-end is not part of this project, it should be represented as an external system that the front-end relies on.
Architectural Patterns & Design Principles
• Separation of Concerns:
• The project structure clearly separates UI, state management, API logic, and configuration.
• Component-Based Design:
• The use of Vue and uni-app promotes reusability and modular design via components.
• MVVM (Model-View-ViewModel) or similar concepts:
• Views (pages/components), models (data from API and store) and business logic (utils and API abstraction) are clearly separated.
• Layered Architecture: