How shopstr-eng/shopstr works
Project Overview
• Shopstr is a Next.js-based, global, permissionless Nostr marketplace for Bitcoin commerce.
• The README details support for a number of Nostr Improvement Proposals (NIPs), which shows that the system is heavily integrated with the Nostr protocol (e.g., remote signing, messaging, reviews, etc.).
• The project mixes client-side UI components with server-side rendering, using Next.js pages and middleware, and integrates a rich utility layer for handling Nostr interactions.
Main Components
a. Frontend UI (Presentation Layer):
• Next.js Pages: In the “pages” directory, you see pages for various routes such as home (/pages/index.tsx), cart (/pages/cart), listing details (/pages/listing), marketplace (/pages/marketplace), wallet (/pages/wallet), settings (/pages/settings), and more.
• UI Components: The “components” folder houses many React components (e.g., product modals, forms, navigation, wallet actions, messaging panels). These further break down into submodules like “home,” “wallet,” “messages,” “utility-components,” etc.
• Hooks & Context: Custom hooks within “components/hooks” and context providers under “utils/context” for managing client-side state and routing interactions.
b. Backend / Server Logic:
• Next.js Middleware: The “middleware.ts” file suggests edge middleware logic that might handle authentication, routing, or request transformations.
• Next.js Configuration: Files like “next.config.cjs” and “pages/_document.tsx” point to SSR configurations and custom document or app-level setups.
• API or Server-Side Logic: Although not policy-separated into API routes, Next.js pages along with middleware manage server-side functionality.
c. Utility and Integration Layer:
• Nostr Integration: The “utils/nostr” directory contains modules for cache service, fetch service, helper functions, a Nostr manager, and several “signers” that deal with different remote signing methods (e.g., NIP-07, NIP-46). This is critical for interacting with the Nostr network.
• Parsers and Message Utilities: “utils/parsers” and “utils/messages” process product and review data or messaging events.
• Static Config & Constants: “utils/STATIC-VARIABLES.ts” and “utils/types” define application-wide constants and TypeScript types.
d. Configuration & Deployment:
• Dockerfile: Indicates containerization for deployment.
• Styling: “tailwind.config.ts” and “styles” indicate the use of Tailwind CSS for styling.
Relationships and Interactions
• User interactions occur via the browser, engaging with the Next.js frontend.
• UI components (in “components” and “pages”) communicate with server-side logic (middleware and page controllers) which in turn may trigger calls to the utility layer for Nostr-related interactions.
• The Nostr integration layer (under “utils/nostr”) acts as the bridge between the application logic and external Nostr services/relays.
• Custom hooks and context providers ensure state management and data sharing across the modularized UI.
• Docker, CI/CD, and configuration files are part of the deployment pipeline, ensuring that the environment is consistent and reproducible.
Architectural Patterns & Design Principles
• Modular Component-Based Architecture: There’s a clear separation of concerns across UI components, utility functions, and integration modules, leading to high cohesion and low coupling.
• Integration of External Protocols: The design leverages several Nostr protocol improvements (as evidenced by the README), suggesting a design that treats external network interactions as a first-class module.