# yamang02/skku_fac architecture

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

- Interactive diagram: https://gitdiagram.com/yamang02/skku_fac
- Repository: https://github.com/yamang02/skku_fac

## Overview

##### Project type and purpose
- This is a full-stack web application (“SKKU 성미회 갤러리”) for managing and viewing art exhibitions and artworks.
- Backend: Node.js + Express.js with a layered, DDD-inspired folder structure (domain, infrastructure, common).
- Frontend: Server-rendered EJS templates + vanilla JavaScript + custom CSS.
- External services: MySQL database (via Sequelize ORM), Cloudinary for image storage, Railway for hosting, Swagger for API docs.

##### File structure
- Top-level “src/” holds:
- app.js (Express setup), server.js (boot), routeIndex.js (router aggregator)
- domain/ (per-feature MVC: controller, service, model/dto)
- infrastructure/ (cloudinary integration + DB adapter, repository, entity/relationship models)
- common/ (middleware, error types, utilities)
- config/ (environment-specific settings, infrastructure wiring)
- public/ (static assets: CSS, JS, images, uploads)
- views/ (EJS templates grouped by “admin” and “main” UX)
- Supporting files: swagger.json, ESLint/Stylelint configs, README, docs, CI/CD scripts.

##### Key insights from README
- Layered architecture with clear separation of concerns (Controller → Service → Repository).
- MVC pattern for each domain (auth, user, artwork, exhibition, admin).
- Repository/Adapter pattern abstracts DB operations.
- Uses middleware for sessions, auth, rate-limiting, helmet for security.

a. Main components:
- Client (Browser)
- Static assets: CSS, vanilla JS, images
- EJS-rendered pages
- Express Server
- Routing layer (routeIndex → domain routers)
- Controllers (per-domain API and view controllers)
- Middleware (auth, error handler, image upload, rate limiter, helmet)
- Services (business logic)
- Repositories & Adapters (DB access via Sequelize)
- MySQL Database (with entity tables & relationships)
- Cloudinary (external object storage for images)
- Session Store (backed by MySQL or in-memory store)
- Swagger UI (API documentation endpoint)
- CI/CD pipeline on Railway

b. Relationships & interactions:
- Browser → HTTP(S) → Express router → Controller → Service → Repository → MySQL.
- Image upload flows: Browser submits multipart → Express multer middleware → Cloudinary provider → returns URL → service persists URL in DB.
- Session management: After login, Express-session middleware ties user session to session store in DB.
- API docs: Browser ↔ Swagger-UI served from swagger.json.

c. Architectural patterns & principles:
- Layered (Presentation → Controller → Service → Repository → DB).
- MVC per domain (views + controllers + services).
- Repository & Adapter patterns decouple business logic from ORM details.
- DDD-style “domain” folder groups related artifacts.
- Separation of static assets (public) vs. dynamic rendering (views).

d. Key technologies & frameworks:
- Node.js, Express.js
- Sequelize ORM → MySQL
- EJS templating engine
- Vanilla JS for client scripts
- Cloudinary (image hosting)
- Middleware: Helmet, express-rate-limit, multer-storage-cloudinary
- Security: Session auth (express-session), bcrypt for passwords
- Deployment: Railway, environment variables via dotenv

