# fizasayyed/betterworld architecture

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

- Interactive diagram: https://gitdiagram.com/fizasayyed/betterworld
- Repository: https://github.com/fizasayyed/betterworld

## Overview

##### Main System Components

A. Frontend Layer (Next.js Application)
- Client-side Components
- Server-side Components
- Authentication System
- API Integration Layer

B. Backend Layer (Node.js Application)
- API Routes
- Controllers
- Models
- Database Integration
- Payment Processing

##### Detailed Component Breakdown

Frontend Section:
- Core Pages (/, /donate, /donate/create/payment/stripe)
- Authentication Components (SignIn/SignOut)
- UI Components Layer
- Form Management (useFormStore)
- API Client Services

Backend Section:
- API Routes Layer
- Controllers (Payment, User, Webhook)
- Models Layer (Payment, User)
- Database Connection
- Configuration Management

##### External Services Integration
- Stripe Payment Processing
- Authentication Provider (NextAuth.js)
- Database System

##### Connection Flows

- Frontend → Backend API calls
- Backend → Database operations
- Payment Flow: Frontend → Stripe → Webhook → Backend
- Authentication Flow: User → NextAuth → External Provider

##### Specific Implementation Details

- Next.js 13+ App Router architecture
- RESTful API endpoints
- Stripe payment integration
- NextAuth.js authentication flow
- Database models and relationships

##### Component Relationships

Key relationships:
- Frontend form components → API client → Backend controllers
- Payment controller → Stripe integration → Webhook handling
- User authentication → Protected routes
- Database models → Controller operations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        FPages["Pages"]
        AuthSystem["Authentication System"]
        UIComp["UI Components"]
        FormMgmt["Form Management"]
        APIInt["API Integration"]
        CoreComp["Core Components"]
        CheckoutForm["Checkout Form"]
    end

    subgraph Backend
        APIRoutes["API Routes"]
        Controllers["Controllers"]
        Models["Models"]
        DBInt["Database Integration"]
        WebhookC["Webhook Controller"]
    end

    subgraph External
        Stripe["Stripe Payment"]
        NextAuth["NextAuth.js"]
        DB[(Database)]
    end

    %% Frontend Relationships
    FPages --> APIInt
    AuthSystem --> NextAuth
    FormMgmt --> APIInt
    CheckoutForm --> Stripe
    CoreComp --> APIInt

    %% Backend Relationships
    APIInt --> APIRoutes
    APIRoutes --> Controllers
    Controllers --> Models
    Models --> DBInt
    DBInt --> DB
    Stripe --> WebhookC
    WebhookC --> Models

    %% Authentication Flow
    NextAuth --> AuthSystem
    
    %% Styling
    classDef frontend fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef backend fill:#98ff98,stroke:#333,stroke-width:2px
    classDef external fill:#e6b3ff,stroke:#333,stroke-width:2px
    classDef database fill:#ffa07a,stroke:#333,stroke-width:2px

    class FPages,AuthSystem,UIComp,FormMgmt,APIInt,CoreComp,CheckoutForm frontend
    class APIRoutes,Controllers,Models,DBInt,WebhookC backend
    class Stripe,NextAuth external
    class DB database

    %% Click Events
    click FPages "https://github.com/fizasayyed/betterworld/tree/main/frontend/src/app"
    click AuthSystem "https://github.com/fizasayyed/betterworld/blob/main/frontend/src/app/api/auth/[...nextauth]"
    click UIComp "https://github.com/fizasayyed/betterworld/tree/main/frontend/src/components/ui"
    click FormMgmt "https://github.com/fizasayyed/betterworld/blob/main/frontend/src/lib/useFormStore.ts"
    click APIInt "https://github.com/fizasayyed/betterworld/blob/main/frontend/src/lib/api/apiClient.ts"
    click CoreComp "https://github.com/fizasayyed/betterworld/blob/main/frontend/src/components/navbar/navbar.tsx"
    click CheckoutForm "https://github.com/fizasayyed/betterworld/blob/main/frontend/src/components/checkoutForm/checkoutForm.tsx"
    click APIRoutes "https://github.com/fizasayyed/betterworld/blob/main/backend/src/routes/api.js"
    click Controllers "https://github.com/fizasayyed/betterworld/blob/main/backend/src/controllers/paymentController.js"
    click Models "https://github.com/fizasayyed/betterworld/blob/main/backend/src/models/payment.js"
    click DBInt "https://github.com/fizasayyed/betterworld/blob/main/backend/config/database.js"
    click WebhookC "https://github.com/fizasayyed/betterworld/blob/main/backend/src/controllers/webhookController.js"
```
