# signothecat/sloggist architecture

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

- Interactive diagram: https://gitdiagram.com/signothecat/sloggist
- Repository: https://github.com/signothecat/sloggist

## Overview

##### Project type and purpose
- Sloggist is a full-stack, server-rendered web application built with Next.js.
- It lets users log “slogs” (super logs) by channel, view histories, and manage user state.

##### File structure
- Frontend/UI:
- components/ (React UI components, organized by feature)
- styles/ (CSS modules)
- pages/ (Next.js page files, including channel routes and index)
- public/ (static assets)
- Backend/API:
- pages/api/ (Next.js API Routes subdivided by resource: channels, logs, me)
- lib/ (shared utilities—HTTP helpers, error definitions, Prisma client)
- services/ (business-logic layer for users, channels, logs, HTTP cookies)
- Data layer:
- prisma/ (database schema, migrations)
- State management:
- contexts/ (React Contexts for User, Channels, Logs, ChannelRoute)
- Deployment/build:
- next.config.mjs, jsconfig.json, eslint.config.mjs
- package.json, package-lock.json

##### Main components & relationships

A. Client Layer (Browser)
- Next.js “pages” + React components
- React Contexts inject state into UI (UserContext, ChannelsContext, LogsContext)
- Actions (client helpers) call internal API endpoints (e.g., getValidChannel.js)

