# johnkingzy/postiz-app architecture

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

- Interactive diagram: https://gitdiagram.com/johnkingzy/postiz-app
- Repository: https://github.com/johnkingzy/postiz-app

## Overview

##### Main Components
- Frontend: Located in apps/frontend, this is the NextJS/React web client. It handles UI, routing, authentication views, and making API calls.
- Backend: Found in apps/backend (built with NestJS). It includes multiple API controllers (e.g., agencies, auth, billing, webhooks) and core modules as defined in the “src” folder.
- Workers: In apps/workers, responsible for asynchronous processing (posts, stars, plugs, etc.) and likely processing/background jobs.
- Cron & Commands: In apps/cron and apps/commands respectively, these run scheduled and CLI-based tasks like token refreshes, checking stars, and syncing trending posts.
- Shared Libraries: Including helper libraries (e.g., authentication, configuration, utilities), NestJS libraries (e.g., database with Prisma repositories, bullMQ transport, integrations), and React shared libraries (e.g., components, forms, helpers). These encapsulate reusable business logic, integrations, and UI elements.
- Database: Managed by Prisma (default PostgreSQL schema as referenced in libraries/nestjs-libraries/src/database/prisma).
- Job Queue/Cache: Redis integrated with BullMQ to handle background processing.
- External Services: Email notifications via Resend, social media integrations (e.g., Facebook, Instagram, Twitter, TikTok, etc.), and other services for analytics and social posting.

##### Out the Relationships and Interactions
– The Frontend communicates with the Backend through a RESTful (or potentially GraphQL) API layer. In the file tree, API routes are defined in apps/backend/src/api and apps/frontend/src/app/api.
– The Backend uses shared libraries for common business logic and interacts with the Database (using Prisma based on the schema found in libraries/nestjs-libraries).
– The Backend enqueues background jobs into Redis using BullMQ. Workers subscribe to these queues to process tasks asynchronously.
– Cron and Command applications autonomously trigger scheduled tasks or maintenance operations, potentially delegating work to the backend and workers.
– Authentication, integrations, notifications, and media uploads are orchestrated via dedicated modules within the backend and/or shared libraries.
– Shared libraries for React are used to maintain UI consistency across different parts of the frontend.

##### Architectural Patterns & Important Technologies
– NX Monorepo: Clearly indicates a modular, multi-app structure.
– Microservice-like Split: Even though within one repository, splitting of responsibilities is clear (API backend, frontend client, background workers, etc.).
– MVC or Modular Pattern: Backend modules (controllers, services, middleware) follow best practices in NestJS, while frontend components and pages in NextJS are arranged consistently.
– Asynchronous Processing: Use of Redis/BullMQ for job queues.
– Data Persistence: Prisma as ORM interacting with PostgreSQL.
– Integration: Component-based integrations for multiple social media platforms.

##### Detailed Elements
– Connect the backend to the Database (Prisma/PostgreSQL) and also to the Redis queue.
– Illustrate external integrations (Resend, various social networks) as endpoints that the backend communicates with.
– Optionally, include the NX Monorepo as an umbrella label indicating that all these modules reside in one coordinated monorepo ecosystem.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Frontend Layer"
        FE["NextJS Frontend (apps/frontend)"]:::frontend
        RSL["Shared React Libraries (libraries/react-shared-libraries)"]:::shared
    end

    subgraph "Backend Layer"
        BE["NestJS API (apps/backend)"]:::backend
        NSL["Shared NestJS Libraries (libraries/nestjs-libraries)"]:::shared
        HEL["Shared Helper Libraries (libraries/helpers)"]:::shared
    end

    subgraph "Job Queue & Cache"
        JQ1["BullMQ Transport (Job Queue)"]:::jobqueue
        JQ2["Redis Service"]:::jobqueue
    end

    subgraph "Background Processing"
        WORK["Background Worker (apps/workers)"]:::workers
    end

    subgraph "Schedulers & Commands"
        CRON["Cron Jobs (apps/cron)"]:::scheduler
        CLI["CLI Commands (apps/commands)"]:::scheduler
    end

    DB["PostgreSQL (Prisma)"]:::database

    EXT["External Integration (Resend Email & Social APIs)"]:::external

    %% Data Flow Connections
    FE -->|"HTTP/REST"| BE
    FE -->|"Uses"| RSL
    BE -->|"Uses"| NSL
    BE -->|"Uses"| HEL
    BE -->|"Queries"| DB
    BE -->|"EnqueueJob"| JQ1
    JQ1 -->|"Processes"| WORK
    BE -->|"Calls"| EXT
    CRON -->|"Triggers"| BE
    CLI -->|"Triggers"| BE
    CRON -->|"Dispatches"| WORK
    CLI -->|"Dispatches"| WORK
    JQ1 ---|"WorksWith"| JQ2

    %% Styles
    classDef frontend fill:#A3D5FF,stroke:#1F78B4,stroke-width:2px;
    classDef backend fill:#FFB3BA,stroke:#E31A1C,stroke-width:2px;
    classDef workers fill:#BFFCC6,stroke:#33A02C,stroke-width:2px;
    classDef scheduler fill:#FFFFBA,stroke:#FFD700,stroke-width:2px;
    classDef shared fill:#FFC3A0,stroke:#FF7F00,stroke-width:2px;
    classDef database fill:#D5E8D4,stroke:#82B366,stroke-width:2px;
    classDef jobqueue fill:#FCE5CD,stroke:#B45F06,stroke-width:2px;
    classDef external fill:#F8CECC,stroke:#D44646,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/johnkingzy/postiz-app/tree/main/apps/frontend"
    click BE "https://github.com/johnkingzy/postiz-app/tree/main/apps/backend"
    click WORK "https://github.com/johnkingzy/postiz-app/tree/main/apps/workers"
    click CRON "https://github.com/johnkingzy/postiz-app/tree/main/apps/cron"
    click CLI "https://github.com/johnkingzy/postiz-app/tree/main/apps/commands"
    click HEL "https://github.com/johnkingzy/postiz-app/tree/main/libraries/helpers"
    click NSL "https://github.com/johnkingzy/postiz-app/tree/main/libraries/nestjs-libraries"
    click RSL "https://github.com/johnkingzy/postiz-app/tree/main/libraries/react-shared-libraries"
    click DB "https://github.com/johnkingzy/postiz-app/tree/main/libraries/nestjs-libraries/src/database/prisma"
    click JQ1 "https://github.com/johnkingzy/postiz-app/tree/main/libraries/nestjs-libraries/src/bull-mq-transport-new"
    click JQ2 "https://github.com/johnkingzy/postiz-app/blob/main/libraries/nestjs-libraries/src/redis/redis.service.ts"
    click EXT "https://github.com/johnkingzy/postiz-app/blob/main/libraries/nestjs-libraries/src/emails/resend.provider.ts"
```
