# cpavel/zack architecture

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

- Interactive diagram: https://gitdiagram.com/cpavel/zack
- Repository: https://github.com/cpavel/zack

## Overview

##### Main System Components

a) Web Layer:
- Nginx (reverse proxy)
- Django Web Server
- UI Components (Tailwind CSS)

b) Application Core:
- Django Apps:
- Campaigns
- Data
- Leads
- UI

c) Background Processing:
- Celery Worker
- Redis (message broker)

d) External Services:
- OpenAI API
- HackerNews Algolia API

e) Data Store:
- PostgreSQL Database

##### Component Relationships

a) Client Flow:
- External Client → Nginx → Django Server
- Static Files: Nginx → Static Files Directory

b) Data Flow:
- Django → PostgreSQL (bidirectional)
- Django → Celery → Redis (task queue)
- Celery → External APIs (OpenAI, HN Algolia)

##### Architectural Patterns to Highlight

a) Service Architecture:
- Clear separation between web server and worker processes
- API-based communication between components
- Asynchronous task processing

b) Data Processing Pipeline:
- Search term processing
- Template selection
- AI evaluation flow
- Lead generation process

##### Specific Implementation Details

Key elements:

a) Django Apps Structure:
- Campaigns: Campaign management and orchestration
- Data: Search terms, prompt templates, evaluation templates
- Leads: Lead management and processing
- UI: Frontend interface

b) Processing Flow:

##### Data Storage Layer (Bottom)

Each component should include:

- Component name
- Primary function
- Key configurations
- Critical dependencies

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph "Web Server Layer"
        Nginx["Nginx Reverse Proxy"]:::server
        click Nginx "https://github.com/cpavel/zACK/blob/master/docker/nginx/default.conf"
        Django["Django Web Server"]:::server
        click Django "https://github.com/cpavel/zACK/blob/master/ack/wsgi.py"
        UI["UI Components"]:::frontend
        click UI "https://github.com/cpavel/zACK/blob/master/ui/templates/base.html"
    end

    subgraph "Application Layer"
        Campaigns["Campaigns Module"]:::app
        click Campaigns "https://github.com/cpavel/zACK/blob/master/campaigns/models.py"
        Data["Data Module"]:::app
        click Data "https://github.com/cpavel/zACK/blob/master/data/models.py"
        Leads["Leads Module"]:::app
        click Leads "https://github.com/cpavel/zACK/blob/master/leads/models.py"
        Config["Environment & Config"]:::config
        click Config "https://github.com/cpavel/zACK/blob/master/ack/settings.py"
    end

    subgraph "Background Processing"
        Celery["Celery Worker"]:::worker
        click Celery "https://github.com/cpavel/zACK/blob/master/ack/celery.py"
        Redis["Redis Message Broker"]:::cache
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        HNAlgolia["HackerNews Algolia API"]:::external
        click HNAlgolia "https://github.com/cpavel/zACK/blob/master/ack/instructions/hacker_news.py"
    end

    subgraph "Data Storage"
        PostgreSQL[(PostgreSQL)]:::database
        Migrations["Database Migrations"]:::database
        click Migrations "https://github.com/cpavel/zACK/tree/master/campaigns/migrations/"
    end

    %% Client Layer Connections
    Browser --> Nginx
    Nginx --> Django
    Nginx --> UI

    %% Application Layer Connections
    Django --> Campaigns
    Django --> Data
    Django --> Leads
    Django --> Config

    %% Data Flow
    Campaigns --> PostgreSQL
    Data --> PostgreSQL
    Leads --> PostgreSQL
    PostgreSQL --> Migrations

    %% Background Processing Flow
    Django -.-> Redis
    Redis -.-> Celery
    Celery -.-> OpenAI
    Celery -.-> HNAlgolia

    %% Styles
    classDef server fill:#6b9bd2
    classDef frontend fill:#42b883
    classDef app fill:#4a69bd
    classDef worker fill:#b71540
    classDef cache fill:#fa983a
    classDef external fill:#78e08f
    classDef database fill:#fad390
    classDef config fill:#82ccdd

    %% Legend
    subgraph Legend
        L1["Web Services"]:::server
        L2["Frontend"]:::frontend
        L3["App Modules"]:::app
        L4["Workers"]:::worker
        L5["Cache"]:::cache
        L6["External APIs"]:::external
        L7["Data Storage"]:::database
        L8["Configuration"]:::config
    end
```
