# unfazed-eco/unfazed architecture

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

- Interactive diagram: https://gitdiagram.com/unfazed-eco/unfazed
- Repository: https://github.com/unfazed-eco/unfazed

## Overview

##### Main Components
- ASGI Protocol & Entry Point: Show the core ASGI interface (found in unfazed/protocol/asgi.py) that handles incoming HTTP requests. This is the backbone that connects external requests to internal components.
- Command Line Interface (CLI): Represent the CLI tools (unfazed/cli.py and unfazed/command/*) that provide commands such as runserver, startproject, and startapp. Illustrate how these utilities kick-start and manage the framework.
- Middleware: Include the middleware subsystem (unfazed/middleware and unfazed/contrib/*/middleware) that manages request/response transformations, authentication, logging, CORS, gzip, trusted host functions, etc.
- HTTP & Routing: Illustrate the HTTP request and response handling (unfazed/http, unfazed/route) that direct traffic to the appropriate endpoints and handle parameter parsing, request validations (using serializer frameworks) and error handling.
- ORM & Database Integration: Show the integration with Tortoise-ORM, which is concentrated under unfazed/db/tortoise. This component is used for models, database migrations, and related commands.
- Caching: Include the caching subsystem (unfazed/cache with its locmem and redis backends, compressors, and serializers) used to improve application performance.
- OpenAPI/Swagger Support: Represent the OpenAPI components (unfazed/openapi) that build and serve the API documentation, including endpoints, routes, and templates for swagger-ui and redoc.
- Configuration & Settings: Highlight the components for configuration management (unfazed/conf and tests */settings.py files) which centralize app and environment settings.
- Static Files & Templates: Illustrate support for serving static files (unfazed/static) and templated resources (unfazed/template), especially for admin and frontend assets.

##### Relationships and Interactions
- How the command-line interface (CLI) enables developers to generate projects and manage apps, which then integrate into the core registry.
- Demonstrate how the ORM sub-system connects with the database and how caching layers (with both in-memory and Redis backends) are used to optimize database operations.

##### Architectural Patterns
- Pluggable App System: Show that the framework is highly modular, where apps, middleware, and even caching/ORM mechanisms can be interchanged.
- Separation of Concerns: Clearly demarcate the handling of HTTP requests, command-line operations, middleware processing, business logic (apps), and data persistence.
- Pipeline Architecture: Emphasize the cascaded processing for HTTP requests through middleware before reaching the routing logic.
- Template-Driven Code Generation: Represent the project and app templates that streamline project creation.

##### Relevant Technologies and Frameworks
- Python and ASGI: Base technology with asynchronous capabilities.
- Tortoise-ORM: For ORM and database interactions.
- Docker & docker-compose: Deployment and development environment setups (visible by Dockerfile and docker-compose.yml).
- OpenAPI / Swagger: For API documentation and interface definitions.
- Third-party integration points such as support for Redis caching and potential future admin interfaces.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Runtime Flow"
        IR("Incoming Request"):::external
        ASGI("ASGI Protocol & Entry Point"):::core
        MW("Middleware"):::core
        HTTP("HTTP & Routing"):::core
        APPS("App & Pluggable System"):::core
        ORM("ORM & Database Integration"):::core
        CACHE("Caching"):::infra
        API("OpenAPI/Swagger Support"):::infra
        LOG("Logging & Exception Handling"):::infra
        STATIC("Static Files & Templates"):::static
    end

    subgraph "Developer Tools"
        CLI("Command Line Interface (CLI)"):::dev
        CONFIG("Configuration & Settings"):::config
    end

    IR --> ASGI
    ASGI --> MW
    MW --> HTTP
    HTTP --> APPS
    APPS --> ORM
    APPS --> CACHE
    HTTP --> API
    HTTP --> STATIC
    ORM --> LOG
    CACHE --> LOG

    CLI --> APPS
    CLI --> CONFIG

    %% Click Events for Component Mapping
    click ASGI "https://github.com/unfazed-eco/unfazed/blob/main/unfazed/protocol/asgi.py"
    click CLI "https://github.com/unfazed-eco/unfazed/blob/main/unfazed/cli.py"
    click CLI "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/command"
    click APPS "https://github.com/unfazed-eco/unfazed/blob/main/unfazed/app/registry.py"
    click APPS "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/template/app"
    click MW "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/middleware"
    click MW "https://github.com/unfazed-eco/unfazed/blob/main/unfazed/contrib/auth/middleware.py"
    click MW "https://github.com/unfazed-eco/unfazed/blob/main/unfazed/contrib/session/middleware.py"
    click HTTP "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/http"
    click HTTP "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/route"
    click ORM "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/db/tortoise"
    click CACHE "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/cache"
    click API "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/openapi"
    click LOG "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/logging"
    click LOG "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/exception"
    click CONFIG "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/conf"
    click STATIC "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/static"
    click STATIC "https://github.com/unfazed-eco/unfazed/tree/main/unfazed/template"

    %% Class Definitions for Styling
    classDef external fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef core fill:#FFF2CC,stroke:#333,stroke-width:2px;
    classDef infra fill:#DFF2BF,stroke:#333,stroke-width:2px;
    classDef dev fill:#FFD699,stroke:#333,stroke-width:2px;
    classDef config fill:#F9CB9C,stroke:#333,stroke-width:2px;
    classDef static fill:#EAD1DC,stroke:#333,stroke-width:2px;
```
