# avayyyyyyy/opinify architecture

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

- Interactive diagram: https://gitdiagram.com/avayyyyyyy/opinify
- Repository: https://github.com/avayyyyyyy/opinify

## Overview

##### High-Level Architecture Overview

a) Client Layer:
- Next.js Frontend (app directory structure)
- Embedded Widget Component (for third-party websites)
- Authentication UI Components

b) Server Layer:
- Next.js API Routes
- Authentication System (NextAuth)
- Server Actions

c) Database Layer:
- PostgreSQL Database (indicated by Prisma usage)
- Prisma ORM

##### Key Components

Frontend Components:
- Public pages (home, about, privacy)
- Dashboard section
- Feedback management interface
- UI Components library (components/ui directory)

API Layer:
- Authentication endpoints (/api/auth)
- Feedback endpoints (/api/feedback)
- Server actions (createProject, deleteFeedback, etc.)

Database Layer:
- Prisma models and relationships:
- User model
- Project model
- Feedback model
- Relationships between these models

External Services:
- Google OAuth (for authentication)
- Any third-party integrations

##### Data Flow Representation

- Authentication flow (user → Google OAuth → NextAuth → Database)
- Feedback collection flow (Embedded Widget → API → Database)
- Dashboard data retrieval flow (Database → API → Frontend)

##### Technical Stack Indicators

- Next.js
- TypeScript
- Prisma
- PostgreSQL
- TailwindCSS
- NextAuth

##### Deployment Architecture

Show:
- Production environment
- Development environment
- Database hosting
- Static asset serving

**[Client Layer (Browser/Embedded Widget)]**
- ↕
**[Next.js Frontend Layer]**
- ↕
**[API/Server Layer]**
- ↕
**[Database Layer]**

- Separation between the dashboard application and the embedded widget
- Authentication flow as it's crucial for the SaaS model
- Clear boundaries between public and authenticated sections
- Feedback collection pipeline from third-party websites to the dashboard
- Demonstrate how real-time updates will be implemented
- Future features (like customizable modal and analytics) as planned expansions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Browser/Client"]
        Widget["Embedded Widget"]:::widget
    end

    subgraph Frontend
        NextApp["Next.js Application"]:::frontend
        click NextApp "https://github.com/avayyyyyyy/opinify/blob/main/app/layout.tsx"
        
        subgraph PublicPages
            Home["Home Page"]:::frontend
            click Home "https://github.com/avayyyyyyy/opinify/blob/main/app/page.tsx"
            About["About Page"]:::frontend
            click About "https://github.com/avayyyyyyy/opinify/blob/main/app/about/page.tsx"
            Privacy["Privacy Page"]:::frontend
            click Privacy "https://github.com/avayyyyyyy/opinify/blob/main/app/privacy/page.tsx"
        end

        subgraph DashboardUI
            Dashboard["Dashboard Interface"]:::frontend
            click Dashboard "https://github.com/avayyyyyyy/opinify/blob/main/app/dashboard/page.tsx"
            FeedbackMgmt["Feedback Management"]:::frontend
            click FeedbackMgmt "https://github.com/avayyyyyyy/opinify/tree/main/app/dashboard/feedbacks"
            ProjectMgmt["Project Management"]:::frontend
            click ProjectMgmt "https://github.com/avayyyyyyy/opinify/blob/main/components/CreateProject.tsx"
        end

        UILib["UI Components Library"]:::frontend
        click UILib "https://github.com/avayyyyyyy/opinify/tree/main/components/ui"
    end

    subgraph ServerLayer
        subgraph APIRoutes
            AuthAPI["Authentication API"]:::api
            click AuthAPI "https://github.com/avayyyyyyy/opinify/blob/main/app/api/auth/[...nextauth]/route.ts"
            FeedbackAPI["Feedback API"]:::api
            click FeedbackAPI "https://github.com/avayyyyyyy/opinify/blob/main/app/api/feedback/route.ts"
        end

        subgraph ServerActions
            CreateProject["Create Project Action"]:::action
            click CreateProject "https://github.com/avayyyyyyy/opinify/blob/main/app/actions/createProject.ts"
            DeleteFeedback["Delete Feedback Action"]:::action
            click DeleteFeedback "https://github.com/avayyyyyyy/opinify/blob/main/app/actions/deleteFeedback.ts"
            DeleteProject["Delete Project Action"]:::action
            click DeleteProject "https://github.com/avayyyyyyy/opinify/blob/main/app/actions/deleteProject.ts"
        end

        Auth["Authentication System"]:::auth
        click Auth "https://github.com/avayyyyyyy/opinify/blob/main/lib/auth.ts"
    end

    subgraph Database
        PostgreSQL["PostgreSQL Database"]:::db
        PrismaORM["Prisma ORM"]:::db
        click PrismaORM "https://github.com/avayyyyyyy/opinify/blob/main/prisma/schema.prisma"
        
        subgraph Models
            UserModel["User Model"]:::model
            ProjectModel["Project Model"]:::model
            FeedbackModel["Feedback Model"]:::model
        end
    end

    subgraph ExternalServices
        GoogleOAuth["Google OAuth"]:::external
    end

    %% Relationships
    Browser --> NextApp
    Widget --> FeedbackAPI
    NextApp --> APIRoutes
    NextApp --> ServerActions
    Auth --> GoogleOAuth
    Auth --> PostgreSQL
    APIRoutes --> PrismaORM
    ServerActions --> PrismaORM
    PrismaORM --> PostgreSQL
    
    %% Model Relationships
    UserModel --> ProjectModel
    ProjectModel --> FeedbackModel

    %% Styles
    classDef frontend fill:#3498db,color:#fff
    classDef api fill:#2ecc71,color:#fff
    classDef action fill:#27ae60,color:#fff
    classDef auth fill:#9b59b6,color:#fff
    classDef db fill:#f1c40f,color:#000
    classDef model fill:#e67e22,color:#fff
    classDef external fill:#95a5a6,color:#fff
    classDef widget fill:#e74c3c,color:#fff

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Endpoint"]:::api
        Action["Server Action"]:::action
        AuthComp["Auth Component"]:::auth
        Database["Database Component"]:::db
        Model["Data Model"]:::model
        External["External Service"]:::external
        WidgetComp["Widget Component"]:::widget
    end
```
