# uthra-karunakaran/filevault architecture

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

- Interactive diagram: https://gitdiagram.com/uthra-karunakaran/filevault
- Repository: https://github.com/uthra-karunakaran/filevault

## Overview

##### Main Components

a) Client Layer:
- EJS frontend with Tailwind CSS
- Views directory structure
- Public assets section

b) Application Layer:
- Express.js server (app.js as the entry point)
- Authentication system (Passport.js, authMiddleware)
- Route handlers (all routes in the routes directory)
- Controllers layer (showing all controllers)
- Services layer (including cron services)

c) Storage Layer:
- PostgreSQL database (via Prisma ORM)
- Supabase cloud storage
- Relationship between them

##### Component Relationships

**Client Layer → Application Layer → Storage Layer**

Use these specific connections:

a) Authentication Flow:
**Client → Passport.js → User Controller → Database**

b) File Operations Flow:
**Client → File Router → File Controller → Supabase Storage**
- → PostgreSQL (metadata)

c) Sharing System Flow:
**Client → Shared Router → Shared Controller → Database**
- → Storage

##### Key Elements to Highlight

a) Security Layer:
- AuthMiddleware placement
- Passport.js integration
- Password utils

b) Data Management:
- Prisma ORM layer
- Database schema (from prisma/schema.prisma)
- File storage in Supabase

c) Automation:
- Cron job service for cleanup
- Expired link deletion system

##### Specific Implementation Details

- Public access zone (shared links)
- Authenticated zone (user files/folders)
- Admin zone (if applicable)

##### Architectural Patterns to Emphasize

- MVC architecture (Models via Prisma, Views in EJS, Controllers separate)
- Middleware pattern for authentication
- Service-based pattern for business logic
- Repository pattern for data access

##### Integration points

Remember to include:
- Version control integration points
- Error handling flows
- Caching mechanisms (if implemented)
- Backup systems (if applicable)

This will provide a complete picture of the system while keeping it understandable and maintainable.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        EJS[EJS Frontend]
        Views[Views Layer]
        Public[Public Assets]
        TW[Tailwind CSS]
    end

    subgraph Server
        Express[Express Server]:::server
        click Express "https://github.com/Uthra-karunakaran/fileVault/blob/main/app.js"

        subgraph Auth
            Passport[Passport.js]:::auth
            click Passport "https://github.com/Uthra-karunakaran/fileVault/blob/main/passportconfig.js"
            AuthMW[Auth Middleware]:::auth
            click AuthMW "https://github.com/Uthra-karunakaran/fileVault/blob/main/authMiddleWare.js"
            PassUtils[Password Utils]:::auth
            click PassUtils "https://github.com/Uthra-karunakaran/fileVault/blob/main/passwordUtils.js"
        end

        subgraph Routes
            MainRouter[Main Router]:::route
            click MainRouter "https://github.com/Uthra-karunakaran/fileVault/blob/main/routes/mainRouter.js"
            FileRouter[File Router]:::route
            click FileRouter "https://github.com/Uthra-karunakaran/fileVault/blob/main/routes/FileRouter.js"
            FolderRouter[Folder Router]:::route
            click FolderRouter "https://github.com/Uthra-karunakaran/fileVault/blob/main/routes/FolderRouter.js"
            LibraryRouter[Library Router]:::route
            click LibraryRouter "https://github.com/Uthra-karunakaran/fileVault/blob/main/routes/LibraryRouter.js"
            UserRouter[User Router]:::route
            click UserRouter "https://github.com/Uthra-karunakaran/fileVault/blob/main/routes/UserRouter.js"
            SharedRouter[Shared Router]:::route
            click SharedRouter "https://github.com/Uthra-karunakaran/fileVault/blob/main/routes/SharedRouter.js"
        end

        subgraph Controllers
            FileController[File Controller]:::controller
            click FileController "https://github.com/Uthra-karunakaran/fileVault/blob/main/controllers/fileController.js"
            FolderController[Folder Controller]:::controller
            click FolderController "https://github.com/Uthra-karunakaran/fileVault/blob/main/controllers/folderController.js"
            LibraryController[Library Controller]:::controller
            click LibraryController "https://github.com/Uthra-karunakaran/fileVault/blob/main/controllers/libraryController.js"
            UserController[User Controller]:::controller
            click UserController "https://github.com/Uthra-karunakaran/fileVault/blob/main/controllers/userController.js"
            SharedController[Shared Controller]:::controller
            click SharedController "https://github.com/Uthra-karunakaran/fileVault/blob/main/controllers/sharedController.js"
        end

        subgraph Services
            CronService[Cron Service]:::service
            click CronService "https://github.com/Uthra-karunakaran/fileVault/blob/main/services/cronServices.js"
            LinkExpiration[Link Expiration]:::service
            click LinkExpiration "https://github.com/Uthra-karunakaran/fileVault/blob/main/deleteExpiredLinks.js"
            Upload[Upload Service]:::service
            click Upload "https://github.com/Uthra-karunakaran/fileVault/blob/main/multerConfig.js"
        end
    end

    subgraph Storage
        PostgreSQL[(PostgreSQL)]:::db
        click PostgreSQL "https://github.com/Uthra-karunakaran/fileVault/blob/main/prisma/schema.prisma"
        Supabase[(Supabase Storage)]:::storage
        click Supabase "https://github.com/Uthra-karunakaran/fileVault/blob/main/supabaseConfig.js"
    end

    %% Client Layer Connections
    EJS --> Views
    Views --> Public
    Public --> TW

    %% View Components
    click Views "https://github.com/Uthra-karunakaran/fileVault/tree/main/views/"
    ViewsLayout[Layout Templates]:::view
    click ViewsLayout "https://github.com/Uthra-karunakaran/fileVault/blob/main/views/layout.ejs"
    AuthViews[Auth Views]:::view
    click AuthViews "https://github.com/Uthra-karunakaran/fileVault/blob/main/views/login.ejs"
    FileViews[File Views]:::view
    click FileViews "https://github.com/Uthra-karunakaran/fileVault/blob/main/views/file-view.ejs"
    FolderViews[Folder Views]:::view
    click FolderViews "https://github.com/Uthra-karunakaran/fileVault/blob/main/views/folder-layout.ejs"
    ShareViews[Share Views]:::view
    click ShareViews "https://github.com/Uthra-karunakaran/fileVault/blob/main/views/share-folder-view.ejs"

    %% Server Connections
    Views --> Express
    Express --> MainRouter
    MainRouter --> FileRouter & FolderRouter & LibraryRouter & UserRouter & SharedRouter
    
    FileRouter --> FileController
    FolderRouter --> FolderController
    LibraryRouter --> LibraryController
    UserRouter --> UserController
    SharedRouter --> SharedController

    %% Auth Flow
    Express --> Passport
    Passport --> AuthMW
    AuthMW --> PassUtils
    
    %% Controller to Storage
    FileController --> PostgreSQL
    FileController --> Supabase
    FolderController --> PostgreSQL
    LibraryController --> PostgreSQL
    UserController --> PostgreSQL
    SharedController --> PostgreSQL
    SharedController --> Supabase

    %% Services
    CronService --> PostgreSQL
    LinkExpiration --> PostgreSQL
    Upload --> Supabase

    %% Styling
    classDef server fill:#3498db
    classDef auth fill:#f1c40f
    classDef route fill:#2ecc71
    classDef controller fill:#9b59b6
    classDef service fill:#e67e22
    classDef db fill:#34495e
    classDef storage fill:#e74c3c
    classDef view fill:#1abc9c
```
