# trylinky/linky architecture

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

- Interactive diagram: https://gitdiagram.com/trylinky/linky
- Repository: https://github.com/trylinky/linky

## Overview

##### Project Type and Purpose
- Linky is an open-source, full-stack monorepo for a dynamic personal page builder.
- It comprises three Next.js applications (app.api, app.frontend, app.marketing) plus shared packages for blocks, UI components, notifications, Prisma schema, Tinybird analytics, and common utilities.

##### File Structure Analysis
- Top-level apps:
- app.api – the backend HTTP API, TypeScript Node service with modules for auth, billing (Stripe), analytics, integrations, email (Resend), database (Prisma), error tracking (Sentry), and orchestrators.
- app.frontend – the customer-facing Next.js client, server- and client-rendered pages; dynamically loads “blocks” (Instagram, Spotify, etc.) via shared package.blocks and common API lib.
- app.marketing – the marketing/landing site Next.js app for blog, docs, pricing, signup, integration callbacks.
- Shared packages (in `package.*`):
- package.blocks – definitions and configs for page “blocks.”
- package.ui – design system, React UI primitives.
- package.common – shared auth, billing UI, API-fetch helpers.
- package.notifications – email templates (Resend).
- package.prisma – database schema and migration history (PostgreSQL).
- package.tinybird – analytics pipeline definitions and browser tracker.
- Config files: Turbo (`turbo.json`), Docker Compose, ESLint, Prettier, TSConfig at root.

##### README Insights
- Tech stack: Next.js, TypeScript, Tailwind CSS, NextAuth.js, Resend, Vercel.
- Self-hosting docs pointing to local/dev and Docker Compose setups.

