# dailydotdev/daily-api architecture

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

- Interactive diagram: https://gitdiagram.com/dailydotdev/daily-api
- Repository: https://github.com/dailydotdev/daily-api

## Overview

##### Main Components

a. Core API Layer:
- GraphQL API (Apollo Server)
- REST API (Fastify)
- Compatibility Layer (for API v1)

b. Data Storage:
- PostgreSQL Database (primary data store)
- Redis (caching and pub/sub)
- Algolia (search functionality)

c. Background Processing:
- Workers System
- Cron Jobs
- Temporal Workflows

d. External Services Integration:
- CloudinaryImage (image processing)
- OneSignal (push notifications)
- Customer.io (CIO)
- Paddle (payments)
- Slack Integration

##### Component Relationships

**Client Requests -> API Layer (GraphQL/REST)**

- ↓
**Authentication/Authorization Layer**

- ↓
**Core Services Layer:**
- Feed Management
- User Management
- Content Management
- Notification System
- Search

- ↓
**Data Access Layer:**
- TypeORM Entities
- Data Loaders
- Caching Layer

- ↓
**Background Processing:**
- Workers
- Cron Jobs
- Temporal Workflows

##### Key Architectural Patterns to Highlight

a. Service Organization:
- Entity Layer (`src/entity/`)
- Schema Layer (`src/schema/`)
- Workers Layer (`src/workers/`)
- Common Utilities (`src/common/`)

b. Data Flow Patterns:
- Pub/Sub System for async operations
- GraphQL resolvers for data fetching
- Background workers for heavy processing
- Cron jobs for scheduled tasks

##### Important Subsystems to Detail

a. Notification System:
- Flow from trigger → worker → delivery
- Temporal workflows

b. Content Management:
- Post processing pipeline
- Image handling
- Content moderation flow

c. Feed System:
- Content aggregation
- Personalization
- Delivery pipeline

##### Infrastructure Components

- Kubernetes deployment
- CircleCI integration
- Monitoring and telemetry
- Database migrations system

##### Additional Elements

- Version information
- Scaling points
- Failure recovery paths
- Security boundaries

##### Implementation Details to Note

- Database replication flows
- Caching mechanisms
- Rate limiting points

##### Security boundaries and authentication flows

Remember to include annotations explaining key architectural decisions and their rationale, particularly around:

- The use of TypeORM for database operations
- The choice of GraphQL as the primary API layer
- The worker-based background processing system
- The temporal workflow implementation for complex operations

This will provide a clear understanding of the system's architecture while highlighting its scalability and maintainability aspects.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Requests]
    end

    subgraph "API Layer"
        GQL["GraphQL API"]:::api
        REST["REST API"]:::api
        COMPAT["Compatibility Layer"]:::api
    end

    subgraph "Security"
        AUTH["Authentication/Authorization"]:::security
    end

    subgraph "Core Services"
        FEED["Feed Management"]:::service
        USER["User Management"]:::service
        CONTENT["Content Management"]:::service
        NOTIF["Notification System"]:::service
        SEARCH["Search System"]:::service
    end

    subgraph "Data Layer"
        DB[(PostgreSQL)]:::database
        REDIS[(Redis Cache)]:::database
        ALGOLIA[(Algolia Search)]:::database
        DL["Data Loaders"]:::data
        PUBSUB["Pub/Sub System"]:::data
    end

    subgraph "Background Processing"
        WORKERS["Workers System"]:::worker
        CRON["Cron Jobs"]:::worker
        TEMPORAL["Temporal Workflows"]:::worker
    end

    subgraph "External Services"
        CLOUD["Cloudinary"]:::external
        ONE["OneSignal"]:::external
        CIO["Customer.io"]:::external
        PADDLE["Paddle"]:::external
        SLACK["Slack"]:::external
    end

    CL --> GQL & REST
    REST & GQL --> AUTH
    COMPAT --> AUTH
    AUTH --> FEED & USER & CONTENT & NOTIF & SEARCH
    
    FEED & USER & CONTENT & NOTIF & SEARCH --> DL
    DL --> DB
    FEED & USER & CONTENT & NOTIF & SEARCH --> REDIS
    SEARCH --> ALGOLIA
    
    FEED & USER & CONTENT & NOTIF --> PUBSUB
    PUBSUB --> WORKERS
    WORKERS --> TEMPORAL
    TEMPORAL --> ONE & CIO & SLACK
    CONTENT --> CLOUD
    USER --> PADDLE

    %% Component Mappings
    click GQL "https://github.com/dailydotdev/daily-api/tree/main/src/schema/"
    click REST "https://github.com/dailydotdev/daily-api/tree/main/src/routes/"
    click COMPAT "https://github.com/dailydotdev/daily-api/tree/main/src/compatibility/"
    click DB "https://github.com/dailydotdev/daily-api/tree/main/src/entity/"
    click REDIS "https://github.com/dailydotdev/daily-api/blob/main/src/redis.ts"
    click SEARCH "https://github.com/dailydotdev/daily-api/blob/main/src/common/search.ts"
    click WORKERS "https://github.com/dailydotdev/daily-api/tree/main/src/workers/"
    click CRON "https://github.com/dailydotdev/daily-api/tree/main/src/cron/"
    click TEMPORAL "https://github.com/dailydotdev/daily-api/tree/main/src/temporal/"
    click CLOUD "https://github.com/dailydotdev/daily-api/blob/main/src/common/cloudinary.ts"
    click ONE "https://github.com/dailydotdev/daily-api/blob/main/src/onesignal.ts"
    click CIO "https://github.com/dailydotdev/daily-api/blob/main/src/cio.ts"
    click PADDLE "https://github.com/dailydotdev/daily-api/blob/main/src/paddle.ts"
    click SLACK "https://github.com/dailydotdev/daily-api/blob/main/src/integrations/slack.ts"
    click FEED "https://github.com/dailydotdev/daily-api/blob/main/src/entity/Feed.ts"
    click USER "https://github.com/dailydotdev/daily-api/tree/main/src/entity/user/"
    click CONTENT "https://github.com/dailydotdev/daily-api/tree/main/src/entity/posts/"
    click NOTIF "https://github.com/dailydotdev/daily-api/tree/main/src/notifications/"
    click AUTH "https://github.com/dailydotdev/daily-api/blob/main/src/auth.ts"
    click DL "https://github.com/dailydotdev/daily-api/blob/main/src/dataLoaderService.ts"
    click PUBSUB "https://github.com/dailydotdev/daily-api/blob/main/src/common/pubsub.ts"

    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef security fill:#FDD835,stroke:#F57F17,color:black
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#7E57C2,stroke:#4527A0,color:white
    classDef data fill:#90CAF9,stroke:#1565C0,color:black
    classDef worker fill:#FF7043,stroke:#D84315,color:white
    classDef external fill:#78909C,stroke:#37474F,color:white
```
