# zashouri91/feedbackpulse architecture

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

- Interactive diagram: https://gitdiagram.com/zashouri91/feedbackpulse
- Repository: https://github.com/zashouri91/feedbackpulse

## Overview

##### Main System Components

a) Frontend Layer:
- React-based SPA structure (indicated by src/App.tsx and Vite configuration)
- Feature modules:
- Survey Management
- Analytics Dashboard
- User Management
- Authentication
- Notifications

b) API/Backend Layer:
- Supabase Integration:
- Real-time capabilities (indicated by realtime.sql migration)
- Authentication services
- Database access

c) Database Layer:
- Supabase PostgreSQL database with the following main entities:
- Surveys
- Templates
- Responses
- Users
- Groups
- Locations
- Audit Logs
- Notifications

##### Component Relationships

a) Client-Side Flow:
**UI Components → Hooks → API Clients → Supabase Client**

b) Data Flow:
**Frontend ←→ Supabase Real-time ←→ Database**

##### Specific Architectural Elements

Key architectural patterns:

a) Authentication Flow:
- Auth provider component integration
- RBAC implementation (role-gate and permission-gate components)

b) Real-time Updates:
- Websocket connections for live feedback
- Notification system architecture

c) Analytics Pipeline:
- Data collection flow
- Analytics processing
- Dashboard visualization

##### Technical Stack Indicators

- React + TypeScript (Frontend)
- Supabase (Backend + Database)
- Tailwind CSS (Styling)
- Cypress (Testing)
- Sentry (Error Tracking)
- PostHog (Analytics)

##### Important Details

a) Security Layer:
- RLS policies (shown in migrations)
- Authentication boundaries
- Permission checks

b) Feature Modules:
- Survey management
- Template system
- Analytics dashboard
- User management
- Audit logging
- Notification system

**┌─────────────────────────────────────────────┐**
- Client Layer                │
- (React Components, Hooks, Context Providers)│
- ┤
- Integration Layer              │
- (API Clients, Real-time Subscribers)     │
- ┤
- Supabase Layer               │
- (Auth, Storage, Real-time, RLS Policies)   │
- ┤
- Database Layer                 │
- (PostgreSQL Tables, Functions, Triggers) │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[Frontend SPA]:::frontend
        RC[React Components]:::frontend
        Hooks[Custom Hooks]:::frontend
        ErrorB[Error Boundaries]:::frontend
        
        subgraph "Feature Modules"
            SM[Survey Management]:::frontend
            AD[Analytics Dashboard]:::frontend
            UM[User Management]:::frontend
            NS[Notification System]:::frontend
            TS[Template System]:::frontend
            AL[Audit Logging]:::frontend
            Settings[Settings]:::frontend
        end
        
        subgraph "Auth Components"
            Auth[Authentication]:::auth
            RBAC[Role-Based Access]:::auth
            PG[Permission Gate]:::auth
        end
    end
    
    subgraph "Integration Layer"
        API[API Client]:::api
        RTH[Real-time Handler]:::realtime
        AH[API Hooks]:::api
    end
    
    subgraph "Supabase Layer"
        SC[Supabase Client]:::backend
        RTS[Real-time Service]:::realtime
        AuthS[Auth Service]:::auth
        RLS[Row Level Security]:::security
    end
    
    subgraph "Database Layer"
        DB[(PostgreSQL)]:::database
        Surveys[(Surveys)]:::database
        Templates[(Templates)]:::database
        Users[(Users)]:::database
        Groups[(Groups)]:::database
        Locations[(Locations)]:::database
        AuditLogs[(Audit Logs)]:::database
        Notifs[(Notifications)]:::database
    end
    
    UI --> RC
    RC --> Hooks
    Hooks --> API
    API --> SC
    SC --> DB
    
    RTS --> RTH
    RTH --> NS
    
    Auth --> AuthS
    AuthS --> RLS
    RLS --> DB
    
    %% Component Mappings
    click SM "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/surveys/"
    click AD "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/charts/"
    click UM "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/management/"
    click Auth "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/auth/"
    click NS "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/notifications/"
    click SC "https://github.com/zashouri91/FeedbackPulse/blob/main/src/lib/supabase.ts"
    click API "https://github.com/zashouri91/FeedbackPulse/tree/main/src/lib/api/"
    click RTH "https://github.com/zashouri91/FeedbackPulse/blob/main/src/lib/hooks/use-realtime.ts"
    click DB "https://github.com/zashouri91/FeedbackPulse/blob/main/supabase/migrations/20240101000000_initial_schema.sql"
    click RBAC "https://github.com/zashouri91/FeedbackPulse/blob/main/src/lib/utils/rbac.ts"
    click AL "https://github.com/zashouri91/FeedbackPulse/blob/main/src/components/audit/audit-log-viewer.tsx"
    click ErrorB "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/error-boundary/"
    click TS "https://github.com/zashouri91/FeedbackPulse/blob/main/src/components/surveys/survey-template-editor.tsx"
    click AH "https://github.com/zashouri91/FeedbackPulse/tree/main/src/lib/hooks/"
    click PG "https://github.com/zashouri91/FeedbackPulse/blob/main/src/components/auth/permission-gate.tsx"
    click Settings "https://github.com/zashouri91/FeedbackPulse/tree/main/src/components/settings/"
    click RTS "https://github.com/zashouri91/FeedbackPulse/blob/main/supabase/migrations/20240310_enable_realtime.sql"

    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef database fill:#FFC107,color:black
    classDef auth fill:#9C27B0,color:white
    classDef realtime fill:#FF5722,color:white
    classDef api fill:#607D8B,color:white
    classDef security fill:#F44336,color:white

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        B[Backend]:::backend
        D[Database]:::database
        A[Auth]:::auth
        R[Real-time]:::realtime
        AP[API]:::api
        S[Security]:::security
    end
```
