# zeusnotfound04/nano-mail architecture

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

- Interactive diagram: https://gitdiagram.com/zeusnotfound04/nano-mail
- Repository: https://github.com/zeusnotfound04/nano-mail

## Overview

Based on your project’s file tree and README, NanoMail is clearly a full-stack disposable email system built with a Go backend and a Next.js/TypeScript frontend. It leverages a custom SMTP server for receiving emails, a PostgreSQL database for secure and temporary storage (using Prisma via the UI’s Prisma client), and a real-time update mechanism (such as websockets) to keep the browser UI responsive and dynamic.

##### Main Components
- External Email Sources – Represent the different email servers that send messages to your disposable inbox.
- SMTP Server (Go):
– Source files in cmd/server and internal/server indicate that your Go application primarily handles SMTP communication.
– Include internal configuration (internal/config) and connection limiting logic (internal/limiter) as sub-components or annotated details.
- Database (PostgreSQL):
– The “database” directory and integration via Prisma (inside ui/prisma) show that emails are stored in PostgreSQL.
- Message and Helper Modules:
– The helper and pkg/message folders imply modules to handle error management and message processing. These can be noted as utility components that support the SMTP and database workflows.
- Frontend Application (Next.js UI):
– The entire “ui” folder is dedicated to building the user interface, including components, pages, real-time actions, and styling with Tailwind and TypeScript.
– Highlight that this UI also uses a layer for real-time updates (e.g., through websockets or server-sent events) that delivers email notifications instantly to the end-user’s browser.
- Real-time Communication Channel:

##### Detail Component Relationships and Data Flow
– Receives and processes emails.
– Leverages internal modules for configuration and connection management.
- From the SMTP server, show data flow:
– Emails are stored into the “Database (PostgreSQL)”.
– Also, the server triggers events (via websockets or similar) that immediately update the “Next.js UI”.
– The UI retrieves initial email data via API endpoints if needed and receives real-time updates.
– Detail that the UI uses Next.js (with TypeScript, Tailwind CSS, and additional libraries such as Motion for animations) to provide the reactive user experience.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
– The backend (SMTP server, email processing, and database storage) is clearly separated from the frontend (Next.js UI responsible for display and interactivity).
- Modular Design:
– The Go code is split into organized modules (cmd, internal, helper, pkg) that isolate configuration, connection limiting, and server functions.
– The UI is compartmentalized into components, actions, and utility libraries.
- Real-Time Data Flow:
– Real-time socket connections ensure that the moment a new email is processed, the front-end receives an update. Emphasize the importance of bidirectional data flow and responsive interactions.
- Technology Stack Annotation:

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Email Sources"]:::external

    subgraph "SMTP Server (Go)"
      direction TB
      smtp_main["Main SMTP Server Logic"]:::backend
      smtp_add["Additional SMTP Handling"]:::backend
      smtp_session["SMTP Session Management"]:::backend
      smtp_config["Configuration Management"]:::backend
      smtp_lim["Connection Limiter"]:::backend
    end

    subgraph "Database (PostgreSQL)"
      direction TB
      db_int["Database Integration"]:::database
      prisma["Prisma Schema"]:::database
    end

    subgraph "Message & Helper Modules"
      direction TB
      err_helper["Error Handling Helper"]:::utility
      email_proc["Email Message Processing"]:::utility
    end

    subgraph "Real-time Communication Channel"
      direction TB
      rt["Real-time Channel"]:::realtime
    end

    fe["Next.js UI (Frontend)"]:::frontend

    %% Connections
    A -->|"sendsEmail"| smtp_main
    smtp_main -->|"triggersAdditional"| smtp_add
    smtp_main -->|"triggersSession"| smtp_session
    smtp_main -->|"loadsConfig"| smtp_config
    smtp_main -->|"appliesLimiter"| smtp_lim
    smtp_main -->|"errorSupport"| err_helper
    smtp_main -->|"msgProcessing"| email_proc
    smtp_main -->|"storesEmail"| db_int
    smtp_main -->|"triggersRT"| rt
    db_int -->|"fetchesData"| fe
    rt -->|"pushesUpdates"| fe

    %% Click Events
    click smtp_main "https://github.com/zeusnotfound04/nano-mail/blob/main/cmd/server/main.go"
    click smtp_add "https://github.com/zeusnotfound04/nano-mail/blob/main/internal/server/server.go"
    click smtp_session "https://github.com/zeusnotfound04/nano-mail/blob/main/internal/server/session.go"
    click smtp_config "https://github.com/zeusnotfound04/nano-mail/blob/main/internal/config/config.go"
    click smtp_lim "https://github.com/zeusnotfound04/nano-mail/blob/main/internal/limiter/connection_limiter.go"
    click db_int "https://github.com/zeusnotfound04/nano-mail/blob/main/database/database.go"
    click prisma "https://github.com/zeusnotfound04/nano-mail/blob/main/ui/prisma/schema.prisma"
    click err_helper "https://github.com/zeusnotfound04/nano-mail/blob/main/helper/error.go"
    click email_proc "https://github.com/zeusnotfound04/nano-mail/blob/main/pkg/message/message.go"
    click fe "https://github.com/zeusnotfound04/nano-mail/tree/main/ui/"
    click rt "https://github.com/zeusnotfound04/nano-mail/tree/main/ui/src/actions"

    %% Styles
    classDef external fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef database fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef utility fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef realtime fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef frontend fill:#d0e0e3,stroke:#0b5394,stroke-width:2px;
```
