# electrium-mobility/electrium-store architecture

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

- Interactive diagram: https://gitdiagram.com/electrium-mobility/electrium-store
- Repository: https://github.com/electrium-mobility/electrium-store

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce web application.
- Its purpose is to serve as an online shop where users can browse products, sign up/log in, add items to a cart, and complete purchases. There is also user account management (forgot/reset password, email verification) and additional pages (rentals, items, protected routes).

##### Main Components
a. Frontend Interface:
– The Next.js application in the “app” folder, which contains route handlers for pages like home, products, cart, checkout, authentication (login, signup, password management), error pages, etc.
– Layout and shared components such as “layout.tsx”, “globals.css”, and components in the “components” directory (Shop UI like Navbar, Footer, AboutUs, Header, and specialized tutorial components).

b. Backend/API and Middleware:
– API routes for authentication (e.g., “app/auth/callback/route.ts”, “app/auth/confirm/route.ts”) and other server-side actions.
– Middleware (middleware.ts and utils/supabase/middleware.ts) used to handle authentication and other request-level validations.

c. Data and External Services:
– Integration with Supabase (see “utils/supabase” with client, server files, and references in tutorial components) for functionalities like user authentication, data fetching, and storing orders.
– A potential “database” layer, even if managed externally by Supabase, that stores product, cart, and user data.

d. Utilities and Helpers:
– Utility functions (e.g., “utils/encodedRedirect.ts”, “utils/getBike.tsx”, “utils/useSessionStorage.tsx”) for common operations.
– Build and configuration files such as next.config.js, tailwind.config.ts, postcss.config.js, and tsconfig.json.

e. CI/CD and Project Configuration:
– The GitHub workflows directory (.github/workflows/nextjs.yml) which indicates automated deployment/testing procedures.
– Environment setup instructions from the README indicating local configuration (via .env) and dependency management (npm, package.json).

##### Relationships and Interactions
- The user interacts with the front end (Next.js pages and components). These pages use React for rendering UI elements and communicate with server routes for dynamic content.
- When a user initiates actions (e.g., login, signup, add to cart, checkout), the corresponding API routes (implemented in the “app/auth”, “app/products”, “app/checkout” folders) are activated.
- Server routes and middleware contact Supabase via utility functions (in “utils/supabase”) to perform authentication or data operations.
- The CI/CD pipeline (defined in GitHub workflows) ensures the project builds and deploys correctly, which ties back into overall system reliability.

