# alexxito23/2fa-cloudsite architecture

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

- Interactive diagram: https://gitdiagram.com/alexxito23/2fa-cloudsite
- Repository: https://github.com/alexxito23/2fa-cloudsite

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js 13 application that implements a secure file-sharing/cloud-storage platform.
- The README confirms it was bootstrapped with create-next-app, and the file tree shows:
- A React/Next.js front-end in `app/` and `components/`
- A set of server-side API routes under `app/api/` for auth, user file operations, groups, sharing, encryption, notifications, etc.

##### File Structure
- Top-level artifacts:
- `app/` – Next.js 13 App Router directory containing SSR/SSG pages, layouts, and API routes
- `components/`, `hooks/`, `utils/`, `lib/` – reusable UI components, React hooks, helper functions
- `middleware.ts`, `next.config.ts` – routing guards, config
- `public/`, `styles` (`globals.css`, `tailwind.config.ts`) – static assets and styling
- `Dockerfile`, `.env.local` – containerization and environment variables
- API patterns:
- Under `app/api/` are Next.js Serverless Functions handling authentication (`auth/*`), group management (`groups/*`), and user file operations (`user/*`).
- No monolithic “backend” folder: business logic lives alongside API route handlers, and shared helpers (`utils/`, `lib/`).

##### Inspect README and Implicit Architecture
- No explicit database or storage vendor is shown in the code tree, but environment variables and routes (e.g., file upload, encryption) imply:
- A persistent database (e.g., PostgreSQL, MongoDB) for users, groups, metadata
- A file storage layer (could be local, S3, or other object storage)
- Crypto libraries invoked in API handlers for encryption/decryption

##### Main Components
a. Client Layer
- Browser or mobile client
- Next.js front-end (React Server & Client Components, SSR/SSG via `app/`)
b. API Layer
- Next.js Serverless Functions (routes in `app/api/`)
- Business logic modules (`utils/`, `lib/`)
c. Data Layer
- Relational/NoSQL Database (Users, Groups, Metadata)
- Object Storage Service (Encrypted Files)
d. Cross-Cutting Concerns
- Authentication & Session Store
- Encryption Service (could be an internal module or external KMS)
- Middleware (route protection)
- Cache or CDN (Vercel edge caching, static assets)

##### Relationships and Data Flows
- The client issues HTTP(S) requests to Next.js pages (SSR) or directly to API endpoints for actions (login, upload, download, share).
- The API layer validates/authenticates via JWT or session cookie, invokes business logic, and reads/writes to the database and storage.
- Encrypted files are stored/retrieved from object storage; metadata is stored in the database.
- Middleware enforces route-level guards before API handlers.
- Static assets and front-end bundles are served via a CDN.

##### Architectural Patterns & Design Principles
- Layered Architecture (Presentation → API/Business → Data)
- Separation of Concerns (UI components vs. API vs. utilities)
- Serverless Functions for horizontal scalability
- Use of React Server Components in Next.js 13 for SSR/SSG and smaller client bundles
- Environment-driven configuration for cloud portability