##### Detail
- Middleware as a horizontal strip across the request flow.
- Notes on security (helmet, rate-limit) and caching for static assets.
- API documentation endpoint (/api-docs) connecting to swagger.json.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Presentation)" 
        direction TB
        Browser["Browser"]:::external
        StaticAssets["Static Assets\n(CSS, JS, Images)"]:::frontend
        EJSViews["EJS Views"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express Server)"
        direction TB

        subgraph "Server Setup"
            direction TB
            AppJs["app.js"]:::backend
            ServerJs["server.js"]:::backend
            RouteIndex["routeIndex.js"]:::backend
        end

        subgraph "Configuration"
            direction TB
            InfrastructureConfig["infrastructure.js"]:::backend
        end

        subgraph "Middleware"
            direction TB
            AuthMiddleware["auth.js"]:::middleware
            ImageUploadMiddleware["imageUploadMiddleware.js"]:::middleware
            PageTracker["PageTracker.js"]:::middleware
            ErrorHandler["Error Types"]:::middleware
            Utilities["Common Utilities"]:::middleware
        end

        subgraph "Routing & Controllers"
            direction TB
            AuthRouter["AuthRouter\nAuthApiController"]:::controller
            UserRouter["UserRouter\nUserController\nUserApiController"]:::controller
            ArtworkRouter["ArtworkRouter\nArtworkController\nArtworkApiController"]:::controller
            ExhibitionRouter["ExhibitionRouter\nExhibitionController\nExhibitionApiController"]:::controller
            HomeRouter["HomeRouter\nHomeController"]:::controller
            AdminRouter["AdminRouter\nAdminControllerIndex"]:::controller
        end

        subgraph "Services"
            direction TB
            AuthService["AuthService"]:::service
            UserService["UserService"]:::service
            ArtworkService["ArtworkService"]:::service
            ExhibitionService["ExhibitionService"]:::service
            AdminServices["Admin Services"]:::service
        end

        subgraph "Data Access & Repositories"
            direction TB
            MySQLAdapter["MySQLDatabase Adapter"]:::dataaccess
            EntityModels["ORM Entity Models"]:::dataaccess
            Relationships["Model Relationships"]:::dataaccess
            Repositories["Repositories"]:::dataaccess
        end
    end

    %% External Services
    MySQLDB["MySQL Database"]:::database
    Cloudinary["Cloudinary"]:::external
    SessionStore["Session Store"]:::database
    SwaggerUI["Swagger UI\n(/api-docs)"]:::external
    Railway["Railway CI/CD"]:::external

    %% Flows
    Browser -->|HTTP/HTTPS| RouteIndex
    StaticAssets -->|served via Express| Browser
    EJSViews -->|rendered by Controllers| Browser

    RouteIndex -->|routes to| AuthRouter
    RouteIndex -->|routes to| UserRouter
    RouteIndex -->|routes to| ArtworkRouter
    RouteIndex -->|routes to| ExhibitionRouter
    RouteIndex -->|routes to| HomeRouter
    RouteIndex -->|routes to| AdminRouter

    AuthRouter --> AuthService
    UserRouter --> UserService
    ArtworkRouter --> ArtworkService
    ExhibitionRouter --> ExhibitionService
    AdminRouter --> AdminServices
    HomeRouter -->|calls| EntityModels

    AuthService --> Repositories
    UserService --> Repositories
    ArtworkService --> Repositories
    ExhibitionService --> Repositories
    AdminServices --> Repositories

    Repositories --> MySQLAdapter
    MySQLAdapter --> MySQLDB
    Repositories --> EntityModels
    EntityModels --> Relationships

    Browser -->|multipart upload| ImageUploadMiddleware
    ImageUploadMiddleware --> Cloudinary
    Cloudinary -->|URL| ArtworkService

    Browser -->|login| AuthMiddleware
    AuthMiddleware --> SessionStore
    SessionStore --> MySQLDB

    Browser --> SwaggerUI

    Railway --> AppJs
    Railway --> InfrastructureConfig

    %% Click Events
    click AppJs "https://github.com/yamang02/skku_fac/blob/main/src/app.js"
    click ServerJs "https://github.com/yamang02/skku_fac/blob/main/src/server.js"
    click RouteIndex "https://github.com/yamang02/skku_fac/blob/main/src/routeIndex.js"
    click InfrastructureConfig "https://github.com/yamang02/skku_fac/blob/main/src/config/infrastructure.js"
    click AuthMiddleware "https://github.com/yamang02/skku_fac/blob/main/src/common/middleware/auth.js"
    click ImageUploadMiddleware "https://github.com/yamang02/skku_fac/blob/main/src/common/middleware/imageUploadMiddleware.js"
    click PageTracker "https://github.com/yamang02/skku_fac/blob/main/src/common/middleware/PageTracker.js"
    click ErrorHandler "https://github.com/yamang02/skku_fac/tree/main/src/common/error/"
    click Utilities "https://github.com/yamang02/skku_fac/tree/main/src/common/utils/"
    click AuthRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/auth/controller/AuthRouter.js"
    click AuthService "https://github.com/yamang02/skku_fac/blob/main/src/domain/auth/service/AuthService.js"
    click UserRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/user/controller/UserRouter.js"
    click UserRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/user/controller/UserController.js"
    click UserRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/user/controller/api/UserApiController.js"
    click UserService "https://github.com/yamang02/skku_fac/blob/main/src/domain/user/service/UserService.js"
    click ArtworkRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/artwork/controller/ArtworkRouter.js"
    click ArtworkRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/artwork/controller/ArtworkController.js"
    click ArtworkRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/artwork/controller/api/ArtworkApiController.js"
    click ArtworkService "https://github.com/yamang02/skku_fac/blob/main/src/domain/artwork/service/ArtworkService.js"
    click ExhibitionRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/exhibition/controller/ExhibitionRouter.js"
    click ExhibitionRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/exhibition/controller/ExhibitionController.js"
    click ExhibitionRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/exhibition/controller/api/ExhibitionApiController.js"
    click ExhibitionService "https://github.com/yamang02/skku_fac/blob/main/src/domain/exhibition/service/ExhibitionService.js"
    click HomeRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/home/controller/HomeRouter.js"
    click HomeRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/home/controller/HomeController.js"
    click AdminRouter "https://github.com/yamang02/skku_fac/blob/main/src/domain/admin/controller/AdminRouter.js"
    click InfrastructureConfig "https://github.com/yamang02/skku_fac/blob/main/src/config/infrastructure.js"
    click Cloudinary "https://github.com/yamang02/skku_fac/blob/main/src/infrastructure/cloudinary/provider/cloudinaryStorageFactory.js"
    click MySQLAdapter "https://github.com/yamang02/skku_fac/blob/main/src/infrastructure/db/adapter/MySQLDatabase.js"
    click EntityModels "https://github.com/yamang02/skku_fac/tree/main/src/infrastructure/db/model/entity/"
    click Relationships "https://github.com/yamang02/skku_fac/tree/main/src/infrastructure/db/model/relationship/"
    click Repositories "https://github.com/yamang02/skku_fac/tree/main/src/infrastructure/db/repository/"
    click StaticAssets "https://github.com/yamang02/skku_fac/tree/main/src/public/css"
    click StaticAssets "https://github.com/yamang02/skku_fac/tree/main/src/public/js"
    click StaticAssets "https://github.com/yamang02/skku_fac/tree/main/src/public/images"
    click StaticAssets "https://github.com/yamang02/skku_fac/tree/main/src/public/uploads"
    click EJSViews "https://github.com/yamang02/skku_fac/tree/main/src/views/admin/"
    click EJSViews "https://github.com/yamang02/skku_fac/tree/main/src/views/main/"
    click EJSViews "https://github.com/yamang02/skku_fac/tree/main/src/views/common/"
    click SwaggerUI "https://github.com/yamang02/skku_fac/blob/main/src/swagger.json"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064
    classDef backend fill:#E8F5E9,stroke:#1B5E20
    classDef middleware fill:#FFF3E0,stroke:#E65100
    classDef controller fill:#E3F2FD,stroke:#0D47A1
    classDef service fill:#E8F5E9,stroke:#2E7D32
    classDef dataaccess fill:#FFF3E0,stroke:#EF6C00
    classDef database fill:#FFE0B2,stroke:#BF360C
    classDef external fill:#E0E0E0,stroke:#424242
```
