# du411/chicknotify architecture

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

- Interactive diagram: https://gitdiagram.com/du411/chicknotify
- Repository: https://github.com/du411/chicknotify

## Overview

##### Main Components

A. External Services Layer:
- Chickpt.com (Job Source)
- AWS Lambda (Scraping Service)
- Notification Channels (Email, Discord, Telegram)

B. Core Application Components:
- FastAPI Application Server
- PostgreSQL Database
- Redis Cache/Pub-Sub System

**[External Sources] → [Application Core] → [Notification Destinations]**

##### Detailed Component Breakdown

A. Data Flow Section:
**[Chickpt.com] → [AWS Lambda Scraper] → [Redis Pub/Sub] → [FastAPI Backend]**

B. Core Application Section:
**FastAPI Backend:**
- API Layer (Routers)
- Service Layer
- Repository Layer
- Model Layer

C. Storage Section:
**[PostgreSQL] ← → [FastAPI Backend] ← → [Redis]**

##### Key Relationships to Highlight

A. Data Flow:
- Lambda scraper to Redis pub/sub
- Redis pub/sub to notification service
- User subscriptions to notification matching

B. Service Dependencies:
- Authentication flow
- Subscription management
- Job matching system
- Notification dispatch

##### Specific Implementation Details

Key services based on the file structure:
- JobService (app/services/job_service.py)
- NotificationService (app/services/notification_service.py)
- KeywordRankingService (app/services/keyword_ranking_service.py)
- ScraperService (app/services/scraper_service.py)

##### Database Schema Overview

Main entities:
- Users
- Jobs
- Notifications
- Subscriptions
- NotificationTypes
- SubscriptionItems

##### Additional Elements

A. Infrastructure Components:
- Docker containers
- Alembic migrations
- Environment configurations

B. Security Layer:
- JWT Authentication
- Security dependencies

Key Considerations:

##### Monitoring and logging points

Remember to emphasize:
- The event-driven nature of the notification system
- The separation of concerns in the service layer
- The role of Redis in both caching and pub/sub
- The extensibility of the notification system

This will provide a complete picture of the system while maintaining clarity and usefulness for development and maintenance purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Services Layer
    subgraph External
        Chickpt[Chickpt.com]:::external
        Lambda["AWS Lambda Scraper"]:::external
        click Lambda "https://github.com/Du411/chicknotify/blob/main/lambda_function.py"
    end

    %% Core Application Layer
    subgraph Core
        FastAPI["FastAPI Server"]:::core
        click FastAPI "https://github.com/Du411/chicknotify/blob/main/app/main.py"

        subgraph Services
            direction TB
            JobSvc["Job Service"]:::service
            NotifSvc["Notification Service"]:::service
            KeywordSvc["Keyword Ranking Service"]:::service
            ScraperSvc["Scraper Service"]:::service
            SubSvc["Subscription Service"]:::service
            click JobSvc "https://github.com/Du411/chicknotify/blob/main/app/services/job_service.py"
            click NotifSvc "https://github.com/Du411/chicknotify/blob/main/app/services/notification_service.py"
            click KeywordSvc "https://github.com/Du411/chicknotify/blob/main/app/services/keyword_ranking_service.py"
            click ScraperSvc "https://github.com/Du411/chicknotify/blob/main/app/services/scraper_service.py"
            click SubSvc "https://github.com/Du411/chicknotify/blob/main/app/services/subscription_service.py"
        end

        subgraph API
            direction TB
            JobsAPI["Jobs API"]:::api
            NotifAPI["Notifications API"]:::api
            SubAPI["Subscriptions API"]:::api
            UsersAPI["Users API"]:::api
            click JobsAPI "https://github.com/Du411/chicknotify/blob/main/app/routers/jobs.py"
            click NotifAPI "https://github.com/Du411/chicknotify/blob/main/app/routers/notifications.py"
            click SubAPI "https://github.com/Du411/chicknotify/blob/main/app/routers/subscriptions.py"
            click UsersAPI "https://github.com/Du411/chicknotify/blob/main/app/routers/users.py"
        end

        subgraph Models
            direction TB
            Users["Users"]:::model
            Jobs["Jobs"]:::model
            Notifs["Notifications"]:::model
            Subs["Subscriptions"]:::model
            NotifTypes["Notification Types"]:::model
            UserSubs["User Subscriptions"]:::model
            click Users "https://github.com/Du411/chicknotify/blob/main/app/models/users.py"
            click Jobs "https://github.com/Du411/chicknotify/blob/main/app/models/jobs.py"
            click Notifs "https://github.com/Du411/chicknotify/blob/main/app/models/notifications.py"
            click Subs "https://github.com/Du411/chicknotify/blob/main/app/models/subscription_items.py"
            click NotifTypes "https://github.com/Du411/chicknotify/blob/main/app/models/notification_types.py"
            click UserSubs "https://github.com/Du411/chicknotify/blob/main/app/models/user_subscriptions.py"
        end

        subgraph Auth
            AuthDep["Auth Dependencies"]:::security
            AuthSchema["Auth Schemas"]:::security
            click AuthDep "https://github.com/Du411/chicknotify/blob/main/app/dependencies/auth.py"
            click AuthSchema "https://github.com/Du411/chicknotify/blob/main/app/schemas/auth.py"
        end
    end

    %% Storage Layer
    subgraph Storage
        Postgres[(PostgreSQL)]:::database
        Redis[("Redis Cache/Pub-Sub")]:::cache
        click Redis "https://github.com/Du411/chicknotify/tree/main/redis/Dockerfile"
    end

    %% Notification Channels
    subgraph Notifications
        Email["Email Service"]:::notification
        Discord["Discord Service"]:::notification
        Telegram["Telegram Service"]:::notification
        click Email "https://github.com/Du411/chicknotify/blob/main/app/services/notifications/email.py"
        click Discord "https://github.com/Du411/chicknotify/blob/main/app/services/notifications/discord.py"
        click Telegram "https://github.com/Du411/chicknotify/blob/main/app/services/notifications/telegram.py"
    end

    %% Relationships
    Chickpt -->|Jobs Data| Lambda
    Lambda -->|Published Jobs| Redis
    Redis -->|Events| FastAPI
    FastAPI --> Services
    Services --> API
    Services --> Models
    API --> Auth
    FastAPI -.->|Read/Write| Postgres
    FastAPI -.->|Cache/Events| Redis
    NotifSvc -->|Send| Email
    NotifSvc -->|Send| Discord
    NotifSvc -->|Send| Telegram

    %% Styles
    classDef external fill:#2374ab
    classDef core fill:#48a9a6
    classDef service fill:#4ea5d9
    classDef api fill:#44cfcb
    classDef model fill:#d4f4dd
    classDef security fill:#e63946
    classDef database fill:#ffb703
    classDef cache fill:#fb8500
    classDef notification fill:#e63946

    %% Legend
    subgraph Legend
        L1[External Services]:::external
        L2[Core Components]:::core
        L3[Services]:::service
        L4[API Layer]:::api
        L5[Models]:::model
        L6[Security]:::security
        L7[(Database)]:::database
        L8[("Cache/Pub-Sub")]:::cache
        L9[Notifications]:::notification
    end
```
