# drogonframework/drogon architecture

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

- Interactive diagram: https://gitdiagram.com/drogonframework/drogon
- Repository: https://github.com/drogonframework/drogon

## Overview

##### Main Components
- Core Framework (Drogon Engine): This encapsulates modules such as the HTTP server implementation (in lib/src/HttpServer.cc and related files), asynchronous I/O (relying on epoll/kqueue through the trantor library), request parsing (HttpRequestParser, HttpResponseParser), and response generation.
- Routing & Controller Dispatch: This component handles the mapping of incoming URLs to controllers and filters (see the “HttpController”, “HttpSimpleController”, and associated binding code in both lib and drogon_ctl).
- Middleware & Filter Chains: These are used to implement cross-cutting concerns like authentication, logging, and HTTP method verification.
- Plugins and Extensions: Encapsulated in the plugin interface files (in lib/inc/drogon/plugins/) and managed at runtime via the plugins system.
- Command-Line Tool (drogon_ctl): A separate module providing an interface for code scaffolding and project creation. It uses templates (under drogon_ctl/templates) to generate new controllers, models, plugins, views, etc.
- ORM and Database Support: Areas in “orm_lib” provide object-to-database mapping and support asynchronous database access for SQL databases, while “nosql_lib” provides Redis integration.
- Configuration System: Managed through configuration files (e.g., config.example.json, config.example.yaml) in the root folder and facilitated by ConfigLoader & various ConfigAdapters.
- Build/CI Infrastructure: Captured through CMake scripts, GitHub workflows, and other related build scripts for testing and analysis.
- Testing Modules: Unit tests, integration tests, and sample applications (in “lib/tests” and “examples”) that show the end-to-end use of the framework.

##### Relationships and Interactions
- Asynchronous Processing: Represent the non-blocking event loop (powered by epoll/kqueue) that handles I/O and dispatches callbacks to controllers.
- Middleware Chain: Show how pre-request filters or middleware components intercept requests before reaching the designated controller.
- Configuration Loader: Indicate that the application’s runtime behavior (e.g., listening ports, thread pool settings) is dynamically loaded through configuration files.
- Command-Line Interface: Include drogon_ctl as a separate auxiliary tool that generates the scaffold for new controllers, plugins, or views, feeding into the core modules.

##### Important Architectural Patterns/Design Principles
- Asynchronous and Non-Blocking I/O: Emphasize that the framework is designed for high concurrency by using an event-driven architecture.
- Modular Design and Separation of Concerns: Controllers, filters, and plugins are developed as separate modules, allowing for extensibility and customization.
- Code Generation & Template Use: The drogon_ctl component’s use of templates promotes standard patterns in code across the project.
- Middleware Pattern: Clearly indicate how filter chains are used to inject additional logic into request processing.

##### Relevant Technologies, Frameworks, or Libraries
- C++17/20 Standard: The project is built in modern C++.
- Trantor Library: For asynchronous I/O operations.
- CMake and Conan: For build configuration and dependency management.
- JSON and YAML Processing: For configuration and potentially for responses.
- Integration with OpenSSL for HTTPS support.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Framework"
        HTTPServer["HTTP Server & I/O Manager"]:::core
        RequestParser["HTTP Request/Response Parsing"]:::core
        EventLoop["Event Loop/Asynchronous Core"]:::core
        Routing["Routing & Controller Dispatch"]:::core
        Middleware["Middleware & Filter Chains"]:::core
        Plugins["Plugins Manager"]:::core
    end

    subgraph "Configuration & Build"
        ConfigLoader["Configuration Loader"]:::config
        BuildCI["Build/CI Infrastructure"]:::build
    end

    subgraph "CLI & Tools"
        CLI["drogon_ctl (CLI Tool)"]:::cli
    end

    subgraph "Database Support"
        ORM["ORM & SQL DB Connector"]:::external
        NoSQL["NoSQL (Redis) Connector"]:::external
    end

    subgraph "Testing & Examples"
        Testing["Testing Modules & Examples"]:::test
    end

    %% Request Flow
    HTTPServer -->|"parses"| RequestParser
    RequestParser -->|"routes"| Routing
    Routing -->|"applies"| Middleware
    Middleware -->|"invokes"| Plugins
    HTTPServer -->|"uses"| EventLoop
    Routing -->|"DBOp"| ORM
    Routing -->|"DBOp"| NoSQL

    %% Configuration influences
    ConfigLoader -->|"configures"| HTTPServer
    ConfigLoader -->|"configures"| Middleware

    %% CLI scaffolding relationships
    CLI -->|"scaffolds"| Routing
    CLI -->|"scaffolds"| Plugins
    CLI -->|"scaffolds"| ConfigLoader

    %% Build and Testing
    BuildCI -->|"builds"| HTTPServer
    Testing -->|"tests"| HTTPServer

    %% Click Events
    click HTTPServer "https://github.com/drogonframework/drogon/blob/master/lib/src/HttpServer.cc"
    click Routing "https://github.com/drogonframework/drogon/blob/master/lib/inc/drogon/HttpController.h"
    click Middleware "https://github.com/drogonframework/drogon/blob/master/lib/inc/drogon/HttpFilter.h"
    click Plugins "https://github.com/drogonframework/drogon/tree/master/lib/inc/drogon/plugins/"
    click CLI "https://github.com/drogonframework/drogon/tree/master/drogon_ctl/"
    click ORM "https://github.com/drogonframework/drogon/tree/master/orm_lib/"
    click NoSQL "https://github.com/drogonframework/drogon/tree/master/nosql_lib/redis/"
    click ConfigLoader "https://github.com/drogonframework/drogon/blob/master/lib/src/ConfigLoader.cc"
    click BuildCI "https://github.com/drogonframework/drogon/blob/master/CMakeLists.txt"
    click Testing "https://github.com/drogonframework/drogon/tree/master/lib/tests/"

    %% Styles
    classDef core fill:#8FBC8F,stroke:#333,stroke-width:2px;
    classDef cli fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef config fill:#F4A460,stroke:#333,stroke-width:2px;
    classDef build fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef test fill:#9370DB,stroke:#333,stroke-width:2px;
```
