# codelash-shaktivel/incognito_feedback architecture

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

- Interactive diagram: https://gitdiagram.com/codelash-shaktivel/incognito_feedback
- Repository: https://github.com/codelash-shaktivel/incognito_feedback

## Overview

##### Main Components
- Frontend (UI): Represented by the Next.js “app” directory and the “components” directory. Include key UI pages like the dashboard, authentication pages (sign-in, sign-up, verification), and user profile pages. Also highlight the use of UI libraries/components (e.g., alert-dialog, card, carousel, etc.).
- Backend API: Under the “src/app/api” directory, you have several API endpoints – for example, authentication via next-auth, endpoints for messages (get, send, delete, suggest), and endpoints for user-related interactions like check-username-unique and verify-code. Each API route can be modeled as an individual service or endpoint.
- Authentication Service: Note the presence of NextAuth integration (in “src/app/api/auth/[...nextauth]”) along with an AuthProvider context (in “src/context/AuthProvider.tsx”), which manages user authentication state both server-side and client-side.
- Email Service: The presence of “emails/VerificationEmail.tsx” and helper functions like “src/helpers/sendVerificationEmail.ts” indicate an external (or internal) email service used for sending verification and confirmation emails.

##### Relationships & Interactions
- The user interacts with the Frontend UI layer (pages in “src/app/(app)” and “src/app/(auth)”) which communicates with the Backend API endpoints via REST calls or Next.js’s built-in routing.
- The API endpoints handle operations like sending messages, authentication, and verifying codes; these endpoints then interact with the Database via utility and helper functions (e.g., “dbConnect.ts” and model/schema validations).
- Authentication requests are managed via NextAuth (configured in “src/app/api/auth/[...nextauth]”), and the AuthProvider on the frontend ensures that user session data is maintained.
- Upon user sign-up or verification, the system triggers the email service to send verification emails, linking the frontend user action to backend email delivery.

##### Architectural Patterns & Design Principles
- Separation of concerns: UI components, API endpoints, database connection, authentication, and email handling are clearly modularized.
- RESTful API design: Each API endpoint (with its own route file) is responsible for specific functionality.
- Use of middleware: “src/middleware.ts” indicates that there may be early pattern request handling or authentication checks.
- Component-based UI: Extensive use of reusable components and UI elements (in “src/components/ui”) makes the frontend modular and maintainable.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend UI
    subgraph "Frontend UI"
        A["Next.js Pages"]:::frontend
        B["Reusable UI Components"]:::frontend
    end

    %% Authentication Service
    subgraph "Authentication Service"
        C["AuthProvider Context"]:::auth
        D["NextAuth Integration"]:::auth
    end

    %% Backend API
    subgraph "Backend API"
        E["API Endpoints"]:::api
    end

    %% Database
    subgraph "Database"
        F["DB Connect"]:::database
        G["User Model"]:::database
        H["Schemas"]:::database
    end

    %% Email Service
    subgraph "Email Service"
        I["Verification Email Template"]:::email
        J["Send Email Helper"]:::email
    end

    %% Connections
    A -->|"API_Call"| E
    B -->|"API_Call"| E
    A -->|"Session_Management"| C
    E -->|"Auth_Request"| D
    D -->|"Session_Update"| C
    E -->|"DB_Query"| F
    E -->|"DB_Query"| G
    E -->|"DB_Query"| H
    E -->|"Email_Verification"| I
    E -->|"Email_Verification"| J

    %% Click Events
    click A "https://github.com/codelash-shaktivel/incognito_feedback/tree/main/src/app"
    click B "https://github.com/codelash-shaktivel/incognito_feedback/tree/main/src/components/ui"
    click E "https://github.com/codelash-shaktivel/incognito_feedback/tree/main/src/app/api"
    click F "https://github.com/codelash-shaktivel/incognito_feedback/blob/main/src/lib/dbConnect.ts"
    click G "https://github.com/codelash-shaktivel/incognito_feedback/blob/main/src/model/User.ts"
    click H "https://github.com/codelash-shaktivel/incognito_feedback/tree/main/src/schemas"
    click C "https://github.com/codelash-shaktivel/incognito_feedback/blob/main/src/context/AuthProvider.tsx"
    click D "https://github.com/codelash-shaktivel/incognito_feedback/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click I "https://github.com/codelash-shaktivel/incognito_feedback/blob/main/emails/VerificationEmail.tsx"
    click J "https://github.com/codelash-shaktivel/incognito_feedback/blob/main/src/helpers/sendVerificationEmail.ts"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef auth fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef api fill:#ffb6c1,stroke:#333,stroke-width:2px;
    classDef database fill:#ffe4b5,stroke:#333,stroke-width:2px;
    classDef email fill:#f5deb3,stroke:#333,stroke-width:2px;
```
