# codehagen/sitemint architecture

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

- Interactive diagram: https://gitdiagram.com/codehagen/sitemint
- Repository: https://github.com/codehagen/sitemint

## Overview

##### Project type and purpose
- Sitemint is a full-stack, server-rendered web management toolkit built on Next.js App Router.
- It provides a dashboard UI for site creation, workspace management, deployment, data scraping, and analytics, with a Prisma-backed database and integrations (OpenAI, external hosting).

##### High-level system components
a. Client (Browser)
- React components (app/page.tsx, components/**)
- Context providers (BreadcrumbContext)
- Tailwind CSS for styling, Framer Motion for animation
b. Next.js Server
- App Router (app/(…)/page.tsx, app/layout.tsx)
- Server Components vs. Client Components
- Server Actions (app/actions/**) for business logic
- API Routes (app/api/auth/[...all]/route.ts)
- Middleware (middleware.ts) for auth, routing
c. Business Logic / Services
- Database Actions (siteActions.ts, workspaceActions.ts)
- Deployment Actions (deploymentActions.ts)
- Scraper Actions (scraperActions.ts)
- Workspace Creation (createWorkspace.ts)
d. Database
- Prisma Client (lib/prisma.ts) connecting to PostgreSQL (connection string via .env)
- Prisma schema (prisma/schema.prisma)
e. External Services
- OpenAI API (AI-powered features)
- Hosting/deployment provider (e.g., Vercel)
- Potential third-party scraping targets
f. Dev/Build Tooling
- pnpm, bun (bun.lock), TypeScript, ESLint, PostCSS, Tailwind, config files
- Next.js build & dev server

##### Relationships and data flows
- The user’s browser renders React pages served by Next.js.
- Client components dispatch calls to Server Actions or fetch from API Routes.
- Server Actions handle business logic and talk to Prisma.
- API Routes manage authentication flows (NextAuth) and can also expose REST endpoints.
- Prisma Client executes SQL queries against the PostgreSQL database.
- Actions like deploymentActions invoke external deployment APIs or services.
- scraperActions may call external sites, parse data, and store results in the database.
- Real-time updates or toasts (Sonner) provide UX feedback.

##### Architectural patterns and principles
- Separation of concerns: UI (components/), business logic (app/actions/), API (app/api/), data layer (Prisma).
- Next.js App Router leverages React Server Components for fast page loads and streaming.
- File-system routing for dynamic subdomains (app/sites/[subdomain]).
- Contexts & hooks for shared client-side state.
- Type-safe schemas & validation (TypeScript + Zod).

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Client Layer
  subgraph "Client (Browser UI)" 
    direction TB
    RC["React Components"]:::frontend
    CP["BreadcrumbContext"]:::frontend
    SA["Styling & Animation"]:::frontend
  end

  %% Next.js Core Layer
  subgraph "Next.js Server" 
    direction TB
    subgraph "App Router" 
      direction TB
      LYT["app/layout.tsx"]:::core
      SIG["app/(auth)/sign-in/page.tsx"]:::core
      SUP["app/(auth)/sign-up/page.tsx"]:::core
      DASH_L["app/dashboard/layout.tsx"]:::core
      DASH_P["app/dashboard/page.tsx"]:::core
      SITE_L["app/sites/[subdomain]/layout.tsx"]:::core
      WS_C["app/workspaces/create/page.tsx"]:::core
    end
    MID["middleware.ts"]:::core
    API["Authentication API"]:::core
    subgraph "Server Actions" 
      direction TB
      SA_DB1["siteActions"]:::business
      SA_DB2["siteConfigActions"]:::business
      SA_DB3["workspaceActions"]:::business
      SA_DEP["deploymentActions"]:::business
      SA_SCR["scraperActions"]:::business
      SA_WS["createWorkspace"]:::business
    end
  end

  %% Business Services Layer
  subgraph "Business Services" 
    direction TB
    DB_A["Database Actions"]:::business
    DEP_A["Deployment Actions"]:::business
    SCR_A["Scraper Actions"]:::business
    WS_A["Workspace Creation"]:::business
  end

  %% Data Layer
  subgraph "Data Layer"
    direction TB
    PC["Prisma Client"]:::data
    PS["Prisma Schema"]:::data
    PG["PostgreSQL"]:::data
  end

  %% External Services
  subgraph "External Services"
    direction TB
    OA["OpenAI API"]:::external
    HP["Hosting Provider"]:::external
    TP["Third-Party Sites"]:::external
    AP["NextAuth Provider"]:::external
  end

  %% Connections
  RC -->|"render & client calls"| SA_DB1
  RC -->|"render & client calls"| API
  CP --> RC
  SA --> RC

  API -->|"OAuth handshake"| AP
  SA_DB1 -->|"invoke"| PC
  SA_DB2 -->|"invoke"| PC
  SA_DB3 -->|"invoke"| PC
  SA_WS -->|"invoke"| PC
  SA_DEP -->|"invoke"| DEP_A
  SA_SCR -->|"invoke"| SCR_A

  DEP_A -->|"deploy API call"| HP
  SCR_A -->|"HTTP fetch"| TP
  SCR_A -->|"store results"| PC

  PC -->|"SQL queries"| PG
  PS --> PC

  LYT --> SA_DB1
  SIG --> SA_WS
  SUP --> SA_WS
  DASH_L --> SA_DB3
  DASH_P --> SA_DB3
  SITE_L --> SA_DB2
  WS_C --> SA_WS
  MID --> API
  MID --> SA_DB1

  %% Click Events
  click RC "https://github.com/codehagen/sitemint/tree/main/components/"
  click RC "https://github.com/codehagen/sitemint/blob/main/app/page.tsx"
  click SA "https://github.com/codehagen/sitemint/blob/main/app/globals.css"
  click CP "https://github.com/codehagen/sitemint/blob/main/lib/contexts/BreadcrumbContext.tsx"
  click LYT "https://github.com/codehagen/sitemint/blob/main/app/layout.tsx"
  click SIG "https://github.com/codehagen/sitemint/blob/main/app/(auth)/sign-in/page.tsx"
  click SUP "https://github.com/codehagen/sitemint/blob/main/app/(auth)/sign-up/page.tsx"
  click DASH_L "https://github.com/codehagen/sitemint/blob/main/app/dashboard/layout.tsx"
  click DASH_P "https://github.com/codehagen/sitemint/blob/main/app/dashboard/page.tsx"
  click SITE_L "https://github.com/codehagen/sitemint/blob/main/app/sites/[subdomain]/layout.tsx"
  click WS_C "https://github.com/codehagen/sitemint/blob/main/app/workspaces/create/page.tsx"
  click MID "https://github.com/codehagen/sitemint/blob/main/middleware.ts"
  click SA_DB1 "https://github.com/codehagen/sitemint/blob/main/app/actions/database/siteActions.ts"
  click SA_DB2 "https://github.com/codehagen/sitemint/blob/main/app/actions/database/siteConfigActions.ts"
  click SA_DB3 "https://github.com/codehagen/sitemint/blob/main/app/actions/database/workspaceActions.ts"
  click SA_DEP "https://github.com/codehagen/sitemint/blob/main/app/actions/deploy/deploymentActions.ts"
  click SA_SCR "https://github.com/codehagen/sitemint/blob/main/app/actions/scraper/scraperActions.ts"
  click SA_WS "https://github.com/codehagen/sitemint/blob/main/app/actions/workspace/createWorkspace.ts"
  click API "https://github.com/codehagen/sitemint/blob/main/app/api/auth/[...all]/route.ts"
  click PC "https://github.com/codehagen/sitemint/blob/main/lib/prisma.ts"
  click PS "https://github.com/codehagen/sitemint/blob/main/prisma/schema.prisma"
  click HP "https://github.com/codehagen/sitemint/blob/main/next.config.ts"
  click HP "https://github.com/codehagen/sitemint/blob/main/tsconfig.json"
  click HP "https://github.com/codehagen/sitemint/blob/main/postcss.config.mjs"
  click HP "https://github.com/codehagen/sitemint/blob/main/eslint.config.mjs"
  click HP "https://github.com/codehagen/sitemint/blob/main/bun.lock"
  click HP "https://github.com/codehagen/sitemint/blob/main/pnpm-lock.yaml"
  click HP "https://github.com/codehagen/sitemint/blob/main/package.json"

  %% Styles
  classDef frontend fill:#e0f7fa,stroke:#006064,color:#006064
  classDef core fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
  classDef business fill:#fff3e0,stroke:#ef6c00,color:#e65100
  classDef data fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
  classDef external fill:#ffebee,stroke:#c62828,color:#b71c1c
```
