# swarajbachu/resubs architecture

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

- Interactive diagram: https://gitdiagram.com/swarajbachu/resubs
- Repository: https://github.com/swarajbachu/resubs

## Overview

##### Project type and purpose
- Resubs is a full‑stack web application for subscription tracking.
- Built with Next.js and React on the frontend, Edge‑hosted on Cloudflare Pages, with a Cloudflare D1 database and NextAuth.js for authentication.

##### File structure
- Top‑level:
- next.config.mjs, postcss.config.mjs, tailwind.config.ts, tsconfig.json → build and styling configurations
- wrangler.toml → Cloudflare Pages / Workers configuration
- drizzle.config.ts and drizzle/… → database migration scripts and metadata
- public/ → static assets (logos, images)
- src/app/ → Next.js App Router pages and API routes
- src/components/ → reusable UI, dashboard, analytics, calendar, and logo components
- src/hooks/, src/lib/ → shared hooks and utilities
- src/server/ → server‑side actions, authentication, and database schema/connection
- Architectural pattern:
- Next.js App Router (React components + server components)
- Edge‑deployed Serverless functions for APIs (NextAuth, hello endpoint)
- Drizzle ORM for migrations and database access

##### README insights
- Hosted on Cloudflare Pages (Edge network)
- Uses Cloudflare D1 (SQLite‑compatible) for data storage
- NextAuth.js with Google OAuth
- Tailwind CSS styling

##### Elements
- Clear labels for each component (e.g., “Next.js Edge Function”, “D1 Database”)
- Request flow: Browser → CDN → Edge function → Database → Edge function → Browser
- OAuth flow: Browser → Google → Edge function → Browser
- Green for server/edge functions
- Grey cloud for external OAuth

##### Detailed capture of essential architecture
- Do not over‑partition; use logical layers: UI, API, Data, External
- Drizzle migrations as part of deployment pipeline

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Browser"]:::frontend
        CDN["CDN/Edge (Cloudflare Pages)"]:::infrastructure
        subgraph "UI Components"
            Comp["src/components/"]:::frontend
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        App["Next.js App Router"]:::server
    end

    %% API and Auth
    subgraph "API / Authentication"
        API["API Routes (Edge Functions)"]:::server
        Auth["NextAuth.js"]:::server
    end

    %% Business Logic
    subgraph "Business Logic"
        Actions["Server Actions"]:::server
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["Cloudflare D1 (Drizzle ORM)"]:::database
    end

    %% External Services
    subgraph "External Services"
        Google["Google OAuth"]:::external
    end

    %% Flows
    Browser -->|"GET HTML/CSS/JS"| CDN
    CDN -->|"Serve Static Assets"| Browser
    CDN -->|"Edge SSR"| App
    App -->|"Render Server Components"| CDN
    App -->|"Fetch Client Components"| Comp
    App -->|"API call (/api/hello, /api/auth)"| API
    API -->|"Invoke Auth Handler"| Auth
    API -->|"Call Business Logic"| Actions
    Actions -->|"SQL Query"| DB
    DB -->|"Return Data"| Actions
    Browser -->|"OAuth Redirect"| Google
    Google -->|"OAuth Callback"| Auth

    %% Click Events
    click App "https://github.com/swarajbachu/resubs/tree/main/src/app/"
    click Comp "https://github.com/swarajbachu/resubs/tree/main/src/components/"
    click API "https://github.com/swarajbachu/resubs/tree/main/src/app/api/"
    click Auth "https://github.com/swarajbachu/resubs/blob/main/src/server/auth.ts"
    click Actions "https://github.com/swarajbachu/resubs/tree/main/src/server/actions/"
    click DB "https://github.com/swarajbachu/resubs/blob/main/src/server/db/index.ts"
    click DB "https://github.com/swarajbachu/resubs/blob/main/drizzle.config.ts"
    click Wrangler "https://github.com/swarajbachu/resubs/blob/main/wrangler.toml"
    click Styling "https://github.com/swarajbachu/resubs/blob/main/tailwind.config.ts"

    %% Styles
    classDef frontend fill:#BBE1FA,stroke:#333,stroke-width:1px
    classDef server fill:#C3FDB8,stroke:#333,stroke-width:1px
    classDef database fill:#FFD580,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#E0BBE4,stroke:#333,stroke-width:1px
```
