# yukionishi1129/daily-api architecture

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

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

## Overview

##### Project Type and Purpose
- Daily API V2 is a backend monolith that serves the content “feed” domain for the daily.dev extension. It exposes HTTP/GraphQL endpoints (Fastify + Apollo), runs background processors (workers and cron jobs), and persists data in PostgreSQL via TypeORM. It also integrates with external services (pub/sub, Slack, OneSignal, Customer.io, search, etc.).

##### High-Level Architectural Components
a. API Layer
- Fastify HTTP server (+ REST + GraphQL via Apollo)
- Route handlers (“src/routes”), GraphQL schemas/resolvers (“src/schema”), directives (“src/directive”)
b. Data Layer
- Primary PostgreSQL (TypeORM entities under “src/entity”, migrations under “src/migration”)
- Read replicas / caching layer (Redis pub/sub/cache clients in “src/common/redisCache” and pub/sub abstractions)
c. Background Processing
- Pub/Sub workers (“src/workers” + “src/notifications”, “src/temporal”)
- Cron Jobs (“src/cron” + binaries under “bin”)
- Temporal workflows / client (“src/temporal”)
d. Integrations / External Services
- Message brokers / pub-sub (Google Pub/Sub, or typedPubsub)
- Third-party APIs: Slack, Customer.io, OneSignal, Meilisearch, Snotra, Garmr, etc.
- File/CDN (Cloudinary)
e. Infrastructure & Deployment
- Docker Compose (local: “docker-compose.yml”)
- Kubernetes via Helm chart (“helm” folder)
- Pulumi IaC (“infra” folder)
- CI/CD (CircleCI config, Tiltfile for local microservice orchestration)

##### Relationships & Data Flows
1. Client (Browser extension, other consumers) → HTTP/GraphQL → Fastify
2. Fastify routes/Apollo resolvers → TypeORM → PostgreSQL primary (reads/writes)
3. Read traffic can be served via read-replica or Redis cache where configured
4. Mutations/triggers → publish events to Pub/Sub
5. Worker processes consume Pub/Sub → execute domain logic (notifications, digests, image processing) → write back to DB or send push/Slack notifications
6. Cron scheduler triggers scheduled tasks (daily digest, tag updates) → perform DB reads/writes + publish events
7. Temporal workflows orchestrate long-running processes (e.g., notifications, retries)
8. External integrations are called both synchronously (e.g., Slack when a notification is created) and asynchronously via workers or Temporal

