# whhsky/covid-19-ksh architecture

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

- Interactive diagram: https://gitdiagram.com/whhsky/covid-19-ksh
- Repository: https://github.com/whhsky/covid-19-ksh

## Overview

##### Project Type and Purpose
- The project is a Django-based web application that provides real-time COVID-19 epidemic data visualizations. It combines traditional Django views with a crawler (爬虫) component and incorporates pyecharts for dynamic charting.
- Key components include a web frontend (templates, static assets), backend logic (Django apps for processing, views, models, and serializers), asynchronous task handling (CeleryTask), and a data crawling module (pachong.py under the “demo” app).

##### Analyzing the File Structure
- Top-Level Directories:
- The “keshihua” directory is the main Django project folder, containing configuration files (settings.py, urls.py, wsgi.py) as well as the project-level celery setup (celery.py).
- “CeleryTask” is a Django app that handles background tasks, most likely using Celery to offload heavy or scheduled work.
- “demo” is another Django app which appears to be the core of the COVID data display, with modules for handling CSV files, data serializing, and even a crawler (pachong.py) for data gathering.
- “static” and “templates” are used for the frontend—HTML files, CSS, JavaScript, and even video files to support the visual experience.
- “manage.py” and “requirements.txt” signal the standard Django project structure.
- Notable Files:
- Data files under “demo/csv” and “demo/data” imply that the system processes and possibly stores epidemic-related data (both in CSV and JSON formats).
- The presence of “pachong.py” in the “demo” app shows that there is functionality to scrape or update external data.

- Web Client (Browser):
- Sends HTTP requests to the Django server.
- Receives HTML pages rendered from templates and interacts with dynamic JavaScript (from the static directory) for interactive data visualizations.
- Django Web Server & Core Application (keshihua and demo):
- Central business logic handled within the “demo” app. This part handles routing (via “demo/urls.py”), views (“demo/views.py”), and data models (“demo/models.py”).
- Data visualization via pyecharts likely happens within the views or utility functions.
- The crawler (pachong.py) is part of the demo app, which periodically gathers data from external sources.
- Asynchronous Task Processing (CeleryTask):
- This app contains Celery tasks (notice task.py) and configurations to handle asynchronous operations like data crawling, data processing, and any scheduled updates.
- It interacts with the Django ORM (models) or external APIs to run these tasks without affecting user response times.
- Data Storage:
- While no explicit database type is mentioned, Django migrations exist under both “CeleryTask/migrations” and “demo/migrations” indicating relational DB use for storing epidemic data and task states.
- External Services / Data Sources:
- The crawler in “demo/pachong.py” and the CSV/JSON data files show that external data is acquired and brought into the system.
- There might be scheduled tasks launched by Celery to keep the dataset updated.

##### Technology Stack Indicators
- Python 3.6 as specified in the README.
- Django framework for the web application.
- Celery for task scheduling (as indicated by the “CeleryTask” and “celery.py” configuration).
- pyecharts for data visualization.
- CSV and JSON for data input formats.

