# zomato/espresso architecture

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

- Interactive diagram: https://gitdiagram.com/zomato/espresso
- Repository: https://github.com/zomato/espresso

## Overview

##### Main Components
- Frontend (espresso-ui):
- This is built in Next.js (as seen by next.config.ts, package.json, and Next.js–like folder structure under src/app) and provides a browser-based UI for managing templates and document creation.
- Backend Service (service):
- Implemented in Go (service/main.go, controller for PDF generation, and various configurations).
- Exposes REST APIs for PDF generation and signing.
- Contains controllers (e.g., service/controller/pdf_generation) and internal services (e.g., service/internal/service/generateDoc) that handle document creation workflow.
- Core Libraries (lib):
- Modules like renderer, signer, templatestore, and workerpool abstract and encapsulate core logic.
- For example, the renderer converts HTML/CSS to PDF, the signer handles digital signing using X.509 certificates, and templatestore provides storage interaction with S3, MySQL, or disk.
- Auxiliary Components:
- GitHub workflows, Dockerfiles, and Makefile indicate continuous integration/deployment and containerized deployment.
- Documentation (docs/Integration.md, docs/QuickStart.md) supports deployment and integration.

##### Out Relationships and Interactions
- The Frontend interacts with the Backend Service via REST API calls.
- The Backend Service routes incoming requests to the appropriate controller (i.e., the PDF generation controller).
- The controller then invokes internal services (generateDoc) that coordinate with the libraries:
- The Renderer module (from lib/renderer) converts HTML templates to PDFs.
- The Signer module (from lib/signer) digitally signs the generated PDFs.
- The Template Store (from lib/templatestore) fetches and manages the templates, possibly utilizing different back-ends (S3, MySQL, Disk).
- The Worker Pool (from lib/workerpool) illustrates how tasks may be executed concurrently to handle peak loads.
- External dependencies and integrations (e.g., certificates for signing, cloud storage for S3) should also be depicted.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Different modules handle distinct tasks (rendering, signing, storage).
- Modular Design: Core functionality is abstracted in libraries making the system extensible.
- API-Driven Interaction: The service layer exposes a REST API used by the UI.
- Containerization: Dockerfiles and Docker Compose setup indicate container-based deployments.
- High Performance & Scalability: Use of worker pools and efficient, specialized modules is fundamental.

##### Relevant Technologies
- Frontend: Next.js, React, JavaScript/TypeScript.
- Backend: Go (with modules for PDF generation, digital signing, and templating).
- Container Tools: Docker, Docker Compose.
- Additional Tools: GitHub Actions (CI/CD workflows) and pre-commit hooks (for code quality enforcement).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        FE["Espresso UI (Next.js)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BS["Backend Service (REST API Server)"]:::backend
        PDFCT["PDF Generation Controller"]:::backend
        DOCS["Internal Document Generation Service"]:::backend
    end

    %% Library Modules
    subgraph "Library Modules"
        RENDER["Renderer Module (HTML/CSS to PDF)"]:::library
        SIGNER["Signer Module (Digital Signing)"]:::library
        TEMPLATE["Template Store Module"]:::library
        WP["Worker Pool (Concurrency)"]:::library
    end

    %% External Systems
    subgraph "External Systems"
        S3["Cloud Storage (S3)"]:::external
        MYSQL["Database (MySQL)"]:::external
        CERT["Certificate Authority"]:::external
    end

    %% Deployment & CI/CD
    subgraph "Deployment & CI/CD"
        CI["CI/CD Workflows"]:::deployment
        DOCS_AUX["Documentation & Deployment Scripts"]:::deployment
    end

    %% Relationships
    FE -->|"REST_API_call"| BS
    BS -->|"routes_request"| PDFCT
    PDFCT -->|"invokes_service"| DOCS
    DOCS -->|"calls_renderer"| RENDER
    DOCS -->|"calls_signer"| SIGNER
    DOCS -->|"calls_templatestore"| TEMPLATE
    DOCS -->|"manages_tasks"| WP

    TEMPLATE -->|"fetches/stores"| S3
    TEMPLATE -->|"fetches/stores"| MYSQL
    SIGNER -->|"verifies_with"| CERT

    %% Click Events
    click FE "https://github.com/zomato/espresso/tree/main/espresso-ui/"
    click BS "https://github.com/zomato/espresso/tree/main/service/"
    click PDFCT "https://github.com/zomato/espresso/tree/main/service/controller/pdf_generation/"
    click DOCS "https://github.com/zomato/espresso/tree/main/service/internal/service/generateDoc/"
    click RENDER "https://github.com/zomato/espresso/tree/main/lib/renderer/"
    click SIGNER "https://github.com/zomato/espresso/tree/main/lib/signer/"
    click TEMPLATE "https://github.com/zomato/espresso/tree/main/lib/templatestore/"
    click WP "https://github.com/zomato/espresso/tree/main/lib/workerpool/"
    click CI "https://github.com/zomato/espresso/tree/main/.github/workflows/"
    click DOCS_AUX "https://github.com/zomato/espresso/tree/main/docs/"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef library fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
    classDef deployment fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
