How hosseinnamvar/bitex works
Main Components
• User Interface (UI) Components:
• The storefront pages located in src/app/(store) – these represent the public-facing e-commerce site.
• The admin dashboard pages within src/app/admin – these are used for managing brands, categories, products, and tracking page visits.
• Reusable UI components in src/components and their subdivisions (for example, store UI like navbar, product page components, and admin-specific UI components).
• API and Server-Side Logic:
• The serverless API routes located within src/app/api (e.g., authentication routes using NextAuth).
• Action files in src/actions (organized by domain like brands, category, product, and pageVisits) that encapsulate business logic.
• Data and Persistence:
• Prisma schema (prisma/schema.prisma) tying into MongoDB Atlas.
• Database connections and utilities in src/lib (e.g., db.ts) handling ORM interactions.
• External Services and Supporting Tools:
• NextAuth for authentication with API endpoints.
• Redux for client-side state management in the storefront.
• External services like Cloudinary (for product image hosting) and MongoDB Atlas.
Relationships and Interactions Between Components
• User Interaction:
• Users navigate through the e-commerce store (public pages) and are served assets from the public directory.
• Admin users log in via the authentication system (NextAuth) and interact with the admin pages for CRUD operations on products, brands, and categories.
• Frontend to Backend Communication:
• Frontend pages (both storefront and admin) call API endpoints (located under src/app/api) for authentication, data retrieval, and updates.
• Business logic is implemented within src/actions, which mediate data flow between the UI and the database.
• Data Management:
• Database interactions are managed via Prisma in conjunction with MongoDB.
• The Redux store on the storefront manages client-side states like the shopping cart.
• Static Assets and Styling:
Important Architectural Patterns and Design Principles
• Clear Separation of Concerns:
• Frontend (React components, pages) and backend (API routes, business logic in actions, database layer) are distinctly separated.
• The admin side is isolated from the storefront, each in its own sub-directory structure.
• Server-Side Rendering and API Routes:
• Next.js is used to handle both page rendering and API endpoints seamlessly.
• Modularization:
• The project employs modularity by organizing components, actions, and type definitions into separate folders, facilitating maintainability and scalability.
• Authentication and Authorization:
• Secure access to admin dashboards via NextAuth.
• State Management:
• Use of Redux for dynamic interactions in the storefront (shopping cart management, filters, etc.)