# premieroctet/digestclub architecture

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

- Interactive diagram: https://gitdiagram.com/premieroctet/digestclub
- Repository: https://github.com/premieroctet/digestclub

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (App Router architecture)
- Public-facing pages (/app/(app))
- Admin interface (/app/(admin))
- Authentication pages

b) API Layer:
- REST API endpoints (/pages/api)
- Authentication endpoints
- Team management endpoints
- Bookmark management endpoints
- Digest management endpoints

c) Integration Layer:
- Slack integration
- Twitter/Typefully integration
- Email service integration
- OpenAI integration (for AI features)

d) Data Layer:
- PostgreSQL database (via Prisma ORM)
- Prisma schema and migrations

##### Relationship Flows

a) External Integrations:
- Slack → API Layer (webhooks for link collection)
- Email Service → API Layer (newsletter distribution)
- Twitter → API Layer (thread publishing)

b) Internal Flows:
- Client → API Layer (REST calls)
- API Layer → Database (Prisma queries)
- API Layer → Integration Layer (third-party services)

##### Key Components to Highlight

a) Core Features:
- Bookmarking system
- Digest creation/management
- Team collaboration
- Newsletter distribution

b) Supporting Services:
- Authentication (NextAuth.js)
- File storage
- API rate limiting
- OpenGraph preview generation

##### Technical Details

Annotations for:

- Next.js 13+ with App Router
- Prisma ORM with PostgreSQL
- TailwindCSS for styling
- TypeScript implementation
- Docker containerization

##### Specific Implementation Notes

Architectural patterns:

- Server Components vs Client Components
- API Routes structure
- Database schema relationships
- Authentication flow
- Webhook handling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE[Next.js Frontend]
        PP["Public Pages"]
        AI["Admin Interface"]
        AP["Auth Pages"]
        FE --> PP & AI & AP
    end

    subgraph API
        AE["Auth Endpoints"]
        TM["Team Management"]
        BM["Bookmark Management"]
        DM["Digest Management"]
    end

    subgraph Integrations
        SI["Slack Integration"]
        TI["Typefully Integration"]
        ES["Email Service"]
        OAI["OpenAI Integration"]
    end

    subgraph Data
        DB[(PostgreSQL)]
        PS["Prisma Schema"]
        PM["Migrations"]
        DS["Database Services"]
        PS --> DB
        PM --> DB
        DS --> DB
    end

    subgraph Core_Features
        BS["Bookmarking System"]
        DG["Digest Management"]
        TC["Team Collaboration"]
        ND["Newsletter Distribution"]
    end

    subgraph Supporting_Services
        Auth["Authentication"]
        RL["Rate Limiting"]
        OG["OpenGraph Preview"]
    end

    %% Client Layer Connections
    PP & AI & AP --> API

    %% API Layer Connections
    API --> Core_Features
    API --> Supporting_Services
    API --> Data

    %% Integration Connections
    SI --> API
    TI --> API
    ES --> API
    OAI --> API

    %% Core Features Connections
    BS & DG & TC & ND --> API

    %% Style Definitions
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef integration fill:#e1f5fe,stroke:#0288d1
    classDef database fill:#e8f5e9,stroke:#2e7d32
    classDef api fill:#fff3e0,stroke:#f57c00
    classDef core fill:#f3e5f5,stroke:#7b1fa2
    classDef support fill:#fbe9e7,stroke:#d84315

    %% Apply Styles
    class SI,TI,ES,OAI integration
    class DB,PS,PM,DS database
    class AE,TM,BM,DM api
    class BS,DG,TC,ND core
    class Auth,RL,OG support

    %% Click Events
    click PP "https://github.com/premieroctet/digestclub/tree/main/src/app/(app)"
    click AI "https://github.com/premieroctet/digestclub/tree/main/src/app/(admin)"
    click AP "https://github.com/premieroctet/digestclub/tree/main/src/app/(app)/(routes)/auth"
    click AE "https://github.com/premieroctet/digestclub/tree/main/src/pages/api/auth"
    click TM "https://github.com/premieroctet/digestclub/tree/main/src/pages/api/teams"
    click BM "https://github.com/premieroctet/digestclub/tree/main/src/pages/api/bookmark"
    click DM "https://github.com/premieroctet/digestclub/tree/main/src/pages/api/teams/[teamId]/digests"
    click SI "https://github.com/premieroctet/digestclub/tree/main/src/pages/api/webhooks/slack"
    click TI "https://github.com/premieroctet/digestclub/blob/main/src/utils/typefully.ts"
    click ES "https://github.com/premieroctet/digestclub/tree/main/src/emails"
    click OAI "https://github.com/premieroctet/digestclub/blob/main/src/utils/openai.ts"
    click PS "https://github.com/premieroctet/digestclub/blob/main/prisma/schema.prisma"
    click PM "https://github.com/premieroctet/digestclub/tree/main/prisma/migrations"
    click DS "https://github.com/premieroctet/digestclub/tree/main/src/services/database"
    click BS "https://github.com/premieroctet/digestclub/tree/main/src/components/bookmark"
    click DG "https://github.com/premieroctet/digestclub/tree/main/src/components/digests"
    click TC "https://github.com/premieroctet/digestclub/tree/main/src/components/teams"
    click ND "https://github.com/premieroctet/digestclub/tree/main/src/components/newsletter"
    click Auth "https://github.com/premieroctet/digestclub/blob/main/src/pages/api/auth/[...nextauth].tsx"
    click RL "https://github.com/premieroctet/digestclub/blob/main/src/utils/rateLimit.ts"
    click OG "https://github.com/premieroctet/digestclub/blob/main/src/utils/open-graph.tsx"
```
