# getfider/fider architecture

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

- Interactive diagram: https://gitdiagram.com/getfider/fider
- Repository: https://github.com/getfider/fider

## Overview

##### Main Components
- Frontend Client: Represented by the “public” folder which holds the React components, pages, hooks, models, and service-related code. This layer handles the user interface (UI) and client-side logic, including server-side rendering (indicated by files such as ssr.tsx).
- Backend API & Business Logic: The “app” directory contains the core backend logic. This includes:
– Actions: Contains business logic for various operations (user management, posts, tags, billing, invites, OAuth, etc.).
– Handlers: HTTP API endpoints. You have both generic endpoints and versioned API handlers (apiv1).
– Middlewares: Components that provide cross-cutting concerns such as authentication, caching, CORS, instrumentation, and security.
– Models & Data Layer: Organized under “models”, this layer defines the database entities, DTOs (data transfer objects), and query layers. There’s also an extraction to “services/sqlstore” for interacting with the underlying database, likely PostgreSQL as hinted by the SQL migration scripts under “migrations” and package names ("postgres").
– Jobs & Tasks: Background jobs and asynchronous tasks (e.g., email suppression, purge of notifications).
– Services & External Integrations: Provided under “services” and “pkg” directories, this includes integrations for email, billing (Paddle), blob storage (local file system, S3, SQL blob), HTTP clients, logging, JWT authentication, and more.
- External Services: There are integrations with third-party providers:
– Billing providers (e.g., Paddle)
– Email services (AWS SES, Mailgun, SMTP, plus a mock implementation)
– OAuth providers, webhooks, etc.
- DevOps/Deployment: The presence of Dockerfile, docker-compose.yml, and Kubernetes/Procfile (for Heroku or similar) shows containerization and process management. Also, configuration-related files like .env, Makefile, and GitHub workflows indicate CI/CD pipelines.

##### Relationships and Data Flows
- The Frontend communicates with the Backend via HTTP/REST API calls (or SSR calls). Represent the flow from the “public” UI components to the “handlers” in the backend.
- The Handlers, using the “actions” layer and “middlewares”, process HTTP requests, interact with the “models” (and hence the Database), and integrate with external services (billing, email).
- The background “jobs” and “tasks” run asynchronously to perform time-based or event-driven operations.
- External integrations (such as email or billing) are invoked by both the actions and services layer to communicate with third-party APIs.
- Configuration and deployment artifacts (Docker, migration scripts) manage application start-up and environment setup.

##### Architectural Patterns and Principles
- Separation of Concerns: The division among frontend (UI), backend controllers/handlers, business logic (actions), and persistence (models, SQL store) is clear.
- Modular Design: Different packages and directories (middlewares, models, services, etc.) indicate that the design follows modularization, which supports scalability and easier maintenance.
- Testability: Presence of test files for most components (e.g., actions_test.go, handlers_test.go) indicates an emphasis on testable code.
- Integration with Continuous Integration/Deployment (CI/CD) tools is indicated through GitHub workflows and Docker configurations.

##### Relevant Technologies and Frameworks
- Go (Golang) for backend development.
- React (and TypeScript) for frontend development.
- PostgreSQL (or similar relational database) for persistence.
- Docker for containerization.
- Various packages for logging, authentication (JWT), billing, email, and web utilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        FE["Frontend UI – React"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        H["API Handlers – Go"]:::backend
        MW["Middlewares"]:::backend
        AC["Business Logic (Actions)"]:::backend
        MD["Models & Data Layer"]:::backend
        JT["Jobs & Tasks"]:::backend
    end

    %% External Integrations
    subgraph "External Integrations"
        BILL["External Billing"]:::integration
        EMAIL["External Email Providers"]:::integration
        OAUTH["External OAuth Providers"]:::integration
    end

    %% Data Layer
    subgraph "Data Layer"
        DB[(Database – PostgreSQL)]:::database
    end

    %% DevOps/CI/CD
    subgraph "DevOps/CI/CD"
        DEVOPS["DevOps & CI/CD"]:::devops
    end

    %% Connections
    FE -->|"HTTP_request"| H
    H -->|"middleware_chain"| MW
    MW -->|"process_request"| AC
    AC -->|"db_operations"| MD
    MD -->|"query_update"| DB
    AC -->|"billing_call"| BILL
    AC -->|"email_call"| EMAIL
    AC -->|"oauth_call"| OAUTH
    AC -->|"trigger_async_job"| JT
    JT -->|"job_updates"| DB
    DEVOPS ---|"deploys"| FE
    DEVOPS ---|"deploys"| H

    %% Click Events
    click FE "https://github.com/getfider/fider/tree/main/public/"
    click AC "https://github.com/getfider/fider/tree/main/app/actions/"
    click H "https://github.com/getfider/fider/tree/main/app/handlers/"
    click H "https://github.com/getfider/fider/tree/main/app/handlers/apiv1/"
    click MW "https://github.com/getfider/fider/tree/main/app/middlewares/"
    click MD "https://github.com/getfider/fider/tree/main/app/models/"
    click MD "https://github.com/getfider/fider/tree/main/app/services/sqlstore/"
    click JT "https://github.com/getfider/fider/tree/main/app/jobs/"
    click JT "https://github.com/getfider/fider/tree/main/app/tasks/"
    click BILL "https://github.com/getfider/fider/blob/main/app/actions/billing.go"
    click BILL "https://github.com/getfider/fider/tree/main/app/services/billing/"
    click EMAIL "https://github.com/getfider/fider/tree/main/app/services/email/"
    click OAUTH "https://github.com/getfider/fider/blob/main/app/actions/oauth.go"
    click OAUTH "https://github.com/getfider/fider/tree/main/app/services/oauth/"
    click DB "https://github.com/getfider/fider/tree/main/migrations/"
    click DEVOPS "https://github.com/getfider/fider/tree/main/Dockerfile"
    click DEVOPS "https://github.com/getfider/fider/blob/main/docker-compose.yml"
    click DEVOPS "https://github.com/getfider/fider/tree/main/Procfile"
    click DEVOPS "https://github.com/getfider/fider/tree/main/.github/workflows/"

    %% Styles
    classDef frontend fill:#ffcccc,stroke:#000,stroke-width:1px;
    classDef backend fill:#ccffcc,stroke:#000,stroke-width:1px;
    classDef integration fill:#ccccff,stroke:#000,stroke-width:1px;
    classDef database fill:#ffffcc,stroke:#000,stroke-width:1px;
    classDef devops fill:#ffcc99,stroke:#000,stroke-width:1px;
```
