# rony-star1/emailcraft_pro architecture

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

- Interactive diagram: https://gitdiagram.com/rony-star1/emailcraft_pro
- Repository: https://github.com/rony-star1/emailcraft_pro

## Overview

##### Project Type and Purpose
- This is a full-stack web application. The front end is a React single-page application (SPA) built with Vite, TailwindCSS, React Router v6, Redux Toolkit, D3/Recharts, React Hook Form, Framer Motion, Jest/RTL.
- The back end is a Node.js/Express API server in `server/`, exposing REST routes for campaigns, contacts, payments, analytics, and AI. It uses middleware for auth/validation and services to integrate with external providers (MistralAI, DodoPayments).

##### File Structure
- Top-level directories:
- `public/`: static assets, HTML template, manifest, redirects, images.
- `src/`: React app source—components, pages, routes, styles, utils, services.
- `server/`: Express app—`.env` template, middleware, routes, services, `server.js`.
- Config files:
- Vite (`vite.config.mjs`), Tailwind (`tailwind.config.js`, `postcss.config.js`), environment (`.env`, `server/.env.example`).
- Patterns:
- Front-end follows component-based and page-based routing (React Router).
- Back-end follows MVC-style separation: routes → middleware → services.

##### README Insights
- Confirms tech stack and tools (React 18, Vite, Tailwind, Redux Toolkit, etc.)
- No internal DB folder—likely uses an external database (not in code tree).
- Mentions data visualization and form management components.

##### Main Components
a. Frontend SPA
– Entry point (`index.html` → `src/index.jsx`)
– React component tree (`App.jsx`, `Routes.jsx`, `pages/`, `components/`)
– State management (Redux Toolkit slices, not shown but implied)
b. Backend API
– Express server (`server/server.js`)
– Route modules (`server/routes/*.js`)
– Middleware (`auth.js`, `validation.js`)
– Service modules (`mistralAI.js`, `dodoPayments.js`)
c. External Services
– AI provider (MistralAI)
– Payment gateway (DodoPayments or third-party API)
– Analytic store or external analytics if any
– (Implicit) Database (Postgres, MongoDB, etc.)
d. Static Asset Hosting
– Public folder served by Vite/Express or CDN

##### Relationships and Data Flows
- User browser ←→ Frontend SPA (HTTP/HTTPS)
- SPA → Backend API (REST calls, JSON payloads)
- Backend → External Services (HTTP/HTTPS calls to AI and payments)
- Backend ↔ Database (CRUD operations)
- SPA ← Static assets (CSS, images) from CDN or Express static server

