How imtiajrex/artspace works
Project Type and Purpose
• This is a full-stack web application (“ArtSpace”) built with SvelteKit (handles both frontend UI and backend API) and MySQL for persistence, with Cloudinary used for art asset storage.
• Users (artists) can sign up, upload art, view others’ art, leave comments and ratings. Admins have a protected area to manage users, moderate content, and view dashboards.
High-Level Architecture Components
A. Client (Browser)
• Renders SvelteKit pages (SSR + SPA hydration)
• Sends HTTP requests to API routes for login, signup, art listing, posting comments/ratings
• Uploads images via client code (e.g., Cloudinary widget or direct upload endpoint)
B. SvelteKit Server
1. Routing Layer
– File-based routes under src/routes/ for page rendering (+layout.svelte, +page.svelte)
– API endpoints under src/routes/api/** with +server.js handlers
2. Server Utilities (src/lib/server)
– db.ts: wraps MySQL connection/query logic
– cloudinary.ts: handles image upload and URL generation
– adminTokenChecker.ts: middleware to verify admin JWT tokens
3. Component Library (src/lib/components)
– Shared Svelte UI components (buttons, cards, forms, navbars)
– Admin-specific components (dashboard cards, moderation buttons)
– Home feed components, user profile UI elements
C. MySQL Database
– Stores users, admins, art metadata, comments, ratings
– Accessed by db.ts using SQL queries
D. Cloudinary (External Service)
– Stores uploaded image files
– Provides CDN URLs for art images
Relationships and Data Flows
• Browser → SvelteKit Server (Pages)
– User navigates: SSR fetches data via load functions that call internal API or db.ts
• Browser → SvelteKit Server (API Endpoints)
– AJAX/Fetch requests to /api/* for CRUD operations (signup, login, art create/list, comments, ratings)
• SvelteKit Server → MySQL
– db.ts executes queries and returns results to API handlers or load functions
• SvelteKit Server → Cloudinary
– cloudinary.ts uploads image binaries and returns secure URLs stored in MySQL
• AdminTokenChecker middleware
– Intercepts admin API routes, verifies JWT, allows/denies access
Key Architectural Patterns and Design Principles
– File-based routing (SvelteKit) enforces clear separation of pages vs API
– Layered separation: Presentation (components & pages), Application logic (API handlers & load functions), Infrastructure (db.ts, cloudinary.ts)
– Middleware for auth/authorization (adminTokenChecker)
– Single codebase for frontend SSR + backend API simplifies deployment
– Clear labels on each component (e.g., “+page.svelte / +server.js”, “db.ts”)
– Arrowheads indicating request/response or data flow direction