# q0k0late/virtual-art-gallery architecture

> Architecture diagram of the GitHub repository q0k0late/virtual-art-gallery, 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/q0k0late/virtual-art-gallery
- Repository: https://github.com/q0k0late/virtual-art-gallery

## Overview

##### Main Components
- Frontend Client:
- “views” layer that uses the EJS template engine, organized into sections (artworks, exhibitions, pages, purchases, and users).
- Static assets served from the “public” directory (CSS, JavaScript—including the Three.js-based exhibition script—and uploads).
- Backend Server:
- The core Express.js application (app.js) that handles incoming HTTP requests.
- “Routes” are distributed across multiple files (artworkRoutes.js, exhibitionRoutes.js, etc.) for RESTful endpoints.
- “Controllers” implement the business logic for each resource (artwork, exhibition, purchase, user, etc.).
- “Middleware” for authentication, file uploads, and other request-processing functions.
- Data and Persistence:
- Mongoose-powered models (Artwork.js, Exhibition.js, Purchase.js, User.js) that interact with MongoDB.
- A configuration module under “config/db.js” that sets up the database connection.
- Authentication & Security:
- Passport.js integration configured in “config/passport.js” and supported by custom auth middleware.
- External Services and APIs:
- The “services” directory (apiService.js) for handling external API calls such as the weather API and Art Institute of Chicago API.
- Additional Infrastructure:
- Environment configuration (.env file in production) and build/deployment instructions.
- Integration of additional tools like Multer (file upload handling), Connect-flash (flash messages), and method-override for handling RESTful routes.

##### Relationships and Interactions
- The client (browser) sends HTTP requests to various route endpoints.
- Routes then direct these requests to dedicated controllers.
- Controllers process input and interact with both the models (for CRUD operations on MongoDB) and external services via the service layer.
- Middleware functions act as gatekeepers, managing authentication (Passport via routes/middleware/auth.js) and file uploads (middleware/upload.js) prior to request processing.
- Static assets and view templates deliver the interactive front-end experience (including 3D visualization with Three.js).
- Configuration modules handle setup for database connections and authentication strategies.

##### Architectural Patterns
- The project follows an MVC style separation:
- Models represent the data (Mongoose schemas).
- Views (EJS templates) render the data.
- Controllers mediate between the models and views.
- The design also uses modular routing, which means the system is decomposed into several domain-specific service layers (artworks, exhibitions, users, purchases).
- Incorporation of external API integrations highlights a service-oriented mindset, isolating API calls in a dedicated services component.

