# diegovianagomes/architecture-survey architecture

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

- Interactive diagram: https://gitdiagram.com/diegovianagomes/architecture-survey
- Repository: https://github.com/diegovianagomes/architecture-survey

## Overview

##### Main Components

- Frontend (User Interface):
- Pages and Routes: Represented by the Next.js "app" directory, which holds various pages including home, survey page, researcher/admin login, survey confirmation, and even example submissions.
- UI Components: Use of folders such as "components" and "components/ui" indicates a rich, reusable component system for elements like forms, charts (bar, pie, vertical-bar charts), alerts, dialogs, and other interactive UI elements.
- Styling: Global styles from "app/globals.css" and Tailwind configuration (tailwind.config.ts) should be noted.

- API Layer:
- A variety of API endpoints under "app/api" that handle different functionalities: email check, registration, survey submission, and reset data. These endpoints define routes to interact with both client-side and server-side logic.

- Backend / Data Services:
- Supabase Integration: The "lib/supabase", "lib/supabase-admin.ts", and "lib/supabase-client.ts" files indicate how the project communicates with Supabase for authentication, database queries, and possibly real-time data updates.
- Utility Functions: Located in "lib/utils" and related files, these provide helper functions (like email encryption and other business logic) related to data processing and security.

- Administration and Data Analysis:
- Admin Pages: The "app/admin" directory encapsulates the administration panel, used for reviewing and exporting research results.

##### Relationships and Interactions

- User Interaction Flow:
- Users (students/respondents) access the survey page to enter their responses.
- The frontend sends these responses to API endpoints (e.g., "app/api/submit-survey" or "app/api/survey/submit"), where the data is validated and then processed.
- During the survey process, email verification is performed (via endpoints like "app/api/check-email" and "app/api/register-email") with encryption before saving.

- Administrative Flow:
- Researchers or administrators log in via designated pages such as "app/researcher-login" or "app/admin/page.tsx".
- Once authenticated (backed by Supabase’s authentication processes), they can view survey results and detailed analyses.
- Data visualization is achieved through multiple chart components that render statistics on user responses.

- Data and Security:
- The API endpoints interact with a database (Supabase) through the lib layer.
- A dedicated set of utilities (under "lib/utils/email-crypto.ts") is used for ensuring email uniqueness and encryption, highlighting the security measures built into the system.

##### Architectural Patterns and Technologies

- Modern Full-Stack Architecture:
- Frontend built with Next.js using both server- and client-side rendering.
- API routes following RESTful patterns that handle data submission, retrieval, and security functions.

- Component-Based UI:
- Extensive use of reusable React components from shadcn/ui for consistency and scalability.

- Backend as a Service:
- Supabase integration central to managing data, making authentication secure, and executing CRUD operations on survey responses.

