# espebra/filebin2 architecture

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

- Interactive diagram: https://gitdiagram.com/espebra/filebin2
- Repository: https://github.com/espebra/filebin2

## Overview

##### Main Components

a) Web Application Layer
- HTTP Server (Go-based)
- Admin Interface
- Public Interface
- Metrics Endpoint
- Integration Endpoints (Slack)

b) Storage Layer
- S3 Storage (for file storage)
- PostgreSQL Database (for metadata)

c) Background Services
- Lurker Service (cleanup jobs)
- GeoIP Service

##### Component Relationships

a) Client-facing Flow:
**External Users -> HTTP Server -> {**
- File Upload/Download Flow -> S3 Storage
- Metadata Operations -> PostgreSQL
**}**

b) Admin Flow:
**Admin Users -> Admin Interface -> {**
- Bin Management
- Client Management
- File Management
- Metrics Viewing
**}**

##### Architectural Patterns to Highlight

a) Service Architecture:
- Core Services (dbl/ directory - database layer)
- Domain Services (ds/ directory - domain specific logic)
- HTTP Handlers (http_*.go files)
- Static Content Serving (static/ directory)
- Template Rendering (templates/ directory)

b) Integration Points:
- S3 Storage Interface (s3/ directory)
- Prometheus Metrics
- Slack Integration
- GeoIP Services (geoip/ directory)

##### Specific Implementation Details

Technical elements:

**Frontend Layer:**
- Static Files (CSS/JS)
- HTML Templates
- Custom JavaScript (filebin2.js)

**Backend Layer:**
- REST API Endpoints
- Authentication System
- File Processing
- Bin Management
- Transaction Handling

##### Additional Elements

- Security boundaries
- Authentication flows
- Rate limiting and quota management
- File lifecycle management
- Monitoring and metrics flow

**Top Layer: Client Interface (Web/API)**
**Middle Layer: Application Logic**
**Bottom Layer: Storage & Persistence**
**Cross-cutting: Security, Monitoring, Background Jobs**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        CL1[External Users]
        CL2[Admin Users]
    end

    subgraph "Web Application Layer"
        direction TB
        WS["HTTP Server"]:::server
        click WS "https://github.com/espebra/filebin2/blob/master/http.go"
        
        subgraph "HTTP Handlers"
            direction TB
            AH["Admin Interface"]:::handler
            FH["File Handler"]:::handler
            BH["Bin Handler"]:::handler
            MH["Metrics Handler"]:::handler
            IH["Integration Handler"]:::handler
            click AH "https://github.com/espebra/filebin2/blob/master/http_admin.go"
            click FH "https://github.com/espebra/filebin2/blob/master/http_file.go"
            click BH "https://github.com/espebra/filebin2/blob/master/http_bin.go"
            click MH "https://github.com/espebra/filebin2/blob/master/http_metrics.go"
            click IH "https://github.com/espebra/filebin2/blob/master/http_integration.go"
        end

        subgraph "Frontend Assets"
            direction TB
            JS["Application JS"]:::frontend
            CSS["Custom CSS"]:::frontend
            TPL["HTML Templates"]:::frontend
            ATPL["Admin Templates"]:::frontend
            click JS "https://github.com/espebra/filebin2/blob/master/static/js/filebin2.js"
            click CSS "https://github.com/espebra/filebin2/blob/master/static/css/custom.css"
            click TPL "https://github.com/espebra/filebin2/tree/master/templates/"
            click ATPL "https://github.com/espebra/filebin2/blob/master/templates/admin_*.html"
        end
    end

    subgraph "Domain Services"
        direction TB
        BS["Bin Service"]:::service
        FS["File Service"]:::service
        CS["Client Service"]:::service
        MS["Metrics Service"]:::service
        CF["Configuration"]:::service
        click BS "https://github.com/espebra/filebin2/blob/master/ds/bin.go"
        click FS "https://github.com/espebra/filebin2/blob/master/ds/file.go"
        click CS "https://github.com/espebra/filebin2/blob/master/ds/client.go"
        click MS "https://github.com/espebra/filebin2/blob/master/ds/metrics.go"
        click CF "https://github.com/espebra/filebin2/blob/master/ds/config.go"
    end

    subgraph "Background Services"
        direction TB
        LS["Lurker Service"]:::background
        GS["GeoIP Service"]:::background
        GDB["GeoIP Databases"]:::background
        click LS "https://github.com/espebra/filebin2/blob/master/lurker.go"
        click GS "https://github.com/espebra/filebin2/blob/master/geoip/mmdb.go"
        click GDB "https://github.com/espebra/filebin2/blob/master/mmdb/GeoLite2-City.mmdb"
    end

    subgraph "Storage Layer"
        direction TB
        S3["S3 Storage"]:::storage
        DB["PostgreSQL"]:::storage
        DBL["Database Layer"]:::storage
        click S3 "https://github.com/espebra/filebin2/blob/master/s3/s3ao.go"
        click DBL "https://github.com/espebra/filebin2/blob/master/dbl/db.go"
    end

    subgraph "Deployment"
        direction TB
        DC["Docker Config"]:::deployment
        K8S["Kubernetes"]:::deployment
        GKE["GKE Config"]:::deployment
        click DC "https://github.com/espebra/filebin2/tree/master/Dockerfile"
        click K8S "https://github.com/espebra/filebin2/blob/master/k8s/deployments/filebin2-deployment.yaml"
        click GKE "https://github.com/espebra/filebin2/blob/master/k8s/gke/filebin2-deployment.yaml"
    end

    %% Relationships
    CL1 --> WS
    CL2 --> AH
    WS --> |Routes| AH & FH & BH & MH & IH
    AH & FH & BH --> BS & FS & CS
    BS & FS & CS --> DBL
    DBL --> DB
    FS --> S3
    LS --> DB
    GS --> GDB

    %% Styles
    classDef server fill:#3498db,stroke:#2980b9,color:white
    classDef handler fill:#2ecc71,stroke:#27ae60,color:white
    classDef frontend fill:#e74c3c,stroke:#c0392b,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    classDef background fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#1abc9c,stroke:#16a085,color:white
    classDef deployment fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1["Server Component"]:::server
        L2["HTTP Handler"]:::handler
        L3["Frontend Asset"]:::frontend
        L4["Domain Service"]:::service
        L5["Background Service"]:::background
        L6["Storage Component"]:::storage
        L7["Deployment Config"]:::deployment
    end
```
