# nizzyabi/mail0 architecture

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

- Interactive diagram: https://gitdiagram.com/nizzyabi/mail0
- Repository: https://github.com/nizzyabi/mail0

## Overview

##### Main Components

A. Frontend Layer:
- Next.js Application (indicated by the app directory structure)
- Key UI Components (found in /components)
- Authentication Flow (/app/(auth))
- Mail Management Interface (/app/(routes)/mail)
- Draft System (/app/(routes)/draft)

B. Backend Layer:
- API Routes (/app/api)
- Authentication Service (/app/api/auth)
- Database Layer (indicated by /db directory)
- Rate Limiting System (/lib/rateLimit.ts)

C. External Services:
- OAuth Providers (Google, as mentioned in README)
- Third-party Email Services Integration

**[Client Layer]**
- ↓↑
**[Next.js Server Layer]**
- ↓↑
**[API Layer]**
- ↓↑
**[Service Layer]**
- ↓↑
**[Database Layer]**
- ↓↑
**[External Services]**

##### Component Relationships

- Client-Server communication via Next.js App Router
- API routes handling authentication and mail operations
- Database interactions for storing user data and mail content
- External service integrations (OAuth, email providers)

##### Technical Details to Highlight

- Next.js 13+ App Router architecture
- Database schema and migrations (/db/migrations)
- Authentication system with multiple providers
- API rate limiting implementation
- Docker containerization support

##### Key Architectural Patterns

- Client-Server Architecture
- Microservices approach for email handling
- Provider pattern (shown in /providers directory)
- Component-based UI architecture
- Database migration system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        UI[UI Components]
        Theme[Theme System]
        Draft[Draft Interface]
        Mail[Mail Interface]
        Auth[Auth Interface]
    end

    subgraph NextServer[Next.js Server Layer]
        AppRouter[App Router]
        Pages[Pages & Routes]
        StateManagement[State Management]
        Config[Configuration]
    end

    subgraph APILayer[API Layer]
        API[API Routes]
        RateLimit[Rate Limiter]
        AuthService[Auth Service]
    end

    subgraph ServiceLayer[Service Layer]
        Providers[Provider System]
        Types[Type System]
        Utils[Utilities]
    end

    subgraph DataLayer[Database Layer]
        DB[(Database)]
        Schema[Schema]
        Migrations[Migrations]
    end

    subgraph External[External Services]
        OAuth[OAuth Providers]
        EmailProviders[Email Providers]
    end

    %% Connections
    Client --> AppRouter
    AppRouter --> Pages
    Pages --> API
    API --> RateLimit
    API --> AuthService
    AuthService --> Providers
    Providers --> External
    API --> ServiceLayer
    ServiceLayer --> DataLayer
    
    %% Component styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    
    class UI,Theme,Draft,Mail,Auth frontend
    class API,RateLimit,AuthService backend
    class DB,Schema,Migrations database
    class OAuth,EmailProviders external
    class Config,StateManagement config

    %% Click events
    click UI "https://github.com/nizzyabi/Mail0/tree/main/components/ui"
    click Theme "https://github.com/nizzyabi/Mail0/tree/main/components/theme"
    click Draft "https://github.com/nizzyabi/Mail0/tree/main/app/(routes)/draft"
    click Mail "https://github.com/nizzyabi/Mail0/tree/main/app/(routes)/mail"
    click Auth "https://github.com/nizzyabi/Mail0/tree/main/app/(auth)"
    click AppRouter "https://github.com/nizzyabi/Mail0/tree/main/app"
    click API "https://github.com/nizzyabi/Mail0/tree/main/app/api"
    click RateLimit "https://github.com/nizzyabi/Mail0/blob/main/lib/rateLimit.ts"
    click AuthService "https://github.com/nizzyabi/Mail0/tree/main/app/api/auth"
    click Providers "https://github.com/nizzyabi/Mail0/tree/main/providers"
    click Types "https://github.com/nizzyabi/Mail0/blob/main/types/index.ts"
    click DB "https://github.com/nizzyabi/Mail0/tree/main/db"
    click Schema "https://github.com/nizzyabi/Mail0/blob/main/db/schema.ts"
    click Migrations "https://github.com/nizzyabi/Mail0/tree/main/db/migrations"
    click StateManagement "https://github.com/nizzyabi/Mail0/tree/main/store"
    click Config "https://github.com/nizzyabi/Mail0/blob/main/config/site-config.ts"

    %% Legend
    subgraph Legend
        Frontend[Frontend]:::frontend
        Backend[Backend]:::backend
        DatabaseLegend[Database]:::database
        ExternalLegend[External Services]:::external
        ConfigLegend[Configuration]:::config
    end
```
