# parth-420/zapmail architecture

> Architecture diagram of the GitHub repository parth-420/zapmail, 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/parth-420/zapmail
- Repository: https://github.com/parth-420/zapmail

## Overview

##### Project Type and Purpose
- This is primarily an SMTP server implemented in Go. It implements a full SMTP protocol handler with support for commands like HELO, MAIL FROM, RCPT TO, DATA, and QUIT.
- In addition, the repository contains a distinct "ui" folder, which is structured as a Next.js web application. Although the README focuses on the SMTP server, the UI likely serves as an administrative or monitoring front end (or another user-facing interface) that complements the backend.

##### Analyzing the File Structure
- The top-level is split mainly into two parts:
- The “backend” directory contains the Go code (go.mod, main.go, etc.) which implements the SMTP server functionalities.
- The “ui” directory holds a Next.js application with components, pages (organized under “ui/src/app”), configuration files (e.g., next.config.ts, tailwind.config.ts), and supporting libraries.
- This structure suggests a separation of concerns – the backend is responsible for email processing, while the UI handles user interactions, possibly for monitoring, configuration, or administration.

- Main Components to Represent:
a. SMTP Backend Server:
- Core SMTP engine written in Go.
- Handles email transactions, logs activity, supports concurrency.
- Configuration via environment variables for host and port.
b. UI Frontend Application:
- Next.js-based web interface.
- User interface components (e.g., Navbar, Card, EmailCard) and app pages for contact, FAQ, mail, and user management.
- Likely interacts with backend services (perhaps through API endpoints) or directly reads logs/data.
c. External SMTP Clients:
- Clients (like telnet or any SMTP client) that connect to the backend server to send mail using the standard SMTP commands.
d. (Potential) Data Layer:
- Although not fully detailed in the README, the UI includes “db.ts” in its lib folder suggesting that there might be a database used for storing or displaying logged email transactions. This can be represented if applicable.

##### Relationships and Interactions
- SMTP clients communicate directly with the SMTP backend, sending standard SMTP commands.
- The backend processes these commands and logs or possibly stores the transactions.
- The UI may interact with the backend or the underlying data store to display logs, current activity, or configuration status.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly isolate the email processing logic (backend, implemented in Go) from the user interface (Next.js UI).
- Concurrency: Indicate that the SMTP server supports multiple concurrent connections.
- Configurability: Show that environmental variables (like SMTP_HOST and SMTP_PORT) configure the backend behavior.
- If applicable, note any microservices pattern where two logically independent services (SMTP handling vs. UI dashboard) reside in separate layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    SMTP_Clients("SMTP Clients"):::external

    %% Backend Layer
    subgraph "Backend Layer"
        SMTP_Server("SMTP Server (Backend – Go)"):::backend
        Config_Mod("Config: go.mod"):::backend
        Config_Sum("Config: go.sum"):::backend
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        Web_UI("Web UI (Frontend – Next.js)"):::frontend
        UI_Components("UI Components"):::frontend
        UI_Pages("UI Application Pages"):::frontend
    end

    %% Data Layer
    Data_Layer("Data Layer (Database Interaction)"):::data

    %% Connections
    SMTP_Clients -->|"connects"| SMTP_Server
    SMTP_Server -->|"uses"| Config_Mod
    SMTP_Server -->|"uses"| Config_Sum
    SMTP_Server -->|"stores_logs"| Data_Layer
    SMTP_Server -->|"exposes_API"| Web_UI
    Data_Layer -->|"provides_data"| Web_UI
    Web_UI -->|"renders"| UI_Components
    Web_UI -->|"renders"| UI_Pages

    %% Click Events
    click SMTP_Server "https://github.com/parth-420/zapmail/blob/main/backend/main.go"
    click Config_Mod "https://github.com/parth-420/zapmail/blob/main/backend/go.mod"
    click Config_Sum "https://github.com/parth-420/zapmail/blob/main/backend/go.sum"
    click Web_UI "https://github.com/parth-420/zapmail/tree/main/ui/"
    click UI_Components "https://github.com/parth-420/zapmail/tree/main/ui/src/components"
    click UI_Pages "https://github.com/parth-420/zapmail/tree/main/ui/src/app"
    click Data_Layer "https://github.com/parth-420/zapmail/blob/main/ui/src/lib/db.ts"

    %% Styles
    classDef backend fill:#ffcccb,stroke:#b30000,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
