# henrybhudson/pay-it-forward architecture

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

- Interactive diagram: https://gitdiagram.com/henrybhudson/pay-it-forward
- Repository: https://github.com/henrybhudson/pay-it-forward

## Overview

##### Project type and purpose
- Pay it Forward is a full-stack web application.
- Front end: static HTML/JS/CSS in the “client” folder, providing pages for index, login, registration, and chain interactions.
- Back end: Node.js + Express in the “server” folder exposing RESTful endpoints.
- Persistence: flat-file JSON database (users.json, chains.json, events.json).

##### File structure
- Top-level folders:
– client/ (static UI)
– client_old/ (previous version of UI)
– server/ (API server)
- server/ subfolders:
– routes/ (defines HTTP endpoints in userRoutes.js)
– controllers/ (request handlers in userController.js)
– database/ (JSON files as the data store)
- Core files: server/index.js (Express app entry point), package.json (dependencies).

##### README
- Purpose: enable users to start and extend “chains” of goodwill.
- Run instructions: server with “node index.js”; front end with Live Server.
- No external services—communication is purely between browser and the Express server.

a. Main components
- Browser / Client UI (index.html, login.html, register.html, script.js, login.js, register.js).
- API Server (Express application):
– HTTP listener (index.js)
– Routing layer (userRoutes.js)
– Controller layer (userController.js)
– Data access (reads/writes JSON in database/).
- Data store: JSON files as a lightweight database.
b. Relationships and interactions
- Browser → HTTP requests (GET/POST/PUT) → Express server routes
- Routes → Controller logic → read/write JSON files → controller returns JSON → Browser updates UI
c. Architectural patterns and design principles
- Layered MVC-style separation: routes (entry), controllers (business logic), database (persistence).
- RESTful API design for user authentication, chain creation, nomination.
- Flat-file database for simplicity—no external RDBMS.
d. Key technologies and libraries
- Node.js, Express.js for server
- Vanilla JavaScript, HTML, CSS for client
- JSON files as data store

##### Essential details
- Every JSON file you depend on in the database layer.
- Folder hierarchy in your sub-components (e.g., server/routes, server/controllers).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Side"
        direction TB
        subgraph "Current Client (client)"
            direction TB
            Index["index.html"]:::client
            LoginPage["login.html"]:::client
            RegisterPage["register.html"]:::client
            Script["script.js"]:::client
            LoginJS["login.js"]:::client
            RegisterJS["register.js"]:::client
            CSS["main.css"]:::client
        end
        subgraph "Legacy Client (client_old)"
            direction TB
            OldIndex["index.html"]:::client
            OldScript["script.js"]:::client
            OldCSS["main.css"]:::client
        end
    end

    subgraph "Server Side"
        direction TB
        Entry["server/index.js"]:::server
        subgraph "Routing Layer (routes)"
            direction TB
            Routes["userRoutes.js"]:::server
        end
        subgraph "Controller Layer (controllers)"
            direction TB
            Controller["userController.js"]:::server
        end
        subgraph "Data Store (JSON Files)"
            direction TB
            Users["users.json"]:::data
            Chains["chains.json"]:::data
            Events["events.json"]:::data
        end
        Dependencies["package.json\npackage-lock.json"]:::server
    end

    Index -->|"POST /login\nGET /chains"| Entry
    LoginPage -->|"POST /login"| Entry
    RegisterPage -->|"POST /register"| Entry
    Script -->|"AJAX calls"| Entry
    Entry -->|"uses routes"| Routes
    Routes -->|"calls handlers"| Controller
    Controller -->|"read/write"| Users
    Controller -->|"read/write"| Chains
    Controller -->|"read/write"| Events
    Controller -->|"sends JSON"| Index

    click Index "https://github.com/henrybhudson/pay-it-forward/blob/main/client/index.html"
    click LoginPage "https://github.com/henrybhudson/pay-it-forward/blob/main/client/login.html"
    click RegisterPage "https://github.com/henrybhudson/pay-it-forward/blob/main/client/register.html"
    click Script "https://github.com/henrybhudson/pay-it-forward/blob/main/client/script.js"
    click LoginJS "https://github.com/henrybhudson/pay-it-forward/blob/main/client/login.js"
    click RegisterJS "https://github.com/henrybhudson/pay-it-forward/blob/main/client/register.js"
    click CSS "https://github.com/henrybhudson/pay-it-forward/blob/main/client/main.css"
    click OldIndex "https://github.com/henrybhudson/pay-it-forward/blob/main/client_old/index.html"
    click OldScript "https://github.com/henrybhudson/pay-it-forward/blob/main/client_old/script.js"
    click OldCSS "https://github.com/henrybhudson/pay-it-forward/blob/main/client_old/main.css"
    click Entry "https://github.com/henrybhudson/pay-it-forward/blob/main/server/index.js"
    click Routes "https://github.com/henrybhudson/pay-it-forward/blob/main/server/routes/userRoutes.js"
    click Controller "https://github.com/henrybhudson/pay-it-forward/blob/main/server/controllers/userController.js"
    click Users "https://github.com/henrybhudson/pay-it-forward/blob/main/server/database/users.json"
    click Chains "https://github.com/henrybhudson/pay-it-forward/blob/main/server/database/chains.json"
    click Events "https://github.com/henrybhudson/pay-it-forward/blob/main/server/database/events.json"
    click Dependencies "https://github.com/henrybhudson/pay-it-forward/blob/main/server/package.json"

    classDef client fill:#8fbc8f,stroke:#333,stroke-width:1px
    classDef server fill:#87cefa,stroke:#333,stroke-width:1px
    classDef data fill:#ffa500,stroke:#333,stroke-width:1px
```
