# brainstation-23/openofficesurvey architecture

> Architecture diagram of the GitHub repository brainstation-23/openofficesurvey, 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/brainstation-23/openofficesurvey
- Repository: https://github.com/brainstation-23/openofficesurvey

## Overview

##### Main Components
- Frontend Client: Represent the client-side React application that includes:
- Pages (admin, user, survey, live, public, etc.) and components (UI library, navigation, dashboards, etc.).
- State management and hooks (React Query, custom hooks for OKR, survey responses, etc.).
- Routing management as seen from the pages organized under src/pages.
- Backend & Database (Supabase):
- Supabase Database: PostgreSQL with pre-defined SQL setup and seed scripts located under supabase/DB Setup and supabase/Seed Data.
- Supabase Authentication: Using Supabase Auth for sign-in (Email, OAuth, Magic Link) as indicated in the README and integrations.
- Supabase Functions (Serverless/API):
- Serverless functions located in supabase/functions, handling operations such as creating users, sending emails, managing surveys, toggling user status, etc.
- CI/CD & Deployment:
- GitHub workflows (.github/workflows folder) for continuous integration (SonarCloud, gitguardian, ORT) and configuration files like netlify.toml that show the deployment to Netlify.
- Third-Party Libraries & Tools:
- Tailwind CSS and Shadcn UI for styling.
- Vite as the build tool.
- ESLint, TypeScript configurations, and testing directories for quality and testing.

##### Interactions and Data Flow
- The Client (Frontend):
- Interacts with Supabase using the client integration found in src/integrations/supabase/client.ts.
- Communicates with Supabase Auth for user login and role-based access.
- Fetches and manages data (surveys, analytics, user data) via React Query and the provided custom hooks.
- Backend & Serverless:
- The Supabase Database stores survey details, user data, responses and configuration.
- Supabase Functions act as the API layer for survey management tasks (e.g., bulk operations, sending reminders, email service) and communicate with the database.
- CI/CD and Deployment:
- Code quality and automated testing are enforced via GitHub workflows.
- The frontend is deployed (Netlify) and integrated with the Supabase backend.

##### Architectural Patterns and Principles
- Component-Based Frontend Design: Strict separation of UI components into logical modules (admin, OKRs, surveys, team, etc.), layouts, and navigation.
- Modular Backend with Serverless Functions: Supabase functions encapsulate discrete business logic, keeping the backend modular and scalable.
- Integration & Config Driven: Use of configuration files (tsconfig, vite.config.ts, and supabase/config.toml) to manage environment-specific settings.
- Test-Driven Development: The presence of a robust __tests__ directory for backend and component-level testing shows a focus on quality assurance.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend Layer"
        F["Frontend Client (React + TypeScript)"]:::frontend
        P["Pages & Routing (src/pages)"]:::frontend
        I["Supabase Client Integration"]:::frontend
    end

    subgraph "Backend Layer"
        A["Supabase Authentication"]:::backend
        D["Supabase Database (PostgreSQL)"]:::backend
        S["Supabase Functions (Serverless APIs)"]:::functions
    end

    subgraph "CI/CD & Deployment"
        G["GitHub Workflows (CI/CD)"]:::infra
        N["Netlify Deployment"]:::infra
    end

    F -->|"auth_calls"| A
    F -->|"api_calls"| S
    S -->|"db_ops"| D
    A -->|"user_verification"| D
    F -->|"render_pages"| P
    F -->|"integration"| I
    G -->|"deploys_to"| N
    N -->|"hosts"| F

    click F "https://github.com/brainstation-23/openofficesurvey/tree/main/src/"
    click P "https://github.com/brainstation-23/openofficesurvey/tree/main/src/pages"
    click I "https://github.com/brainstation-23/openofficesurvey/blob/main/src/integrations/supabase/client.ts"
    click D "https://github.com/brainstation-23/openofficesurvey/tree/main/supabase/DB Setup"
    click A "https://github.com/brainstation-23/openofficesurvey/blob/main/supabase/functions/_shared/auth-service.ts"
    click S "https://github.com/brainstation-23/openofficesurvey/tree/main/supabase/functions"
    click G "https://github.com/brainstation-23/openofficesurvey/tree/main/.github/workflows"
    click N "https://github.com/brainstation-23/openofficesurvey/blob/main/netlify.toml"

    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef functions fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef infra fill:#d3d3d3,stroke:#000,stroke-width:2px;
```
