# sumitcoder01/anony-texts architecture

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

- Interactive diagram: https://gitdiagram.com/sumitcoder01/anony-texts
- Repository: https://github.com/sumitcoder01/anony-texts

## Overview

##### Project type and purpose
- This is a full-stack web application (“Anony Texts”) built on Next.js (app router), offering anonymous messaging with authentication, email notifications, and AI-enhanced features.

##### File structure
- src/app: Next.js pages & layouts (client-side and server-side rendered UI).
- src/app/api: API routes (Next.js serverless functions) handling auth, messaging, file upload, etc.
- src/lib: Business logic and integration code (DB connection, Cloudinary, email sending, AI prompts).
- src/models & src/schemas: Data models (User) and validation schemas (Zod).
- src/context: React Context providers (AuthContext, ThemeContext).
- config files: next.config.mjs, tailwind.config.ts, postcss.config.mjs, tsconfig.json.

##### README
- Next.js + Tailwind CSS + shadcn UI library for presentation layer
- NextAuth for authentication
- Resend for email delivery
- Zod + React Hook Form for schema validation and form handling
- Gemini (AI) integration for enhanced messaging features
- Deployed on Vercel

##### Main components and their interactions
a. User’s Browser (Client)
- Interacts with Next.js pages (SSR/CSR) and static assets (public folder).
- Uses React Hook Form + Zod validation in forms.
b. Next.js Frontend (App Router)
- Layouts & pages in src/app
- UI Components from src/components
- ThemeContext & AuthContext provide state and theming.
c. Next.js API Routes (Serverless Functions)
- Auth endpoints (NextAuth, register, login, verify-user, forgot/update-password)
- Messaging endpoints (send-message, get-messages, delete-message, accept-messages)
- Utility endpoints (check-username-unique)
d. Business Logic Layer (src/lib)
- dbConnect: Connects to MongoDB (or another DB)
- cloudinary: Handles image uploads
- sendEmail / resend: Manages email notifications
- suggestMessages / Gemini: AI-powered messaging suggestions
e. Data Layer
- src/models/User.ts: Mongoose schema for users
- Zod schemas: Request validation
f. External Services
- Database (MongoDB Atlas or similar)
- Cloudinary (image hosting)
- Resend (email delivery)
- OpenAI / Gemini (AI features)

##### Architectural patterns and design principles
- Separation of concerns: UI layer (components) vs. API layer vs. business logic vs. data layer
- Serverless micro-endpoints: Each API route is a discrete function
- Context-driven global state: Auth & Theme via React Context
- Schema-driven validation: Zod for request and form validation
- Component-driven UI: Reusable UI primitives (shadcn) and shared components

## Diagram (Mermaid)

```mermaid
graph TD
    User("User"):::external
    Browser("Browser / Client"):::ui

    User -->|Uses| Browser

    subgraph "Next.js Frontend"
        direction TB
        subgraph "App Router (src/app)"
            direction TB
            Lay("Layouts & Pages"):::ui
        end
        Static("Static Assets (public/uploads)"):::ui
        subgraph "Context Providers"
            direction TB
            AuthCtx("AuthContextProvider"):::ui
            ThemeCtx("ThemeContextProvider"):::ui
        end
        comp("Shared UI Components"):::ui
    end

    Browser -->|GET/POST| Lay
    Lay --> comp
    Lay --> AuthCtx
    Lay --> ThemeCtx
    Lay --> Static

    subgraph "API Routes (Serverless Functions)"
        direction TB
        subgraph "Auth Routes"
            direction TB
            AuthAPI("Auth Endpoints"):::api
        end
        SendMsg("Send Message"):::api
        GetMsg("Get Messages"):::api
        DelMsg("Delete Message"):::api
        AccMsg("Accept Messages"):::api
        CheckUser("Check Username Unique"):::api
    end

    Lay -->|API call| AuthAPI
    Lay -->|API call| SendMsg
    Lay -->|API call| GetMsg
    Lay -->|API call| DelMsg
    Lay -->|API call| AccMsg
    Lay -->|API call| CheckUser

    subgraph "Business Logic Services"
        direction TB
        DBConn("dbConnect"):::service
        Cloud("cloudinary"):::service
        EmailSend("sendEmail / resend"):::service
        AISug("suggestMessages"):::service
        Zod("Zod Validation"):::service
    end

    AuthAPI -->|validate via Zod| Zod
    AuthAPI --> DBConn
    SendMsg --> Zod
    SendMsg --> Cloud
    SendMsg --> DBConn
    SendMsg --> EmailSend
    SendMsg --> AISug
    GetMsg --> DBConn
    DelMsg --> DBConn
    AccMsg --> DBConn
    CheckUser --> DBConn

    DBConn --> Mongo("MongoDB Atlas"):::external
    Cloud --> CloudExt("Cloudinary"):::external
    EmailSend --> Resend("Resend"):::external
    AISug --> OpenAI("OpenAI / Gemini"):::external

    click Lay "https://github.com/sumitcoder01/anony-texts/tree/main/src/app"
    click comp "https://github.com/sumitcoder01/anony-texts/tree/main/src/components"
    click AuthCtx "https://github.com/sumitcoder01/anony-texts/blob/main/src/context/AuthContext.tsx"
    click ThemeCtx "https://github.com/sumitcoder01/anony-texts/blob/main/src/context/ThemeContext.tsx"
    click AuthAPI "https://github.com/sumitcoder01/anony-texts/tree/main/src/app/api/auth"
    click SendMsg "https://github.com/sumitcoder01/anony-texts/blob/main/src/app/api/send-message/route.ts"
    click GetMsg "https://github.com/sumitcoder01/anony-texts/blob/main/src/app/api/get-messages/route.ts"
    click DelMsg "https://github.com/sumitcoder01/anony-texts/blob/main/src/app/api/delete-message/[messageId]/route.ts"
    click AccMsg "https://github.com/sumitcoder01/anony-texts/blob/main/src/app/api/accept-messages/route.ts"
    click CheckUser "https://github.com/sumitcoder01/anony-texts/blob/main/src/app/api/check-username-unique/route.ts"
    click DBConn "https://github.com/sumitcoder01/anony-texts/blob/main/src/lib/dbConnect.ts"
    click Cloud "https://github.com/sumitcoder01/anony-texts/blob/main/src/lib/cloudinary.ts"
    click EmailSend "https://github.com/sumitcoder01/anony-texts/blob/main/src/lib/sendEmail.ts"
    click EmailSend "https://github.com/sumitcoder01/anony-texts/blob/main/src/lib/resend.ts"
    click AISug "https://github.com/sumitcoder01/anony-texts/blob/main/src/lib/suggestMessages.ts"
    click Mongo "https://github.com/sumitcoder01/anony-texts/blob/main/src/models/User.ts"
    click Zod "https://github.com/sumitcoder01/anony-texts/tree/main/src/schemas"
    click Static "https://github.com/sumitcoder01/anony-texts/blob/main/public/uploads/.gitkeep"

    classDef ui fill:#cfe2f3,stroke:#0366d6,color:#000
    classDef api fill:#d9ead3,stroke:#38761d,color:#000
    classDef service fill:#fff2cc,stroke:#bf9000,color:#000
    classDef db fill:#f4cccc,stroke:#a61c00,color:#000
    classDef external fill:#e6e6e6,stroke:#666,color:#000
```
