# hosseinnamvar/bitex architecture

> Architecture diagram of the GitHub repository hosseinnamvar/bitex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hosseinnamvar/bitex
- Repository: https://github.com/hosseinnamvar/bitex

## Overview

##### 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.)

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Presentation Layer"
    A1["Storefront Pages<br>(Next.js, Tailwindcss)"]:::presentation
    A2["Admin Dashboard Pages<br>(Next.js, Tailwindcss)"]:::presentation
    A3["Reusable UI Components (Store)"]:::presentation
    A4["Reusable UI Components (Admin)"]:::presentation
    A5["Shared UI Components"]:::presentation
    A6["Redux Store (Client-side State)"]:::presentation
  end

  subgraph "Backend/API Layer"
    B1["API: NextAuth (Authentication)"]:::api
    B2["API: Other Endpoints"]:::api
    B3["Action Brands"]:::business
    B4["Action Categories"]:::business
    B5["Action Products"]:::business
    B6["Action Page Visits"]:::business
  end

  subgraph "Data Access Layer"
    D1["Prisma & ORM (schema.prisma, db.ts)"]:::data
    D2["MongoDB Atlas"]:::external
  end

  subgraph "External Services"
    E1["Cloudinary (Image Hosting)"]:::external
  end

  A1 -->|"fetchData"| B2
  A2 -->|"fetchData"| B2
  A1 -->|"authenticate"| B1
  A2 -->|"authenticate"| B1

  B1 -->|"triggers"| B3
  B2 -->|"callsLogic"| B3
  B2 -->|"callsLogic"| B4
  B2 -->|"callsLogic"| B5
  B2 -->|"callsLogic"| B6

  B3 -->|"CRUD"| D1
  B4 -->|"CRUD"| D1
  B5 -->|"CRUDandImageUpload"| D1
  B5 -->|"uploadImage"| E1
  B6 -->|"recordAnalytics"| D1

  D1 -->|"storesData"| D2

  A1 -->|"renderWith"| A3
  A2 -->|"renderWith"| A4
  A1 -->|"stateManagedBy"| A6

  click A1 "https://github.com/hosseinnamvar/bitex/tree/main/src/app/(store)"
  click A2 "https://github.com/hosseinnamvar/bitex/tree/main/src/app/admin"
  click A3 "https://github.com/hosseinnamvar/bitex/tree/main/src/components/store"
  click A4 "https://github.com/hosseinnamvar/bitex/tree/main/src/components/admin"
  click A5 "https://github.com/hosseinnamvar/bitex/tree/main/src/components/UI"
  click B1 "https://github.com/hosseinnamvar/bitex/blob/main/src/app/api/auth/[...nextauth]"
  click B2 "https://github.com/hosseinnamvar/bitex/tree/main/src/app/api"
  click B3 "https://github.com/hosseinnamvar/bitex/blob/main/src/actions/brands/brands.ts"
  click B4 "https://github.com/hosseinnamvar/bitex/blob/main/src/actions/category/category.ts"
  click B5 "https://github.com/hosseinnamvar/bitex/blob/main/src/actions/product/product.ts"
  click B6 "https://github.com/hosseinnamvar/bitex/blob/main/src/actions/pageVisit/pageVisitServices.ts"
  click D1 "https://github.com/hosseinnamvar/bitex/blob/main/prisma/schema.prisma"
  click D1 "https://github.com/hosseinnamvar/bitex/blob/main/src/lib/db.ts"
  click A6 "https://github.com/hosseinnamvar/bitex/tree/main/src/store"

  classDef presentation fill:#cce5ff,stroke:#004085,stroke-width:2px;
  classDef api fill:#d4edda,stroke:#155724,stroke-width:2px;
  classDef business fill:#fff3cd,stroke:#856404,stroke-width:2px;
  classDef data fill:#f8d7da,stroke:#721c24,stroke-width:2px;
  classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
