# nonsouddy/sir_john_spelling_bee architecture

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

- Interactive diagram: https://gitdiagram.com/nonsouddy/sir_john_spelling_bee
- Repository: https://github.com/nonsouddy/sir_john_spelling_bee

## Overview

##### Project type and purpose
- This is a full-stack Next.js 13 application (using the App Router) that serves both a public website (marketing pages, blog, resources, FAQ, contact, registration, etc.) and an authenticated administration panel (contestant/event/material/staff management).
- It integrates with:
- A relational database via Prisma (likely PostgreSQL)
- Sanity.io as a headless CMS for blog posts and possibly other content
- File storage for uploads (images, materials) served from the public folder or a cloud provider
- Email service for registration/payment confirmations
- Built-in Next.js route-handlers (app/api) and React Server Actions (actions/server)

##### File structure
- “app/” holds the Next.js App-Router pages and layouts. Under “(root)” are public pages; under “(Admin)” are admin pages.
- “app/api/” contains Next.js route-handler endpoints (REST-style serverless functions).
- “actions/fetch/” are client-side fetch wrappers for API calls; “actions/server/” are React Server Actions for mutations.
- “components/” holds reusable React UI components (grouped by feature).
- “lib/” contains utility modules: prisma client, token handling, email templates, formatting, etc.
- “prisma/” holds the schema and migrations.
- “sanity/” contains the Sanity studio config, schemas, and client.
- “app/schemas” uses Zod schemas for data validation.
- “assets/” and “public/” serve static CSS, images, SVGs.

##### Details
- Include:
- Next.js App Router layouts (root vs Admin)
- app/api route-handlers vs actions/server
- Fetch wrappers (actions/fetch)
- Prisma → schema.prisma
- Sanity Studio & schemas
- Static asset directory
- Middleware layer (middleware.ts) for auth
- This level of granularity ensures every architectural element is represented.
- Don’t hesitate to break out sub-components (e.g., Email Service vs Token Service vs File Storage) for clarity.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Zone
    subgraph "Client Zone"
        direction TB
        PublicUI["Public UI (Next.js App Router)"]:::ui
        AdminUI["Admin UI (Next.js App Router)"]:::ui
    end

    %% Server Zone
    subgraph "Server Zone"
        direction TB
        subgraph "API & Server Actions"
            direction TB
            FetchWrappers["Client Fetch Wrappers"]:::api
            APIRoutes["Next.js API Route Handlers"]:::api
            ServerActions["React Server Actions"]:::api
        end
        AuthMiddleware["Authentication & Middleware"]:::api
    end

    %% Data & Persistence Zone
    subgraph "Persistence Layer"
        direction TB
        PrismaClient["Prisma Client & Schema"]:::persistence
        Database["Relational Database"]:::persistence
        SanityClient["Sanity Client & Config"]:::persistence
        CMSStudio["Sanity Studio UI"]:::persistence
        FileStorage["Static Asset Storage / Uploads"]:::persistence
        ZodValidation["Validation Schemas (Zod)"]:::api
    end

    %% External Services
    subgraph "External Services"
        direction TB
        EmailService["Email Service"]:::external
        Deployment["Vercel Deployment"]:::external
    end

    %% Client to Server interactions
    PublicUI -->|"fetch data"| FetchWrappers
    AdminUI -->|"fetch data"| FetchWrappers
    PublicUI -->|"mutations"| ServerActions
    AdminUI -->|"mutations"| ServerActions
    PublicUI -->|"auth check"| AuthMiddleware
    AdminUI -->|"auth check"| AuthMiddleware

    %% Fetch to API
    FetchWrappers -->|"call endpoints"| APIRoutes
    APIRoutes -->|"validate"| ZodValidation

    %% Server Actions flows
    ServerActions -->|"use ORM"| PrismaClient
    ServerActions -->|"store files"| FileStorage
    ServerActions -->|"send emails"| EmailService
    ServerActions -->|"validate"| ZodValidation

    %% API to Persistence
    APIRoutes -->|"use ORM"| PrismaClient
    APIRoutes -->|"query CMS"| SanityClient
    APIRoutes -->|"serve studio"| CMSStudio
    APIRoutes -->|"read/write files"| FileStorage

    %% ORM to DB
    PrismaClient -->|"SQL queries"| Database

    %% Sanity flows
    SanityClient -->|"CRUD content"| CMSStudio

    %% Deployment
    APIRoutes -->|"hosted on"| Deployment
    ServerActions -->|"hosted on"| Deployment
    PublicUI -->|"SSR/hosting"| Deployment
    AdminUI -->|"SSR/hosting"| Deployment

    %% Click Events
    click PublicUI "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/app/(root)"
    click AdminUI "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/app/(Admin)"
    click FetchWrappers "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/actions/fetch"
    click APIRoutes "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/app/api"
    click ServerActions "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/actions/server"
    click PrismaClient "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/lib/prismadb.ts"
    click PrismaClient "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/prisma/schema.prisma"
    click SanityClient "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/sanity/lib/client.ts"
    click SanityClient "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/sanity.config.ts"
    click CMSStudio "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/app/studio/[[...tool]]/page.tsx"
    click FileStorage "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/public/"
    click EmailService "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/lib/email.ts"
    click EmailService "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/app/emails/Register.tsx"
    click EmailService "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/app/emails/PaymentConfirmation.tsx"
    click ZodValidation "https://github.com/nonsouddy/sir_john_spelling_bee/tree/main/app/schemas"
    click AuthMiddleware "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/lib/token.ts"
    click AuthMiddleware "https://github.com/nonsouddy/sir_john_spelling_bee/blob/main/middleware.ts"

    %% Styles
    classDef ui fill:#D0E7FF,stroke:#0366D6,color:#0366D6,stroke-width:1px
    classDef api fill:#D8F8D0,stroke:#28A745,color:#28A745,stroke-width:1px
    classDef persistence fill:#FFE4B3,stroke:#E67E22,color:#E67E22,stroke-width:1px
    classDef external fill:#E8DAEF,stroke:#8E44AD,color:#8E44AD,stroke-width:1px
```
