# goktugcy/hono-boilerplate architecture

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

- Interactive diagram: https://gitdiagram.com/goktugcy/hono-boilerplate
- Repository: https://github.com/goktugcy/hono-boilerplate

## Overview

##### Main Components

a) Client Layer:
- External clients/applications that consume the API
- HTTP/HTTPS requests coming in

b) Cloudflare Workers Layer:
- Main application container
- Hono framework as the core HTTP handling framework
- Following internal components:
- Routes Handler (from routes.ts)
- Authentication Middleware
- Controllers (Auth and Country)

c) Supabase Layer:
- Two distinct Supabase clients:
- Supabase Anon Client (public operations)
- Supabase Service Client (privileged operations)
- Supabase Auth Service
- Supabase Database

##### Component Relationships

- Client → Cloudflare Workers (HTTP requests)
- Routes → Controllers
- Controllers → Supabase Clients
- Auth Middleware → Supabase Auth Service
- Supabase Clients → Supabase Services

##### Authentication Flow

- Token extraction from cookies
- Token verification process
- Token refresh flow
- Cookie setting mechanism

##### Specific Implementation Details

**a) Controllers:**
- AuthController
- CountryController

**b) Middleware:**
- authMiddleware

**c) Database Clients:**
- supabaseAnon
- supabaseService

##### Environment Configuration

A small section showing the configuration dependencies:
- SUPABASE_URL
- SUPABASE_SERVICE_KEY
- SUPABASE_ANON_KEY
- STAGE (dev/prod)

##### Response handling

- Keep components well-spaced and aligned
- Use consistent sizing for similar components
- Brief descriptions for key processes
- Version/environment indicators

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef client fill:#2374AB,color:white
    classDef worker fill:#7C7C7C,color:white
    classDef middleware fill:#FFD700,color:black
    classDef controller fill:#4CAF50,color:white
    classDef database fill:#9C27B0,color:white
    classDef config fill:#FF9800,color:black
    classDef error fill:#FF0000,color:white,stroke-dasharray: 5 5

    %% Client Layer
    Client[External Client]:::client

    %% Cloudflare Workers Layer
    subgraph CloudflareWorker["Cloudflare Workers Environment"]
        Entry["Main Application Entry"]
        Routes["Routes Handler"]
        AuthMW["Authentication Middleware"]
        
        subgraph Controllers["Controllers"]
            AuthC["Auth Controller"]
            CountryC["Country Controller"]
        end
        
        Helpers["Helper Functions"]
        Config["Environment Config"]
    end

    %% Supabase Layer
    subgraph Supabase["Supabase Services"]
        SupaClients["Supabase Clients"]
        SupaAuth["Supabase Auth"]
        SupaDB[(Supabase Database)]
    end

    %% Connections
    Client --> Entry
    Entry --> Routes
    Routes --> AuthMW
    Routes --> Controllers
    AuthMW --> SupaAuth
    AuthC --> SupaClients
    CountryC --> SupaClients
    SupaClients --> SupaAuth
    SupaClients --> SupaDB
    Helpers --> Controllers

    %% Error paths
    AuthError[Authentication Error]:::error
    AuthMW -.-> AuthError
    SupaAuth -.-> AuthError

    %% Click events
    click Routes "https://github.com/goktugcy/hono-boilerplate/blob/main/src/routes.ts"
    click AuthMW "https://github.com/goktugcy/hono-boilerplate/blob/main/src/middlewares/authMiddleware.ts"
    click AuthC "https://github.com/goktugcy/hono-boilerplate/blob/main/src/controllers/AuthController.ts"
    click CountryC "https://github.com/goktugcy/hono-boilerplate/blob/main/src/controllers/CountryController.ts"
    click SupaClients "https://github.com/goktugcy/hono-boilerplate/blob/main/src/db/supabaseClient.ts"
    click Entry "https://github.com/goktugcy/hono-boilerplate/blob/main/index.ts"
    click Config "https://github.com/goktugcy/hono-boilerplate/blob/main/wrangler.toml"
    click Helpers "https://github.com/goktugcy/hono-boilerplate/blob/main/src/helpers.ts"

    %% Legend
    subgraph Legend
        Client2[Client]:::client
        Worker2[Worker Component]:::worker
        Middleware2[Middleware]:::middleware
        Controller2[Controller]:::controller
        Database2[Database]:::database
        Config2[Configuration]:::config
        Error2[Error Path]:::error
    end
```