##### Architectural Patterns and Key Technologies
- Next.js App Router and Server Components: The use of file-based routing to separate concerns by functionality (auth, products, checkout, etc.).
- MVC-like Separation: The “app” directory acts as contain-and-route logic (views and controllers) while “components” hold presentational logic.
- External Service Integration: Supabase is central to the data management and authentication strategy.
- Tailwind CSS for styling and GitHub Actions for workflow automation.
- Emphasis on modularity and reusability, as seen with multiple “components” directories (shop and tutorial components).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    U("User"):::utility

    %% Frontend Layer
    subgraph "Frontend Layer"
        FP1("Home Page (app/page.tsx)"):::frontend
        FP2("Layout (app/layout.tsx)"):::frontend
        FP3("Products Page (app/products)"):::frontend
        FP4("Cart Page (app/cart)"):::frontend
        FP5("Checkout Page (app/checkout)"):::frontend
        FP6("Login Page (app/login)"):::frontend
        FP7("Signup Page (app/signup)"):::frontend
        FP8("Error Page (app/error)"):::frontend

        UI1("Navbar (components/shop/Navbar.tsx)"):::frontend
        UI2("Footer (components/shop/Footer.tsx)"):::frontend
        UI3("About Us (components/shop/AboutUs.tsx)"):::frontend
        UI4("Tutorial Components (components/tutorial)"):::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        BA1("Authentication API (app/auth)"):::backend
        BA2("Auth Actions (app/action/auth.tsx)"):::backend

        BM1("Global Middleware (middleware.ts)"):::middleware
        BM2("Supabase Middleware (utils/supabase/middleware.ts)"):::middleware

        BU1("Encoded Redirect (utils/encodedRedirect.ts)"):::utility
        BU2("Get Bike (utils/getBike.tsx)"):::utility
        BU3("Session Storage Hook (utils/useSessionStorage.tsx)"):::utility
    end

    %% External Services
    subgraph "External Services"
        ES1("Supabase Client (utils/supabase/client.ts)"):::external
        ES2("Supabase Server (utils/supabase/server.ts)"):::external
    end

    %% CI/CD & Configuration
    subgraph "CI/CD & Configuration"
        CC1("GitHub Actions Workflow (.github/workflows/nextjs.yml)"):::cicd
        CC2("Next Config (next.config.js)"):::cicd
        CC3("Tailwind Config (tailwind.config.ts)"):::cicd
        CC4("PostCSS Config (postcss.config.js)"):::cicd
        CC5("TypeScript Config (tsconfig.json)"):::cicd
        CC6("Package.json (package.json)"):::cicd
    end

    %% Connections from User to Frontend
    U --> FP1

    %% Frontend to Backend/API
    FP6 -->|"calls"| BA1
    FP7 -->|"calls"| BA1
    FP5 -->|"triggers"| BA2

    %% Backend/API interactions with External Services
    BA1 -->|"auth_request"| ES1
    BA2 -->|"process_request"| ES1
    BM2 -->|"validates"| ES1

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef middleware fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef cicd fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef utility fill:#e2e3e5,stroke:#383d41,stroke-width:2px;

    %% Click Events for Frontend Interface
    click FP1 "https://github.com/electrium-mobility/electrium-store/blob/main/app/page.tsx"
    click FP2 "https://github.com/electrium-mobility/electrium-store/blob/main/app/layout.tsx"
    click FP3 "https://github.com/electrium-mobility/electrium-store/tree/main/app/products"
    click FP4 "https://github.com/electrium-mobility/electrium-store/tree/main/app/cart"
    click FP5 "https://github.com/electrium-mobility/electrium-store/tree/main/app/checkout"
    click FP6 "https://github.com/electrium-mobility/electrium-store/tree/main/app/login"
    click FP7 "https://github.com/electrium-mobility/electrium-store/tree/main/app/signup"
    click FP8 "https://github.com/electrium-mobility/electrium-store/tree/main/app/error"
    
    click UI1 "https://github.com/electrium-mobility/electrium-store/blob/main/components/shop/Navbar.tsx"
    click UI2 "https://github.com/electrium-mobility/electrium-store/blob/main/components/shop/Footer.tsx"
    click UI3 "https://github.com/electrium-mobility/electrium-store/blob/main/components/shop/AboutUs.tsx"
    click UI4 "https://github.com/electrium-mobility/electrium-store/tree/main/components/tutorial"

    %% Click Events for Backend/API and Middleware
    click BA1 "https://github.com/electrium-mobility/electrium-store/blob/main/app/auth/callback/route.ts"
    click BA2 "https://github.com/electrium-mobility/electrium-store/blob/main/app/action/auth.tsx"
    click BM1 "https://github.com/electrium-mobility/electrium-store/blob/main/middleware.ts"
    click BM2 "https://github.com/electrium-mobility/electrium-store/blob/main/utils/supabase/middleware.ts"
    click BU1 "https://github.com/electrium-mobility/electrium-store/blob/main/utils/encodedRedirect.ts"
    click BU2 "https://github.com/electrium-mobility/electrium-store/blob/main/utils/getBike.tsx"
    click BU3 "https://github.com/electrium-mobility/electrium-store/blob/main/utils/useSessionStorage.tsx"

    %% Click Events for External Services
    click ES1 "https://github.com/electrium-mobility/electrium-store/blob/main/utils/supabase/client.ts"
    click ES2 "https://github.com/electrium-mobility/electrium-store/blob/main/utils/supabase/server.ts"

    %% Click Events for CI/CD & Project Configuration
    click CC1 "https://github.com/electrium-mobility/electrium-store/blob/main/.github/workflows/nextjs.yml"
    click CC2 "https://github.com/electrium-mobility/electrium-store/blob/main/next.config.js"
    click CC3 "https://github.com/electrium-mobility/electrium-store/blob/main/tailwind.config.ts"
    click CC4 "https://github.com/electrium-mobility/electrium-store/blob/main/postcss.config.js"
    click CC5 "https://github.com/electrium-mobility/electrium-store/blob/main/tsconfig.json"
    click CC6 "https://github.com/electrium-mobility/electrium-store/blob/main/package.json"
```
