# atyantik/flarekit architecture

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

- Interactive diagram: https://gitdiagram.com/atyantik/flarekit
- Repository: https://github.com/atyantik/flarekit

## Overview

##### Main Components

a) Frontend Layer (apps/web):
- Astro-based web application
- Pages component (gallery, CDN)
- Middleware handling
- Layout system

b) Backend Layer (apps/backend):
- Hono-based API service
- Route handlers
- Utility services (upload, hash, base64)

c) Database Layer (packages/database):
- D1 Database integration
- Drizzle ORM implementation
- Storage schemas
- Database services
- Migration system

d) Infrastructure Layer:
- Cloudflare Workers
- Cloudflare Pages
- R2 Storage
- Cloudflare D1
- Cloudflare Queues

**┌─ Client Zone ─────────────────┐**
- Browser/End Users          │
- ┬───────────────┘
- ↓
**┌─ Edge Zone ────────────────────────────────────┐**
- ┌─ Frontend (Astro) ─┐  ┌─ Backend (Hono) ─┐ │
- Gallery          │  │ - Upload Route    │ │
- CDN             │←→│ - Utils           │ │
- Layouts         │  │ - API Endpoints   │ │
- ┘  └─────────┬──────────┘ │
- ┼────────────┘
- ↓
**┌─ Services Zone ──────────────────────────────┐**
- ┌─ Database Layer ─────────────────────┐    │
- ┌─ Drizzle ORM ─┐ ┌─ Services ────┐ │    │
- Schemas     │ │ - Storage     │ │    │
- Migrations  │ │ - Queries     │ │    │
- ┘ └──────────────┘ │    │
- ┘    │
- ┬────────────────────────────┘
- ↓
**┌─ Cloudflare Infrastructure ─────────────────┐**
- ┌─ Workers ─┐ ┌─ Pages ─┐ ┌─ Storage ───┐ │
- R2        │ │
- ┘ └─────────┘ │ - D1        │ │
- ┘ │
- ┘

##### Important Elements to Highlight

a) Edge-First Architecture:
- How the frontend and backend services run at the edge
- Distributed nature of the application

b) Data Flow:
- Client-to-Edge communication
- Inter-service communication
- Database operations
- Storage interactions

c) Development Tools:
- A separate section showing development tooling:
- TurboRepo
- ESLint/Prettier
- Testing Framework
- GitHub Actions

##### Deployment Flow
- GitHub Actions workflow
- Build process
- Testing stages
- Deployment to Cloudflare

This system design should effectively communicate both the high-level architecture and the detailed interactions between components, making it valuable for both new team members and experienced developers working on the project.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Zone"]
        Browser["Browser/End Users"]
    end

    subgraph Edge["Edge Zone"]
        subgraph Frontend["Frontend Layer"]
            FPages["Pages"]:::frontend
            FGallery["Gallery"]:::frontend
            FCDN["CDN"]:::frontend
            FLayout["Layout System"]:::frontend
            FMiddleware["Middleware"]:::frontend
        end

        subgraph Backend["Backend Layer"]
            BMain["Main Service"]:::backend
            BRoutes["Route Handlers"]:::backend
            BUpload["Upload Service"]:::backend
            BUtils["Utilities"]:::backend
        end
    end

    subgraph Services["Services Zone"]
        subgraph Database["Database Layer"]
            DSchema["Schema Definitions"]:::database
            DStorage["Storage Schema"]:::database
            DServices["Database Services"]:::database
            DMigrations["Migrations"]:::database
        end
    end

    subgraph Infrastructure["Cloudflare Infrastructure"]
        Workers["Workers"]:::infra
        Pages["Pages"]:::infra
        subgraph Storage["Storage"]
            R2["R2"]:::storage
            D1["D1"]:::storage
        end
    end

    subgraph DevTools["Development Tools"]
        Turbo["TurboRepo"]:::dev
        ESLint["ESLint/Prettier"]:::dev
        Testing["Testing Framework"]:::dev
        GHActions["GitHub Actions"]:::dev
    end

    %% Connections
    Browser --> Frontend
    Frontend <--> Backend
    Backend --> Database
    Database --> Storage
    Frontend --> Pages
    Backend --> Workers
    
    %% Component Relationships
    FPages --> FGallery
    FPages --> FCDN
    FPages --> FLayout
    BMain --> BRoutes
    BRoutes --> BUpload
    BRoutes --> BUtils
    DSchema --> DStorage
    DSchema --> DServices

    %% Style Definitions
    classDef frontend fill:#a8e6cf
    classDef backend fill:#dcedc1
    classDef database fill:#ffd3b6
    classDef storage fill:#ffaaa5
    classDef infra fill:#98c1d9
    classDef dev fill:#e6e6ea

    %% Click Events
    click FPages "https://github.com/Atyantik/flarekit/tree/main/apps/web/src/pages"
    click FGallery "https://github.com/Atyantik/flarekit/tree/main/apps/web/src/pages/gallery"
    click FCDN "https://github.com/Atyantik/flarekit/tree/main/apps/web/src/pages/cdn"
    click FLayout "https://github.com/Atyantik/flarekit/blob/main/apps/web/src/layouts/Layout.astro"
    click FMiddleware "https://github.com/Atyantik/flarekit/blob/main/apps/web/src/middleware.ts"
    click BMain "https://github.com/Atyantik/flarekit/blob/main/apps/backend/src/index.ts"
    click BRoutes "https://github.com/Atyantik/flarekit/tree/main/apps/backend/src/routes"
    click BUpload "https://github.com/Atyantik/flarekit/blob/main/apps/backend/src/routes/upload.route.ts"
    click BUtils "https://github.com/Atyantik/flarekit/tree/main/apps/backend/src/utils"
    click DSchema "https://github.com/Atyantik/flarekit/tree/main/packages/database/src/schema"
    click DStorage "https://github.com/Atyantik/flarekit/blob/main/packages/database/src/schema/storage.schema.ts"
    click DServices "https://github.com/Atyantik/flarekit/tree/main/packages/database/src/services"
    click DMigrations "https://github.com/Atyantik/flarekit/tree/main/packages/database/migrations"
    click Workers "https://github.com/Atyantik/flarekit/blob/main/apps/backend/wrangler.config.json"
    click Pages "https://github.com/Atyantik/flarekit/blob/main/apps/web/wrangler.config.json"
    click Turbo "https://github.com/Atyantik/flarekit/blob/main/turbo.json"
    click ESLint "https://github.com/Atyantik/flarekit/blob/main/eslint.config.js"
    click Testing "https://github.com/Atyantik/flarekit/blob/main/vitest.config.ts"
    click GHActions "https://github.com/Atyantik/flarekit/blob/main/.github/workflows/deploy.yml"
```
