# mjwhite10/diverr architecture

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

- Interactive diagram: https://gitdiagram.com/mjwhite10/diverr
- Repository: https://github.com/mjwhite10/diverr

## Overview

##### Overall Project Breakdown
- Two major layers:
- Frontend Client: Built with React and organized into pages, components, hooks, context, services, and utilities.
- Backend API Server: A Node/Express application that exposes RESTful endpoints, controls business logic through controllers (for users and diverrs), and connects to an SQL database.
- Database as a separate component, using the provided SQL schema definitions and relationships (User, Diverrs, States, Categories, Solutions, and Comments).

##### Main Components and Their Interactions
a. Frontend (React):
- Pages: Representing various views (HomePage, DiverrPage, LoginPage, RegisterPage, etc.).
- Components: Divided into smaller, reusable UI pieces (Header, Footer, DiverrCard, Comment, etc.).
- Context Providers: AuthContext and QueryContext that manage authentication state and search functionalities.
- Services & Utilities: API service functions to handle HTTP calls (userService, diverrService, API utility).
- Hooks: Custom hooks (e.g., useDiverr, useMyDiverrs, useCategories) for managing data fetching and state.

b. Backend (Express API):
- Server Bootstrap: The entry point (server.js) that sets up the Express server and middleware.
- Controllers: Separated by domain (users and diverrs). The controllers folder further divides operations into CRUD actions (e.g., new, delete, edit, list, get) for both users and diverrs (and their associated comments/solutions).
- Middlewares: For authentication and role verification (e.g., isUser, isAdmin) ensuring proper access control.
- Validators: To enforce correct request payloads (diverrsValidators.js and userValidators.js).
- Database Layer: Contains database initialization (initDB.js), queries (getDB.js), and SQL file (diverr.sql). It represents the connection and interactions with the SQL-based datastore.
- Helpers & Utilities: Shared functions that orchestrate common logic across controllers.

c. Database:
- A SQL database that stores:
- Users (with credentials, profile details, etc.)
- Diverrs (each digital service need with title, info, file associations, price, etc.)
- Comments, Solutions, Categories, and Statuses for diverrs.

- For the Frontend:
- Main sub-components (Pages, Components, Contexts, Hooks, Services, Utilities).
- For the Backend:
- Backend to the Database indicating CRUD operations performed by the backend.
- For the Database:
- Data flow from Backend → Database and vice versa.
- Optionally, indicate the testing and configuration files (like .env, .eslint, etc.) as supporting the overall configuration and reliability of the system.

##### Emphasizing Architectural Patterns and Technologies
- That the project employs a layered architecture:
- The presentation layer (React Frontend) is decoupled from business logic (Express backend).
- The backend itself follows a controller-service pattern with middleware for authentication/authorization.
- That RESTful API endpoints are used for all interactions, following a typical full-stack pattern.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend (React)"
        FE_Pages["Pages"]
        FE_Components["Components"]
        FE_Context["Context Providers"]
        FE_Hooks["Hooks"]
        FE_Utilities["Utilities"]
        FE_Services["Services"]
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        BE_Server["Server Bootstrap"]
        BE_UserCtrls["User Controllers"]
        BE_DiverrCtrls["Diverr Controllers"]
        BE_Middlewares["Middlewares"]
        BE_Validators["Validators"]
        BE_Utils["Helpers & Utilities"]
        BE_DB["Database Layer"]
    end

    %% Database Component
    DB["SQL Database (Users, Diverrs, States, Categories, Solutions, Comments)"]

    %% Frontend Internal Flow
    FE_Pages -->|"renders"| FE_Services
    FE_Components -->|"renders"| FE_Services
    FE_Context -->|"state_management"| FE_Services
    FE_Hooks -->|"data_fetching"| FE_Services
    FE_Utilities -->|"support"| FE_Services

    %% Frontend to Backend Communication
    FE_Services -->|"API_call"| BE_Server

    %% Backend Internal Flow
    BE_Server -->|"routes"| BE_UserCtrls
    BE_Server -->|"routes"| BE_DiverrCtrls

    BE_UserCtrls -->|"middleware"| BE_Middlewares
    BE_DiverrCtrls -->|"middleware"| BE_Middlewares

    BE_UserCtrls -->|"validation"| BE_Validators
    BE_DiverrCtrls -->|"validation"| BE_Validators

    BE_UserCtrls -->|"uses"| BE_Utils
    BE_DiverrCtrls -->|"uses"| BE_Utils

    %% Backend to Database Communication
    BE_Server -->|"CRUD_operations"| BE_DB
    BE_DB -->|"SQL_interactions"| DB
    DB -->|"results"| BE_DB

    %% Click Events for Frontend Components
    click FE_Pages "https://github.com/mjwhite10/diverr/tree/main/frontend/src/pages"
    click FE_Components "https://github.com/mjwhite10/diverr/tree/main/frontend/src/components"
    click FE_Context "https://github.com/mjwhite10/diverr/tree/main/frontend/src/context"
    click FE_Hooks "https://github.com/mjwhite10/diverr/tree/main/frontend/src/hooks"
    click FE_Services "https://github.com/mjwhite10/diverr/tree/main/frontend/src/services"
    click FE_Utilities "https://github.com/mjwhite10/diverr/tree/main/frontend/src/utilities"

    %% Click Events for Backend Components
    click BE_Server "https://github.com/mjwhite10/diverr/blob/main/backend/server.js"
    click BE_UserCtrls "https://github.com/mjwhite10/diverr/tree/main/backend/controllers/users"
    click BE_DiverrCtrls "https://github.com/mjwhite10/diverr/tree/main/backend/controllers/diverrs"
    click BE_Middlewares "https://github.com/mjwhite10/diverr/tree/main/backend/middlewares"
    click BE_Validators "https://github.com/mjwhite10/diverr/tree/main/backend/validators"
    click BE_Utils "https://github.com/mjwhite10/diverr/blob/main/backend/helpers.js"
    click BE_DB "https://github.com/mjwhite10/diverr/tree/main/backend/db"

    %% Click Event for Database
    click DB "https://github.com/mjwhite10/diverr/blob/main/backend/db/diverr.sql"

    %% Style Definitions
    classDef frontend fill:#D0EFFF,stroke:#333,stroke-width:2px;
    classDef backend fill:#FFD8B1,stroke:#333,stroke-width:2px;
    classDef database fill:#DFFFD0,stroke:#333,stroke-width:2px;

    class FE_Pages,FE_Components,FE_Context,FE_Hooks,FE_Services,FE_Utilities frontend;
    class BE_Server,BE_UserCtrls,BE_DiverrCtrls,BE_Middlewares,BE_Validators,BE_Utils,BE_DB backend;
    class DB database;
```
