How signothecat/sloggist works
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)