# httprunner/httprunnermanager architecture

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

- Interactive diagram: https://gitdiagram.com/httprunner/httprunnermanager
- Repository: https://github.com/httprunner/httprunnermanager

## Overview

##### Project Type and Purpose
- This is a full-stack web application (Django “MTV” / MVC pattern) that provides an interface for managing, executing, scheduling, and reporting on HTTP API tests based on HttpRunner.
- Core purpose: allow users to create projects, modules, test cases and configurations; run tests synchronously or asynchronously (via Celery+RabbitMQ); view and persist reports; schedule periodic tasks; integrate with CI (e.g., Jenkins); send email notifications.

##### File Structure
- Top-level:
– HttpRunnerManager/​*: Django project settings, URL routing, WSGI entry point, Celery config
– ApiManager/​*: Django app implementing models, views, admin, custom managers, Celery tasks, utilities, template tags
– static/ & templates/: front-end assets (CSS/JS/images), HTML templates
– logs/: application logs
– uwsgi.ini, manage.py, requirements.txt
- Architectural patterns:
– Django’s MTV (Models in ApiManager/models.py, Views in views.py + templates, URL routes in HttpRunnerManager/urls.py)
– Asynchronous task queue (DJCelery + RabbitMQ broker)
– Modular separation: API management logic in ApiManager app, project-wide settings and bootstrapping in HttpRunnerManager project

##### Extract Key Architecture from README
- DB: MySQL (persistent storage of projects, modules, tests, reports, schedules, users)
- Broker: RabbitMQ (task queue)
- Workers: Celery workers + Celery-beat scheduler (execute tests, send emails)
- Runner: HttpRunner instances invoked by Celery tasks to run tests
- Frontend: jQuery-based pages, served by Django’s staticfiles via Nginx/uWSGI or Django dev server
- External integrations: SMTP mail server (for notifications), Jenkins (CI hook), RabbitMQ management UI (e.g., Celery Flower)

##### Main Components and Their Interactions
1. Browser / UI (HTML templates + static JS/CSS)
2. Web Server Layer
- Nginx (or dev server)
- uWSGI (WSGI app server)
3. Django Application
- HttpRunnerManager (settings, URL router)
- ApiManager app (models, views, admin, utils, Celery tasks)
4. Relational Database (MySQL)
5. Message Broker (RabbitMQ)
6. Celery Workers & Scheduler (celery worker + celery beat)
7. HttpRunner Core (invoked by workers)
8. Email / SMTP Service
9. CI/CD System (Jenkins)
10. Logging (log files in logs/)

1. User → Browser → HTTP request → Nginx → uWSGI → Django views
2. Django view (synchronous operations) ↔ MySQL (ORM in ApiManager/models.py)
3. Django view triggers Celery task → RabbitMQ → Celery worker
4. Celery worker executes HttpRunner test, writes results → MySQL; optionally sends email via SMTP
5. Celery-beat reads periodic task entries from MySQL → enqueues tasks on RabbitMQ
6. Browser polls/requests report pages → Django views → MySQL → renders report_template.html
7. Jenkins (external) triggers HTTP API endpoints on Django to kick off test runs

c. Architectural Patterns & Principles:
- MTV (Model-Template-View) separation of concerns
- Asynchronous task queue for long-running test executions
- Pluggable modular design: ApiManager encapsulates all test management logic
- Externalization of configuration: Django settings.py for DB / broker credentials
- Scheduled tasks via Celery-beat (crontab expressions stored in Django DB)

