# meanmachine889/memora architecture

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

- Interactive diagram: https://gitdiagram.com/meanmachine889/memora
- Repository: https://github.com/meanmachine889/memora

## Overview

##### Project type and purpose
- This is a full-stack Web3 application (“Memora”) that lets content creators mint their courses as NFT-based memberships.
- Frontend: Next.js + React + TailwindCSS + Wagmi for wallet integration.
- Backend: Vercel Serverless Functions (Next API routes) + Prisma ORM + PostgreSQL (NeonDB).
- Blockchain layer: Solidity smart contracts (ERC-721) on Ethereum, interfaced via ethers.js.
- Off-chain storage: IPFS (via Pinata) for images and metadata.

##### Key components from the file structure
- /src/app – Next.js 13+ app directory with pages, layouts, global styles.
- /src/app/api – Serverless API routes for CRUD actions (add-address, add-ipfs, create-course, etc.).
- /src/components – UI primitives and composite React components (CourseCard, NFT dialogs, sidebar, forms).
- /ethereum/abi – ABI JSON files for MemNft and MemNftFactory contracts.
- prisma/ – Database schema and migration history.
- public/ – Static assets.
- config.ts, next.config.ts – Build/runtime configuration.
- package.json, tsconfig.json – Dependencies and TypeScript config.

##### Insights from README
- Users connect wallets via MetaMask → authenticate & sign transactions (wagmi).
- Courses minted: course metadata pushed to IPFS; smart contract minted on Ethereum; membership details persisted in PostgreSQL.
- Membership transfers preserve remaining duration and update on-chain & off-chain state.
- Deployment target: Vercel (serverless), NeonDB for Postgres, Pinata for IPFS.

##### Relationships and data flows
- User → Frontend: connect wallet, fill course info →
1. → API /create-course → off-chain DB record + deploys new MemNftFactory →
2. → Ethereum network: deploy contract
- User → Frontend: mint NFT →
1. → API /add-ipfs (upload images & metadata) → IPFS
2. → Frontend triggers ethers.js contract call → mint on-chain
3. → API /add-address (record recipient, expiration) → DB
- Transfer flow: user initiates from UI → smart contract transfer → webhook/event listener (could be polled by serverless) → update DB membership expiry

##### Architectural patterns & principles
- Separation of concerns: UI vs API vs blockchain vs storage
- Event-driven updates: on-chain events update off-chain DB
- Stateless serverless functions for scalability
- ORM (Prisma) for schema-first DB migrations
- Modular UI components for reusability

##### Detailed but not overly granular
- Aggregate internal React components under “Frontend UI” with a note on “CourseCard, Sidebar, Wallet Dialog, etc.”
- API routes under “Serverless Functions (Next.js API Routes)” listing key endpoints.
- Ethers.js inside frontend & serverless functions interacting with contract ABIs.

- Captures every major piece of the Memora platform
- Clearly shows on-chain vs off-chain boundaries
- Illustrates how user actions flow through the system
- Helps stakeholders and new engineers quickly comprehend the architecture

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Browser"]:::external
        MetaMask["MetaMask / WalletConnect"]:::external
        Browser -->|"connect wallet (wagmi)"| MetaMask
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        subgraph "Frontend (src/app)"
            direction TB
            FrontendUI["Frontend UI (Next.js App)"]:::frontend
            GlobalStyles["Global Styles"]:::frontend
        end
        WalletConnector["Wallet Connector (wagmi)"]:::frontend
        FrontendUI --> WalletConnector
    end

    MetaMask -->|"signed TX"| FrontendUI
    WalletConnector -->|"HTTP (REST)"| API

    %% API Layer
    subgraph "Serverless Functions (Next.js API Routes)" 
        direction TB
        CreateCourse["POST /api/create-course"]:::api
        AddIPFS["POST /api/add-ipfs"]:::api
        AddAddress["POST /api/add-address"]:::api
        ImageIPFS["POST /api/image-ipfs"]:::api
        GetAllCourses["GET /api/get-all-courses"]:::api
        GetCourses["GET /api/get-courses"]:::api
        GetNFT["GET /api/get-nft"]:::api
    end

    API --> CreateCourse
    API --> AddIPFS
    API --> AddAddress
    API --> ImageIPFS
    API --> GetAllCourses
    API --> GetCourses
    API --> GetNFT

    CreateCourse --> Prisma
    AddAddress --> Prisma
    GetAllCourses --> Prisma
    GetCourses --> Prisma
    GetNFT --> Prisma

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Prisma["Prisma ORM"]:::db
        Postgres["PostgreSQL (NeonDB)"]:::db
        IPFS["IPFS Storage (Pinata)"]:::storage
    end

    Prisma -->|"SQL" | Postgres
    AddIPFS --> IPFS
    ImageIPFS --> IPFS

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        direction TB
        RPC["Ethereum RPC Provider\n(Infura/Alchemy)"]:::blockchain
        MemNftFactory["MemNftFactory Contract"]:::contract
        MemNft["MemNft Contract"]:::contract
    end

    FrontendUI -->|"ethers.js JSON-RPC"| RPC
    CreateCourse -->|"deploy() via ethers.js"| RPC
    AddAddress -->|"contract call"| RPC
    RPC --> MemNftFactory
    RPC --> MemNft

    %% Click Events
    click FrontendUI "https://github.com/meanmachine889/memora/tree/main/src/app"
    click GlobalStyles "https://github.com/meanmachine889/memora/blob/main/src/app/globals.css"
    click CreateCourse "https://github.com/meanmachine889/memora/blob/main/src/app/api/create-course/route.ts"
    click AddIPFS "https://github.com/meanmachine889/memora/blob/main/src/app/api/add-ipfs/route.ts"
    click AddAddress "https://github.com/meanmachine889/memora/blob/main/src/app/api/add-address/route.ts"
    click ImageIPFS "https://github.com/meanmachine889/memora/blob/main/src/app/api/image-ipfs/route.ts"
    click GetAllCourses "https://github.com/meanmachine889/memora/blob/main/src/app/api/get-all-courses/route.ts"
    click GetCourses "https://github.com/meanmachine889/memora/blob/main/src/app/api/get-courses/route.ts"
    click GetNFT "https://github.com/meanmachine889/memora/blob/main/src/app/api/get-nft/route.ts"
    click Prisma "https://github.com/meanmachine889/memora/blob/main/prisma/schema.prisma"
    click MemNftFactory "https://github.com/meanmachine889/memora/blob/main/ethereum/abi/MemNftFactory.json"
    click MemNft "https://github.com/meanmachine889/memora/blob/main/ethereum/abi/MemNft.json"
    click WalletConnector "https://github.com/meanmachine889/memora/blob/main/src/components/wallet-dialog.tsx"

    %% Styles
    classDef frontend fill:#eef6ff,stroke:#4a90e2,stroke-width:2px
    classDef api fill:#fff4e5,stroke:#f5a623,stroke-width:2px
    classDef db fill:#e9f7ef,stroke:#00a86b,stroke-width:2px
    classDef storage fill:#f0f0f0,stroke:#909090,stroke-width:2px
    classDef blockchain fill:#f5e8ff,stroke:#9b59b6,stroke-width:2px
    classDef contract fill:#f0e2ff,stroke:#8e44ad,stroke-width:2px
    classDef external fill:#ffeef0,stroke:#d73a49,stroke-width:2px
```
