# yeahitsmeagain/tgstorage architecture

> Architecture diagram of the GitHub repository yeahitsmeagain/tgstorage, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yeahitsmeagain/tgstorage
- Repository: https://github.com/yeahitsmeagain/tgstorage

## Overview

##### Project Type Analysis
This is a full-stack application that serves as a cloud storage solution utilizing Telegram bots for file storage. The project uses FastAPI (evident from the backend structure), MySQL, and Nginx, with OAuth integration for authentication.

##### Main Components

A. Client Layer:
- External Client Applications
- OAuth (Google) Integration Point

B. Infrastructure Layer:
- Nginx Reverse Proxy (with SSL/TLS termination)
- Docker Containers

C. Application Layer:
- FastAPI Backend Service
- Telegram Bot Integration
- Redis Cache

D. Data Layer:
- MySQL Database
- Telegram Storage (for actual files)

**[Client Layer]**
- ↓
**[Infrastructure Layer]**
- ↓
**[Application Layer]**
- ↓
**[Data Layer]**

##### Specific Component Relationships to Highlight

A. API Routes (from /backend/app/routes):
- Auth Routes (/auth)
- File Routes (/file)
- Folder Routes (/folder)
- Share Routes (/share)
- User Routes (/user)

B. Database Models (from /backend/app/db/models):
- Relationships between:
- User
- File
- Folder
- SharedResource
- AbstractResource

C. External Services:
- Google OAuth
- Telegram Bot API

##### Important Flows

A. Authentication Flow:
Client → Nginx → FastAPI → Google OAuth → Database

B. File Operations Flow:
Client → Nginx → FastAPI → Telegram Bot API → Telegram Storage

C. Data Access Flow:
Client → Nginx → FastAPI → MySQL Database

##### Additional Elements

- Environment configurations
- Security layers (OAuth, middleware)
- Caching layer (Redis)
- Load balancing (if applicable)

##### Technical Details to Note

- Use the CRUD operations structure from /backend/app/db/crud
- Middleware layer for upload size limits
- Dependency injection system
- Event handling system

- Use double lines for data persistence operations
- Version numbers for major components
- Timestamps for cache operations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Client1[External Client Applications]
        OAuth[Google OAuth]
    end

    subgraph Infrastructure
        Nginx[Nginx Reverse Proxy]:::proxy
        Docker[Docker Containers]:::container
    end

    subgraph Application
        FastAPI[FastAPI Backend]:::backend
        TeleBot[Telegram Bot]:::telegram
        Redis[Redis Cache]:::cache
        
        subgraph Modules
            Auth[Auth Module]:::module
            FileM[File Management]:::module
            FolderM[Folder Management]:::module
            ShareM[Share Management]:::module
            UserM[User Management]:::module
        end
        
        subgraph CRUD
            FileCRUD[File CRUD]:::crud
            FolderCRUD[Folder CRUD]:::crud
            UserCRUD[User CRUD]:::crud
            ShareCRUD[Share CRUD]:::crud
        end
    end

    subgraph Data
        MySQL[(MySQL Database)]:::database
        TStorage[Telegram Storage]:::storage
        
        subgraph Models
            UserModel[User Model]:::model
            FileModel[File Model]:::model
            FolderModel[Folder Model]:::model
            SharedModel[Shared Resource Model]:::model
            AbstractModel[Abstract Resource Model]:::model
        end
    end

    %% Relationships
    Client1 --> OAuth
    OAuth --> FastAPI
    Client1 --> Nginx
    Nginx --> FastAPI
    FastAPI --> Redis
    FastAPI --> TeleBot
    TeleBot --> TStorage
    
    %% Module Relationships
    Auth --> UserCRUD
    FileM --> FileCRUD
    FolderM --> FolderCRUD
    ShareM --> ShareCRUD
    
    %% CRUD to Model Relationships
    FileCRUD --> FileModel
    FolderCRUD --> FolderModel
    UserCRUD --> UserModel
    ShareCRUD --> SharedModel
    
    %% All Models connect to MySQL
    FileModel --> MySQL
    FolderModel --> MySQL
    UserModel --> MySQL
    SharedModel --> MySQL
    AbstractModel --> MySQL

    %% Click Events
    click Nginx "https://github.com/YeahItsMeAgain/tgstorage/tree/master//services/nginx/"
    click Docker "https://github.com/YeahItsMeAgain/tgstorage/blob/master//docker-compose.yml"
    click FastAPI "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/main.py"
    click Auth "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/routes/auth.py"
    click FileM "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/routes/file.py"
    click FolderM "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/routes/folder.py"
    click ShareM "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/routes/share.py"
    click UserM "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/routes/user.py"
    click FileCRUD "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/crud/file.py"
    click FolderCRUD "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/crud/folder.py"
    click UserCRUD "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/crud/user.py"
    click ShareCRUD "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/crud/share.py"
    click UserModel "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/models/user.py"
    click FileModel "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/models/file.py"
    click FolderModel "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/models/folder.py"
    click SharedModel "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/models/shared_resource.py"
    click AbstractModel "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/db/models/abstract_resource.py"
    click TeleBot "https://github.com/YeahItsMeAgain/tgstorage/blob/master//backend/app/dependencies/connect_bot.py"

    %% Styling
    classDef proxy fill:#A9A9A9
    classDef container fill:#A9A9A9
    classDef backend fill:#90EE90
    classDef telegram fill:#87CEEB
    classDef cache fill:#FFB6C1
    classDef module fill:#98FB98
    classDef crud fill:#DDA0DD
    classDef database fill:#F0E68C
    classDef storage fill:#F0E68C
    classDef model fill:#FFE4B5
```
