# tybens/sartorial architecture

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

- Interactive diagram: https://gitdiagram.com/tybens/sartorial
- Repository: https://github.com/tybens/sartorial

## Overview

##### Main Components
- Frontend Application: Focus on the React code located in the “src” folder. This includes UI components, pages, hooks, assets, and routing. This portion is responsible for the overall user interface and interaction.
- Static Assets and Hosting: The “public” folder contains HTML files, images, videos, PDFs, and other static content. Firebase Hosting deploys these assets along with the React bundle.
- Backend Services – Firebase Cloud Functions: The “functions” directory contains server-side JavaScript that handles backend logic such as processing donations, handling checkout payments, or sending emails. This is an important microservice component.
- Database – Cloud Firestore: The presence of “firestore.rules” and “firestore.indexes.json” indicates a Firestore database, which stores transactional data, user data, products, orders, etc.
- Email Templates: The “emails” directory provides HTML templates for different email communications (like pickup or receipt notifications).

##### Relationships and Data Flow
- User Interaction: A user accesses the site via Firebase Hosting. The static files in “public” load the React app from “src.”
- API Calls: As users interact with the site (for example, submitting donation forms or checking out in the shop), the React application makes calls to Firebase Cloud Functions (in “functions”) to execute server-side operations.
- Database Integration: Cloud Functions interact with Firestore for reading and writing data (orders, product details, etc.). Also, the React frontend might query Firestore directly for real-time data, depending on the implementation.
- Email Communication: On events like order confirmation or shipment notifications, a Cloud Function sends emails using the HTML templates from the “emails” folder.
- Hosting Updates: Changes in the code (for instance, updates in “src” or “public”) are deployed via Firebase Hosting as configured by “firebase.json” and related configuration files.

##### Architectural Patterns and Important Design Principles
- Separation of Concerns: The clear separation between the React frontend (UI), Firebase Cloud Functions (backend logic), and Firestore (data storage) makes the architecture modular.
- Serverless Backend: Using Firebase Cloud Functions provides horizontal scalability and isolates concerns between business logic and the UI layer.
- Declarative UI and Component-Based Structure: The “src/components” and “src/pages” directories follow a component-based design typical of modern React applications.
- Security and Indexing: The Firestore rules and indexes ensure that data is secured and performance-tuned.
- Continuous Integration/Deployment: The presence of GitHub workflows (in .github/workflows) suggests automated CI/CD pipelines, which may be noted in the system deployment overview.

##### Relevant Technologies and Frameworks
- React for the frontend.
- Firebase Hosting for static content delivery.
- Firebase Cloud Functions (Node.js-based) for backend processing.
- Cloud Firestore for the database.
- GitHub Actions for deployment workflows (firebase-hosting-merge and pull-request workflows).

- Make note of any deployment configuration details, such as Firebase Hosting and GitHub workflows, to provide context on continuous integration/deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User["User Browser"]:::user
    CI_CD["CI/CD Pipeline (GitHub Actions)"]:::backend

    %% Frontend Layer
    Firebase_Hosting["Firebase Hosting"]:::hosting
    React_App["React App"]:::frontend

    %% Backend Layer
    Firebase_Cloud_Functions["Firebase Cloud Functions"]:::backend

    %% Database Layer
    subgraph "Cloud Firestore"
        FR["Security Rules"]:::database
        FI["Indexes"]:::database
    end

    %% Email Service
    Email_Service["Email Service"]:::email

    %% Connections
    User -->|"accesses"| Firebase_Hosting
    CI_CD -->|"deploys"| Firebase_Hosting
    CI_CD -->|"deploys"| Firebase_Cloud_Functions
    Firebase_Hosting -->|"loads UI"| React_App
    React_App -->|"APIcalls"| Firebase_Cloud_Functions
    React_App -->|"query"| FR
    Firebase_Cloud_Functions -->|"read/write"| FR
    Firebase_Cloud_Functions -->|"sendEmail"| Email_Service

    %% Click Events
    click React_App "https://github.com/tybens/sartorial/tree/main/src/"
    click Firebase_Hosting "https://github.com/tybens/sartorial/tree/main/public/"
    click Firebase_Cloud_Functions "https://github.com/tybens/sartorial/tree/main/functions/"
    click FR "https://github.com/tybens/sartorial/blob/main/firestore.rules"
    click FI "https://github.com/tybens/sartorial/blob/main/firestore.indexes.json"
    click Email_Service "https://github.com/tybens/sartorial/tree/main/emails/"

    %% Styles
    classDef user fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef frontend fill:#AEC6CF,stroke:#333,stroke-width:2px;
    classDef hosting fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef backend fill:#F4A460,stroke:#333,stroke-width:2px;
    classDef database fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef email fill:#FFB6C1,stroke:#333,stroke-width:2px;
```
