# akhan280/radar-rules-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/akhan280/radar-rules-frontend
- Repository: https://github.com/akhan280/radar-rules-frontend

## Overview

##### Project type and purpose
- This is a full-stack Next.js (v13+) web application that lets users sign up/log in, create projects, upload CSVs, define “rules,” train models, and pay via Stripe. It uses React on the frontend, Next.js API routes for backend logic, Redux slices for client state, Prisma (with Supabase Postgres) for persistence, and Supabase for auth/session management.

##### File structure
- Top-level “app” directory follows Next.js App Router conventions:
- app/page.tsx – public landing page
- app/auth/* – sign-up, login, email-check, callback flows
- app/checkout, app/dashboard/* – private pages behind auth
- app/api/stripe/* – API handlers for creating Stripe checkout sessions and webhook endpoints
- “components” holds shared UI elements (and a nested “ui” folder for primitives)
- “lib” contains:
- db.ts / prisma.ts – Prisma client setup
- supabase-*.ts – Supabase client, server helpers & middleware
- actions/*.ts – business-logic functions called from pages & API routes
- store/*.ts – Redux toolkit slices and store
- Configuration: next.config.ts, middleware.ts (for Supabase session gating), Tailwind, ESLint, TypeScript, etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Browser)"
        direction TB
        subgraph "Page Layer"
            direction TB
            PublicLanding["Public Landing Page"]:::frontend
            AuthFlow["Auth Pages"]:::frontend
            CheckoutPage["Checkout Page"]:::frontend
            DashboardPages["Dashboard Pages"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            SharedUI["Shared UI Components"]:::frontend
            DomainUI["Domain-specific UI Components"]:::frontend
        end
        ReduxStore["Redux Store & Slices"]:::frontend
    end

    %% Server Layer
    subgraph "Next.js Server"
        direction TB
        Middleware["Supabase Middleware"]:::backend
        subgraph "Page Rendering"
            direction TB
            SSR["SSR / App Router"]:::backend
        end
        subgraph "API Layer"
            direction TB
            StripeCreate["Create Checkout Handler"]:::backend
            StripeWebhook["Stripe Webhook Handler"]:::backend
        end
        BusinessLogic["Business Logic (lib/actions)"]:::backend
    end

    %% Data & Auth Layer
    subgraph "Data & Auth"
        direction TB
        PrismaClient["Prisma ORM"]:::data
        Postgres["Supabase Postgres"]:::data
        SupabaseAuth["Supabase Auth & Session"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        StripeAPI["Stripe API"]:::external
    end

    %% Relationships
    PublicLanding -->|"SSR GET/POST"| SSR
    AuthFlow -->|"SSR GET/POST"| SSR
    CheckoutPage -->|"SSR GET/POST"| SSR
    DashboardPages -->|"SSR GET/POST"| SSR

    PublicLanding -->|client API| StripeCreate
    CheckoutPage -->|client API| StripeCreate
    DomainUI -->|dispatch actions| ReduxStore
    ReduxStore -->|calls| BusinessLogic

    SSR -->|reads middleware| Middleware
    Middleware -->|validates session| SupabaseAuth
    StripeCreate -->|uses business logic| BusinessLogic
    StripeWebhook -->|uses business logic| BusinessLogic
    BusinessLogic -->|CRUD| PrismaClient
    PrismaClient -->|SQL| Postgres
    BusinessLogic -->|auth calls| SupabaseAuth
    StripeCreate -->|REST| StripeAPI
    StripeWebhook -->|webhook| StripeAPI
    StripeAPI -->|webhook POST| StripeWebhook

    %% Click Events
    click PublicLanding "https://github.com/akhan280/radar-rules-frontend/blob/main/app/page.tsx"
    click AuthFlow "https://github.com/akhan280/radar-rules-frontend/tree/main/app/auth"
    click CheckoutPage "https://github.com/akhan280/radar-rules-frontend/blob/main/app/checkout/page.tsx"
    click DashboardPages "https://github.com/akhan280/radar-rules-frontend/tree/main/app/dashboard"
    click SharedUI "https://github.com/akhan280/radar-rules-frontend/tree/main/components/ui"
    click DomainUI "https://github.com/akhan280/radar-rules-frontend/tree/main/components"
    click ReduxStore "https://github.com/akhan280/radar-rules-frontend/blob/main/lib/store/index.ts"
    click BusinessLogic "https://github.com/akhan280/radar-rules-frontend/blob/main/lib/actions/actions.ts"
    click PrismaClient "https://github.com/akhan280/radar-rules-frontend/blob/main/prisma/schema.prisma"
    click SupabaseAuth "https://github.com/akhan280/radar-rules-frontend/blob/main/lib/supabase/supabase-client.ts"
    click Middleware "https://github.com/akhan280/radar-rules-frontend/blob/main/middleware.ts"
    click StripeCreate "https://github.com/akhan280/radar-rules-frontend/blob/main/app/api/stripe/create-checkout/route.ts"
    click StripeWebhook "https://github.com/akhan280/radar-rules-frontend/blob/main/app/api/stripe/webhook/route.ts"

    %% Styles
    classDef frontend fill:#B3E5FC,stroke:#0288D1,color:#01579B
    classDef backend fill:#C8E6C9,stroke:#2E7D32,color:#1B5E20
    classDef data fill:#FFF9C4,stroke:#F9A825,color:#F57F17
    classDef external fill:#E1BEE7,stroke:#6A1B9A,color:#4A148C
```
