# str-well/orcamentos-pai architecture

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

- Interactive diagram: https://gitdiagram.com/str-well/orcamentos-pai
- Repository: https://github.com/str-well/orcamentos-pai

## Overview

##### Main Components
- Frontend (Client):
- Located in the client/ directory.
- Built with React, TypeScript, Tailwind CSS, Radix UI, and other libraries.
- Contains pages (authentication, dashboard, budgets CRUD, PDF preview, and price search), UI components (from common buttons to intricate UI patterns), and hooks for state and API integration.
- Backend & API:
- Found in both the server/ and api/ directories.
- Handles authentication (server/auth), budget operations (CRUD endpoints), routing, business logic, and PDF generation (server/pdf-generator.ts).
- Contains utility libraries (like supabase API wrappers and openai integration).
- Supabase Infrastructure:
- Shown in the supabase/ folder with functions (e.g., generate-budget-pdf and update-budget-status) and migrations.
- Acts as the Database (PostgreSQL), provides authentication (via Supabase Auth), storage, and edge functions.
- Shared Resources:
- shared/ and src/ directories hold common schema definitions and contexts which are utilized across both client and server layers to ensure consistency.

- From the API/Backend, show interactions with “Supabase Database & Storage” for reading/writing data, handling authentication, and file storage.
- A connection/path for third-party libraries (such as Puppeteer for PDF or OpenAI for smart functionalities if applicable).

##### Architectural Patterns and Design Principles
- Separation between the frontend and backend. Note how the API endpoints (e.g., POST/GET/PUT/DELETE for budgets) provide a RESTful interface.
- Use of containerized or modular components; for example, in the frontend, components and hooks are grouped by function (budget pages vs. shared components).
- Use of “shared” schema definitions to maintain consistency between client and server models.
- Asynchronous data flow via React Query, automated state management using hooks, and how user authentication is handled via Supabase.

##### Relevant Technologies & Frameworks
- Frontend: React, TypeScript, Tailwind CSS, Radix UI, Shadcn UI, React Hook Form, Zod, React Query, Framer Motion, Wouter, Recharts.
- Backend: Node/TypeScript, Express-style routing (or similar), supabase libraries, Puppeteer (for PDF generation), and potential integrations with OpenAI.
- Infrastructure: Supabase for database (PostgreSQL), authentication, storage, and edge functions.

##### Additional Details
- Details such as how authentication flows from login/registration screens (client) to the API and then to Supabase Auth.
- Role of utility libraries such as those in client/src/lib and server/lib for managing essential operations like protected routes and querying Supabase.
- Incorporate deployment elements: note that the frontend is deployed on Vercel and backend likely runs in serverless functions or a managed container environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (React App)"]:::frontend
        PC["Pages & UI Components"]:::frontend
        Auth["Authentication Page"]:::frontend
        Dash["Dashboard"]:::frontend
        CRUD["Budget CRUD"]:::frontend
        PDFP["PDF Preview"]:::frontend
        Price["Price Search"]:::frontend
        FE --> PC
        FE --> Auth
        Auth --> Dash
        Dash --> CRUD
        CRUD --> PDFP
        PDFP --> Price
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        API["API/Backend Services"]:::backend
        AuthLogic["Authentication & Business Logic"]:::backend
        PDFModule["PDF Generation Module"]:::backend
        APIEndpoints["RESTful API Endpoints"]:::backend
        ThirdParty["Third-Party Integrations (Puppeteer&OpenAI)"]:::backend
        API --> AuthLogic
        API --> PDFModule
        API --> APIEndpoints
        PDFModule -->|"integrates"| ThirdParty
    end

    %% Supabase Infrastructure
    subgraph "Supabase Infrastructure"
        Supa["Supabase (DB & Auth)"]:::supabase
        Storage["Storage"]:::supabase
        Edge["Edge Functions"]:::supabase
        Supa --> Storage
        Supa --> Edge
    end

    %% Shared Resources
    subgraph "Shared Resources"
        Shared["Shared Schema & Contexts"]:::shared
        SharedLib["Client-Server Shared Lib"]:::shared
        Shared --> SharedLib
    end

    %% Interactions
    FE ---|"client_requests"| API
    API ---|"data_CRUD"| Supa
    API ---|"trigger_functions"| Edge
    Shared ---|"provides_schema"| FE
    Shared ---|"provides_context"| API

    %% Styles
    classDef frontend fill:#A7D7C5,stroke:#333,stroke-width:2px;
    classDef backend fill:#F7D794,stroke:#333,stroke-width:2px;
    classDef supabase fill:#F3A683,stroke:#333,stroke-width:2px;
    classDef shared fill:#C39BD3,stroke:#333,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/str-well/orcamentos-pai/tree/main/client/"
    click PC "https://github.com/str-well/orcamentos-pai/tree/main/client/src"
    click API "https://github.com/str-well/orcamentos-pai/tree/main/server/"
    click AuthLogic "https://github.com/str-well/orcamentos-pai/tree/main/server/auth"
    click PDFModule "https://github.com/str-well/orcamentos-pai/blob/main/server/pdf-generator.ts"
    click APIEndpoints "https://github.com/str-well/orcamentos-pai/blob/main/api/[...path].ts"
    click Supa "https://github.com/str-well/orcamentos-pai/tree/main/supabase/"
    click Shared "https://github.com/str-well/orcamentos-pai/tree/main/shared/"
    click SharedLib "https://github.com/str-well/orcamentos-pai/tree/main/src/"
```