##### Architectural Patterns and Principles
- Frontend: component-based UI, declarative routing, unidirectional data flow via Redux
- Backend: layered architecture (routes → middleware → services)
- Separation of concerns: UI, business logic, data access, external integrations
- Environment-based configuration (`.env`) for secrets and endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend (Browser)"
        A_index["index.html"]:::frontend
        A_bootstrap["src/index.jsx"]:::frontend
        A_root["src/App.jsx"]:::frontend
        A_routes["src/Routes.jsx"]:::frontend
        A_components["src/components"]:::frontend
        A_pages["src/pages"]:::frontend
        A_apiClient["src/utils/api.js"]:::frontend
        A_public["public/"]:::frontend
        A_vite["vite.config.mjs"]:::frontend
        A_tailwind["tailwind.config.js"]:::frontend
        A_postcss["postcss.config.js"]:::frontend
    end

    subgraph "Backend (Express API)"
        B_server["server/server.js"]:::backend
        subgraph "Routes"
            B_routesFolder["server/routes/"]:::backend
            B_ai["server/routes/ai.js"]:::backend
            B_analytics["server/routes/analytics.js"]:::backend
            B_campaigns["server/routes/campaigns.js"]:::backend
            B_contacts["server/routes/contacts.js"]:::backend
            B_paymentsRoute["server/routes/payments.js"]:::backend
        end
        subgraph "Middleware"
            B_auth["server/middleware/auth.js"]:::backend
            B_validation["server/middleware/validation.js"]:::backend
        end
        subgraph "Services"
            B_mistral["server/services/mistralAI.js"]:::backend
            B_paymentsService["server/services/dodoPayments.js"]:::backend
        end
        B_envServer["server/.env.example"]:::backend
    end

    subgraph "Data & External Services"
        DB["External Database"]:::database
        AI["MistralAI Service"]:::external
        Payment["Payment Gateway"]:::external
    end

    %% Frontend flow
    A_index --> A_bootstrap
    A_bootstrap --> A_root
    A_root --> A_routes
    A_root --> A_components
    A_root --> A_pages
    A_routes --> A_apiClient
    A_root --> A_public
    A_root -.-> A_vite
    A_root -.-> A_tailwind
    A_root -.-> A_postcss

    %% API calls
    A_apiClient -->|"REST API calls"| B_server

    %% Backend internal structure
    B_server --> B_routesFolder
    B_routesFolder --> B_ai
    B_routesFolder --> B_analytics
    B_routesFolder --> B_campaigns
    B_routesFolder --> B_contacts
    B_routesFolder --> B_paymentsRoute
    B_routesFolder --> B_auth
    B_routesFolder --> B_validation
    B_routesFolder --> B_mistral
    B_routesFolder --> B_paymentsService
    B_server --> B_envServer

    %% Service integrations
    B_mistral -->|"AI requests"| AI
    B_paymentsService -->|"Payment processing"| Payment
    B_server -->|"CRUD operations"| DB

    %% Click Events
    click A_index "https://github.com/rony-star1/emailcraft_pro/blob/main/index.html"
    click A_bootstrap "https://github.com/rony-star1/emailcraft_pro/blob/main/src/index.jsx"
    click A_root "https://github.com/rony-star1/emailcraft_pro/blob/main/src/App.jsx"
    click A_routes "https://github.com/rony-star1/emailcraft_pro/blob/main/src/Routes.jsx"
    click A_components "https://github.com/rony-star1/emailcraft_pro/tree/main/src/components"
    click A_pages "https://github.com/rony-star1/emailcraft_pro/tree/main/src/pages"
    click A_apiClient "https://github.com/rony-star1/emailcraft_pro/blob/main/src/utils/api.js"
    click A_public "https://github.com/rony-star1/emailcraft_pro/tree/main/public/"
    click A_vite "https://github.com/rony-star1/emailcraft_pro/blob/main/vite.config.mjs"
    click A_tailwind "https://github.com/rony-star1/emailcraft_pro/blob/main/tailwind.config.js"
    click A_postcss "https://github.com/rony-star1/emailcraft_pro/blob/main/postcss.config.js"
    click B_server "https://github.com/rony-star1/emailcraft_pro/blob/main/server/server.js"
    click B_routesFolder "https://github.com/rony-star1/emailcraft_pro/tree/main/server/routes/"
    click B_ai "https://github.com/rony-star1/emailcraft_pro/blob/main/server/routes/ai.js"
    click B_analytics "https://github.com/rony-star1/emailcraft_pro/blob/main/server/routes/analytics.js"
    click B_campaigns "https://github.com/rony-star1/emailcraft_pro/blob/main/server/routes/campaigns.js"
    click B_contacts "https://github.com/rony-star1/emailcraft_pro/blob/main/server/routes/contacts.js"
    click B_paymentsRoute "https://github.com/rony-star1/emailcraft_pro/blob/main/server/routes/payments.js"
    click B_auth "https://github.com/rony-star1/emailcraft_pro/blob/main/server/middleware/auth.js"
    click B_validation "https://github.com/rony-star1/emailcraft_pro/blob/main/server/middleware/validation.js"
    click B_mistral "https://github.com/rony-star1/emailcraft_pro/blob/main/server/services/mistralAI.js"
    click B_paymentsService "https://github.com/rony-star1/emailcraft_pro/blob/main/server/services/dodoPayments.js"
    click B_envServer "https://github.com/rony-star1/emailcraft_pro/blob/main/server/.env.example"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef database fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px
```
