# nalindalal/zapier architecture

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

- Interactive diagram: https://gitdiagram.com/nalindalal/zapier
- Repository: https://github.com/nalindalal/zapier

## Overview

##### Project’s Main Components
- Frontend – A Next.js application (located under the “frontend” folder) that provides the user interface for login, signup, dashboard, and zap creation. It interfaces with the backend through API calls (using axios).
- Primary Backend – An Express.js-based service (in the “primary-backend” folder) that sets up routes (e.g., user and zap routers) to handle core requests from the frontend. It also integrates schema-based validations (with libraries like zod) and authentication logic.
- Hooks – A component that initializes webhooks and sets up database interactions using Prisma. It includes the initial schema (User, Zap, Trigger, Action, etc.) and represents the first entry point for webhook-related processes.
- Processor – A Kafka-based service (in the “processor” folder) that is responsible for consuming and processing asynchronous events from Kafka topics (like “zap-events”). It further processes the data received (e.g., by performing transformations or filtering) before passing it along.
- Worker – A background job handler (in the “worker” folder) that takes on additional processing tasks such as sending emails, parsing data, and interacting with external services (like Solana blockchain operations).

##### Interactions and Data Flow
- The Frontend issues API calls to the Primary Backend. The frontend also may trigger events that eventually result in webhooks being created.
- The Primary Backend receives these requests and interacts with the database using Prisma. It may also forward events to the asynchronous processing layer.
- The Hooks component manages webhook registrations and directly deals with webhook events (e.g., an event fired from GitHub), ensuring that the correct trigger states are updated and data is recorded.
- When a webhook event occurs, it is communicated asynchronously—typically published into the Kafka message broker.
- The Processor service consumes these Kafka messages, processes them, and may prepare specific payloads for further actions.
- The Worker module picks up processing tasks (e.g., sending emails, parsing data, executing Solana-related actions) based on outputs from the processor or through scheduled triggers.
- A PostgreSQL database (run in Docker in different modules) is central to storing the schema-driven data. Ensure you capture that each service uses Prisma to interact with a shared or replicated DB.

##### Architectural Patterns and Design Principles
- Separation of Concerns – Notice how the frontend, API/backend, webhooks, asynchronous processing (processor) and background tasks (worker) are separated into different modules.
- Asynchronous Messaging – The use of Kafka clearly defines a decoupled, event-driven architecture for handling webhook events.
- Monorepo Structure – Emphasize that while each module (frontend, hooks, primary-backend, processor, worker) exists independently, they are orchestrated together as part of a larger system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE["Frontend (Next.js, Tailwind, axios)"]:::ui
    end

    subgraph "Backend Services"
        PB["Primary Backend (Express, Zod, Prisma)"]:::backend
        HK["Hooks (Webhooks, Prisma)"]:::backend
    end

    subgraph "Asynchronous Processing"
        PR["Processor (Kafka, kafkajs)"]:::async
        WK["Worker (Nodemailer, Solana, etc)"]:::async
    end

    Kafka["Kafka Broker (zap-events)"]:::external
    DB[(PostgreSQL Database)]:::db

    FE -->|"APIcalls"| PB
    PB -->|"DB_ReadWrite"| DB
    HK -->|"TriggerUpdates"| DB
    PB -->|"PublishEvents"| Kafka
    HK -->|"PublishWebhook"| Kafka
    Kafka -->|"ConsumeMessages"| PR
    PR -->|"TriggerTasks"| WK
    PR -->|"PersistData"| DB

    click FE "https://github.com/nalindalal/zapier/tree/main/frontend/"
    click PB "https://github.com/nalindalal/zapier/tree/main/primary-backend/"
    click HK "https://github.com/nalindalal/zapier/tree/main/hooks/"
    click PR "https://github.com/nalindalal/zapier/tree/main/processor/"
    click WK "https://github.com/nalindalal/zapier/tree/main/worker/"

    classDef ui fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef async fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef db fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;
```
