# farkroft/emaily architecture

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

## Overview

##### Project Type and Purpose
- This is a full-stack JavaScript personal project named “emaily.”

##### Analyzing the File Structure
a. Client (Frontend):
- Located in the "client" directory, it includes environment configurations (e.g., .env.development, .env.production).
- The "src" folder contains React components (App, Dashboard, Landing, etc.) and Redux related files (actions, reducers).
- It also contains setup files such as setupProxy.js to handle API routing to the backend during development.
- This clearly shows a single-page application approach using React and Redux.

b. Server (Backend):
- The root contains Express server entry point (index.js), configuration files (in the "config" directory) for keys and production settings.
- There are directories for routes (authRoutes.js, billingRoutes.js, surveyRoutes.js), controllers (surveys_controller.js), models (User, Survey, Recipient), and middlewares (requireLogin, requireCredits).
- The "services" directory contains utilities such as Mailer.js and emailTemplates (for survey emails) and passport.js for authentication.

c. Additional Infrastructure:
- The presence of configuration files (.gitignore, package.json, etc.) and a SendGrid webhook script indicate integration with external email delivery services.
- The separation between client and server folders suggests a clear separation of concerns, which is a typical full-stack design pattern.

##### Final Advice
- Be very detailed in capturing every key architectural element outlined in the file tree. Do not hesitate to split the system into as many logical components as possible.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Application"
        FE["Client (React SPA)"]:::frontend
        FE_C["Components (React UI)"]:::frontend
        FE_A["Redux Actions"]:::frontend
        FE_R["Redux Reducers"]:::frontend
        FE_P["Setup Proxy"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Application"
        BS["Express Server"]:::backend
        %% API Routes Sub-layer
        subgraph "API Routes"
            R_Auth["Auth Routes"]:::backend
            R_Billing["Billing Routes"]:::backend
            R_Survey["Survey Routes"]:::backend
        end
        Controller["Surveys Controller"]:::backend
        subgraph "Middlewares"
            MW_Login["requireLogin"]:::backend
            MW_Credits["requireCredits"]:::backend
        end
        Models["Data Models"]:::backend
        AuthPassport["Authentication (Passport)"]:::backend
        %% Configuration Sub-layer
        subgraph "Configurations"
            Config_Keys["Keys Configuration"]:::config
            Config_Prod["Production Config"]:::config
        end
    end

    %% External Services Layer
    subgraph "External Services"
        Mailer["Mailer Service (SendGrid)"]:::external
        EmailTemplates["Email Templates"]:::external
        Webhook["SendGrid Webhook"]:::external
    end

    %% Frontend Connections
    FE -->|"apiCall"| BS
    FE --> FE_C
    FE --> FE_A
    FE --> FE_R
    FE --> FE_P

    %% Backend Connections
    BS -->|"handles"| R_Auth
    BS -->|"handles"| R_Billing
    BS -->|"handles"| R_Survey
    R_Survey -->|"invokes"| Controller
    R_Auth -->|"uses"| MW_Login
    R_Survey -->|"checks"| MW_Login
    R_Survey -->|"verifies"| MW_Credits
    Controller -->|"modifies"| Models
    BS -->|"integrates"| AuthPassport
    BS -->|"loads"| Config_Keys
    BS -->|"loads"| Config_Prod
    Controller -->|"sends emails"| Mailer

    %% External Services Connections
    Mailer -->|"includes"| EmailTemplates
    Mailer -->|"triggers"| Webhook

    %% Styling
    classDef frontend fill:#a8dadc,stroke:#457b9d,stroke-width:2px;
    classDef backend fill:#f4a261,stroke:#e76f51,stroke-width:2px;
    classDef external fill:#e9c46a,stroke:#f4a261,stroke-width:2px;
    classDef config fill:#b7e4c7,stroke:#2a9d8f,stroke-width:2px;

    %% Click Events for Frontend
    click FE "https://github.com/farkroft/emaily/tree/master/client"
    click FE_C "https://github.com/farkroft/emaily/tree/master/client/src/components"
    click FE_A "https://github.com/farkroft/emaily/tree/master/client/src/actions"
    click FE_R "https://github.com/farkroft/emaily/tree/master/client/src/reducers"
    click FE_P "https://github.com/farkroft/emaily/blob/master/client/src/setupProxy.js"

    %% Click Events for Backend
    click BS "https://github.com/farkroft/emaily/blob/master/index.js"
    click R_Auth "https://github.com/farkroft/emaily/blob/master/routes/authRoutes.js"
    click R_Billing "https://github.com/farkroft/emaily/blob/master/routes/billingRoutes.js"
    click R_Survey "https://github.com/farkroft/emaily/blob/master/routes/surveyRoutes.js"
    click Controller "https://github.com/farkroft/emaily/blob/master/controllers/surveys_controller.js"
    click MW_Login "https://github.com/farkroft/emaily/blob/master/middlewares/requireLogin.js"
    click MW_Credits "https://github.com/farkroft/emaily/blob/master/middlewares/requireCredits.js"
    click Models "https://github.com/farkroft/emaily/tree/master/models/"
    click AuthPassport "https://github.com/farkroft/emaily/blob/master/services/passport.js"
    click Config_Keys "https://github.com/farkroft/emaily/blob/master/config/keys.js"
    click Config_Prod "https://github.com/farkroft/emaily/blob/master/config/prod.js"

    %% Click Events for External Services
    click Mailer "https://github.com/farkroft/emaily/blob/master/services/Mailer.js"
    click EmailTemplates "https://github.com/farkroft/emaily/tree/master/services/emailTemplates/"
    click Webhook "https://github.com/farkroft/emaily/blob/master/sendgrid_webhook.sh"
```
