# nirlekaartha/project-kelas-008 architecture

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

- Interactive diagram: https://gitdiagram.com/nirlekaartha/project-kelas-008
- Repository: https://github.com/nirlekaartha/project-kelas-008

## Overview

##### Project type and purpose
- This is a full-stack web application built with React (frontend) and a Node/TypeScript backend (API server), using Vite for fast HMR, and a relational database defined in `database/db_schema.sql`.
- The frontend delivers UI for user authentication, blogs, galleries and profiles; the backend exposes REST endpoints and orchestrates business logic; a SQL database persists users, blogs, gallery metadata, etc.

##### File structure
- Top-level:
- `src/client` holds React components, pages, routes, layouts, assets, Redux-style slices in `store`
- `src/server` contains API routes (`api/`), controllers (`controllers/`), data models (`models/`), middleware, helpers, tests, and file upload handling
- `src/services` implements domain-level business logic and DB access wrappers
- `database/db_schema.sql` defines schema; `docker-compose.yml` orchestrates DB and server containers
- Scripts for DB initialization and dev environment setup
- Patterns:
- MVC-style separation: API → controller → service → model → DB
- Client-side state managed via Redux slices
- Utility modules for cross-cutting concerns (auth, validation, file handling)

##### README for additional insights
- The README provides guidance on ESLint/TS integration and Vite plugins; confirms React+TS+Vite stack.

a. Main components:
- Frontend (React + Vite dev server)
- Backend API Server (Node.js + TypeScript + Express or built-in HTTP server)
- Database (PostgreSQL or chosen SQL engine)
- File Storage (uploads directory or external storage if configured)
- External services (e.g., authentication provider or cloud storage if used)
b. Relationships and interactions:
- Browser ↔ Frontend: HTTP(S) for web UI, HMR in dev
- Frontend → Backend API: REST calls (login, CRUD on blogs/gallery/users)
- Backend → Database: SQL queries via `dbServices`
- Backend → File Storage: read/write user uploads
- Services layer orchestrates model operations and returns domain DTOs
c. Architectural patterns:
- Client-server separation with a clear API boundary
- Controller-Service-Model layering in the backend
- Redux (slice) pattern for client state management
- Utility modules for shared concerns (validation, auth tokens, file handling)
d. Key technologies and libraries:
- Frontend: React, Vite, TypeScript, Redux Toolkit (`authSlice`, `blogSlice`, etc.)
- Backend: Node.js, TypeScript, Express/HTTP server, middleware, controllers
- Database: SQL engine defined in `db_schema.sql`, connection managed via `dbConnection.ts`
- Deployment/config: Docker Compose, shell/PowerShell scripts for setup

##### Detail
- Every major directory as a node or sub-node (e.g., `src/client/components`, `src/server/middleware`).
- How `scripts/init-db.sh` and `docker-compose.yml` tie into the overall deployment.
- Shared utility modules (`authUtils`, `validationUtils`) as reusable components across services and controllers.

## Diagram (Mermaid)