a. Main Components
- Users (Browser)
- Frontend App (app.frontend)
- Marketing Site (app.marketing)
- Backend API Service (app.api)
- PostgreSQL Database (package.prisma)
- Analytics Pipeline (Tinybird)
- Third-Party Services: Stripe, PostHog, Resend (emails), Sentry, External Integrations (Instagram, Spotify, TikTok, Threads)
- Monorepo Build System (Turborepo, Docker)
b. Relationships & Data Flows
- User → app.frontend over HTTPS (Next.js SSR/CSR)
- User → app.marketing for landing pages, blog
- app.frontend ↔ app.api (REST/JSON) for CRUD operations: pages, themes, billing, flags
- app.marketing → app.api (via shared api-server lib) for featured pages, integration callbacks
- app.api → PostgreSQL via Prisma ORM
- app.api → Resend for transactional emails
- Stripe Webhooks → app.api billing module → updates DB
- app.frontend, app.api → PostHog for event tracking
- PostHog raw events → Tinybird pipes → analytics dashboards
- app.api orchestrators → external integrations’ APIs
- Sentry integrated into all apps for error reporting
c. Architectural Patterns & Principles
- Monorepo with Turborepo for code sharing & parallel builds
- Modular backend: decorators, modules-per-domain (analytics, billing, pages, flags, orchestrators)
- Shared component libraries (package.ui, package.common) for DRY UI & logic
- Prisma migrations for schema versioning
- Event-driven billing via Stripe webhooks
- Server-Side Rendering (SSR) Next.js with dynamic routes for user pages
d. Key Technologies & Frameworks
- Next.js (app.frontend, app.marketing)
- Node.js + TypeScript (app.api)
- Prisma + PostgreSQL
- Stripe for subscription billing
- PostHog + Tinybird for analytics
- Resend for email delivery
- Sentry for monitoring
- Turborepo for monorepo orchestration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    User["User (Browser)"]:::external

    %% Applications Layer
    subgraph "Applications"
      subgraph "app.frontend (Next.js)"
        FE_Dynamic["Dynamic Page Renderer"]:::internal
        FE_Blocks["Block Loader"]:::internal
      end
      subgraph "app.marketing (Next.js)"
        MKT_Content["Landing, Blog, Docs"]:::internal
      end
    end

    %% Backend Service Layer
    subgraph "app.api (Node.js + TypeScript)"
      API_Service["API Service"]:::internal
      API_Auth["Auth Module"]:::internal
      API_Billing["Billing Module"]:::internal
      API_Pages["Pages Module"]:::internal
      API_Integrations["Integrations Module"]:::internal
      API_Orchestrators["Orchestrators"]:::internal
    end

    %% Data & Analytics Layer
    DB["PostgreSQL Database"]:::database
    TB["Tinybird Analytics"]:::database

    %% Third-Party Services
    subgraph "Third-Party Services"
      Stripe["Stripe"]:::external
      PostHog["PostHog"]:::external
      Resend["Resend (Emails)"]:::external
      Sentry["Sentry"]:::external
      Instagram["Instagram API"]:::external
      Spotify["Spotify API"]:::external
      TikTok["TikTok API"]:::external
      Threads["Threads API"]:::external
    end

    %% Monorepo & Build Config
    subgraph "Monorepo / Build System"
      Turbo["Turborepo (turbo.json)"]:::repo
      DockerCompose["Docker Compose (docker-compose.yml)"]:::repo
      ESLint["ESLint (eslint.config.mjs)"]:::repo
      Prettier["Prettier (prettier.config.js)"]:::repo
      TSConfig["TypeScript Config (tsconfig.json)"]:::repo
      package_blocks["package.blocks"]:::repo
      package_ui["package.ui"]:::repo
      package_common["package.common"]:::repo
      package_notifications["package.notifications"]:::repo
      package_prisma["package.prisma"]:::repo
      package_tinybird["package.tinybird"]:::repo
    end

    %% Connections: User to Apps
    User -->|HTTPS| FE_Dynamic
    User -->|HTTPS| MKT_Content

    %% Frontend & Marketing to API
    FE_Dynamic -->|REST/JSON| API_Service
    FE_Blocks -->|loads blocks| package_blocks
    MKT_Content -->|API calls| API_Service

    %% API Modules internal links
    API_Service --> API_Auth
    API_Service --> API_Billing
    API_Service --> API_Pages
    API_Service --> API_Integrations
    API_Service --> API_Orchestrators

    %% API to Database & Analytics
    API_Service -->|SQL via Prisma| DB
    API_Service -->|events| PostHog
    PostHog -->|raw events| TB

    %% Billing Webhook
    Stripe -.->|"webhook"| API_Billing
    API_Billing -->|update DB| DB

    %% Email
    API_Service -->|send emails| Resend

    %% Analytics Tracking
    FE_Dynamic -.->|event tracking| PostHog
    API_Service -.->|event tracking| PostHog

    %% Integrations
    API_Orchestrators -->|calls| Instagram
    API_Orchestrators -->|calls| Spotify
    API_Orchestrators -->|calls| TikTok
    API_Orchestrators -->|calls| Threads

    %% Error Reporting
    Sentry -.-> API_Service
    Sentry -.-> FE_Dynamic
    Sentry -.-> MKT_Content

    %% Monorepo to Apps
    Turbo --> FE_Dynamic
    Turbo --> API_Service
    Turbo --> MKT_Content
    DockerCompose --> API_Service
    DockerCompose --> DB

    %% Shared Packages usage
    FE_Dynamic -->|uses| package_ui
    MKT_Content -->|uses| package_ui
    FE_Dynamic -->|uses| package_common
    MKT_Content -->|uses| package_common
    API_Service -->|uses| package_common
    API_Service -->|Prisma schema| package_prisma
    FE_Dynamic -->|analytics lib| package_tinybird

    %% Click Events
    click FE_Dynamic "https://github.com/trylinky/linky/tree/main/app.frontend/"
    click FE_Blocks "https://github.com/trylinky/linky/tree/main/package.blocks/"
    click MKT_Content "https://github.com/trylinky/linky/tree/main/app.marketing/"
    click API_Service "https://github.com/trylinky/linky/tree/main/app.api/"
    click package_prisma "https://github.com/trylinky/linky/blob/main/package.prisma/prisma/schema.prisma"
    click package_prisma "https://github.com/trylinky/linky/tree/main/package.prisma/prisma/migrations/"
    click package_tinybird "https://github.com/trylinky/linky/tree/main/package.tinybird/"
    click package_blocks "https://github.com/trylinky/linky/tree/main/package.blocks/"
    click package_ui "https://github.com/trylinky/linky/tree/main/package.ui/"
    click package_common "https://github.com/trylinky/linky/tree/main/package.common/"
    click package_notifications "https://github.com/trylinky/linky/tree/main/package.notifications/"
    click Turbo "https://github.com/trylinky/linky/blob/main/turbo.json"
    click DockerCompose "https://github.com/trylinky/linky/blob/main/docker-compose.yml"
    click ESLint "https://github.com/trylinky/linky/blob/main/eslint.config.mjs"
    click Prettier "https://github.com/trylinky/linky/blob/main/prettier.config.js"
    click TSConfig "https://github.com/trylinky/linky/blob/main/tsconfig.json"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#0062cc,color:#004085
    classDef database fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef repo fill:#e2e3e5,stroke:#6c757d,color:#343a40
```
