# surajbisht105/true-feedback architecture

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

- Interactive diagram: https://gitdiagram.com/surajbisht105/true-feedback
- Repository: https://github.com/surajbisht105/true-feedback

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“True-Feedback”) built with Next.js on the frontend and Node.js on the backend, backed by MongoDB.
- Its purpose is to let registered users receive anonymous feedback via a unique URL, with AI-powered suggestions (OpenAI) and secure authentication (NextAuth with email OTP).

##### File Structure
- Top-level folders and files:
- src/app: Next.js 13 “app” router holding pages, layouts, and API routes under /api.
- src/components & src/components/ui: React UI components (MessageCard, Navbar, ShadCN-styled controls).
- src/context: AuthProvider for client-side auth state.
- src/lib: Database connection (dbConnect.ts), utilities (resend, utils).
- src/model: Mongoose models (User).
- src/schemas: Validation with Zod for each API input.
- src/helpers: email logic (sendVerificationEmail).
- public: static assets.
- config & env: next.config.js, tailwind.config.js, .env for secrets (Mongo URI, OpenAI key, NextAuth secret, Resend API key).

##### Insights from the README
- Clarifies core features: anonymous feedback, AI suggestions, secure login, email OTP, MongoDB storage, unique user URLs.
- Tech stack: Next.js (React), Node.js, MongoDB, NextAuth.js, OpenAI, Resend email service.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Client-side)"
        direction TB
        Pages["Next.js App Router\n(src/app/)"]:::frontend
        Components["React Components\n(src/components/, src/components/ui/)"]:::frontend
        AuthProvider["AuthProvider\n(src/context/AuthProvider.tsx)"]:::frontend
        FeedbackPage["User Feedback Page\n(src/app/u/[username]/page.tsx)"]:::frontend
        GlobalCSS["Global CSS\n(src/app/globals.css)"]:::frontend
        Middleware["Middleware\n(src/middleware.ts)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Server-side)"
        direction TB
        API["API Routes\n(src/app/api/)"]:::backend
        NextAuthRoute["NextAuth Route\n(src/app/api/auth/[...nextauth]/route.ts)"]:::backend
        NextAuthOptions["NextAuth Options\n(src/app/api/auth/[...nextauth]/options.ts)"]:::backend
        SuggestRoute["Suggest Messages Route\n(src/app/api/suggest-messages/route.ts)"]:::backend
        ZodSchemas["Validation Schemas\n(src/schemas/)"]:::backend
        SendEmailHelper["sendVerificationEmail\n(src/helpers/sendVerificationEmail.ts)"]:::backend
        DBConnect["DB Connect\n(src/lib/dbConnect.ts)"]:::backend
        UserModel["User Model\n(src/model/User.ts)"]:::backend
        Utils["Utils\n(src/lib/utils.ts)"]:::backend
        ResendClient["Resend Client\n(src/lib/resend.ts)"]:::backend
    end

    %% Database Layer
    Mongo["MongoDB Atlas"]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI API"]:::external
        Resend["Resend Email Service"]:::external
        VerificationEmail["VerificationEmail Template\n(emails/VerificationEmail.tsx)"]:::external
    end

    %% Connections
    Pages -->|renders| Components
    Pages -->|wraps| AuthProvider
    Pages -->|styles via| GlobalCSS
    Pages -->|handled by| Middleware

    FeedbackPage -->|requests feedback| API
    API -->|validates| ZodSchemas
    API -->|connects| DBConnect
    DBConnect -->|reads/writes| Mongo
    API -->|uses model| UserModel
    API -->|calls util| Utils

    SuggestRoute -->|calls| OpenAI
    API -->|invokes| SuggestRoute

    NextAuthRoute -->|configures| NextAuthOptions
    API -->|routes auth| NextAuthRoute
    AuthProvider <--> NextAuthRoute

    SendEmailHelper -->|uses client| ResendClient
    SendEmailHelper -->|sends template| VerificationEmail
    API -->|on signup| SendEmailHelper
    SendEmailHelper -->|delivers via| Resend

    %% Click Events
    click Pages "https://github.com/surajbisht105/true-feedback/tree/main/src/app/"
    click Components "https://github.com/surajbisht105/true-feedback/tree/main/src/components/"
    click AuthProvider "https://github.com/surajbisht105/true-feedback/blob/main/src/context/AuthProvider.tsx"
    click FeedbackPage "https://github.com/surajbisht105/true-feedback/blob/main/src/app/u/[username]/page.tsx"
    click GlobalCSS "https://github.com/surajbisht105/true-feedback/blob/main/src/app/globals.css"
    click Middleware "https://github.com/surajbisht105/true-feedback/blob/main/src/middleware.ts"
    click API "https://github.com/surajbisht105/true-feedback/tree/main/src/app/api/"
    click NextAuthRoute "https://github.com/surajbisht105/true-feedback/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click NextAuthOptions "https://github.com/surajbisht105/true-feedback/blob/main/src/app/api/auth/[...nextauth]/options.ts"
    click SuggestRoute "https://github.com/surajbisht105/true-feedback/blob/main/src/app/api/suggest-messages/route.ts"
    click ZodSchemas "https://github.com/surajbisht105/true-feedback/tree/main/src/schemas/"
    click SendEmailHelper "https://github.com/surajbisht105/true-feedback/blob/main/src/helpers/sendVerificationEmail.ts"
    click DBConnect "https://github.com/surajbisht105/true-feedback/blob/main/src/lib/dbConnect.ts"
    click UserModel "https://github.com/surajbisht105/true-feedback/blob/main/src/model/User.ts"
    click Utils "https://github.com/surajbisht105/true-feedback/blob/main/src/lib/utils.ts"
    click ResendClient "https://github.com/surajbisht105/true-feedback/blob/main/src/lib/resend.ts"
    click VerificationEmail "https://github.com/surajbisht105/true-feedback/blob/main/emails/VerificationEmail.tsx"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#E6FFED,stroke:#28A745,color:#28A745;
    classDef database fill:#FFF5BA,stroke:#DBAB09,color:#DBAB09;
    classDef external fill:#FFE4E1,stroke:#D93240,color:#D93240;
```