d. Key Technologies / Libraries:
- Framework: Django
- Task Queue: Celery + djcelery
- Broker: RabbitMQ
- Test Runner: HttpRunner
- Database: MySQL
- Web Server: uWSGI + (optional) Nginx
- Front-end: HTML templates + jQuery, custom CSS
- Reporting: ExtentReports (via templates in templates/extent_report_template.html)
- Email: Django’s email utilities configured in settings.py

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    Browser["Browser / UI"]:::frontend
    Jenkins["Jenkins CI/CD"]:::ext
    SMTP["Email / SMTP Service"]:::ext
    Logging["Logging (logs/*.log)"]:::storage

    %% Web Server Layer
    subgraph "Web Server Layer"
        Nginx["Nginx"]:::webserver
        uWSGI["uWSGI"]:::webserver
    end

    %% Django Application
    subgraph "Django Application"
        direction TB
        subgraph "HttpRunnerManager"
            settings["settings.py"]:::config
            urls["urls.py"]:::config
            wsgi["wsgi.py"]:::config
            celery_conf["celery.py"]:::config
            activator["activator.py"]:::config
        end
        subgraph "ApiManager App"
            direction TB
            models["models.py"]:::backend
            views["views.py"]:::backend
            admin["admin.py"]:::backend
            managers["managers.py"]:::backend
            tasks["tasks.py"]:::backend
            templatetags["custom_tags.py"]:::backend
            subgraph "Utilities"
                common["common.py"]:::util
                emails["emails.py"]:::util
                operation["operation.py"]:::util
                pagination["pagination.py"]:::util
                runner_util["runner.py"]:::util
                task_opt["task_opt.py"]:::util
                testcase_util["testcase.py"]:::util
            end
        end
        templates["HTML Templates"]:::frontend
        staticassets["Static Assets"]:::frontend
    end

    %% Infrastructure
    MySQL["MySQL Database"]:::db
    RabbitMQ["RabbitMQ Broker"]:::broker
    CeleryWorker["Celery Worker"]:::worker
    CeleryBeat["Celery-beat Scheduler"]:::worker
    HttpRunnerCore["HttpRunner Core"]:::worker

    %% Flows
    Browser -- "HTTP Request" --> Nginx
    Nginx --> uWSGI
    uWSGI --> views
    views -- "ORM Read/Write" --> MySQL
    views -- "Trigger Task (AMQP)" --> RabbitMQ
    CeleryBeat -- "Poll PeriodicTask" --> MySQL
    CeleryBeat -- "Enqueue Task (AMQP)" --> RabbitMQ
    RabbitMQ --> CeleryWorker
    CeleryWorker --> HttpRunnerCore
    HttpRunnerCore --> MySQL
    CeleryWorker -- "Send Email (SMTP)" --> SMTP
    Browser -- "Poll Reports" --> views
    Jenkins -- "HTTP API" --> views
    views --> templates
    views --> staticassets
    DjangoLogging["Django Logs"]:::storage
    uWSGI --> DjangoLogging
    CeleryWorker --> DjangoLogging

    %% Click Events
    click templates "https://github.com/httprunner/httprunnermanager/tree/master/templates/"
    click staticassets "https://github.com/httprunner/httprunnermanager/tree/master/static/assets/"
    click settings "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/settings.py"
    click urls "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/urls.py"
    click wsgi "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/wsgi.py"
    click celery_conf "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/celery.py"
    click activator "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/activator.py"
    click models "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/models.py"
    click views "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/views.py"
    click admin "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/admin.py"
    click managers "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/managers.py"
    click tasks "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/tasks.py"
    click templatetags "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/templatetags/custom_tags.py"
    click common "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/common.py"
    click emails "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/emails.py"
    click operation "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/operation.py"
    click pagination "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/pagination.py"
    click runner_util "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/runner.py"
    click task_opt "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/task_opt.py"
    click testcase_util "https://github.com/httprunner/httprunnermanager/blob/master/ApiManager/utils/testcase.py"
    click RabbitMQ "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/celery.py"
    click CeleryBeat "https://github.com/httprunner/httprunnermanager/blob/master/HttpRunnerManager/celery.py"
    click DjangoLogging "https://github.com/httprunner/httprunnermanager/blob/master/logs/all.log"

    %% Styles
    classDef frontend fill:#E8F4FD,stroke:#1E90FF,color:#1E90FF
    classDef webserver fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef backend fill:#FFF7E6,stroke:#F5A623,color:#F5A623
    classDef util fill:#F2FFF2,stroke:#2ECC71,color:#2ECC71
    classDef db fill:#FFF0F0,stroke:#D0021B,color:#D0021B
    classDef broker fill:#F0FFF0,stroke:#7ED321,color:#7ED321
    classDef worker fill:#F5F5F5,stroke:#9B9B9B,color:#9B9B9B
    classDef ext fill:#F5E8FF,stroke:#8E44AD,color:#8E44AD
    classDef config fill:#EDEDED,stroke:#A0A0A0,color:#555
    classDef storage fill:#EFEFEF,stroke:#666,color:#444
```
