# chandrashekharagrawal/postiz-app architecture

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

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

## Overview

##### Main Components
- Frontend: The NextJS application (located in apps/frontend) is responsible for the user interface and experiences (routing, page layouts, authentication screens, and dashboards).
- Backend API: The NestJS application (in apps/backend) includes numerous API controllers (for agencies, auth, billing, integrations, media, etc.) and services (authentication middleware, public APIs, etc.) to serve as the core business logic layer.
- Background Services:
– Cron: A dedicated module (apps/cron) handling scheduled tasks (e.g., checking for updates, syncing trends).
– Workers: (apps/workers) for processing asynchronous/background jobs, likely triggered via Redis queues.
– Commands: (apps/commands) providing CLI task runners or utility commands.
- Databases & Messaging:
– Database: Prisma is used for interacting with a PostgreSQL database. The libraries subfolders (e.g., libraries/nestjs-libraries) include the Prisma schema and custom repository code.
– Cache/Queue: Redis (via BullMQ) for managing background tasks such as social media posting jobs.
- Email Notifications: Integration with Resend for sending emails (as highlighted in the README).
- External Integrations: Numerous authentication providers and social network integrations are implemented both in the frontend and backend, visible via provider folders for GitHub, Google, wallet, and many social platforms.
- Shared Libraries: Several libraries (e.g., libraries/helpers, libraries/react-shared-libraries, libraries/plugins) house common logic, decorators, utility functions, and plugin systems which support both backend and frontend needs.

##### Depicting Relationships & Interactions
- Frontend (NextJS) communicating with the Backend API via HTTP/REST calls (or GraphQL if applicable) to perform authentication, schedule posts, manage billing, etc.
- Within the Backend API, illustrate modular services handling specific routes (for example, authentication, billing, notifications) and how they depend on the shared libraries.
- That the Backend interacts directly with the PostgreSQL database (via Prisma) for CRUD operations.
- Integrations with external services (social media APIs, email provider Resend) using interface connectors.
- NX monorepo structure as an overarching “container” that encapsulates all these apps and libraries.

##### Architectural Patterns & Design Principles
- The application follows a modular, microservices-like architecture even though it lives in a single repository. Highlight the separation of concerns (frontend UI, backend business logic, task scheduling, and command-line utilities).
- The use of dependency injection in NestJS (as seen in the libraries and service files) and middleware for authentication/authorization are key design principles.
- Extensibility: the plugin system and dedicated providers for social media platforms clearly indicate that the architecture is designed to be easily extended to support new functionalities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% NX Monorepo Container
    subgraph "NX Monorepo"
        %% Applications Subgraph
        subgraph "Applications"
            FE["Frontend (NextJS)"]:::frontend
            BE["Backend API (NestJS)"]:::backend
            CR["Cron Scheduler (Background Services)"]:::background
            WK["Workers (Background Job Processing)"]:::background
            CM["Commands (CLI Task Runners)"]:::cli
        end

        %% Infrastructure Subgraph
        subgraph "Infrastructure"
            DB["Database (PostgreSQL via Prisma)"]:::db
            RD["Redis (BullMQ)"]:::redis
            EM["Email Notifications (Resend)"]:::external
            EI["External Integrations (Social Providers)"]:::external
        end

        %% Shared Libraries Subgraph
        subgraph "Shared Libraries"
            SH["Helpers"]:::shared
            RS["React Shared Libraries"]:::shared
            PL["Plugins"]:::shared
        end
    end

    %% Relationships
    FE -->|"APICalls"| BE
    BE -->|"CRUD"| DB
    BE -->|"JobQueue"| RD
    RD -->|"ScheduledJobs"| CR
    RD -->|"AsyncJobs"| WK
    BE -->|"SocialAPI"| EI
    BE -->|"EmailAPI"| EM
    WK -->|"SocialAPI"| EI
    WK -->|"EmailAPI"| EM
    FE -->|"Uses"| SH
    FE -->|"Uses"| RS
    FE -->|"Uses"| PL
    BE -->|"Uses"| SH
    BE -->|"Uses"| RS
    BE -->|"Uses"| PL

    %% Click Events
    click FE "https://github.com/chandrashekharagrawal/postiz-app/tree/main/apps/frontend"
    click BE "https://github.com/chandrashekharagrawal/postiz-app/tree/main/apps/backend"
    click CR "https://github.com/chandrashekharagrawal/postiz-app/tree/main/apps/cron"
    click WK "https://github.com/chandrashekharagrawal/postiz-app/tree/main/apps/workers"
    click CM "https://github.com/chandrashekharagrawal/postiz-app/tree/main/apps/commands"
    click DB "https://github.com/chandrashekharagrawal/postiz-app/tree/main/libraries/nestjs-libraries/src/database/prisma"
    click RD "https://github.com/chandrashekharagrawal/postiz-app/tree/main/libraries/nestjs-libraries/src/redis"
    click EM "https://github.com/chandrashekharagrawal/postiz-app/blob/main/libraries/nestjs-libraries/src/emails/resend.provider.ts"
    click EI "https://github.com/chandrashekharagrawal/postiz-app/tree/main/libraries/nestjs-libraries/src/integrations/social"
    click SH "https://github.com/chandrashekharagrawal/postiz-app/tree/main/libraries/helpers"
    click RS "https://github.com/chandrashekharagrawal/postiz-app/tree/main/libraries/react-shared-libraries"
    click PL "https://github.com/chandrashekharagrawal/postiz-app/tree/main/libraries/plugins"

    %% Class Definitions for Colors
    classDef frontend fill:#a2d2ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#bde0fe,stroke:#333,stroke-width:2px;
    classDef background fill:#ffdea2,stroke:#333,stroke-width:2px;
    classDef cli fill:#ffe3a3,stroke:#333,stroke-width:2px;
    classDef db fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef redis fill:#ffadad,stroke:#333,stroke-width:2px;
    classDef external fill:#ffd6a5,stroke:#333,stroke-width:2px;
    classDef shared fill:#e0e0e0,stroke:#333,stroke-width:2px;
```
