# synmmmm/synmm architecture

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

- Interactive diagram: https://gitdiagram.com/synmmmm/synmm
- Repository: https://github.com/synmmmm/synmm

## Overview

##### Project Type and Purpose
- This is a full-stack, server-rendered React application built on Next.js (App Router) with two primary user interfaces: a public “app” section and an authenticated “admin” section.
- It uses NextAuth for user authentication, Prisma as its ORM to talk to a relational database, serverless API routes for CRUD operations (blog, contact, admin auth), and integrates with external services (eBird, OpenWeather, email provider).

##### File Structure Insights
- src/app: holds the Next.js App Router directory, split into two parallel route groups:
- `(app)` – public‐facing pages (blog listings, contact form, dynamic eBird/OpenWeather labs)
- `(admin)` – protected/admin pages (login, register, blog management, password reset)
- src/app/api: Next.js route handlers running as serverless functions for each domain (admin/auth/login, blog, contact, eBird data, weather)
- prisma: database migrations + schema.prisma (PostgreSQL/MySQL/SQLite) + generated client
- common, components, features, store: shared UI components, hooks, validation schemas, global state
- emails: server-side email templates to notify on contact submission and verification

##### Key System Components
a. Frontend (Browser)
- Public UI – pages under `src/app/(app)` rendered via SSR/SSG or client components (React + Tailwind CSS)
- Admin UI – pages under `src/app/(admin)` guarded by NextAuth session checks
b. Next.js Serverless Layer
- App Router – handles SSR, routing, and client component hydration
- API Routes – each folder under `src/app/api` becomes a serverless endpoint
- NextAuth – session store, JWT, callbacks integrated via `src/app/api/auth/[...nextauth]`
- Prisma Client – imported into API routes (`common/utils/prismadb.ts`) to perform DB queries
c. Database
- Managed via Prisma migrations; holds Users, Blogs, Contacts, etc.
d. External Services
- eBird REST API (observations, species, refs)
- OpenWeather API (current weather)
- Email Delivery Service (SendGrid, Mailgun, etc.) via server-side templates in `src/emails`
e. Deployment & Infrastructure
- Vercel (Serverless Functions runtime for API routes + edge caching)
- Public assets served from `public/` (logos, textures)
- Environment Variables for DB connection, API keys, Email credentials

##### Component Relationships & Data Flows
- User Browser → Next.js App Server (SSR/SSG) → Browser
- Browser (public or admin) → fetch() → Next.js API Route (serverless)
- API Route → Prisma Client → Database
- API Route → External REST API (eBird/OpenWeather) → Response
- API Route → Email Service → Outbound email
- NextAuth routes manage session cookies & JWT in between Browser ↔ Server

