# ihatenodejs/librecloud-web architecture

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

- Interactive diagram: https://gitdiagram.com/ihatenodejs/librecloud-web
- Repository: https://github.com/ihatenodejs/librecloud-web

## Overview

##### Project Type and Purpose
- This repository is a full-stack Next.js application serving as the public website, user dashboard, and JSON API for LibreCloud.
- The “app” directory contains both React/SSR pages (Next.js 13+ “app router”) and a collection of serverless API endpoints under `app/api`.
- It integrates user authentication (NextAuth), database persistence (Prisma), and external services (SMTP, Git/Gitea, Nextcloud, OTP/captcha).

##### High-Level File-Structure Analysis
- Top-level “app/” – Next.js pages & layouts, subdivided into “account” (dashboard + login/signup flows), “api” (REST routes), and “legal” (privacy/terms).
- “components/” – reusable UI primitives (components/ui), page-specific composites, and dashboard cards.
- “lib/” – business-logic helpers (email, OTP, Prisma client, Nextcloud integration).
- “prisma/” – database schema and migration definitions, used by Prisma ORM.
- Deployment/configuration: Dockerfile, docker-compose.yml, GitHub Actions workflow, environment configs (next.config.ts, .env).

##### Key Functionality from README
- Hosts the main marketing site (Hero, Pricing, Docs links).
- Provides a secure dashboard allowing users to manage accounts, link Git repos, generate OTPs, view statistics, download resources, and adjust settings.
- Exposes a REST-style API for auth, user management, mail/password resets, captcha issuance, and Git linking/unlinking.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client and CDN
    subgraph "Client (Browser/Mobile)"
        Client["Client (Browser/Mobile UI Pages)"]:::frontend
    end
    CDN["CDN / Static Assets"]:::frontend
    Client -->|"HTTP(S)"| CDN

    %% Next.js Server Components
    subgraph "Next.js Server" 
        subgraph "SSR Pages"
            SSRHome["Home & Marketing Pages"]:::frontend
            Privacy["Privacy Page"]:::frontend
            Terms["Terms Page"]:::frontend
        end
        subgraph "Account Pages"
            AccountLayout["Account Layout"]:::frontend
            Dashboard["Dashboard Home"]:::frontend
            Stats["Statistics"]:::frontend
            Downloads["Downloads"]:::frontend
            Exchange["Exchange"]:::frontend
            Settings["Settings"]:::frontend
            Support["Support"]:::frontend
            Upgrades["Upgrades"]:::frontend
            AI["AI Page"]:::frontend
            Login["Login Page"]:::frontend
            Signup["Signup Page"]:::frontend
            SignupSuccess["Signup Success"]:::frontend
        end
        API["API Routes"]:::backend
        Middleware["Middleware (Auth & Logging)"]:::backend
        Business["Business Logic (lib/)"]:::backend
        ORM["Prisma Client"]:::backend
    end

    %% Database
    DB["Database\n(Users, Sessions, Settings, Stats)"]:::datastore

    %% External Services
    subgraph "External Services"
        SMTP["SMTP Provider"]:::external
        GitSvc["Git Service (Gitea)"]:::external
        Nextcloud["Nextcloud"]:::external
        OTP["OTP/Captcha Engine"]:::external
    end

    %% CI/CD
    subgraph "CI/CD Pipeline"
        GHActions["GitHub Actions"]:::pipeline
        DockerImg["Docker Image"]:::pipeline
        Deploy["Deployment"]:::pipeline
    end

    %% Connections
    CDN -->|"Serves HTML/JS/CSS"| SSRHome
    CDN -->|"Serves HTML/JS/CSS"| Privacy
    CDN -->|"Serves HTML/JS/CSS"| Terms
    Client -->|"API Calls /api/*"| API
    SSRHome -->|uses| Middleware
    API -->|auth & logging| Middleware
    API -->|"Prisma Query"| ORM
    ORM -->|"SQL Queries"| DB
    Business -->|SMTP| SMTP
    Business -->|Git API| GitSvc
    Business -->|Nextcloud API| Nextcloud
    Business -->|TOTP/Captcha| OTP
    API -->|calls| Business

    GHActions --> DockerImg --> Deploy
    Deploy -->|"Deploys Container"| Server["Next.js Server"]:::backend

    %% Click Events
    click Client "https://github.com/ihatenodejs/librecloud-web/blob/main/app/page.tsx"
    click SSRHome "https://github.com/ihatenodejs/librecloud-web/blob/main/app/page.tsx"
    click Privacy "https://github.com/ihatenodejs/librecloud-web/blob/main/app/legal/privacy/page.tsx"
    click Terms "https://github.com/ihatenodejs/librecloud-web/blob/main/app/legal/terms/page.tsx"
    click AccountLayout "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/layout.tsx"
    click Dashboard "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/page.tsx"
    click Stats "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/statistics/page.tsx"
    click Downloads "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/downloads/page.tsx"
    click Exchange "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/exchange/page.tsx"
    click Settings "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/settings/page.tsx"
    click Support "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/support/page.tsx"
    click Upgrades "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/upgrades/page.tsx"
    click AI "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/dashboard/ai/page.tsx"
    click Login "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/login/page.tsx"
    click Signup "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/signup/page.tsx"
    click SignupSuccess "https://github.com/ihatenodejs/librecloud-web/blob/main/app/account/signup/success/page.tsx"
    click NextAuth "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Captcha "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/captcha/create/route.ts"
    click GitLink "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/git/link/route.ts"
    click GitUnlink "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/git/unlink/route.ts"
    click GitUser "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/git/user/route.ts"
    click EmailAPI "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/mail/password/route.ts"
    click UserCreate "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/users/create/route.ts"
    click UserDelete "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/users/delete/route.ts"
    click UserOTP "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/users/otp/route.ts"
    click UserSecurity "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/users/security/route.ts"
    click UserSettings "https://github.com/ihatenodejs/librecloud-web/blob/main/app/api/users/settings/route.ts"
    click Middleware "https://github.com/ihatenodejs/librecloud-web/blob/main/middleware.ts"
    click UIComp "https://github.com/ihatenodejs/librecloud-web/tree/main/components/ui"
    click Cards "https://github.com/ihatenodejs/librecloud-web/tree/main/components/cards/dashboard"
    click Pages "https://github.com/ihatenodejs/librecloud-web/tree/main/components/pages/dashboard"
    click EmailLib "https://github.com/ihatenodejs/librecloud-web/blob/main/lib/email.ts"
    click NextcloudLib "https://github.com/ihatenodejs/librecloud-web/blob/main/lib/nextcloud.ts"
    click OTPLib "https://github.com/ihatenodejs/librecloud-web/blob/main/lib/otp.ts"
    click PrismaLib "https://github.com/ihatenodejs/librecloud-web/blob/main/lib/prisma.ts"
    click Utils "https://github.com/ihatenodejs/librecloud-web/blob/main/lib/utils.ts"
    click HMAC "https://github.com/ihatenodejs/librecloud-web/blob/main/tools/hmac.ts"
    click PrismaSchema "https://github.com/ihatenodejs/librecloud-web/blob/main/prisma/schema.prisma"
    click Public "https://github.com/ihatenodejs/librecloud-web/tree/main/public"
    click GlobalsCSS "https://github.com/ihatenodejs/librecloud-web/blob/main/app/globals.css"
    click Tailwind "https://github.com/ihatenodejs/librecloud-web/blob/main/tailwind.config.ts"
    click PostCSS "https://github.com/ihatenodejs/librecloud-web/blob/main/postcss.config.mjs"
    click NextConfig "https://github.com/ihatenodejs/librecloud-web/blob/main/next.config.ts"
    click TSConfig "https://github.com/ihatenodejs/librecloud-web/blob/main/tsconfig.json"
    click Dockerfile "https://github.com/ihatenodejs/librecloud-web/tree/main/Dockerfile"
    click DockerCompose "https://github.com/ihatenodejs/librecloud-web/blob/main/docker-compose.yml"
    click Workflow "https://github.com/ihatenodejs/librecloud-web/blob/main/.github/workflows/docker.yml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef datastore fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef pipeline fill:#f8d7da,stroke:#721c24,color:#721c24;
```
