How adilzhany/ay-directory works
Project type and purpose
• This is a full-stack, server-rendered Next.js 13 application (“app” folder) that serves as a directory of startups (AY Directory).
• It uses Sanity.io as a headless CMS for content storage and NextAuth for GitHub-based user authentication.
File structure
• Top-level “app” directory implements Next.js App Router:
• app/layout.tsx & globals.css — global shell, CSS/ Tailwind setup
• app/page.tsx — homepage
• app/(root)/startup & app/(root)/user — dynamic routes for startups & user profiles
• app/api/auth/[...nextauth]/route.ts — NextAuth API route
• app/api/* — potential other API endpoints
• “components” folder holds UI React components (server & client). “components/ui” contains atomic UI elements.
• “lib” contains shared utilities (actions.ts, utils.ts, validation.ts) called both server- and client-side.
• “hooks” houses custom React hooks (e.g. use-toast).
• “sanity” directory encapsulates CMS integration:
• sanity/lib/client.ts — configured Sanity client for reading
• sanity/lib/write-client.ts — client with write privileges
• sanity/lib/queries.ts — GROQ queries
• sanity/schemaTypes — content schema definitions (author, playlist, startup)
• sanity/structure.ts — Studio customization
• Config files: next.config.ts, postcss.config.mjs, tailwind.config.ts, tsconfig.json.
• README highlights the use of Next.js, Sanity CMS, NextAuth, Tailwind, and environment variable setup.
Main components
a. Frontend (Client)
• Browser / user agent that loads SSR/SSG pages and hydrates client components.
• Components: Navbar, SearchForm, StartupCard, etc.
b. Next.js Server (App Router)
• Route handlers in “app” folder: server components fetch data from Sanity via client.
• API routes: NextAuth for authentication, potential custom REST/GraphQL.
c. Sanity Headless CMS
• Hosted service storing content (startups, authors, playlists).
• Two clients: read-only and write (for privileged operations).
d. Authentication Provider
• NextAuth server route integrates with GitHub OAuth endpoints.
• External service: GitHub OAuth API.
e. Database / CDN (optional)
• Sanity’s internal datastore + CDN-delivered assets.
f. Edge/CDN (if deployed on Vercel or similar)
• Caching layer for SSR/SSG pages, static assets.
Relationships and data flows
• Browser → Next.js SSR/SSG: HTTP requests for pages (e.g. GET /startup/123)
• Next.js Server → Sanity (read-client): fetch content using GROQ queries
• Next.js Server → Sanity (write-client): for privileged write operations (if any)
• Browser → Next.js API Route (/api/auth/[...nextauth]): sign-in, callback flows
• NextAuth → GitHub OAuth Endpoint: token exchange, user profile fetch
• Next.js Server → Database/CDN: static file delivery (fonts, images in /public)
Architectural patterns and design principles
• App Router pattern (Next.js 13): separation of server components (data fetching) and client components (interactive UI).
• Headless CMS: Sanity as an external service decouples content from presentation.
• Modular UI: atomic design in “components/ui”, domain components in “components”.
• Utility libraries in “lib” abstract business logic and validation.
• API route segregation: authentication routes under /api/auth, future REST endpoints can live under /api/*.