##### Architectural Patterns & Principles
- Monolithic serverless architecture: Next.js App + API in one repo
- App Router pattern: separation of page vs. API logic by directory
- ORM pattern with Prisma and declarative migrations
- Edge-neutral serverless functions – stateless, invoked per request
- React Server Components vs Client Components (inferred from file extensions)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Browser" 
        direction TB
        BrowserPublic["Browser (Public UI)"]:::frontend
        BrowserAdmin["Browser (Admin UI)"]:::frontend
    end
    click BrowserPublic "https://github.com/synmmmm/synmm/tree/main/src/app/(app)"
    click BrowserAdmin "https://github.com/synmmmm/synmm/tree/main/src/app/(admin)"

    %% Next.js Server Layer
    NextSSR["Next.js SSR (App Router)"]:::server

    %% Serverless Layer
    subgraph "Next.js Serverless Layer"
        direction TB
        NextAuthAPI["API: NextAuth"]:::api
        click NextAuthAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/auth/[...nextauth]/route.ts"
        AdminLoginAPI["API: /api/admin/login"]:::api
        click AdminLoginAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/admin/login/route.ts"
        AdminRegisterAPI["API: /api/admin/register"]:::api
        click AdminRegisterAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/admin/register/route.ts"
        AdminVerifyAPI["API: /api/admin/verify-token"]:::api
        click AdminVerifyAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/admin/verify-token/route.ts"
        BlogAPI["API: /api/blog"]:::api
        click BlogAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/blog/route.ts"
        ContactAPI["API: /api/contact"]:::api
        click ContactAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/contact/route.ts"
        eBirdObsAPI["API: /api/eBird/getObs"]:::api
        click eBirdObsAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/eBird/getObs/route.ts"
        eBirdSpeciesAPI["API: /api/eBird/getObsSpecies"]:::api
        click eBirdSpeciesAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/eBird/getObsSpecies/route.ts"
        eBirdRefsAPI["API: /api/eBird/refs"]:::api
        click eBirdRefsAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/eBird/refs/route.ts"
        WeatherAPI["API: /api/openWeather/getWeather"]:::api
        click WeatherAPI "https://github.com/synmmmm/synmm/blob/main/src/app/api/openWeather/getWeather/route.ts"
        PrismaClient["Prisma Client Utility"]:::util
        click PrismaClient "https://github.com/synmmmm/synmm/blob/main/src/common/utils/prismadb.ts"
        ValidationAdmin["Validation: loginSchema"]:::util
        click ValidationAdmin "https://github.com/synmmmm/synmm/blob/main/src/features/validations/admin/loginSchema.ts"
        ValidationContact["Validation: contactSchema"]:::util
        click ValidationContact "https://github.com/synmmmm/synmm/blob/main/src/features/validations/app/contactSchema.ts"
    end

    %% Email Templates
    subgraph "Email Templates"
        direction TB
        EmailContactReceived["contactReceived.tsx"]:::email
        click EmailContactReceived "https://github.com/synmmmm/synmm/blob/main/src/emails/contactReceived.tsx"
        EmailContactSent["contactSent.tsx"]:::email
        click EmailContactSent "https://github.com/synmmmm/synmm/blob/main/src/emails/contactSent.tsx"
        EmailVerify["verifyEmail.tsx"]:::email
        click EmailVerify "https://github.com/synmmmm/synmm/blob/main/src/emails/static/verifyEmail.tsx"
    end

    %% Database Layer
    Database["Database (Prisma)"]:::db
    click Database "https://github.com/synmmmm/synmm/blob/main/prisma/schema.prisma"

    %% External Services
    subgraph "External Services"
        direction TB
        eBirdCloud["eBird REST API"]:::external
        WeatherCloud["OpenWeather API"]:::external
        EmailService["Email Delivery Service"]:::external
    end

    %% Connections: Client to SSR and API
    BrowserPublic -->|"GET page"| NextSSR
    BrowserAdmin -->|"GET page (auth check)"| NextSSR
    BrowserAdmin -->|"session check"| NextAuthAPI

    %% SSR to Client
    NextSSR --> BrowserPublic
    NextSSR --> BrowserAdmin

    %% Public APIs: Blog & Contact
    BrowserPublic -->|"fetch() blog data"| BlogAPI
    BlogAPI -->|"DB query (Prisma)"| PrismaClient
    PrismaClient -->|"SQL"| Database
    BlogAPI -->|"JSON response"| BrowserPublic

    BrowserPublic -->|"POST /contact"| ContactAPI
    ContactAPI -->|"validate"| ValidationContact
    ContactAPI -->|"DB write"| PrismaClient
    ContactAPI -->|"sendEmail()"| EmailService
    ContactAPI --> EmailContactReceived
    ContactAPI --> EmailContactSent
    EmailService -->|"email delivery"| BrowserPublic

    %% Admin APIs
    BrowserAdmin -->|"POST /admin/login"| AdminLoginAPI
    AdminLoginAPI -->|"validate"| ValidationAdmin
    AdminLoginAPI -->|"DB query"| PrismaClient
    AdminLoginAPI -->|"issue session"| NextAuthAPI

    BrowserAdmin -->|"POST /admin/register"| AdminRegisterAPI
    AdminRegisterAPI -->|"validate"| ValidationAdmin
    AdminRegisterAPI -->|"DB write"| PrismaClient
    AdminRegisterAPI --> NextAuthAPI

    BrowserAdmin -->|"POST /admin/verify-token"| AdminVerifyAPI
    AdminVerifyAPI -->|"DB query"| PrismaClient

    %% eBird & Weather flows
    BrowserPublic -->|"fetch() observations"| eBirdObsAPI
    eBirdObsAPI -->|"REST call"| eBirdCloud
    eBirdObsAPI --> BrowserPublic

    BrowserPublic -->|"fetch() species"| eBirdSpeciesAPI
    eBirdSpeciesAPI -->|"REST call"| eBirdCloud
    eBirdSpeciesAPI --> BrowserPublic

    BrowserPublic -->|"fetch() refs"| eBirdRefsAPI
    eBirdRefsAPI -->|"REST call"| eBirdCloud
    eBirdRefsAPI --> BrowserPublic

    BrowserPublic -->|"fetch() weather"| WeatherAPI
    WeatherAPI -->|"REST call"| WeatherCloud
    WeatherAPI --> BrowserPublic

    %% NextAuth DB
    NextAuthAPI -->|"DB query"| PrismaClient

    %% Styles
    classDef frontend fill:#c3e6ff,stroke:#1e3a8a,color:#1e3a8a
    classDef server fill:#d1fae5,stroke:#065f46,color:#065f46
    classDef api fill:#cffafe,stroke:#0e7490,color:#0e7490
    classDef util fill:#f0f9ff,stroke:#0369a1,color:#0369a1
    classDef email fill:#fef3c7,stroke:#92400e,color:#92400e
    classDef db fill:#fde2e1,stroke:#991b1b,color:#991b1b
    classDef external fill:#e5e7eb,stroke:#374151,color:#374151
```