##### Summary Checklist
- [ ] Presentation Layer: Browser, Next.js SSR/Client Components
- [ ] API Layer: Auth, Groups, User Services in Serverless Functions
- [ ] Data Layer: Metadata DB, File Storage
- [ ] Middleware & Session Store
- [ ] External Services: CDN, KMS/Object Storage
- [ ] Technology callouts next to each component

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Browser Client"]:::external
        NextJS["Next.js App (App Router)"]:::presentation
        Providers["Providers & Styles"]:::presentation
        UIComponents["UI Components"]:::presentation
        Hooks["Custom Hooks"]:::presentation
        MenuLib["Menu Definitions"]:::presentation
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Middleware["Middleware & Route Guards"]:::api
        subgraph "Auth Endpoints"
            direction TB
            AuthLogin["login"]:::api
            AuthRegister["register"]:::api
            AuthSession["session"]:::api
            AuthValidate["validate"]:::api
        end
        subgraph "Group Management"
            direction TB
            GroupCreate["create"]:::api
            GroupDelete["delete"]:::api
            GroupFiles["files"]:::api
            GroupScan["scan"]:::api
        end
        subgraph "User File Operations"
            direction TB
            UserEncryptUpload["encrypt-upload"]:::api
            UserEncryptDir["encrypt-dir-upload"]:::api
            UserDownload["download"]:::api
            UserShare["share"]:::api
            UserRevoke["revoke-share"]:::api
            UserFavorite["favorite-file"]:::api
            UserTree["get-tree"]:::api
            UserNotifications["notifications"]:::api
        end
        UtilsAuth["auth.ts"]:::api
        UtilsLogout["logout.ts"]:::api
        UtilsPassVal["passwordValidation.ts"]:::api
    end

    %% Data Layer & External Services
    subgraph "Data & External Services"
        direction TB
        Database["Metadata Database"]:::data
        Storage["Object Storage (Encrypted Files)"]:::data
        CDN["CDN / Edge Cache"]:::external
        KMS["Encryption Service (KMS)"]:::external
    end

    %% Other
    Docker["Dockerfile & Env"]:::external

    %% Connections
    Browser -->|"HTTPS"| CDN
    Browser -->|"HTTPS"| NextJS
    NextJS -->|"SSR/SSG, React Components"| Providers
    NextJS -->|"Imports"| UIComponents
    NextJS -->|"Imports"| Hooks
    NextJS -->|"Imports"| MenuLib
    NextJS -->|"Static Assets"| CDN

    NextJS -->|"API Calls (JSON)"| Middleware
    Middleware -->|"Validation/Auth"| AuthLogin
    Middleware --> AuthRegister
    Middleware --> AuthSession
    Middleware --> AuthValidate
    Middleware --> GroupCreate
    Middleware --> GroupDelete
    Middleware --> GroupFiles
    Middleware --> GroupScan
    Middleware --> UserEncryptUpload
    Middleware --> UserEncryptDir
    Middleware --> UserDownload
    Middleware --> UserShare
    Middleware --> UserRevoke
    Middleware --> UserFavorite
    Middleware --> UserTree
    Middleware --> UserNotifications

    AuthLogin -->|"Business Logic"| UtilsAuth
    AuthRegister --> UtilsAuth
    AuthSession --> UtilsAuth
    AuthValidate --> UtilsAuth

    GroupCreate -->|"DB Ops"| Database
    GroupDelete --> Database
    GroupFiles --> Database
    GroupScan --> Database

    UserEncryptUpload -->|"Encrypt via KMS"| KMS
    UserEncryptUpload -->|"Store Blob"| Storage
    UserEncryptDir -->|"Encrypt via KMS"| KMS
    UserEncryptDir -->|"Store Blob"| Storage

    UserDownload -->|"Fetch Blob"| Storage
    UserDownload -->|"Decrypt via KMS"| KMS

    UserShare --> Database
    UserRevoke --> Database
    UserFavorite --> Database
    UserTree --> Database
    UserNotifications --> Database

    %% Click Events
    click NextJS "https://github.com/alexxito23/2fa-cloudsite/tree/main/app/"
    click Providers "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/providers.tsx"
    click Providers "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/globals.css"
    click Providers "https://github.com/alexxito23/2fa-cloudsite/blob/main/tailwind.config.ts"
    click UIComponents "https://github.com/alexxito23/2fa-cloudsite/tree/main/components/"
    click Hooks "https://github.com/alexxito23/2fa-cloudsite/tree/main/hooks/"
    click AuthLogin "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/auth/login/route.ts"
    click AuthRegister "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/auth/register/route.ts"
    click AuthSession "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/auth/session/route.ts"
    click AuthValidate "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/auth/validate/route.ts"
    click GroupCreate "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/groups/create/route.ts"
    click GroupDelete "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/groups/delete/route.ts"
    click GroupFiles "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/groups/files/route.ts"
    click GroupScan "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/groups/scan/route.ts"
    click UserEncryptUpload "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/encrypt-upload/route.ts"
    click UserEncryptDir "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/encrypt-dir-upload/route.ts"
    click UserDownload "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/download/route.ts"
    click UserShare "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/share/route.ts"
    click UserRevoke "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/revoke-share/route.ts"
    click UserFavorite "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/favorite-file/route.ts"
    click UserTree "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/get-tree/route.ts"
    click UserNotifications "https://github.com/alexxito23/2fa-cloudsite/blob/main/app/api/user/notifications/route.ts"
    click UtilsAuth "https://github.com/alexxito23/2fa-cloudsite/blob/main/utils/auth.ts"
    click UtilsLogout "https://github.com/alexxito23/2fa-cloudsite/blob/main/utils/logout.ts"
    click UtilsPassVal "https://github.com/alexxito23/2fa-cloudsite/blob/main/utils/passwordValidation.ts"
    click MenuLib "https://github.com/alexxito23/2fa-cloudsite/blob/main/lib/menu.tsx"
    click Middleware "https://github.com/alexxito23/2fa-cloudsite/blob/main/middleware.ts"
    click Docker "https://github.com/alexxito23/2fa-cloudsite/tree/main/Dockerfile"
    click Docker "https://github.com/alexxito23/2fa-cloudsite/blob/main/.env.local"

    %% Styles
    classDef presentation fill:#D6EAF8,stroke:#1B4F72,color:#154360
    classDef api fill:#D5F5E3,stroke:#186A3B,color:#1D8348
    classDef data fill:#FCF3CF,stroke:#B9770E,color:#7D6608
    classDef external fill:#F5B7B1,stroke:#922B21,color:#641E16
```
