# maks0101aps/imagegallery architecture

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

- Interactive diagram: https://gitdiagram.com/maks0101aps/imagegallery
- Repository: https://github.com/maks0101aps/imagegallery

## Overview

##### Project Type and Its Purpose
- This is a full-stack image gallery application with an industrial theme.
- The frontend is built in Svelte (with Bootstrap and custom industrial CSS) and handles image display, user interactions (gallery view, login, register, modal viewing) and easter egg presentations.
- The backend is a Node.js/Express server which manages authentication (using JWT), image uploads (via Multer), and interaction with a MySQL database (or JSON-based storage, as indicated by provided SQL and JSON files).

##### File Structure
- The project is organized into two main directories: “backend” and “frontend”. In addition, there’s a “screenshots” folder for assets/documentation.
- In the backend folder:
– Configuration files (.env, database.js) support environment variables and database connection settings.
– The “controllers” directory holds specific business logic for authentication and image management.
– The “middleware” directory includes middleware for secure interactions (e.g., JWT authentication middleware).
– The “models” directory outlines the data schema (e.g., user.model.js) possibly representing database tables.
– The “routes” directory defines API endpoints for auth and image operations.
– Server initialization is centralized in server.js.
- In the frontend folder:
– The source directory (src) contains Svelte components such as Gallery.svelte, Login.svelte, and Register.svelte.
– The entry point is main.js along with the main App.svelte component.
– The index.html file bootstraps the single-page application.
- The presence of configuration files like vite.config.js and package.json files on both sides emphasizes standard build and dependency practices.

##### Key Components and Their Interactions
a. Main Components:
- Frontend Application:
- Svelte components (Gallery, Login, Register, App.svelte)
- Entry point and static assets from index.html
- Backend API Server:
- Express server (server.js)
- Controllers (auth.controller.js, image.controller.js)
- API Routes (auth.routes.js, image.routes.js)
- Middleware for authentication (auth.middleware.js)
- Data models (user.model.js)
- Database initialization scripts (init-db.js, database.sql) and mock data files
- Data Storage:
- MySQL database (or file-based JSON for mocks) as indicated by database.sql and configuration settings in .env
- File Storage:
- "uploads" directory for storing image files uploaded by users.
- External Dependencies & Libraries:
- Authentication via JWT, file uploads handled by Multer, and supporting Node.js modules; on the frontend Svelte, Bootstrap, and web animations.

b. Relationships and Interactions:
- The frontend communicates with the backend via API calls (e.g., for login, image upload, deletion).
- The backend routes map incoming requests to controllers. Controllers access models which interact with the database.
- The auth middleware in the backend intercepts and validates requests to secure protected endpoints.
- Uploaded images are stored in the “uploads” directory while their metadata is recorded in the database.
- The design encourages separation of concerns between UI and business logic.

c. Architectural Patterns and Design Principles:
- Separation of Frontend and Backend concerns is maintained.
- The backend uses a layered structure (routes, controllers, middleware, models), which resembles a common MVC pattern.
- The authentication mechanism is secured using JWT, and file uploads follow best practices by isolating them in a dedicated directory.
- Reactive UI components, dynamic routing, and responsive design principles are integral to the frontend.

##### Final Checklist for the Principal Software Engineer
- Components are clearly labeled with names that match the project (e.g., “Backend Controller: auth.controller.js”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client / Frontend"
        FE_index["Static Asset (index.html)"]:::frontend
        FE_App["Main App (App.svelte)"]:::frontend
        FE_Main["Main Entry (main.js)"]:::frontend
        FE_Components["Svelte Components (Gallery.svelte, Login.svelte, Register.svelte)"]:::frontend
    end

    subgraph "Server / Backend"
        BE_Server["Express Server (server.js)"]:::backend
        BE_Routes["API Routes (auth.routes.js, image.routes.js)"]:::backend
        BE_Middleware["Auth Middleware (auth.middleware.js)"]:::backend
        BE_Controllers["Controllers (auth.controller.js, image.controller.js)"]:::backend
        BE_Models["Data Models (user.model.js)"]:::backend
    end

    subgraph "Data Layer"
        subgraph "Database & Config"
            DB_Node["MySQL Database / JSON Storage"]:::database
            CONF_Env["Environment (.env)"]:::database
            CONF_Config["DB Connection (database.js)"]:::database
            SCHEMA["Database Schema (database.sql)"]:::database
            INIT["Init Script (init-db.js)"]:::database
            MOCK["Mock Data (mock-users.json,mock-images.json)"]:::database
        end
    end

    subgraph "File Storage"
        Uploads["Uploads Directory (uploads)"]:::storage
    end

    %% Connections
    FE_index --> FE_App
    FE_App --> FE_Main
    FE_App --> FE_Components
    FE_Components -- "API_Calls" --> BE_Server
    BE_Server --> BE_Routes
    BE_Routes --> BE_Middleware
    BE_Middleware --> BE_Controllers
    BE_Controllers --> BE_Models
    BE_Controllers -- "store_metadata" --> DB_Node
    BE_Controllers -- "store_image" --> Uploads
    BE_Controllers -- "send_response" --> FE_App

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef database fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef storage fill:#FFD700,stroke:#000,stroke-width:2px;

    %% Click Events for Frontend
    click FE_index "https://github.com/maks0101aps/imagegallery/blob/main/frontend/index.html"
    click FE_App "https://github.com/maks0101aps/imagegallery/blob/main/frontend/src/App.svelte"
    click FE_Main "https://github.com/maks0101aps/imagegallery/blob/main/frontend/src/main.js"
    click FE_Components "https://github.com/maks0101aps/imagegallery/tree/main/frontend/src/components"

    %% Click Events for Backend
    click BE_Server "https://github.com/maks0101aps/imagegallery/blob/main/backend/src/server.js"
    click BE_Routes "https://github.com/maks0101aps/imagegallery/tree/main/backend/src/routes"
    click BE_Middleware "https://github.com/maks0101aps/imagegallery/blob/main/backend/src/middleware/auth.middleware.js"
    click BE_Controllers "https://github.com/maks0101aps/imagegallery/tree/main/backend/src/controllers"
    click BE_Models "https://github.com/maks0101aps/imagegallery/blob/main/backend/src/models/user.model.js"

    %% Click Events for Database & Config
    click CONF_Env "https://github.com/maks0101aps/imagegallery/blob/main/backend/.env"
    click CONF_Config "https://github.com/maks0101aps/imagegallery/blob/main/backend/src/config/database.js"
    click SCHEMA "https://github.com/maks0101aps/imagegallery/blob/main/backend/database.sql"
    click INIT "https://github.com/maks0101aps/imagegallery/blob/main/backend/init-db.js"
    click MOCK "https://github.com/maks0101aps/imagegallery/blob/main/backend/mock-users.json"

    %% Click Event for File Storage
    click Uploads "https://github.com/maks0101aps/imagegallery/tree/main/backend/uploads"
```
