# 100xdevs-cohort-2/zapier-week-33 architecture

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

- Interactive diagram: https://gitdiagram.com/100xdevs-cohort-2/zapier-week-33
- Repository: https://github.com/100xdevs-cohort-2/zapier-week-33

## Overview

##### Project type and purpose
- This is a full-stack web application that includes several distinct services. The frontend is built with Next.js (using React), and the backend is divided into multiple services:
– The “primary-backend” handles the main API endpoints (with routing for users, zap, triggers, and actions).
– The “hooks” service appears to manage database-related routines (likely running Prisma migrations and perhaps additional hook logic).
– The “processor” and “worker” directories indicate asynchronous processing tasks, such as handling email verifications, password resets, and reconciling Solana transactions (as mentioned in the README TODOs).
- The README emphasizes user verification via email, a password reset feature, and specifically handling edge cases with Solana transactions (avoiding duplicate payments). This confirms both user-centric and external system integrations.

##### And break down the components from the file structure
- Frontend:
- Contains a Next.js application with a structured “app” directory that organizes pages for dashboard, login, signup, and specific functionality (e.g., the “zap” feature).
- Contains components and buttons that construct the UI.
- Primary-backend:
- Hosts the main API routes (folders like “router” for actions, triggers, users, and zaps) and handles business logic.
- Uses Prisma (the “schema.prisma”, migrations, and seed files indicate a relational database).
- Hooks:
- Contains its own Prisma schema and associated migrations, suggesting it either runs supplementary tasks during DB changes (or holds shared migrations).
- Likely centralizes some pre- or post-processing hooks for database events.
- Processor:
- Likely serves as an intermediary service that processes tasks asynchronously (as seen from its “index.ts” source file).
- Worker:
- Designed for background job processing (files for email, parsing, and Solana interaction), and is responsible for managing external integrations (sending emails, interacting with the Solana network, etc.).

- Frontend Application (Next.js UI)
- Primary Backend API Service
- Hooks Service (for database migrations and hook-related operations)
- Processor Service (for asynchronous business processing)
- Worker Service (for handling email notifications, parsing, and Solana transactions)
- Shared Database (accessed via Prisma from multiple backend services)
- External Systems (e.g., Email Service Provider and Solana Blockchain Network)

b. Relationships and Interactions:
- User Interaction: Users perform actions (login, signup, dashboard interaction) via the Frontend.
- API Gateway: The Frontend communicates with the Primary Backend API through HTTP requests, triggering endpoints for user actions, zap actions, etc.
- Database Interactions: The Primary Backend (and perhaps the Hooks service) interact with a central database using Prisma, handling migrations and schema updates.
- Asynchronous Processing:
- When a user signs up or needs a password reset, the Primary Backend can trigger events that are processed by the Worker Service — for example, sending verification emails.
- The Worker Service and Processor interact with external systems (sending emails, interacting with the Solana network) and processing asynchronous tasks.
- Hooks service could be visualized as supporting the entire system’s data consistency by managing migrations and potentially triggering business events.

c. Architectural Patterns and Technologies:
- Full-stack separation (Frontend vs. Backend) and a clear API layer.
- Microservices-like separation for different backend jobs (Primary Backend, Processor, Worker, Hooks).
- Asynchronous job processing for handling long-running tasks and external service interactions (e.g., email and blockchain).
- Use of Prisma ORM for database interactions.
- Next.js framework for server-side rendering and React for UI.

– Represent “Hooks” as its own service that deals with migrations; use it to call out the shared purpose.
– Include “Processor” and “Worker” as separate asynchronous job handlers, with “Worker” explicitly interacting with email tasks and the Solana integration.
– Data flow from the Frontend to the Primary Backend.
– Database queries going from backend services (Primary, Hooks, Worker, Processor) to the Database.
– External API calls from Worker/Processor to Email and Solana systems.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User-Facing Component
    FE["Frontend (Next.js/React)"]:::frontend

    %% Backend Services Subgraph
    subgraph "Backend Services"
        PB["Primary Backend API Service"]:::backend
        HS["Hooks Service"]:::backend
        PS["Processor Service"]:::backend
        WS["Worker Service"]:::backend
    end

    %% Shared Resources and External Systems
    DB["Database"]:::database
    ES["Email Service"]:::external
    SN["Solana Network"]:::external

    %% Data flow and communication arrows
    FE -->|"HTTP"| PB
    PB -->|"DBQuery"| DB
    HS -->|"Migrations"| DB
    PS -->|"Job Query"| DB
    WS -->|"Job Query"| DB

    %% Asynchronous processing flows
    PB -.->|"AsyncTrigger"| WS
    WS -->|"SendEmail"| ES
    WS -->|"SolanaReconcile"| SN
    PS -->|"SolanaIntegration"| SN

    %% Click Events
    click FE "https://github.com/100xdevs-cohort-2/zapier-week-33/tree/main/frontend"
    click PB "https://github.com/100xdevs-cohort-2/zapier-week-33/tree/main/primary-backend/src"
    click HS "https://github.com/100xdevs-cohort-2/zapier-week-33/tree/main/hooks"
    click PS "https://github.com/100xdevs-cohort-2/zapier-week-33/blob/main/processor/src/index.ts"
    click WS "https://github.com/100xdevs-cohort-2/zapier-week-33/tree/main/worker/src"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef database fill:#ffcccb,stroke:#333,stroke-width:2px;
    classDef external fill:#ffe4b5,stroke:#333,stroke-width:2px;
```