- Use clear labels for every component (e.g., “Django (Core – demo & keshihua)”, “CeleryTask Worker”, “Database”, “Web Client”).
- Frontend components (Templates, Static Files)
- Backend components (Django apps, Celery tasks)
- External data sources and asynchronous task flow.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Components
    subgraph "Frontend Components"
        WC["Web Client (Browser)"]:::frontend
        T["Templates"]:::frontend
        CSS["CSS Assets"]:::frontend
        JS["JS Assets"]:::frontend
        Video["Video Assets"]:::frontend
        Font["Font Assets"]:::frontend
    end

    %% Django Server (Core) Group
    subgraph "Django Server"
        %% Project Configuration Subgroup
        subgraph "Project Configuration"
            Settings["Settings"]:::backend
            Urls["URLs"]:::backend
            WSGI["WSGI"]:::backend
            CeleryConfig["Celery Config"]:::backend
        end

        %% Demo App Subgroup
        subgraph "Demo App"
            Views["Views"]:::backend
            ModelsDemo["Models"]:::backend
            DemoUrls["URLs"]:::backend
            Serializers["Serializers"]:::backend
            Admin["Admin"]:::backend
            AppConfigDemo["App Config"]:::backend
            Crawler["Crawler Module"]:::backend
            CSVData["CSV Data"]:::backend
            JSONData["JSON Data"]:::backend
        end
    end

    %% Asynchronous Task Processing (CeleryTask)
    subgraph "CeleryTask Worker"
        Task["Task"]:::async
        ViewsCelery["Views"]:::async
        ModelsCelery["Models"]:::async
        AppConfigCelery["App Config"]:::async
        MigrationsCelery["Migrations"]:::async
    end

    %% Data Storage
    DS["Database (Django ORM)"]:::database

    %% External Data Sources
    EX["External Data Sources (CSV/JSON & Web)"]:::external

    %% Connections
    WC -->|"renders"| T
    WC -->|"loads"| CSS
    WC -->|"loads"| JS
    WC -->|"loads"| Video
    WC -->|"loads"| Font

    WC -->|"sends request"| Views
    Settings -->|"configures"| Views
    Urls -->|"routes to"| Views
    WSGI -->|"serves"| Views
    CeleryConfig -->|"configures"| Task

    Views -->|"CRUD"| ModelsDemo
    Views -->|"uses"| Serializers
    Views -->|"admin interface"| Admin
    AppConfigDemo -->|"initializes"| Views
    DemoUrls -->|"maps"| Views

    ModelsDemo -->|"stores data"| DS

    %% Crawler integration
    Crawler -->|"ingests data"| DS
    EX -->|"provides data"| Crawler

    %% Asynchronous Task integration
    Views -->|"triggers tasks"| Task
    ModelsCelery -->|"logs task data"| DS

    %% Click Events for Frontend Components
    click T "https://github.com/whhsky/covid-19-ksh/blob/main/templates/index.html"
    click CSS "https://github.com/whhsky/covid-19-ksh/tree/main/static/css"
    click JS "https://github.com/whhsky/covid-19-ksh/tree/main/static/js"
    click Video "https://github.com/whhsky/covid-19-ksh/tree/main/static/video"
    click Font "https://github.com/whhsky/covid-19-ksh/tree/main/static/font"

    %% Click Events for Project Configuration files
    click Settings "https://github.com/whhsky/covid-19-ksh/blob/main/keshihua/settings.py"
    click Urls "https://github.com/whhsky/covid-19-ksh/blob/main/keshihua/urls.py"
    click WSGI "https://github.com/whhsky/covid-19-ksh/blob/main/keshihua/wsgi.py"
    click CeleryConfig "https://github.com/whhsky/covid-19-ksh/blob/main/keshihua/celery.py"

    %% Click Events for Demo App files
    click Views "https://github.com/whhsky/covid-19-ksh/blob/main/demo/views.py"
    click ModelsDemo "https://github.com/whhsky/covid-19-ksh/blob/main/demo/models.py"
    click DemoUrls "https://github.com/whhsky/covid-19-ksh/blob/main/demo/urls.py"
    click Serializers "https://github.com/whhsky/covid-19-ksh/blob/main/demo/serializer.py"
    click Admin "https://github.com/whhsky/covid-19-ksh/blob/main/demo/admin.py"
    click AppConfigDemo "https://github.com/whhsky/covid-19-ksh/blob/main/demo/apps.py"
    click Crawler "https://github.com/whhsky/covid-19-ksh/blob/main/demo/pachong.py"
    click CSVData "https://github.com/whhsky/covid-19-ksh/tree/main/demo/csv"
    click JSONData "https://github.com/whhsky/covid-19-ksh/tree/main/demo/data"

    %% Click Events for CeleryTask files
    click Task "https://github.com/whhsky/covid-19-ksh/blob/main/CeleryTask/task.py"
    click ViewsCelery "https://github.com/whhsky/covid-19-ksh/blob/main/CeleryTask/views.py"
    click ModelsCelery "https://github.com/whhsky/covid-19-ksh/blob/main/CeleryTask/models.py"
    click AppConfigCelery "https://github.com/whhsky/covid-19-ksh/blob/main/CeleryTask/apps.py"
    click MigrationsCelery "https://github.com/whhsky/covid-19-ksh/tree/main/CeleryTask/migrations"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef async fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