##### Architectural Patterns & Principles
- Single-responsibility: separate web server, cron jobs, and background workers
- Event-driven: Pub/Sub to decouple producer (API, cron) from consumer (workers)
- Hexagonal-ish / layered: HTTP layer → service layer (“src/common/*”) → persistence layer (TypeORM)
- CQRS flavor: GraphQL queries vs. mutation events feeding workers
- Infrastructure as code: Pulumi + Helm for reproducible deployment

- Technologies: Fastify, Apollo, TypeORM, PostgreSQL, Redis, Google Pub/Sub, Temporal, Pulumi, Helm, CircleCI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (Browser Extension / Other Consumers)"]:::api
    Client -->|"HTTP/GraphQL"| API["Fastify HTTP + Apollo GraphQL Server"]:::api
    click API "https://github.com/yukionishi1129/daily-api/blob/main/src/index.ts"

    %% API Layer
    subgraph "API Layer"
        Routes["Route Handlers"]:::api
        click Routes "https://github.com/yukionishi1129/daily-api/tree/main/src/routes/"
        Schema["GraphQL Schemas & Resolvers"]:::api
        click Schema "https://github.com/yukionishi1129/daily-api/tree/main/src/schema/"
        Directives["GraphQL Directives"]:::api
        click Directives "https://github.com/yukionishi1129/daily-api/tree/main/src/directive/"
    end
    API --> Routes
    API --> Schema
    API --> Directives

    %% Data Layer
    subgraph "Data Layer"
        Entities["TypeORM Entities"]:::data
        click Entities "https://github.com/yukionishi1129/daily-api/tree/main/src/entity/"
        Migrations["Database Migrations"]:::data
        click Migrations "https://github.com/yukionishi1129/daily-api/tree/main/src/migration/"
        RedisCache["Redis Cache Client"]:::data
        click RedisCache "https://github.com/yukionishi1129/daily-api/blob/main/src/common/redisCache.ts"
        PubsubAbst["Pub/Sub Abstractions"]:::data
        click PubsubAbst "https://github.com/yukionishi1129/daily-api/blob/main/src/common/pubsub.ts"
        click PubsubAbst "https://github.com/yukionishi1129/daily-api/blob/main/src/common/typedPubsub.ts"
        DBPrimary[(PostgreSQL Primary)]:::data
        DBReplica[(Read Replica)]:::data
    end
    API -->|"SQL"| DBPrimary
    API -->|"Cache Read/Write"| RedisCache
    API -->|"Pub/Sub Events"| PubsubAbst
    DBPrimary --> DBReplica

    %% Messaging
    PubSub[(Pub/Sub Broker)]:::msg
    API -->|"Publish Events"| PubSub

    %% Background Processing
    subgraph "Background Processing"
        Workers["Worker Pool"]:::bg
        click Workers "https://github.com/yukionishi1129/daily-api/tree/main/src/workers/"
        Notifications["Notifications Builder"]:::bg
        click Notifications "https://github.com/yukionishi1129/daily-api/tree/main/src/notifications/"
        Temporal["Temporal Workflows & Client"]:::bg
        click Temporal "https://github.com/yukionishi1129/daily-api/tree/main/src/temporal/"
        Cron["Cron Scheduler"]:::bg
        click Cron "https://github.com/yukionishi1129/daily-api/blob/main/src/cron.ts"
        click Cron "https://github.com/yukionishi1129/daily-api/tree/main/src/cron/"
        CronBin["Cron Binaries & Scripts"]:::bg
        click CronBin "https://github.com/yukionishi1129/daily-api/tree/main/bin/"
    end
    PubSub -->|"Consume Events"| Workers
    Cron -->|"Schedule Tasks"| Workers
    Cron -->|"SQL/Publish"| DBPrimary
    Workers -->|"SQL"| DBPrimary
    Workers -->|"Integrations/API"| Notifications

    %% Integrations
    subgraph "Integrations / External Services"
        SlackHelper["Slack Helpers"]:::ext
        click SlackHelper "https://github.com/yukionishi1129/daily-api/blob/main/src/common/slack.ts"
        SlackRoute["Slack Integration Route"]:::ext
        click SlackRoute "https://github.com/yukionishi1129/daily-api/blob/main/src/routes/integrations/slack.ts"
        CIORoute["Customer.io Webhook"]:::ext
        click CIORoute "https://github.com/yukionishi1129/daily-api/blob/main/src/routes/webhooks/customerio.ts"
        CIOCommon["Customer.io Client"]:::ext
        click CIOCommon "https://github.com/yukionishi1129/daily-api/blob/main/src/common/cio.ts"
        OneSignal["OneSignal Client"]:::ext
        click OneSignal "https://github.com/yukionishi1129/daily-api/blob/main/src/onesignal.ts"
        Meili["Meilisearch Client"]:::ext
        click Meili "https://github.com/yukionishi1129/daily-api/blob/main/src/integrations/meilisearch.ts"
        Snotra["Snotra Client"]:::ext
        click Snotra "https://github.com/yukionishi1129/daily-api/tree/main/src/integrations/snotra/"
        Garmr["Garmr Client"]:::ext
        click Garmr "https://github.com/yukionishi1129/daily-api/blob/main/src/integrations/garmr.ts"
        GCPubSub["Google Cloud Pub/Sub"]:::ext
        click GCPubSub "https://github.com/yukionishi1129/daily-api/blob/main/src/common/googleCloud.ts"
        Cloudinary["Cloudinary (File/CDN)"]:::ext
        click Cloudinary "https://github.com/yukionishi1129/daily-api/blob/main/src/common/cloudinary.ts"
    end
    Workers -->|"HTTP/API"| SlackHelper
    API -->|"HTTP/API"| SlackRoute
    Workers --> CIOCommon
    API --> CIORoute
    Workers --> OneSignal
    Workers --> Meili
    Workers --> Snotra
    Workers --> Garmr

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        Docker["Docker Compose (Local)"]:::infra
        click Docker "https://github.com/yukionishi1129/daily-api/blob/main/docker-compose.yml"
        Helm["Kubernetes Helm Chart"]:::infra
        click Helm "https://github.com/yukionishi1129/daily-api/tree/main/helm/"
        Pulumi["Pulumi IaC"]:::infra
        click Pulumi "https://github.com/yukionishi1129/daily-api/tree/main/infra/"
        CI["CircleCI Config"]:::infra
        click CI "https://github.com/yukionishi1129/daily-api/blob/main/.circleci/config.yml"
        Tilt["Tiltfile"]:::infra
        click Tilt "https://github.com/yukionishi1129/daily-api/tree/main/Tiltfile"
    end

    %% Styles
    classDef api fill:#BFDBFE,stroke:#3B82F6,color:#1E40AF
    classDef data fill:#D1FAE5,stroke:#10B981,color:#065F46
    classDef msg fill:#FED7AA,stroke:#F97316,color:#9A3412
    classDef bg fill:#A7F3D0,stroke:#059669,color:#064E3B
    classDef ext fill:#E5E7EB,stroke:#6B7280,color:#111827
    classDef infra fill:#F3F4F6,stroke:#9CA3AF,color:#1F2937
```
