# garg-sarthak/cryptoapp architecture

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

- Interactive diagram: https://gitdiagram.com/garg-sarthak/cryptoapp
- Repository: https://github.com/garg-sarthak/cryptoapp

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (App Router), React and TypeScript.
- It appears to be a trading-style dashboard (order book, order placement, TradingView charts) with sign-in/sign-up flows, backed by a database and Redis.

##### File structure
- Top level:
- app/             – Next.js App Router: pages, layouts, global styles
- components/      – reusable UI and domain components
- db/              – database connection setup
- lib/             – shared utility functions
- prisma/          – Prisma schema and migrations
- public/          – static assets
- middleware.ts    – Next.js middleware (likely for auth or logging)
- next.config.ts   – Next.js configuration
- tailwind.config.ts, postcss.config.mjs – CSS tooling
- Under app/:
- layout.tsx       – root layout (HTML head, wrappers)
- globals.css      – global styles
- page.tsx         – home page
- sign-in/, sign-up/   – dynamic nested routes for authentication flows
- tradePage/page.tsx   – main trading dashboard
- api/a/route.ts   – an API route handler (likely for server-side operations)

##### README for additional insights
- Confirms a Next.js app bootstrapped with create-next-app.
- Uses optimized fonts via next/font.

##### Elements
- Clear labels: “Browser (React)”, “Next.js Server”, “API Route Handler”, “Prisma → PostgreSQL”, “Redis Cache”, “TradingView Embed”

##### Detailed capture recommendations
- Break the server zone into two sub-components:
1. “App Router / Page Rendering”
2. “API Route Handlers / Server Actions”
- How middleware.ts sits in front of both.
- Call out lib/utils.ts as shared business-logic utilities.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Browser (React Client)"]:::ui
        subgraph "UI Components"
            direction TB
            Button["Button"]:::ui
            Input["Input"]:::ui
            Separator["Separator"]:::ui
            Tabs["Tabs"]:::ui
        end
        subgraph "Domain Components"
            direction TB
            OrderBook["Order Book"]:::ui
            OrderPlacement["Order Placement"]:::ui
            TradingViewEmbed["TradingView Embed"]:::ui
        end
    end

    %% Server Layer
    subgraph "Server Layer (Next.js Server)" 
        direction TB
        Middleware["middleware.ts"]:::server
        subgraph "App Router / Page Rendering"
            direction TB
            RootLayout["Root Layout (app/layout.tsx)"]:::server
            GlobalStyles["Global Styles (app/globals.css)"]:::server
            HomePage["Home Page (app/page.tsx)"]:::server
            TradeDashboard["Trading Dashboard (app/tradePage/page.tsx)"]:::server
            SignInFlow["Sign-In Flow (app/sign-in/.../page.tsx)"]:::server
            SignUpFlow["Sign-Up Flow (app/sign-up/.../page.tsx)"]:::server
        end
        APIHandler["API Route Handler (app/api/a/route.ts)"]:::server
        Utils["Shared Utilities (lib/utils.ts)"]:::server
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        Database["Prisma → PostgreSQL"]:::datastore
        Redis["Redis Cache (dump.rdb)"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        TradingViewAPI["TradingView External API"]:::external
    end

    %% Relationships
    Browser -->|"uses UI Components"| Button
    Browser --> OrderBook
    Browser --> OrderPlacement
    Browser --> TradingViewEmbed
    Browser -->|navigates / fetch| Middleware
    Middleware -->|"routes to rendering"| RootLayout
    Middleware -->|"routes to API"| APIHandler
    APIHandler -->|"calls ORM"| Database
    APIHandler -->|"reads/writes"| Redis
    OrderBook -->|"fetches data"| APIHandler
    OrderPlacement -->|"submits orders"| APIHandler
    TradingViewEmbed -->|"embeds charts from"| TradingViewAPI
    Utils --> APIHandler
    Utils --> RootLayout

    %% Click Events - Client
    click Browser "https://github.com/garg-sarthak/cryptoapp/tree/main/components/"
    click Button "https://github.com/garg-sarthak/cryptoapp/blob/main/components/ui/button.tsx"
    click Input "https://github.com/garg-sarthak/cryptoapp/blob/main/components/ui/input.tsx"
    click Separator "https://github.com/garg-sarthak/cryptoapp/blob/main/components/ui/separator.tsx"
    click Tabs "https://github.com/garg-sarthak/cryptoapp/blob/main/components/ui/tabs.tsx"
    click OrderBook "https://github.com/garg-sarthak/cryptoapp/blob/main/components/orderBook.tsx"
    click OrderPlacement "https://github.com/garg-sarthak/cryptoapp/blob/main/components/orderPlace.tsx"
    click TradingViewEmbed "https://github.com/garg-sarthak/cryptoapp/blob/main/components/tradingView.tsx"

    %% Click Events - Server
    click Middleware "https://github.com/garg-sarthak/cryptoapp/blob/main/middleware.ts"
    click RootLayout "https://github.com/garg-sarthak/cryptoapp/blob/main/app/layout.tsx"
    click GlobalStyles "https://github.com/garg-sarthak/cryptoapp/blob/main/app/globals.css"
    click HomePage "https://github.com/garg-sarthak/cryptoapp/blob/main/app/page.tsx"
    click TradeDashboard "https://github.com/garg-sarthak/cryptoapp/blob/main/app/tradePage/page.tsx"
    click SignInFlow "https://github.com/garg-sarthak/cryptoapp/blob/main/app/sign-in/[[...sign-in]]/page.tsx"
    click SignUpFlow "https://github.com/garg-sarthak/cryptoapp/blob/main/app/sign-up/[[...sign-up]]/page.tsx"
    click APIHandler "https://github.com/garg-sarthak/cryptoapp/blob/main/app/api/a/route.ts"
    click Utils "https://github.com/garg-sarthak/cryptoapp/blob/main/lib/utils.ts"

    %% Click Events - Data Stores
    click Database "https://github.com/garg-sarthak/cryptoapp/blob/main/prisma/schema.prisma"
    click Database "https://github.com/garg-sarthak/cryptoapp/tree/main/prisma/migrations/"
    click Redis "https://github.com/garg-sarthak/cryptoapp/blob/main/dump.rdb"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6;
    classDef server fill:#DFFBDD,stroke:#28a745;
    classDef datastore fill:#FFE4B5,stroke:#c76a1b;
    classDef external fill:#F0F0F0,stroke-dasharray: 2 2;
```