- Utility-driven Logic:
- Lib folders providing encapsulated business logic and helper functions essential for maintaining separation of concerns and reusability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend - Pages
    subgraph "Frontend - Pages"
        FE_Home["Home Page (Next.js)"]:::frontend
        FE_Survey["Survey Page (Next.js)"]:::frontend
        FE_Research["Researcher Login (Next.js)"]:::frontend
        FE_Admin["Admin Page (Next.js)"]:::frontend
    end

    %% Frontend - UI Components
    subgraph "Frontend - UI Components"
        UI_EmailCheck["Email Check Form (React)"]:::frontend
        UI_Button["Button Component (shadcn/ui)"]:::frontend
        UI_Advanced["Advanced Analysis Component (Charts)"]:::frontend
    end

    %% Frontend - Styling
    subgraph "Frontend - Styling"
        GS_Global["Global CSS (Tailwind)"]:::frontend
        GS_Tailwind["Tailwind Config (Tailwind)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        API_Check["Check Email API (REST)"]:::api
        API_Register["Register Email API (REST)"]:::api
        API_Submit["Submit Survey API (REST)"]:::api
    end

    %% Backend / Data Services
    subgraph "Backend / Data Services"
        SUPA["Supabase Core (Auth & DB)"]:::backend
        SUP_Admin["Supabase Admin"]:::backend
        SUP_Client["Supabase Client"]:::backend
        UT_EmailCrypto["Email Encryption Utility"]:::utility
    end

    %% Administration & Analytics
    subgraph "Administration & Analytics"
        AD_Panel["Admin Dashboard"]:::admin
        CH_Charts["Data Analysis & Charts"]:::admin
    end

    %% Connections: Frontend Pages and API
    FE_Survey -->|"submit"| API_Submit
    UI_EmailCheck -->|"check"| API_Check
    UI_EmailCheck -->|"register"| API_Register

    %% Connections: API Layer to Backend / Utilities
    API_Submit -->|"storeData"| SUPA
    API_Check -->|"validateEmail"| UT_EmailCrypto
    API_Register -->|"encryptEmail"| UT_EmailCrypto
    API_Check -->|"dbQuery"| SUPA
    API_Register -->|"dbUpdate"| SUPA

    %% Connections: Supabase internal flows
    SUPA -->|"adminOps"| SUP_Admin
    SUPA -->|"clientOps"| SUP_Client

    %% Connections: Backend to Administration & Analytics
    SUPA -->|"provideData"| AD_Panel
    SUPA -->|"analyticsData"| CH_Charts
    UI_Advanced -->|"renderCharts"| CH_Charts

    %% Connections: Frontend Styling applied to Pages
    GS_Global --- FE_Home
    GS_Global --- FE_Survey
    GS_Global --- FE_Research
    GS_Global --- FE_Admin
    GS_Tailwind --- GS_Global

    %% Navigation connection from Researcher Login to Admin Page
    FE_Research -->|"access"| FE_Admin

    %% Optional connection: UI Components used within Pages
    FE_Survey --- UI_EmailCheck
    FE_Survey --- UI_Button

    %% Click Events for Frontend Pages
    click FE_Home "https://github.com/diegovianagomes/architecture-survey/blob/master/app/page.tsx"
    click FE_Survey "https://github.com/diegovianagomes/architecture-survey/blob/master/app/survey/page.tsx"
    click FE_Research "https://github.com/diegovianagomes/architecture-survey/blob/master/app/researcher-login/page.tsx"
    click FE_Admin "https://github.com/diegovianagomes/architecture-survey/blob/master/app/admin/page.tsx"

    %% Click Events for UI Components
    click UI_EmailCheck "https://github.com/diegovianagomes/architecture-survey/blob/master/components/email-check-form.tsx"
    click UI_Button "https://github.com/diegovianagomes/architecture-survey/blob/master/components/ui/button.tsx"
    click UI_Advanced "https://github.com/diegovianagomes/architecture-survey/blob/master/components/advanced-analysis.tsx"

    %% Click Events for Global Styling
    click GS_Global "https://github.com/diegovianagomes/architecture-survey/blob/master/app/globals.css"
    click GS_Tailwind "https://github.com/diegovianagomes/architecture-survey/blob/master/tailwind.config.ts"

    %% Click Events for API Endpoints
    click API_Check "https://github.com/diegovianagomes/architecture-survey/blob/master/app/api/check-email/route.ts"
    click API_Register "https://github.com/diegovianagomes/architecture-survey/blob/master/app/api/register-email/route.ts"
    click API_Submit "https://github.com/diegovianagomes/architecture-survey/blob/master/app/api/submit-survey/route.ts"

    %% Click Events for Supabase Integration
    click SUPA "https://github.com/diegovianagomes/architecture-survey/tree/master/lib/supabase"
    click SUP_Admin "https://github.com/diegovianagomes/architecture-survey/blob/master/lib/supabase-admin.ts"
    click SUP_Client "https://github.com/diegovianagomes/architecture-survey/blob/master/lib/supabase-client.ts"

    %% Click Event for Utility Function
    click UT_EmailCrypto "https://github.com/diegovianagomes/architecture-survey/blob/master/lib/utils/email-crypto.ts"

    %% Styling Classes
    classDef frontend fill:#ACE1AF,stroke:#333,stroke-width:2px;
    classDef api fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef utility fill:#F4A460,stroke:#333,stroke-width:2px;
    classDef admin fill:#DDA0DD,stroke:#333,stroke-width:2px;
```