```mermaid
graph TB

  %% Browser / Client
  subgraph "Browser/Client"
    Browser["Browser"]:::external
  end

  %% Frontend Layer
  subgraph "Frontend (React + Vite)"
    Vite["Vite Dev Server"]:::infra
    Index["src/client/index.tsx"]:::frontend
    App["src/client/App.tsx"]:::frontend
    Pages["src/client/pages"]:::frontend
    Layouts["src/client/layouts/index.ts"]:::frontend
    Components["src/client/components"]:::frontend
    Assets["src/client/assets"]:::frontend
    Styles["src/client/styles/index.ts"]:::frontend
    ConfigRoot["vite.config.ts"]:::infra
  end

  Browser -->|loads| Vite
  Vite -->|serves| Index
  Index -->|renders| App
  App --> Pages
  App --> Layouts
  App --> Components
  App --> Assets
  App --> Styles

  click Index "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/client/index.tsx"
  click App "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/client/App.tsx"
  click Pages "https://github.com/nirlekaartha/project-kelas-008/tree/main/src/client/pages"
  click Layouts "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/client/layouts/index.ts"
  click Components "https://github.com/nirlekaartha/project-kelas-008/tree/main/src/client/components"
  click Assets "https://github.com/nirlekaartha/project-kelas-008/tree/main/src/client/assets"
  click Styles "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/client/styles/index.ts"
  click ConfigRoot "https://github.com/nirlekaartha/project-kelas-008/blob/main/vite.config.ts"

  %% Backend Layer
  subgraph "Backend API Server (Node.js + TypeScript)"
    Server["src/server/server.ts"]:::server
    Main["src/main.tsx"]:::server

    subgraph "API Routes"
      AuthAPI["src/server/api/auth.ts"]:::server
      BlogAPI["src/server/api/blog.ts"]:::server
      GalleryAPI["src/server/api/gallery.ts"]:::server
      UserAPI["src/server/api/user.ts"]:::server
    end

    subgraph "Controllers"
      LoginCtrl["src/server/controllers/loginController.ts"]:::server
      BlogCtrl["src/server/controllers/blogController.ts"]:::server
      UserCtrl["src/server/controllers/userController.ts"]:::server
      CtrlIndex["src/server/controllers/index.ts"]:::server
    end

    subgraph "Services"
      ServiceIndex["src/services/index.ts"]:::service
      AuthService["src/services/authService.ts"]:::service
      BlogService["src/services/blogService.ts"]:::service
      GalleryService["src/services/galleryService.ts"]:::service
      UserService["src/services/userService.ts"]:::service
      DbServices["src/services/dbServices.ts"]:::service
    end

    subgraph "Models"
      ModelIndex["src/server/models/index.ts"]:::model
      UserModel["src/server/models/user.ts"]:::model
      BlogModel["src/server/models/blog.ts"]:::model
      GalleryModel["src/server/models/gallery.ts"]:::model
    end

    Middleware["src/server/middleware/index.ts"]:::util
    Helpers["src/server/helpers/http-responses.ts"]:::util
    Utils["src/server/utils/index.ts"]:::util
    Uploads["src/server/uploads/index.ts"]:::util
  end

  Server --> AuthAPI
  Server --> BlogAPI
  Server --> GalleryAPI
  Server --> UserAPI
  AuthAPI --> LoginCtrl
  BlogAPI --> BlogCtrl
  UserAPI --> UserCtrl
  LoginCtrl --> AuthService
  BlogCtrl --> BlogService
  UserCtrl --> UserService
  AuthService --> DbServices
  BlogService --> DbServices
  GalleryService --> DbServices
  UserService --> DbServices
  DbServices --> ModelIndex
  ModelIndex --> UserModel
  ModelIndex --> BlogModel
  ModelIndex --> GalleryModel
  Server --> Middleware
  Server --> Helpers
  Server --> Utils
  Server --> Uploads

  click Server "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/server.ts"
  click Main "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/main.tsx"
  click AuthAPI "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/api/auth.ts"
  click BlogAPI "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/api/blog.ts"
  click GalleryAPI "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/api/gallery.ts"
  click UserAPI "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/api/user.ts"
  click LoginCtrl "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/controllers/loginController.ts"
  click BlogCtrl "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/controllers/blogController.ts"
  click UserCtrl "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/controllers/userController.ts"
  click CtrlIndex "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/controllers/index.ts"
  click ServiceIndex "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/services/index.ts"
  click AuthService "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/services/authService.ts"
  click BlogService "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/services/blogService.ts"
  click GalleryService "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/services/galleryService.ts"
  click UserService "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/services/userService.ts"
  click DbServices "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/services/dbServices.ts"
  click ModelIndex "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/models/index.ts"
  click UserModel "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/models/user.ts"
  click BlogModel "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/models/blog.ts"
  click GalleryModel "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/models/gallery.ts"
  click Middleware "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/middleware/index.ts"
  click Helpers "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/helpers/http-responses.ts"
  click Utils "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/utils/index.ts"
  click Uploads "https://github.com/nirlekaartha/project-kelas-008/blob/main/src/server/uploads/index.ts"

  %% Database & Storage
  subgraph "Database & Storage"
    DB["PostgreSQL DB"]:::db
    Schema["database/db_schema.sql"]:::db
    FileStorage["File Storage (uploads dir)"]:::db
  end

  DbServices --> DB
  DB --> Schema
  Server --> FileStorage
  Uploads --> FileStorage

  click Schema "https://github.com/nirlekaartha/project-kelas-008/blob/main/database/db_schema.sql"

  %% Deployment & Scripts
  subgraph "Deployment & Scripts"
    DockerCompose["docker-compose.yml"]:::infra
    InitDB["scripts/init-db.sh"]:::infra
    SetupDevSh["scripts/setup_dev.sh"]:::infra
    SetupDevPS1["scripts/setup_dev.ps1"]:::infra
  end

  Server --> DockerCompose
  DB --> DockerCompose
  DockerCompose --> InitDB
  DockerCompose --> SetupDevSh
  DockerCompose --> SetupDevPS1

  click DockerCompose "https://github.com/nirlekaartha/project-kelas-008/blob/main/docker-compose.yml"
  click InitDB "https://github.com/nirlekaartha/project-kelas-008/blob/main/scripts/init-db.sh"
  click SetupDevSh "https://github.com/nirlekaartha/project-kelas-008/blob/main/scripts/setup_dev.sh"
  click SetupDevPS1 "https://github.com/nirlekaartha/project-kelas-008/blob/main/scripts/setup_dev.ps1"

  %% Project Configuration
  subgraph "Project Configuration"
    Package["package.json"]:::infra
    TSConfigApp["tsconfig.app.json"]:::infra
    TSConfigNode["tsconfig.node.json"]:::infra
    TSConfig["tsconfig.json"]:::infra
    ESLint["eslint.config.js"]:::infra
    Readme["README.md"]:::infra
  end

  %% Styles
  classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
  classDef infra fill:#e2e3e5,stroke:#6c757d,color:#343a40
  classDef server fill:#d4edda,stroke:#155724,color:#155724
  classDef service fill:#d1ecf1,stroke:#0c5460,color:#0c5460
  classDef model fill:#fff3cd,stroke:#856404,color:#856404
  classDef util fill:#f8d7da,stroke:#721c24,color:#721c24
  classDef db fill:#ffeeba,stroke:#856404,color:#856404
  classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24
```
