# astracivictech/greenquest architecture

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

- Interactive diagram: https://gitdiagram.com/astracivictech/greenquest
- Repository: https://github.com/astracivictech/greenquest

## Overview

##### Project type and purpose
- This is a full-stack web application with a React/Vite front end, an Express/Node back end, and a PostgreSQL database accessed via Knex.
- Features include user authentication (cookie-based sessions), user profile management, and CRUD operations on users.

##### File structure
- Top level:
- frontend/ – React app with Vite, organized into adapters (API calls), components, pages, contexts, styles, utils
- server/ – Express API segmented into controllers, models, middleware, and database (knex configuration, migrations, seeds)
- Config files: package.json at root, frontend/package.json, server/package.json, .env.template, knexfile.js
- Documentation folder with architecture and proposal docs

##### Insights from README
- Tech stack: Node, Express, PostgreSQL, React, Knex
- Usage: build & start commands (omitted)
- Style guide: Airbnb JavaScript

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client" 
        direction TB
        Browser["Web Browser"]:::client
        Browser -->|"GET /static assets"| ViteDev["Vite Dev Server / Static Host"]:::infra
    end

    %% Frontend Layer
    subgraph "Frontend (React/Vite)" 
        direction TB
        ReactApp["React App (Vite)"]:::frontend
        ReactApp -->|"renders UI"| Main["main.jsx"]:::frontend
        ReactApp -->|"boots App"| AppJSX["App.jsx"]:::frontend
        ReactApp -->|"config"| ViteConfig["vite.config.js"]:::frontend

        subgraph "Adapters"
            AuthAdapter["auth-adapter.js"]:::frontend
            UserAdapter["user-adapter.js"]:::frontend
        end
        subgraph "Contexts"
            CurrentUserProvider["CurrentUserContextProvider.jsx"]:::frontend
            CurrentUserContext["current-user-context.js"]:::frontend
        end
        subgraph "Components"
            SiteNav["SiteHeadingAndNav.jsx"]:::frontend
            UpdateForm["UpdateUsernameForm.jsx"]:::frontend
            UserLink["UserLink.jsx"]:::frontend
        end
        subgraph "Pages"
            HomePage["Home.jsx"]:::frontend
            LoginPage["Login.jsx"]:::frontend
            SignUpPage["SignUp.jsx"]:::frontend
            UsersPage["Users.jsx"]:::frontend
            UserPage["User.jsx"]:::frontend
            NotFoundPage["NotFound.jsx"]:::frontend
        end
        subgraph "Utils"
            FetchUtils["fetchingUtils.js"]:::frontend
        end

        ReactApp --> Adapters
        ReactApp --> Contexts
        ReactApp --> Components
        ReactApp --> Pages
        ReactApp --> Utils
        Browser --> ReactApp
        ReactApp -->|"API calls"| API["Express API"]:::backend
    end

    %% Backend Layer
    subgraph "Backend API (Express/Node)" 
        direction TB
        APIEntry["index.js"]:::backend
        subgraph "Middleware Stack"
            AuthCheck["checkAuthentication.js"]:::backend
            CookieSession["handleCookieSessions.js"]:::backend
            RouteLogger["logRoutes.js"]:::backend
            ErrorLogger["logErrors.js"]:::backend
        end
        subgraph "Controllers"
            AuthController["authControllers.js"]:::backend
            UserController["userControllers.js"]:::backend
        end
        subgraph "Models"
            UserModel["User.js"]:::backend
        end
        subgraph "DB Config"
            KnexConfig["knex.js"]:::backend
            Knexfile["knexfile.js"]:::backend
            EnvTemplate[".env.template"]:::backend
        end
        subgraph "Migrations"
            Migration1["20230423034706_create_users_table.js"]:::db
            Migration2["20240514201137_add_timestamps_to_users.js"]:::db
        end
        subgraph "Seeds"
            SeedInit["init.js"]:::db
        end

        APIEntry --> MiddlewareStack
        MiddlewareStack --> Controllers
        Controllers --> Models
        Models --> KnexConfig
        KnexConfig -->|"connect"| Postgres[(PostgreSQL)]:::db
        Knexfile --> KnexConfig
        EnvTemplate --> KnexConfig
        KnexConfig --> Migrations
        KnexConfig --> Seeds
    end

    %% Database
    subgraph "Database" 
        direction TB
        Postgres
    end

    %% External/Infrastructure
    subgraph "Infrastructure & External"
        direction TB
        StaticHost["S3/CloudFront or NGINX"]:::infra
        EnvVault["Vault / .env"]:::infra
        CICD["CI/CD Pipeline"]:::infra
    end

    %% Connections
    ViteDev --> StaticHost
    API -->|"SQL queries via Knex"| Postgres
    Postgres -->|"results"| API
    StaticHost --> Browser
    EnvVault --> API
    CICD --> StaticHost
    CICD --> API

    %% Click Events
    click Browser "https://github.com/astracivictech/greenquest/blob/main/frontend/index.html"
    click Main "https://github.com/astracivictech/greenquest/blob/main/frontend/src/main.jsx"
    click AppJSX "https://github.com/astracivictech/greenquest/blob/main/frontend/src/App.jsx"
    click ViteConfig "https://github.com/astracivictech/greenquest/blob/main/frontend/vite.config.js"
    click AuthAdapter "https://github.com/astracivictech/greenquest/blob/main/frontend/src/adapters/auth-adapter.js"
    click UserAdapter "https://github.com/astracivictech/greenquest/blob/main/frontend/src/adapters/user-adapter.js"
    click CurrentUserProvider "https://github.com/astracivictech/greenquest/blob/main/frontend/src/contexts/CurrentUserContextProvider.jsx"
    click CurrentUserContext "https://github.com/astracivictech/greenquest/blob/main/frontend/src/contexts/current-user-context.js"
    click SiteNav "https://github.com/astracivictech/greenquest/blob/main/frontend/src/components/SiteHeadingAndNav.jsx"
    click UpdateForm "https://github.com/astracivictech/greenquest/blob/main/frontend/src/components/UpdateUsernameForm.jsx"
    click UserLink "https://github.com/astracivictech/greenquest/blob/main/frontend/src/components/UserLink.jsx"
    click HomePage "https://github.com/astracivictech/greenquest/blob/main/frontend/src/pages/Home.jsx"
    click LoginPage "https://github.com/astracivictech/greenquest/blob/main/frontend/src/pages/Login.jsx"
    click SignUpPage "https://github.com/astracivictech/greenquest/blob/main/frontend/src/pages/SignUp.jsx"
    click UsersPage "https://github.com/astracivictech/greenquest/blob/main/frontend/src/pages/Users.jsx"
    click UserPage "https://github.com/astracivictech/greenquest/blob/main/frontend/src/pages/User.jsx"
    click NotFoundPage "https://github.com/astracivictech/greenquest/blob/main/frontend/src/pages/NotFound.jsx"
    click FetchUtils "https://github.com/astracivictech/greenquest/blob/main/frontend/src/utils/fetchingUtils.js"
    click APIEntry "https://github.com/astracivictech/greenquest/blob/main/server/index.js"
    click AuthController "https://github.com/astracivictech/greenquest/blob/main/server/controllers/authControllers.js"
    click UserController "https://github.com/astracivictech/greenquest/blob/main/server/controllers/userControllers.js"
    click AuthCheck "https://github.com/astracivictech/greenquest/blob/main/server/middleware/checkAuthentication.js"
    click CookieSession "https://github.com/astracivictech/greenquest/blob/main/server/middleware/handleCookieSessions.js"
    click RouteLogger "https://github.com/astracivictech/greenquest/blob/main/server/middleware/logRoutes.js"
    click ErrorLogger "https://github.com/astracivictech/greenquest/blob/main/server/middleware/logErrors.js"
    click UserModel "https://github.com/astracivictech/greenquest/blob/main/server/models/User.js"
    click KnexConfig "https://github.com/astracivictech/greenquest/blob/main/server/db/knex.js"
    click Knexfile "https://github.com/astracivictech/greenquest/blob/main/server/knexfile.js"
    click EnvTemplate "https://github.com/astracivictech/greenquest/blob/main/server/.env.template"
    click Migration1 "https://github.com/astracivictech/greenquest/blob/main/server/db/migrations/20230423034706_create_users_table.js"
    click Migration2 "https://github.com/astracivictech/greenquest/blob/main/server/db/migrations/20240514201137_add_timestamps_to_users.js"
    click SeedInit "https://github.com/astracivictech/greenquest/blob/main/server/db/seeds/init.js"
    click EnvTemplate "https://github.com/astracivictech/greenquest/blob/main/ .env.template"
    click StaticHost "https://github.com/astracivictech/greenquest/tree/main/infra/ (directory)"
    click EnvVault "https://github.com/astracivictech/greenquest/blob/main/ .env.template"
    click CICD "https://github.com/astracivictech/greenquest/blob/main/documentation/project-architecture.md"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40;
    classDef backend fill:#f1f8e9,stroke:#33691e,color:#1b5e20;
    classDef db fill:#fff3e0,stroke:#e65100,color:#bf360c;
    classDef infra fill:#ede7f6,stroke:#4527a0,color:#311b92;
    classDef client fill:#e8eaf6,stroke:#283593,color:#1a237e;
```
