# mladenovic-13/lunique-events architecture

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

- Interactive diagram: https://gitdiagram.com/mladenovic-13/lunique-events
- Repository: https://github.com/mladenovic-13/lunique-events

## Overview

##### Project Type and Purpose
- Full-stack event management web application built with Next.js.
- Purpose: Enable users (individuals or organizations) to create events, invite guests, manage RSVPs, and handle payments.

##### File Structure
- src/app: Next.js UI (server- and client-side React) organized by feature (auth, event, organization, etc.).
- src/server & src/trpc: Backend logic—tRPC routers, NextAuth, billing webhooks, database access.
- prisma/schema.prisma: Database schema (PostgreSQL via Supabase).
- public & AWS config: Static assets, image upload to S3 + CloudFront (via server/s3.ts).
- server/billing & server/resend: Integration with LemonSqueezy (payments) and Resend (emails).
- Upstash Redis used for rate limiting and session caching.
- External APIs: Google Maps (address auto-complete & maps), CloudFront image optimization.

##### README Insights
- Tech stack: Next.js, tRPC, Prisma/Supabase, Auth.js, Zustand, TailwindCSS/Shadcn, Resend, Tanstack Table, Framer Motion.
- Environment variables reveal dependencies on PostgreSQL, AWS S3/CloudFront, Upstash Redis, LemonSqueezy, Google Maps.

##### Component Relationships and Interactions
- Browser ↔ Next.js Server: HTTP(S)—page navigation, API calls.
- Next.js Server ↔ tRPC Backend: internal function calls via tRPC.
- tRPC Backend ↔ PostgreSQL: Prisma queries.
- tRPC Backend ↔ Redis: rate-limiting checks.
- tRPC Backend ↔ Resend / LemonSqueezy: API calls for emails and payments.
- Next.js Server ↔ S3/CloudFront: direct upload/download of image assets.
- Browser ↔ Google Maps API: client-side calls for map and autocomplete.

##### Architectural Patterns & Design Principles
- Feature-folder pattern in src/app for co-locating routes, UI, and logic.
- End-to-end type safety via tRPC + TypeScript.
- SSR/SSG hybrid rendering in Next.js.
- Separation of concerns: UI (React) ↔ business logic (tRPC) ↔ data layer (Prisma).
- Use of server-less functions (Next API) for third-party integrations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        UI["Frontend UI\n(Next.js Pages & Components)"]:::frontend
        SharedUI["Shared UI Components Library"]:::frontend
        Zustand["Client-side State\n(Zustand Stores)"]:::frontend
        GM["Google Maps Autocomplete"]:::external
    end

    %% Next.js Server Layer
    subgraph "Next.js Server" 
        direction TB
        SSR["SSR/SSG Rendering"]:::backend
        subgraph "API Routes"
            direction TB
            AuthRoute["Auth API Route\n(NextAuth)"]:::backend
            BillingHook["Billing Webhook Route"]:::backend
            TRPCEnd["tRPC Endpoint"]:::backend
        end
        NextAuthCfg["NextAuth Server Config"]:::backend
    end

    %% tRPC Backend Layer
    subgraph "tRPC Backend"
        direction TB
        TRPCSetup["tRPC Server Setup"]:::backend
        RootMW["tRPC Root & Middleware"]:::backend
        Routers["tRPC Routers"]:::backend
        S3Router["S3 Router"]:::backend
        BillingRouter["Billing Router"]:::backend
    end

    %% Data & Cache
    subgraph "Data Stores"
        direction TB
        Postgres["PostgreSQL (Prisma)"]:::datastore
        PrismaSchema["Prisma Schema"]:::datastore
        DBClient["DB Client Init"]:::backend
    end

    Cache["Upstash Redis"]:::cache

    %% Storage & CDN
    subgraph "AWS Storage & CDN"
        direction TB
        S3["AWS S3 Bucket"]:::storage
        CF["CloudFront CDN"]:::storage
    end

    %% External Services
    subgraph "External Services"
        direction TB
        ResendClient["Resend Email Service"]:::external
        EmailTpl["Transactional Email Templates"]:::frontend
        Lemon["LemonSqueezy Payments"]:::external
    end

    %% Connections
    UI <--> SSR
    UI -->|HTTP| AuthRoute
    UI -->|HTTP| BillingHook
    UI -->|HTTP| TRPCEnd
    UI -->|REST| GM

    SSR -->|calls| TRPCEnd
    SSR -->|uses| NextAuthCfg
    SSR -->|uploads/downloads| S3
    S3 --> CF

    TRPCEnd --> TRPCSetup
    TRPCSetup --> RootMW
    RootMW --> Routers
    Routers -->|Prisma| DBClient
    DBClient --> Postgres
    Routers -->|rate-limit| Cache
    Routers -->|send email| ResendClient
    Routers -->|trigger templates| EmailTpl
    Routers -->|payments API| Lemon
    Routers -->|file ops| S3Router
    Routers -->|billing| BillingRouter

    %% Click Events
    click UI "https://github.com/mladenovic-13/lunique-events/tree/master/src/app"
    click SharedUI "https://github.com/mladenovic-13/lunique-events/tree/master/src/components"
    click Zustand "https://github.com/mladenovic-13/lunique-events/tree/master/src/hooks"
    click AuthRoute "https://github.com/mladenovic-13/lunique-events/blob/master/src/app/api/auth/[...nextauth]/route.ts"
    click BillingHook "https://github.com/mladenovic-13/lunique-events/blob/master/src/app/api/billing/webhook/route.ts"
    click TRPCEnd "https://github.com/mladenovic-13/lunique-events/blob/master/src/app/api/trpc/[trpc]/route.ts"
    click NextAuthCfg "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/auth.ts"
    click TRPCSetup "https://github.com/mladenovic-13/lunique-events/blob/master/src/trpc/server.ts"
    click RootMW "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/api/root.ts"
    click Routers "https://github.com/mladenovic-13/lunique-events/tree/master/src/server/api/routers/"
    click Postgres "https://github.com/mladenovic-13/lunique-events/blob/master/prisma/schema.prisma"
    click DBClient "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/db.ts"
    click Cache "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/api/ratelimiters/ratelimiter.ts"
    click ResendClient "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/resend/resend-client.ts"
    click EmailTpl "https://github.com/mladenovic-13/lunique-events/tree/master/src/components/email/"
    click S3Router "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/api/routers/s3.ts"
    click S3 "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/s3.ts"
    click Lemon "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/billing/lemon-squeeze.ts"
    click BillingRouter "https://github.com/mladenovic-13/lunique-events/blob/master/src/server/api/routers/billing.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFA500,stroke:#333,stroke-width:1px
    classDef cache fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef storage fill:#20B2AA,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
