# maruki00/azago architecture

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

- Interactive diagram: https://gitdiagram.com/maruki00/azago
- Repository: https://github.com/maruki00/azago

## Overview

##### Project Type and Purpose
- This is a stand-alone Go HTTP server application (“go-webserver”) with its own minimal framework (under `internal/azago`) and several reusable helper packages (under `pkg`).
- It listens for incoming HTTP requests, routes them to handlers, applies middleware (gzip compression, logging, etc.), and sends back responses.

##### File Structure
- cmd/main.go
- Entry point; constructs and starts the server.
- internal/azago
- Core web framework:
– server.go: HTTP server bootstrapping
– router.go: route registration and dispatch
– request.go / response.go: abstractions over net/http Request/ResponseWriter
– zenith_ctx.go: per-request context management
- internal/common
- pkg/
- gzip/gzip.go: middleware for GZIP compression
- log/logs.go: structured logging
- reader/reader.go: body-parsing utilities
- time/time.go: time-related helpers

##### Key Architectural Patterns
- Layered HTTP handling: middleware chain → router → handler
- Dependency inversion: `internal/azago` defines interfaces (Request, Response, Router) that higher layers use.
- Separation of concerns: `internal/azago` for framework, `pkg/*` for reusable libraries, `internal/common` for shared utilities.

##### Main Components
a. External Clients (Browsers or API callers)
b. go-webserver Binary (cmd/main.go)
c. HTTP Server (internal/azago/server)
d. Middleware Layer
– gzip (pkg/gzip)
– logging (pkg/log)
– request reader (pkg/reader)
– time util (pkg/time)
e. Router (internal/azago/router) → dispatch to handlers
f. Request/Response abstractions (internal/azago/request & response)
g. Shared Utilities (internal/common)

##### Relationships and Data Flow
1. Client issues HTTP request → TCP → Server.Listen (server.go)
2. Incoming request wrapped into `azago.Request`
3. Pass through middleware chain (gzip, log, reader, time); each middleware mutates context or response headers
4. Routed by `azago.Router` to a handler function
5. Handler uses common utilities (`internal/common`) and writes to `azago.Response`
6. Response passes back through any post-processing middleware (e.g., gzip compression)
7. Final HTTP response sent to client

##### Technologies and Frameworks
- Go standard library (`net/http`) under the hood
- Custom mini-framework (`internal/azago`)
- Reusable Go modules in `pkg/`

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actor
    Client["Client (Browser/API)"]:::external

    %% Entry Point
    subgraph "Application Entry Point"
        Main["go-webserver Binary\n(cmd/main.go)"]:::entry
    end

    %% Core Framework Layer
    subgraph "Core Framework (internal/azago)" 
        Server["HTTP Server\n(server.go)"]:::core
        Router["Router\n(router.go)"]:::core
        Request["Request Abstraction\n(request.go)"]:::core
        Response["Response Abstraction\n(response.go)"]:::core
        Ctx["Context Manager\n(zenith_ctx.go)"]:::core
    end

    %% Middleware Layer
    subgraph "Middleware Chain (pkg)"
        Gzip["GZIP Middleware\n(pkg/gzip/gzip.go)"]:::middleware
        Log["Logging Middleware\n(pkg/log/logs.go)"]:::middleware
        Reader["Request Reader Middleware\n(pkg/reader/reader.go)"]:::middleware
        Time["Time Utilities\n(pkg/time/time.go)"]:::middleware
    end

    %% Shared Utilities
    subgraph "Shared Utilities (internal/common)"
        Shared["Common Utils\n(colors.go,status.go,common.go)"]:::shared
    end

    %% Application Handler
    Handler["Handler Functions\n(application)"]:::application

    %% Request Flow
    Client -->|"HTTP Request"| Main
    Main -->|"Initialize Server"| Server
    Server -->|"Wrap into *azago.Request"| Request
    Request --> Ctx
    Ctx --> Gzip
    Gzip --> Log
    Log --> Reader
    Reader --> Time
    Time -->|"Pass *azago.Request"| Router
    Router -->|"Invoke Handler"| Handler
    Handler -->|"Uses Shared Utils"| Shared
    Handler -->|"Writes to azago.Response"| Response

    %% Response Flow
    Response --> Time
    Time --> Reader
    Reader --> Log
    Log --> Gzip
    Gzip --> Server
    Server -->|"HTTP Response"| Client

    %% Click Events
    click Main "https://github.com/maruki00/azago/blob/main/cmd/main.go"
    click Server "https://github.com/maruki00/azago/blob/main/internal/azago/server.go"
    click Router "https://github.com/maruki00/azago/blob/main/internal/azago/router.go"
    click Request "https://github.com/maruki00/azago/blob/main/internal/azago/request.go"
    click Response "https://github.com/maruki00/azago/blob/main/internal/azago/response.go"
    click Ctx "https://github.com/maruki00/azago/blob/main/internal/azago/zenith_ctx.go"
    click Gzip "https://github.com/maruki00/azago/blob/main/pkg/gzip/gzip.go"
    click Log "https://github.com/maruki00/azago/blob/main/pkg/log/logs.go"
    click Reader "https://github.com/maruki00/azago/blob/main/pkg/reader/reader.go"
    click Time "https://github.com/maruki00/azago/blob/main/pkg/time/time.go"
    click Shared "https://github.com/maruki00/azago/blob/main/internal/common/common.go"

    %% Styles
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef entry fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef middleware fill:#90EE90,stroke:#333,stroke-width:1px
    classDef shared fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef application fill:#FFFACD,stroke:#333,stroke-width:1px
```
