# tahirmahmudzade/schmalify architecture

> Architecture diagram of the GitHub repository tahirmahmudzade/schmalify, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tahirmahmudzade/schmalify
- Repository: https://github.com/tahirmahmudzade/schmalify

## Overview

##### Main Components

A. Client-Side Layer:
- Vue 3/Nuxt 3 Frontend Components
- Pages (Home, Categories, Items, Profile, Search)
- Reusable Components (Chat, Modals, Product)
- State Management (stores directory)
- Internationalization (i18n)

B. Server-Side Layer:
- Unjs Nitro Server Engine
- API Routes Structure
- Authentication System
- Database Layer (Drizzle ORM)

C. External Services (NuxtHub Infrastructure):
- Cloudflare D1 (SQLite Database)
- Cloudflare R2 (Blob Storage)
- Cloudflare KV (Key-Value Storage)
- Cloudflare Pages (Deployment)

##### Component Relationships

**[Client Layer]**
- ↕ HTTP/WebSocket
**[Server Layer (Nitro)]**
- ↕ ORM/API
**[Infrastructure Layer]**

##### Detailed Component Breakdown

a. Client Layer (Top):
- Authentication (Login/Register)
- Item Management
- Chat System
- Search & Filtering
- Internationalization
- To corresponding stores and composables

b. Server Layer (Middle):
- API Routes (/server/api):
- Auth endpoints
- Items endpoints
- Messages endpoints
- Users endpoints
- Blob handling
- Services (/server/service):
- User service
- Item service
- Conversation service
- Category service

c. Infrastructure Layer (Bottom):
- Database (Cloudflare D1)
- File Storage (Cloudflare R2)
- KV Storage
- Deployment Platform

##### Additional Elements

- Scalability points
- Critical security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FPages["Frontend Pages"]
        Chat["Chat System"]
        Auth["Authentication UI"]
        ItemMgmt["Item Management"]
        I18n["Internationalization"]:::util
        Search["Search & Filter"]:::util
        
        subgraph StateManagement
            ItemStore["Item Store"]:::store
            MsgStore["Message Store"]:::store
            GenStore["General Store"]:::store
        end
    end

    subgraph Server
        subgraph APIRoutes
            AuthAPI["Auth API"]:::api
            ItemsAPI["Items API"]:::api
            MsgAPI["Messages API"]:::api
            BlobAPI["Blob API"]:::api
            WSEndpoint["WebSocket Endpoint"]:::api
        end

        subgraph Services
            UserSvc["User Service"]:::service
            ItemSvc["Item Service"]:::service
            CatSvc["Category Service"]:::service
            ConvSvc["Conversation Service"]:::service
        end

        ImgProc["Image Processing"]:::util
    end

    subgraph Infrastructure
        DB[(Cloudflare D1)]:::db
        R2[("R2 Storage")]:::storage
        KV[("KV Storage")]:::storage
        Pages["Cloudflare Pages"]:::hosting
    end

    %% Client Layer Connections
    FPages --> ItemStore
    FPages --> MsgStore
    FPages --> GenStore
    Chat --> MsgStore
    Chat --> WSEndpoint
    ItemMgmt --> ItemStore
    Auth --> AuthAPI

    %% Server Layer Connections
    AuthAPI --> UserSvc
    ItemsAPI --> ItemSvc
    MsgAPI --> ConvSvc
    BlobAPI --> ImgProc
    ImgProc --> R2

    %% Service to Database Connections
    UserSvc --> DB
    ItemSvc --> DB
    CatSvc --> DB
    ConvSvc --> DB

    %% Click Events
    click FPages "https://github.com/tahirmahmudzade/schmalify/tree/main/pages"
    click Chat "https://github.com/tahirmahmudzade/schmalify/tree/main/components/inbox"
    click Auth "https://github.com/tahirmahmudzade/schmalify/blob/main/components/modals/LoginModal.vue"
    click ItemMgmt "https://github.com/tahirmahmudzade/schmalify/tree/main/components/product"
    click I18n "https://github.com/tahirmahmudzade/schmalify/tree/main/i18n/internationalization"
    click ItemStore "https://github.com/tahirmahmudzade/schmalify/blob/main/stores/itemStore.ts"
    click MsgStore "https://github.com/tahirmahmudzade/schmalify/blob/main/stores/messageStore.ts"
    click GenStore "https://github.com/tahirmahmudzade/schmalify/blob/main/stores/store.ts"
    click AuthAPI "https://github.com/tahirmahmudzade/schmalify/tree/main/server/api/auth"
    click ItemsAPI "https://github.com/tahirmahmudzade/schmalify/tree/main/server/api/items"
    click MsgAPI "https://github.com/tahirmahmudzade/schmalify/tree/main/server/api/messages"
    click BlobAPI "https://github.com/tahirmahmudzade/schmalify/tree/main/server/api/blob"
    click WSEndpoint "https://github.com/tahirmahmudzade/schmalify/blob/main/server/api/messages/websocket.ts"
    click UserSvc "https://github.com/tahirmahmudzade/schmalify/blob/main/server/service/user.ts"
    click ItemSvc "https://github.com/tahirmahmudzade/schmalify/blob/main/server/service/item.ts"
    click CatSvc "https://github.com/tahirmahmudzade/schmalify/blob/main/server/service/category.ts"
    click ConvSvc "https://github.com/tahirmahmudzade/schmalify/blob/main/server/service/conversation.ts"
    click ImgProc "https://github.com/tahirmahmudzade/schmalify/blob/main/server/utils/processImage.ts"
    click DB "https://github.com/tahirmahmudzade/schmalify/blob/main/server/database/schema.ts"

    %% Styling
    classDef frontend fill:#2196F3,color:white
    classDef api fill:#4CAF50,color:white
    classDef service fill:#8BC34A,color:white
    classDef db fill:#FF9800,color:white
    classDef storage fill:#FF5722,color:white
    classDef hosting fill:#9C27B0,color:white
    classDef store fill:#3F51B5,color:white
    classDef util fill:#757575,color:white

    class FPages,Chat,Auth,ItemMgmt frontend
    class AuthAPI,ItemsAPI,MsgAPI,BlobAPI,WSEndpoint api
    class UserSvc,ItemSvc,CatSvc,ConvSvc service
    class DB db
    class R2,KV storage
    class Pages hosting
    class ItemStore,MsgStore,GenStore store
    class I18n,Search,ImgProc util
```