##### Relevant Technologies and Frameworks
- Backend: Node.js, Express.js, MongoDB (Mongoose ODM), Passport.js (authentication).
- Frontend: EJS template engine, Bootstrap 5, client-side JavaScript, and Three.js for interactive 3D experiences.
- Utility Libraries: Multer (file handling), Connect-flash (notifications), and method-override.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/Frontend Layer
    subgraph "Client/Frontend Layer"
        FE1["EJS Templates: Artworks"]:::frontend
        FE2["EJS Templates: Exhibitions (incl. 3D)"]:::frontend
        FE3["EJS Templates: Pages"]:::frontend
        FE4["EJS Templates: Purchases"]:::frontend
        FE5["EJS Templates: Users"]:::frontend
        FE6["Static Asset: CSS"]:::frontend
        FE7["Static Asset: JavaScript (3D)"]:::frontend
    end

    %% Backend/Server Layer
    subgraph "Backend/Server Layer"
        BS1["Express App (app.js)"]:::backend
        BS2["Artwork Route"]:::backend
        BS3["Exhibition Route"]:::backend
        BS4["Index Route"]:::backend
        BS5["Purchase Route"]:::backend
        BS6["User Route"]:::backend

        BS7["Artwork Controller"]:::backend
        BS8["Exhibition Controller"]:::backend
        BS9["Index Controller"]:::backend
        BS10["Purchase Controller"]:::backend
        BS11["User Controller"]:::backend

        BS12["Auth Middleware"]:::backend
        BS13["Upload Middleware"]:::backend

        BS14["DB Config"]:::backend
        BS15["Passport Config"]:::backend

        BS16["External API Service"]:::backend
    end

    %% Data/Persistence Layer
    subgraph "Data/Persistence Layer"
        DP1(("MongoDB")):::database
        DP2["Artwork Model"]:::database
        DP3["Exhibition Model"]:::database
        DP4["Purchase Model"]:::database
        DP5["User Model"]:::database
    end

    %% Flow from Client to Server
    FE1 ---|"HTTP Request"| BS1
    FE2 ---|"HTTP Request"| BS1
    FE3 ---|"HTTP Request"| BS1
    FE4 ---|"HTTP Request"| BS1
    FE5 ---|"HTTP Request"| BS1
    FE6 ---|"HTTP Request for Assets"| BS1
    FE7 ---|"HTTP Request for Assets"| BS1

    %% Express app uses config
    BS1 ---|"connects"| BS14
    BS1 ---|"uses"| BS15

    %% Express app routes
    BS1 -->|"routes"| BS2
    BS1 -->|"routes"| BS3
    BS1 -->|"routes"| BS4
    BS1 -->|"routes"| BS5
    BS1 -->|"routes"| BS6

    %% Routes pass through middleware then to controllers
    BS2 -->|"auth"| BS12
    BS12 --> BS7
    BS3 -->|"auth"| BS12
    BS12 --> BS8
    BS3 -->|"upload"| BS13
    BS13 --> BS8
    BS4 --> BS9
    BS5 -->|"auth"| BS12
    BS12 --> BS10
    BS6 -->|"auth"| BS12
    BS12 --> BS11

    %% Controllers interacting with Data Models
    BS7 -->|"CRUD"| DP2
    BS8 -->|"CRUD"| DP3
    BS10 -->|"CRUD"| DP4
    BS11 -->|"CRUD"| DP5
    BS9 -->|"renders view"| FE3

    %% Controllers using External API Service
    BS8 -->|"fetchAPI"| BS16
    BS11 -->|"fetchAPI"| BS16

    %% Click Events for Frontend
    click FE1 "https://github.com/q0k0late/virtual-art-gallery/tree/master/views/artworks/"
    click FE2 "https://github.com/q0k0late/virtual-art-gallery/blob/master/views/exhibitions/view3d.ejs"
    click FE3 "https://github.com/q0k0late/virtual-art-gallery/tree/master/views/pages/"
    click FE4 "https://github.com/q0k0late/virtual-art-gallery/tree/master/views/purchases/"
    click FE5 "https://github.com/q0k0late/virtual-art-gallery/tree/master/views/users/"
    click FE6 "https://github.com/q0k0late/virtual-art-gallery/blob/master/public/css/style.css"
    click FE7 "https://github.com/q0k0late/virtual-art-gallery/blob/master/public/js/exhibition3D.js"

    %% Click Events for Backend Server
    click BS1 "https://github.com/q0k0late/virtual-art-gallery/blob/master/app.js"
    click BS2 "https://github.com/q0k0late/virtual-art-gallery/blob/master/routes/artworkRoutes.js"
    click BS3 "https://github.com/q0k0late/virtual-art-gallery/blob/master/routes/exhibitionRoutes.js"
    click BS4 "https://github.com/q0k0late/virtual-art-gallery/blob/master/routes/indexRoutes.js"
    click BS5 "https://github.com/q0k0late/virtual-art-gallery/blob/master/routes/purchaseRoutes.js"
    click BS6 "https://github.com/q0k0late/virtual-art-gallery/blob/master/routes/userRoutes.js"
    click BS7 "https://github.com/q0k0late/virtual-art-gallery/blob/master/controllers/artworkController.js"
    click BS8 "https://github.com/q0k0late/virtual-art-gallery/blob/master/controllers/exhibitionController.js"
    click BS9 "https://github.com/q0k0late/virtual-art-gallery/blob/master/controllers/indexController.js"
    click BS10 "https://github.com/q0k0late/virtual-art-gallery/blob/master/controllers/purchaseController.js"
    click BS11 "https://github.com/q0k0late/virtual-art-gallery/blob/master/controllers/userController.js"
    click BS12 "https://github.com/q0k0late/virtual-art-gallery/blob/master/middleware/auth.js"
    click BS13 "https://github.com/q0k0late/virtual-art-gallery/blob/master/middleware/upload.js"
    click BS14 "https://github.com/q0k0late/virtual-art-gallery/blob/master/config/db.js"
    click BS15 "https://github.com/q0k0late/virtual-art-gallery/blob/master/config/passport.js"
    click BS16 "https://github.com/q0k0late/virtual-art-gallery/blob/master/services/apiService.js"

    %% Click Events for Data Models
    click DP2 "https://github.com/q0k0late/virtual-art-gallery/blob/master/models/Artwork.js"
    click DP3 "https://github.com/q0k0late/virtual-art-gallery/blob/master/models/Exhibition.js"
    click DP4 "https://github.com/q0k0late/virtual-art-gallery/blob/master/models/Purchase.js"
    click DP5 "https://github.com/q0k0late/virtual-art-gallery/blob/master/models/User.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
