# rushikeshg25/bidrealm architecture

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

- Interactive diagram: https://gitdiagram.com/rushikeshg25/bidrealm
- Repository: https://github.com/rushikeshg25/bidrealm

## Overview

##### Main Components
- Next Client – This is the front‑end application (built with Next.js) located under apps/client. It handles UI, user authentication (via Lucia), bid/auction interactions, and image uploads (using UploadThing).
- Express WS Server – Representing the WebSocket server (likely implemented in apps/server) that manages real‑time communication for auctions and bids. Its source files (like Auction.ts, AuctionManager.ts, and WebSocket utilities) indicate the business logic and connection management.
- PostgreSQL DB – While not a “running” component in the file tree, the packages/db directory (with its Prisma schema and migrations) shows that Postgres is used as the main database for persisting auctions, bids, and related user data.
- Redis Message Queue – As described in the README under “Message Queue,” this component is used for queuing email notifications, ensuring that notifications are processed asynchronously.
- Email Notification Worker – Found in apps/email-notification-server. It listens to the Redis message queue and uses NodeMailer to send email notifications (like winning, outbid, or auction end events).

##### Relationships and Interactions
- The Next Client communicates with the Express WS Server through WebSocket connections for real‑time updates.
- The Express WS Server handles business operations (e.g., auction creation, bid placement) and interacts with the PostgreSQL DB (via Prisma ORM) to persist data.
- Upon key auction events, the Express WS Server (or related backend logic) places messages in the Redis queue.
- The Email Notification Worker monitors the Redis queue, processes the messages, and sends emails using NodeMailer.
- Additionally, authentication flows, API requests, and image uploads involve the Next Client and backend coordination.

##### Architectural Patterns and Technologies
- The project employs real‑time communication using WebSockets, implementing a reactive UI.
- There is a separation of concerns where the client, WebSocket server, and background workers (email notifications) are modularized (visible in apps/client, apps/server, and apps/email‑notification‑server).
- Turborepo is used to manage the monorepo, organizing the apps and shared packages (such as db, env, eslint, and typescript-config).
- Use of Prisma ORM integrates the Postgres DB, and the file tree shows migration and seeding files in the db package.
- The use of services like Redis (for queuing) and UploadThing (for image uploads) should also be highlighted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        NC["Next Client"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        ES["Express WS Server"]:::backend
        ES_A["Auction.ts"]:::backend
        ES_AM["AuctionManager.ts"]:::backend
        ES_WS["WS Utils"]:::backend
        EN["Email Notification Worker"]:::worker
        %% Grouping internal server components
        ES --> ES_A
        ES --> ES_AM
        ES --> ES_WS
    end

    %% Data Layer
    subgraph "Data Layer"
        PDB["PostgreSQL DB"]:::db
        PDB_PR["Prisma Schema"]:::db
        PQ["Redis Message Queue"]:::queue
        PDB --> PDB_PR
    end

    %% Connections
    NC -->|"WebSocket/REST_calls"| ES
    ES -->|"Persists_data"| PDB
    ES -->|"Publishes_events"| PQ
    PQ -->|"Delivers_messages"| EN

    %% Click Events
    click NC "https://github.com/rushikeshg25/bidrealm/tree/master/apps/client"
    click ES "https://github.com/rushikeshg25/bidrealm/tree/master/apps/server"
    click ES_A "https://github.com/rushikeshg25/bidrealm/blob/master/apps/server/src/Auction.ts"
    click ES_AM "https://github.com/rushikeshg25/bidrealm/blob/master/apps/server/src/AuctionManager.ts"
    click ES_WS "https://github.com/rushikeshg25/bidrealm/tree/master/apps/server/src/utils"
    click PDB "https://github.com/rushikeshg25/bidrealm/tree/master/packages/db"
    click PDB_PR "https://github.com/rushikeshg25/bidrealm/tree/master/packages/db/prisma"
    click EN "https://github.com/rushikeshg25/bidrealm/tree/master/apps/email-notification-server"

    %% Styles
    classDef frontend fill:#ffebcd,stroke:#d2691e,stroke-width:2px;
    classDef backend fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef db fill:#98fb98,stroke:#006400,stroke-width:2px;
    classDef worker fill:#ffe4b5,stroke:#cd853f,stroke-width:2px;
    classDef queue fill:#ffc0cb,stroke:#db7093,stroke-width:2px;
```
