# javayhu/free-directory-boilerplate architecture

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

- Interactive diagram: https://gitdiagram.com/javayhu/free-directory-boilerplate
- Repository: https://github.com/javayhu/free-directory-boilerplate

## Overview

##### Main Components
a. Client Browser (Web & Mobile)
b. Next.js Application (Frontend & Server)
- App Directory (Pages & Server Components)
- API Routes (app/api/auth/[...nextauth]/route.ts)
- Server Actions (actions/*.ts)
c. Database (PostgreSQL via Prisma)
d. Headless CMS (Sanity)
e. Authentication Providers (GitHub, Google via NextAuth)
f. Payment Gateway (Stripe)
g. Analytics & Monitoring
- Umami
- Google Analytics
- Vercel Analytics / Speed Insights
h. Static Content Generator (Contentlayer reading content/**/*)
i. Deployment & Infrastructure
- Vercel (hosting)
- Docker / docker-compose (local dev)

##### Relationships & Data Flow
- The Client sends HTTP requests to the Next.js App (SSR & CSR).
- Next.js App renders UI, calls:
- NextAuth API route ↔ OAuth providers → user sessions.
- Prisma Client (lib/db.ts) ↔ PostgreSQL for user, listing, application data.
- Server Actions (actions/*.ts) → business logic: create/update applications, generate Stripe customer, open customer portal, share resources.
- Stripe SDK (lib/stripe.ts) ↔ Stripe API for billing & subscriptions.
- Sanity Client (sanity/lib/client.ts) ↔ Sanity API for CMS-managed content (if used for docs/blog) or Contentlayer (content + contentlayer.config.ts) at build time.
- Analytics scripts (components/analytics.tsx, Umami, GA) send events to Umami & Google.
- Static generation (Contentlayer) reads content files, produces MDX pages under app/(main)/(docs) & blog.

##### Architectural Patterns
- App Directory pattern (Next.js 14): Server vs. Client components.
- Server Actions for data mutations.
- API Routes for authentication.
- Prisma ORM for relational data modeling.
- Contentlayer for static content generation alongside dynamic routes.
- Headless CMS (Sanity) as external content source.
- Mono-repo with clear separation:
- /app for routes
- /components for UI
- /lib for core utilities & integrations
- /config for feature toggles & site settings
- /prisma for database schema
- /actions for domain logic

##### Elements
- Annotations for important directories (e.g., “app/api/auth → NextAuth handler”).
- Deployment details (Vercel cloud, Docker for local).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    subgraph "Client Browser" 
        Browser["Web & Mobile Browser"]:::frontend
    end

    %% Next.js App
    subgraph "Next.js Application" 
        subgraph "Routes & Pages"
            Routes["app/[lang]/**"]:::backend
        end
        subgraph "API Routes (NextAuth)"
            AuthAPI["app/api/auth/[...nextauth]/route.ts"]:::backend
        end
        subgraph "Server Actions"
            Actions["actions/*.ts"]:::backend
        end
        subgraph "Lib & Config"
            DBLib["lib/db.ts"]:::backend
            SessionLib["lib/session.ts"]:::backend
            StripeLib["lib/stripe.ts"]:::backend
            SubscriptionLib["lib/subscription.ts"]:::backend
            AuthConfig["auth.config.ts"]:::backend
            ConfigAuth["config/auth.ts"]:::backend
            TypesNextAuth["types/next-auth.d.ts"]:::backend
            ConfigSub["config/subscriptions.ts"]:::backend
            ConfigDir["config/*.ts"]:::backend
        end
        subgraph "Contentlayer Build"
            CLConfig["contentlayer.config.ts"]:::backend
            ContentDir["content/**"]:::backend
        end
    end

    %% Data Stores
    subgraph "Database" 
        Postgres["PostgreSQL<br/>(Prisma ORM)"]:::datastore
        Schema["prisma/schema.prisma"]:::datastore
        Migrations["prisma/migrations/0_init"]:::datastore
    end

    %% CMS
    subgraph "Headless CMS (Sanity)"
        SanityStudio["Sanity Studio"]:::external
        SanityClient["sanity/lib/client.ts"]:::external
        SanityAPI["sanity/lib/api.ts"]:::external
        SanityQueries["sanity/lib/queries.ts"]:::external
    end

    %% Auth Providers
    subgraph "Authentication Providers"
        GitHub["GitHub OAuth"]:::external
        Google["Google OAuth"]:::external
    end

    %% Payment
    subgraph "Payment Gateway"
        StripeAPI["Stripe API"]:::external
    end

    %% Analytics
    subgraph "Analytics & Monitoring"
        AnalyticsComp["components/analytics.tsx"]:::external
        GAComp["components/google-analytics.tsx"]:::external
        ClarityComp["components/clarity-analytics.tsx"]:::external
        VercelAnal["components/vercel-analytics.tsx"]:::external
        VercelSpeed["components/vercel-speed-insights.tsx"]:::external
        Umami["Umami"]:::external
        GA["Google Analytics"]:::external
        VercelMetrics["Vercel Analytics / Speed Insights"]:::external
    end

    %% Infra
    subgraph "Deployment & Infrastructure"
        Vercel["Vercel Hosting"]:::infra
        DockerLocal["Docker / docker-compose"]:::infra
        Dockerfile["Dockerfile"]:::infra
        DockerCompose["docker-compose.yml"]:::infra
        NextDocker["next.config.docker.js"]:::infra
    end

    %% Connections
    Browser -->|"HTTP SSR/CSR"| Routes
    Routes -->|"NextAuth API"| AuthAPI
    AuthAPI -->|"OAuth Flow"| GitHub
    AuthAPI -->|"OAuth Flow"| Google
    Routes -->|"Prisma Client"| DBLib
    DBLib -->|"Schema & Migrations"| Schema
    DBLib -->|"SQL Queries"| Postgres
    Actions -->|"Use DB Client"| DBLib
    Actions -->|"Stripe SDK"| StripeLib
    StripeLib -->|"REST API"| StripeAPI
    Routes -->|"Sanity Client"| SanityClient
    SanityClient -->|"HTTP API"| SanityAPI
    SanityAPI -->|"CMS Content"| SanityStudio
    Routes -->|"Server Actions"| Actions
    Routes -->|"Contentlayer Build"| CLConfig
    CLConfig -->|"Read Content"| ContentDir
    Browser -->|"Analytics Script"| AnalyticsComp
    AnalyticsComp -->|"Events"| Umami
    GAComp -->|"Events"| GA
    VercelAnal -->|"Metrics"| VercelMetrics
    VercelSpeed -->|"Reports"| VercelMetrics
    VercelMetrics --> Vercel
    Browser --> Vercel
    Vercel --> Routes
    DockerLocal --> Routes

    %% Click Events
    click Routes "https://github.com/javayhu/free-directory-boilerplate/tree/main/app/[lang]"
    click AuthAPI "https://github.com/javayhu/free-directory-boilerplate/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Actions "https://github.com/javayhu/free-directory-boilerplate/tree/main/actions"
    click DBLib "https://github.com/javayhu/free-directory-boilerplate/blob/main/lib/db.ts"
    click Schema "https://github.com/javayhu/free-directory-boilerplate/blob/main/prisma/schema.prisma"
    click Migrations "https://github.com/javayhu/free-directory-boilerplate/tree/main/prisma/migrations/0_init"
    click SanityClient "https://github.com/javayhu/free-directory-boilerplate/blob/main/sanity/lib/client.ts"
    click SanityAPI "https://github.com/javayhu/free-directory-boilerplate/blob/main/sanity/lib/api.ts"
    click SanityQueries "https://github.com/javayhu/free-directory-boilerplate/blob/main/sanity/lib/queries.ts"
    click AuthConfig "https://github.com/javayhu/free-directory-boilerplate/blob/main/auth.config.ts"
    click SessionLib "https://github.com/javayhu/free-directory-boilerplate/blob/main/lib/session.ts"
    click ConfigAuth "https://github.com/javayhu/free-directory-boilerplate/blob/main/config/auth.ts"
    click TypesNextAuth "https://github.com/javayhu/free-directory-boilerplate/blob/main/types/next-auth.d.ts"
    click StripeLib "https://github.com/javayhu/free-directory-boilerplate/blob/main/lib/stripe.ts"
    click SubscriptionLib "https://github.com/javayhu/free-directory-boilerplate/blob/main/lib/subscription.ts"
    click GenStripe "https://github.com/javayhu/free-directory-boilerplate/blob/main/actions/generate-user-stripe.ts"
    click CustomerPortal "https://github.com/javayhu/free-directory-boilerplate/blob/main/actions/open-customer-portal.ts"
    click ConfigSub "https://github.com/javayhu/free-directory-boilerplate/blob/main/config/subscriptions.ts"
    click AnalyticsComp "https://github.com/javayhu/free-directory-boilerplate/blob/main/components/analytics.tsx"
    click GAComp "https://github.com/javayhu/free-directory-boilerplate/blob/main/components/google-analytics.tsx"
    click ClarityComp "https://github.com/javayhu/free-directory-boilerplate/blob/main/components/clarity-analytics.tsx"
    click VercelAnal "https://github.com/javayhu/free-directory-boilerplate/blob/main/components/vercel-analytics.tsx"
    click VercelSpeed "https://github.com/javayhu/free-directory-boilerplate/blob/main/components/vercel-speed-insights.tsx"
    click CLConfig "https://github.com/javayhu/free-directory-boilerplate/blob/main/contentlayer.config.ts"
    click ContentDir "https://github.com/javayhu/free-directory-boilerplate/tree/main/content"
    click ConfigDir "https://github.com/javayhu/free-directory-boilerplate/tree/main/config"
    click Dockerfile "https://github.com/javayhu/free-directory-boilerplate/tree/main/Dockerfile"
    click DockerCompose "https://github.com/javayhu/free-directory-boilerplate/blob/main/docker-compose.yml"
    click NextDocker "https://github.com/javayhu/free-directory-boilerplate/blob/main/next.config.docker.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#D8F5D3,stroke:#28A745,color:#155724;
    classDef datastore fill:#FFE5B4,stroke:#FF8C00,color:#8B4513;
    classDef external fill:#E2E3E5,stroke:#6C757D,color:#343A40;
    classDef infra fill:#EAD7FF,stroke:#6F42C1,color:#4B088A;
```