B. API Layer (Serverless/Node.js via Next.js)
- pages/api/* handlers
– /api/me.js
– /api/channels/index.js, [slug].js, [slug]/logs.js
- Each handler calls corresponding service functions

C. Business-Logic Layer (services/)
- services/users (user validation, cookie management, avatar, token parsing)
- services/channels (create, delete, fetch channels, channel contracts)
- services/logs (createLog, getLogsByChannel, logContract)
- services/http (cookie utilities)
- They all depend on lib/prisma.js

D. Utility Layer (lib/)
- lib/http/safeJson.js & pages/api/_utils/respond.js for consistent HTTP response handling
- lib/errors/serverErrors.js for custom error types
- lib/utils/sanitizers.js for input sanitization

E. Persistence Layer
- Prisma ORM (prisma/schema.prisma)
- Underlying relational database (PostgreSQL or similar)
- prisma/migrations/** for schema evolution

F. External/Infrastructure
- Vercel (hosting & serverless runtime)
- Optional: external auth or storage if added in future

- Browser → API endpoints (HTTPS)
- API endpoints → Service functions
- Services → Prisma ORM → Database
- Errors flow back up via lib/http/respond → API → Browser
- Contexts subscribe to component events and dispatch fetch/save calls to actions → API

##### Architectural patterns & design principles
- Layered architecture: UI → API → Services → ORM → DB
- Separation of concerns:
- UI vs. state management vs. business logic vs. data access
- Domain-driven modules: services grouped by aggregate (users, channels, logs)
- Next.js conventions: file-based routing for pages & API

##### Essential elements
- Labels & group titles (Client, Server, Database, External)
- Callouts for key frameworks (Next.js, React, Prisma)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Browser"]:::external
        NextApp["pages/_app.js"]:::front
        IndexPage["pages/index.js"]:::front
        ChannelPage["pages/channel/[slug].js"]:::front
        UIComponentsDir["components/ (UI Components)"]:::front
        ChannelUI["components/channel/"]:::front
        LayoutComp["components/layout/"]:::front
        GenericUI["components/ui/"]:::front
        GlobalStyles["styles/"]:::front
        BootstrapAction["actions/bootstrapUser.js"]:::front
        GetValidChannelAction["actions/getValidChannel.js"]:::front
        UserContext["contexts/UserContext.js"]:::front
        ChannelsContext["contexts/ChannelsContext.js"]:::front
        LogsContext["contexts/LogsContext.js"]:::front
        ChannelRouteContext["contexts/ChannelRouteContext.js"]:::front
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        subgraph "API Routes"
            direction TB
            ApiUtils["pages/api/_utils/respond.js"]:::util
            MeAPI["/api/me.js"]:::api
            ChannelsAPIIndex["/api/channels/index.js"]:::api
            SingleChannelAPI["/api/channels/[slug].js"]:::api
            ChannelLogsAPI["/api/channels/[slug]/logs.js"]:::api
        end
        subgraph "Services"
            direction TB
            UserServices["services/users/"]:::service
            ChannelServices["services/channels/"]:::service
            LogServices["services/logs/"]:::service
            HTTPCookies["services/http/cookies.js"]:::service
        end
        subgraph "Utilities (lib)"
            direction TB
            SafeJson["lib/http/safeJson.js"]:::util
            ServerErrors["lib/errors/serverErrors.js"]:::util
            Sanitizers["lib/utils/sanitizers.js"]:::util
            PrismaClient["lib/prisma.js"]:::util
        end
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        PrismaSchema["prisma/schema.prisma"]:::db
        PrismaMigrations["prisma/migrations/"]:::db
        DBNode["Prisma & PostgreSQL"]:::db
    end

    %% External Infrastructure
    Vercel["Vercel (Hosting & Serverless)"]:::external

    %% Client to API calls
    Browser -->|"GET /api/me"| MeAPI
    Browser -->|"GET /api/channels"| ChannelsAPIIndex
    Browser -->|"GET /api/channels/{slug}"| SingleChannelAPI
    Browser -->|"GET /api/channels/{slug}/logs"| ChannelLogsAPI

    %% Component usage
    NextApp --> UIComponentsDir
    NextApp --> GlobalStyles
    NextApp --> BootstrapAction
    IndexPage --> UIComponentsDir
    ChannelPage --> UIComponentsDir
    IndexPage --> GetValidChannelAction

    UIComponentsDir --> ChannelUI
    UIComponentsDir --> LayoutComp
    UIComponentsDir --> GenericUI

    ChannelPage --> ChannelRouteContext
    IndexPage --> ChannelsContext
    ChannelPage --> ChannelsContext
    IndexPage --> LogsContext

    %% API internals
    MeAPI -->|calls| UserServices
    ChannelsAPIIndex -->|calls| ChannelServices
    SingleChannelAPI -->|calls| ChannelServices
    ChannelLogsAPI -->|calls| LogServices

    %% API utilities
    MeAPI --> ApiUtils
    ChannelsAPIIndex --> ApiUtils
    SingleChannelAPI --> ApiUtils
    ChannelLogsAPI --> ApiUtils

    %% Service dependencies
    UserServices -->|uses| PrismaClient
    ChannelServices -->|uses| PrismaClient
    LogServices -->|uses| PrismaClient
    HTTPCookies -->|uses| PrismaClient

    %% Utility linking
    ApiUtils --> SafeJson
    MeAPI --> ServerErrors
    ChannelsAPIIndex --> ServerErrors
    SingleChannelAPI --> ServerErrors
    ChannelLogsAPI --> ServerErrors
    UserServices --> Sanitizers
    ChannelServices --> Sanitizers
    LogServices --> Sanitizers

    %% ORM to DB
    PrismaClient --> DBNode
    PrismaSchema --> DBNode
    PrismaMigrations --> DBNode

    %% Hosting
    Vercel --> MeAPI
    Vercel --> ChannelsAPIIndex
    Vercel --> SingleChannelAPI
    Vercel --> ChannelLogsAPI
    Vercel --> NextApp

    %% Click Events
    click UIComponentsDir "https://github.com/signothecat/sloggist/tree/main/components/"
    click ChannelUI "https://github.com/signothecat/sloggist/tree/main/components/channel/"
    click LayoutComp "https://github.com/signothecat/sloggist/tree/main/components/layout/"
    click GenericUI "https://github.com/signothecat/sloggist/tree/main/components/ui/"
    click GlobalStyles "https://github.com/signothecat/sloggist/tree/main/styles/"
    click BootstrapAction "https://github.com/signothecat/sloggist/blob/main/actions/bootstrapUser.js"
    click GetValidChannelAction "https://github.com/signothecat/sloggist/blob/main/actions/getValidChannel.js"
    click NextApp "https://github.com/signothecat/sloggist/blob/main/pages/_app.js"
    click IndexPage "https://github.com/signothecat/sloggist/blob/main/pages/index.js"
    click ChannelPage "https://github.com/signothecat/sloggist/blob/main/pages/channel/[slug].js"
    click ApiUtils "https://github.com/signothecat/sloggist/blob/main/pages/api/_utils/respond.js"
    click MeAPI "https://github.com/signothecat/sloggist/blob/main/pages/api/me.js"
    click ChannelsAPIIndex "https://github.com/signothecat/sloggist/blob/main/pages/api/channels/index.js"
    click SingleChannelAPI "https://github.com/signothecat/sloggist/blob/main/pages/api/channels/[slug].js"
    click ChannelLogsAPI "https://github.com/signothecat/sloggist/blob/main/pages/api/channels/[slug]/logs.js"
    click SafeJson "https://github.com/signothecat/sloggist/blob/main/lib/http/safeJson.js"
    click ServerErrors "https://github.com/signothecat/sloggist/blob/main/lib/errors/serverErrors.js"
    click Sanitizers "https://github.com/signothecat/sloggist/blob/main/lib/utils/sanitizers.js"
    click PrismaClient "https://github.com/signothecat/sloggist/blob/main/lib/prisma.js"
    click UserContext "https://github.com/signothecat/sloggist/blob/main/contexts/UserContext.js"
    click ChannelsContext "https://github.com/signothecat/sloggist/blob/main/contexts/ChannelsContext.js"
    click LogsContext "https://github.com/signothecat/sloggist/blob/main/contexts/LogsContext.js"
    click ChannelRouteContext "https://github.com/signothecat/sloggist/blob/main/contexts/ChannelRouteContext.js"
    click UserServices "https://github.com/signothecat/sloggist/tree/main/services/users/"
    click ChannelServices "https://github.com/signothecat/sloggist/tree/main/services/channels/"
    click LogServices "https://github.com/signothecat/sloggist/tree/main/services/logs/"
    click HTTPCookies "https://github.com/signothecat/sloggist/blob/main/services/http/cookies.js"
    click PrismaSchema "https://github.com/signothecat/sloggist/blob/main/prisma/schema.prisma"
    click PrismaMigrations "https://github.com/signothecat/sloggist/tree/main/prisma/migrations/"

    %% Styles
    classDef front fill:#cce5ff,stroke:#004085;
    classDef api fill:#d4edda,stroke:#155724;
    classDef service fill:#d1ecf1,stroke:#0c5460;
    classDef util fill:#fff3cd,stroke:#856404;
    classDef db fill:#f8d7da,stroke:#721c24;
    classDef external fill:#e2e3e5,stroke:#6c757d;
```
