# gabrielrra/upload-ai architecture

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

- Interactive diagram: https://gitdiagram.com/gabrielrra/upload-ai
- Repository: https://github.com/gabrielrra/upload-ai

## Overview

##### Project Type and Purpose
- The project is a full-stack web application where users can upload videos for transcription and use AI to generate assistive content (titles, descriptions, keywords, and promotional texts).
- The backend (API) is built with Fastify (Node.js framework) and uses Prisma for database migrations and interactions.
- The frontend (WebApp) is built with Vite and leverages React (with .tsx files) along with integrated FFmpeg components for handling video-to-audio conversions.

##### Main Components
a. Frontend (Web):
– Represents the UI, located in the “web” directory.
– Contains components for video input, prompt selection, transcription dialogs, and FFmpeg integration (WebAssembly and worker scripts).
– Uses libraries (via axios, Vite) to communicate with the backend API.
b. Backend (API):
– Found in the “api” directory.
– Houses the server code with route definitions for endpoints (upload-video, create-transcription, generate-ai-completion, get-prompts).
– Uses Fastify to serve API requests.
– Manages database operations through Prisma (with migration scripts and seed data).
– Contains Dockerfile(s) and scripts to support containerized deployment.
c. Database:
– Managed through Prisma (the “prisma” directory) with migrations and seed scripts.
– The .env file specifies the DATABASE_URL, which is key to database access.
d. Docker and Deployment:
– Docker configuration files (Dockerfile, docker-compose files) are provided for both development and production environments, indicating containerization.
e. External and Utilities:
– FFmpeg files in the frontend are crucial for video processing.
– Utility libraries and helper functions present in both parts of the project (e.g., axios and ffmpeg logic in web/src/lib, and prisma.ts in api/src/lib).

##### Relationships and Interactions
- The frontend initiating API requests (uploading videos, requesting transcriptions, and AI completions).
- The API processing those requests and interacting with the database via Prisma.
- The API returning responses to the frontend.
- The use of external FFmpeg libraries within the frontend for converting video files.
- That Docker and docker-compose facilitate deployment by containerizing both the API and web components.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly mark out the distinct responsibilities of the frontend (UI/experience) and backend (business logic, data handling).
- API-Driven Communication: Show that the frontend communicates with the backend through well-defined API endpoints.
- Use of Domain-Driven Design: Although not explicitly mentioned, the separation of functionalities (video upload/transcription vs. AI text generation) suggests distinct roles within the API endpoints.

##### Relevant Technologies and Frameworks
- Frontend: Vite, React (with TypeScript .tsx files), FFmpeg core, FFmpeg worker, axios.
- Backend: Node.js, Fastify, Prisma ORM, migration tools (Prisma migrations).
- Database: Likely a SQLite (or similar) database as suggested by the DATABASE_URL in .env, along with migration files.
- Docker-related tools: Dockerfile, docker-compose.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Web Frontend"
        FE["Web Frontend\n(Vite/React, FFmpeg)"]:::frontend
        FF["FFmpeg Integration (WASM & Worker)"]:::frontend
        AX["Axios & Other Utils"]:::frontend
        FT["FFmpeg Utils"]:::frontend
        FE --> FF
        FE --> AX
        FE --> FT
    end

    %% Backend Layer
    subgraph "API Backend"
        BE["API Backend\n(Fastify, Prisma, Routes)"]:::backend
        PU["Prisma Utility"]:::backend
        BE --> PU
    end

    %% Database Component
    subgraph "Database"
        DB["Database\n(Prisma Migrations & Seed)"]:::database
    end

    %% Deployment / Containerization
    subgraph "Deployment"
        D["Docker/Deployment\n(Containerized Environment)"]:::deployment
        D1["Dockerfile (API)"]:::deployment
        D2["Dockerfile.prod (API)"]:::deployment
        D3["docker-compose.yml"]:::deployment
        D4["docker-compose.prod.yml"]:::deployment
        D --> D1
        D --> D2
        D --> D3
        D --> D4
    end

    %% Interactions
    FE -->|"API_request"| BE
    BE -->|"DB_ops"| DB
    BE -->|"Response"| FE
    D -->|"Containerizes"| FE
    D -->|"Containerizes"| BE

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#ffe5b4,stroke:#d39e00,stroke-width:2px;
    classDef deployment fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events for Component Mapping
    click FE "https://github.com/gabrielrra/upload-ai/tree/main/web/"
    click FF "https://github.com/gabrielrra/upload-ai/tree/main/web/src/ffmpeg/"
    click AX "https://github.com/gabrielrra/upload-ai/blob/main/web/src/lib/axios.ts"
    click FT "https://github.com/gabrielrra/upload-ai/blob/main/web/src/lib/ffmpeg.ts"
    click BE "https://github.com/gabrielrra/upload-ai/tree/main/api/"
    click PU "https://github.com/gabrielrra/upload-ai/blob/main/api/src/lib/prisma.ts"
    click DB "https://github.com/gabrielrra/upload-ai/tree/main/api/prisma/"
    click D1 "https://github.com/gabrielrra/upload-ai/tree/main/api/Dockerfile"
    click D2 "https://github.com/gabrielrra/upload-ai/blob/main/api/Dockerfile.prod"
    click D3 "https://github.com/gabrielrra/upload-ai/blob/main/docker-compose.yml"
    click D4 "https://github.com/gabrielrra/upload-ai/blob/main/docker-compose.prod.yml"
```
