# padi2312/gallerimg architecture

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

- Interactive diagram: https://gitdiagram.com/padi2312/gallerimg
- Repository: https://github.com/padi2312/gallerimg

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Frontend Layer:
- Client-side SvelteKit application
- Admin interface
- Public gallery interface
- Common components (located in src/lib/client/components)

b) Backend Layer:
- SvelteKit server-side routes
- API endpoints (v1)
- Core services
- Database repositories
- File storage system

c) External Services:
- PostgreSQL database
- SMTP server for email notifications
- File system for image storage

##### Architecture Pattern

a) Presentation Layer:
- Separation between public and admin interfaces
- Shared components
- SvelteKit routing system

b) Service Layer:
- Core services (folders, mail)
- API endpoints organization
- Authentication/authorization flow

c) Data Layer:
- Database repositories
- File storage system
- Data models and relationships

##### Component Relationships

**[Frontend Components] ←→ [SvelteKit Routes]**
- ↓
**[API Endpoints (v1)] ←→ [Core Services]**
- ↓
**[Repositories] ←→ [Database]**
**[File System] ←→ [Image Storage]**

##### Specific Implementation Details

Technical elements:

- SvelteKit as the full-stack framework
- PostgreSQL database connection
- Docker containerization
- Authentication system
- Image processing and storage
- Email notification system

##### Important Flows to Highlight

a) Image Upload Flow:
**Admin UI → Upload API → Image Processing → File Storage → Database Update**

b) Gallery View Flow:
**Public UI → Gallery Routes → Image Retrieval → Response with Optimized Images**

c) Newsletter Flow:
**Subscription → Mail Service → SMTP Server**

**┌─ Infrastructure (Docker) ─────────────────┐**
- ┌─ Application ─────────────────────────┐ │
- Frontend (Svelte)   Backend (SvelteKit)│ │
- Admin Panel       - API Routes       │ │
- Public Gallery    - Core Services    │ │
- Shared Components - Repositories     │ │
- ┘ │
- ┌─ Storage ──────────┐ ┌─ Services ───┐ │
- PostgreSQL DB    │ │ - SMTP       │ │
- File System      │ │ - Auth       │ │
- ┘ └─────────────┘ │
- ┘

Remember to:
- Use consistent notation
- Version information
- Document all external dependencies
- Security boundaries

This structure accurately represents Gallerimg's architecture while maintaining clarity and providing sufficient detail for understanding the system's components and their interactions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        subgraph Frontend
            AdminUI["Admin Interface"]:::frontend
            PublicUI["Public Gallery Interface"]:::frontend
            CommonComp["Common Components"]:::frontend
            LayoutComp["Layout Components"]:::frontend
        end

        subgraph Backend
            APIEndpoints["API Endpoints (v1)"]:::backend
            CoreServices["Core Services"]:::backend
            AuthSystem["Authentication System"]:::backend
            
            subgraph Routes
                AdminRoutes["Admin Routes"]:::routes
                GalleryRoutes["Public Gallery Routes"]:::routes
            end
            
            subgraph Services
                MailService["Mail Service"]:::service
                NewsletterSystem["Newsletter System"]:::service
                ImageManagement["Image Management"]:::service
            end
        end

        subgraph Storage
            DB[(PostgreSQL DB)]:::storage
            FileSystem["File Storage System"]:::storage
            DBSchema["Database Schema"]:::storage
            DBRepo["Database Repositories"]:::storage
        end

        subgraph External
            SMTP["SMTP Server"]:::external
        end
    end

    %% Relationships
    AdminUI --> AdminRoutes
    PublicUI --> GalleryRoutes
    AdminUI & PublicUI --> CommonComp
    AdminUI & PublicUI --> LayoutComp
    
    AdminRoutes & GalleryRoutes --> APIEndpoints
    APIEndpoints --> AuthSystem
    APIEndpoints --> CoreServices
    
    CoreServices --> DBRepo
    CoreServices --> FileSystem
    DBRepo --> DB
    
    NewsletterSystem --> MailService
    MailService --> SMTP
    
    ImageManagement --> FileSystem
    ImageManagement --> DB

    %% Click Events
    click AdminUI "https://github.com/padi2312/gallerimg/tree/main/src/lib/client/components/admin"
    click PublicUI "https://github.com/padi2312/gallerimg/tree/main/src/lib/client/components/common/gallery"
    click CommonComp "https://github.com/padi2312/gallerimg/tree/main/src/lib/client/components/common"
    click APIEndpoints "https://github.com/padi2312/gallerimg/tree/main/src/routes/api/v1"
    click CoreServices "https://github.com/padi2312/gallerimg/tree/main/src/lib/server/services"
    click DBRepo "https://github.com/padi2312/gallerimg/tree/main/src/lib/server/core/database/repositories"
    click FileSystem "https://github.com/padi2312/gallerimg/tree/main/src/lib/server/core/images"
    click DBSchema "https://github.com/padi2312/gallerimg/blob/main/database/schema.sql"
    click MailService "https://github.com/padi2312/gallerimg/blob/main/src/lib/server/services/mail-service.ts"
    click AdminRoutes "https://github.com/padi2312/gallerimg/tree/main/src/routes/admin/(admin)"
    click GalleryRoutes "https://github.com/padi2312/gallerimg/tree/main/src/routes/gallery"
    click NewsletterSystem "https://github.com/padi2312/gallerimg/tree/main/src/routes/api/v1/newsletter"
    click ImageManagement "https://github.com/padi2312/gallerimg/blob/main/src/lib/server/core/database/repositories/ImagesRepository.ts"
    click AuthSystem "https://github.com/padi2312/gallerimg/blob/main/src/auth.ts"
    click LayoutComp "https://github.com/padi2312/gallerimg/tree/main/src/lib/client/components/layout"

    %% Styles
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef routes fill:#8BC34A,stroke:#558B2F,color:white
    classDef service fill:#FFC107,stroke:#FFA000,color:black
    classDef storage fill:#F44336,stroke:#C62828,color:white
    classDef external fill:#9C27B0,stroke:#6A1B9A,color:white

    %% Legend
    subgraph Legend
        Frontend_L[Frontend]:::frontend
        Backend_L[Backend]:::backend
        Routes_L[Routes]:::routes
        Service_L[Services]:::service
        Storage_L[Storage]:::storage
        External_L[External]:::external
    end
```
