# marconlp/snapify architecture

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

- Interactive diagram: https://gitdiagram.com/marconlp/snapify
- Repository: https://github.com/marconlp/snapify

## Overview

##### Project type and purpose
- Snapify is a full-stack, self-hostable web application built with Next.js. It provides recording, storage, and sharing of video snippets as a Loom alternative. It features server-side rendering (SSR), client-side React components, serverless API routes, database persistence, file storage, authentication, payments, and analytics.

##### File structure
- Top-level:
- Dockerfile, CI/workflow configs, environment definitions (.env.example, next.config.mjs).
- prisma/ (schema + seed script) → data model for MySQL.
- public/ → static assets.
- src/
– assets/, atoms/ (state management), components/ (React UI), styles/.
– pages/ (Next.js SSR/CSR routes & API endpoints).
– server/ (internal API logic, db, auth, AWS S3, Stripe, PostHog, rate limiting).
– utils/ (shared helpers).
- Tests/ uses Playwright for end-to-end.

##### README for technical stack
- Next.js, React, TypeScript, Prisma (MySQL), AWS S3 (Backblaze B2), Stripe, GitHub OAuth (NextAuth), PostHog, TRPC (type-safe RPC), Tailwind CSS.

##### Main components and interactions
a. Frontend
- Browser client (Next.js pages & React components)
- Static assets served via CDN/public
- React state atoms (Recoil or Jotai) manage UI modals and paywall
b. Backend
- Next.js server (SSR, API routes)
- Auth layer (NextAuth with GitHub)
- API endpoints:
– REST (check-expired-videos, stripe webhooks)
– TRPC routers (video CRUD, Stripe integration)
- Business logic: video processing, thumbnail generation
c. Data stores & services
- MySQL (Prisma ORM) for metadata
- AWS S3 / Backblaze B2 for video blobs
- Stripe for billing & subscriptions
- PostHog for analytics
- External OAuth (GitHub)
d. CI/CD & Deployment
- Docker, GitHub Actions, Vercel (or custom Docker)

##### Architectural patterns & principles
- Monolith of serverless functions (Next.js API routes)
- Type-safe end-to-end (TypeScript + TRPC)
- Layered separation: UI → API layer → service layer → persistence layer
- Event-driven (webhooks for Stripe)
- Scheduled/background tasks (expired-videos cleanup)

##### Final advice
- Be as detailed as possible—separate each logical unit
- Call out state management (atoms) and E2E tests as peripheral but important
- CI/CD pipeline (GitHub Actions → Docker/Vercel)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: User / Browser
    subgraph "User / Browser"
        direction TB
        User["User / Browser"]:::ui
    end

    %% Layer 2: Frontend (SSR & CSR)
    subgraph "Frontend (SSR & CSR)"
        direction TB
        NextjsPages["Next.js Pages & React Components"]:::ui
        StaticAssets["Static Assets"]:::ui
        StateAtoms["State Management (Atoms)"]:::ui
    end

    %% Layer 3: API & Business Logic
    subgraph "API & Business Logic (Next.js Serverless & TRPC)"
        direction TB
        NextApi["Next.js API (REST & TRPC)"]:::service
        AuthLayer["Auth Layer (NextAuth)"]:::service
        TRPCRoot["TRPC Routers"]:::service
        BusinessLogic["Business Logic & Helpers"]:::service
        RateLimit["Rate Limiting"]:::service
    end

    %% Layer 4: Data & External Services
    subgraph "Data & External Services"
        direction TB
        Database["Prisma → MySQL"]:::store
        Storage["AWS S3 / Backblaze B2"]:::store
        Stripe["Stripe (Billing & Subscriptions)"]:::external
        PostHog["PostHog (Analytics)"]:::external
        GitHubOAuth["GitHub OAuth"]:::external
    end

    %% Layer 5: CI/CD & Tests
    subgraph "CI/CD & Deployment"
        direction TB
        GitHubActions["GitHub Actions"]:::infra
        DockerfileNode["Dockerfile"]:::infra
        Vercel["Vercel / Docker Deployment"]:::infra
    end

    subgraph "End-to-End Tests (Playwright)"
        direction TB
        E2ETests["E2E Tests"]:::infra
    end

    %% Connections: Frontend
    User -->|uses| NextjsPages
    User -->|loads assets| StaticAssets
    NextjsPages -->|reads state| StateAtoms
    NextjsPages -->|requests| NextApi

    %% Connections: API & Business Logic
    NextApi -->|auth calls| AuthLayer
    NextApi -->|rate-limited| RateLimit
    NextApi -->|RPC & REST| TRPCRoot
    NextApi -->|shared logic| BusinessLogic

    %% Connections: Business Logic to Data/External
    AuthLayer -->|OAuth flow| GitHubOAuth
    TRPCRoot -->|reads/writes| Database
    TRPCRoot -->|uploads/downloads| Storage
    TRPCRoot -->|billing ops| Stripe
    TRPCRoot -->|analytics| PostHog
    BusinessLogic -->|thumbnail gen| Storage
    BusinessLogic -->|metadata| Database

    %% Webhooks & Scheduled
    Stripe -.->|webhooks| NextApi
    NextApi -->|cleanup| Database

    %% CI/CD & Tests connections
    GitHubActions --> DockerfileNode
    GitHubActions --> Vercel
    E2ETests --> NextjsPages

    %% Click Events
    click NextjsPages "https://github.com/marconlp/snapify/tree/main/src/pages/"
    click StaticAssets "https://github.com/marconlp/snapify/tree/main/public/"
    click StateAtoms "https://github.com/marconlp/snapify/tree/main/src/atoms/"
    click NextApi "https://github.com/marconlp/snapify/tree/main/src/pages/api/"
    click AuthLayer "https://github.com/marconlp/snapify/blob/main/src/server/auth.ts"
    click TRPCRoot "https://github.com/marconlp/snapify/blob/main/src/server/api/root.ts"
    click BusinessLogic "https://github.com/marconlp/snapify/blob/main/src/utils/generateThumbnail.ts"
    click RateLimit "https://github.com/marconlp/snapify/blob/main/src/server/rateLimit.ts"
    click Database "https://github.com/marconlp/snapify/blob/main/prisma/schema.prisma"
    click Storage "https://github.com/marconlp/snapify/blob/main/src/server/aws/s3.ts"
    click Stripe "https://github.com/marconlp/snapify/blob/main/src/server/stripe.ts"
    click PostHog "https://github.com/marconlp/snapify/blob/main/src/server/posthog.ts"
    click GitHubOAuth "https://github.com/marconlp/snapify/blob/main/src/pages/api/auth/[...nextauth].ts"
    click DockerfileNode "https://github.com/marconlp/snapify/tree/main/Dockerfile"
    click GitHubActions "https://github.com/marconlp/snapify/blob/main/.github/workflows/ci.yml"
    click E2ETests "https://github.com/marconlp/snapify/blob/main/tests/000-landing.spec.ts"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#0366d6
    classDef service fill:#DFFFE0,stroke:#228B22
    classDef store fill:#FFF4E5,stroke:#FFA500
    classDef external fill:#F3D0FF,stroke:#800080
    classDef infra fill:#E0E0E0,stroke:#888888
```
