# mnaki/pireflics architecture

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

- Interactive diagram: https://gitdiagram.com/mnaki/pireflics
- Repository: https://github.com/mnaki/pireflics

## Overview

##### Main Components

A. Frontend Layer:
- Client-side application (Views - EJS templates)
- Static assets (JS, CSS, images)
- Client-side player component

B. Backend Layer:
- Authentication system
- Movie management
- Torrent handling
- Subtitle management
- User management

C. Services Layer:
- Crawler Service
- Subtitle Service

D. Data Layer:
- Database models (User, Movie, Subtitle, Token, Comment, Torrent)

**[Client Layer]**
- ↑↓
**[Web Server Layer (Sails.js)]**
- ↑↓
**[Services Layer]**
- ↑↓
**[Data Layer]**

##### Component Details

a) Client Layer (Blue):
- Movie viewer component
- Search interface
- User authentication views
- Profile management

b) Web Server Layer (Green):
- Controllers section:
- AuthController
- MovieController
- SubtitleController
- TorrentController
- UserController
- Policies section:
- Authentication middleware
- Session management

c) Services Layer (Orange):
- CrawlerService (for fetching torrent data)
- SubtitleService
- Torrent streaming service

d) Data Layer (Purple):
- Database models:
- User
- Movie
- Subtitle
- Token
- Comment
- Torrent

##### Flow Indicators

- User request flow
- Authentication flow
- Torrent streaming flow
- Data retrieval flow

##### Technical Details

- Sails.js framework
- WebSocket connections (for streaming)
- RESTful API endpoints
- Authentication flow
- File storage system

##### Additional Notes

- Relationship between the torrent streaming system and the video player
- Where subtitle processing occurs
- Authentication checkpoints
- Caching mechanisms if any

##### Integration points with external torrent providers

- Rectangles for services
- Hexagons for external services
- Rounded rectangles for user interfaces

This will create a comprehensive visualization of how Pireflics handles torrent-based video streaming while maintaining a Netflix-like user experience.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e67e22,stroke:#d35400,color:white
    classDef data fill:#9b59b6,stroke:#8e44ad,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    %% Client Layer
    subgraph ClientLayer
        WebInterface["Web Interface"]
        MovieViewer["Movie Viewer"]:::frontend
        SearchUI["Search Interface"]:::frontend
        AuthViews["Authentication Views"]:::frontend
        ProfileUI["Profile Management"]:::frontend
        Player["Video Player"]:::frontend
    end
    click WebInterface "https://github.com/mnaki/pireflics/tree/master/views"
    click AuthViews "https://github.com/mnaki/pireflics/tree/master/views/user"
    click MovieViewer "https://github.com/mnaki/pireflics/tree/master/views/movie"
    click Player "https://github.com/mnaki/pireflics/blob/master/assets/js/player.js"

    %% Web Server Layer
    subgraph ServerLayer
        subgraph Controllers
            AuthC["Auth Controller"]:::backend
            MovieC["Movie Controller"]:::backend
            SubC["Subtitle Controller"]:::backend
            TorrentC["Torrent Controller"]:::backend
            UserC["User Controller"]:::backend
        end

        subgraph Security
            AuthMiddleware["Authentication Middleware"]:::security
            SessionMgmt["Session Management"]:::security
        end
    end
    click AuthC "https://github.com/mnaki/pireflics/blob/master/api/controllers/AuthController.js"
    click MovieC "https://github.com/mnaki/pireflics/blob/master/api/controllers/MovieController.js"
    click SubC "https://github.com/mnaki/pireflics/blob/master/api/controllers/SubtitleController.js"
    click TorrentC "https://github.com/mnaki/pireflics/blob/master/api/controllers/TorrentController.js"
    click UserC "https://github.com/mnaki/pireflics/blob/master/api/controllers/UserController.js"
    click AuthMiddleware "https://github.com/mnaki/pireflics/blob/master/api/policies/isAuthenticated.js"
    click SessionMgmt "https://github.com/mnaki/pireflics/blob/master/api/policies/sessionAuth.js"

    %% Services Layer
    subgraph ServicesLayer
        CrawlerSvc["Crawler Service"]:::service
        SubtitleSvc["Subtitle Service"]:::service
        TorrentStream["Torrent Streaming Service"]:::service
    end
    click CrawlerSvc "https://github.com/mnaki/pireflics/blob/master/api/services/CrawlerService.js"
    click SubtitleSvc "https://github.com/mnaki/pireflics/blob/master/api/services/SubtitleService.js"

    %% Data Layer
    subgraph DataLayer
        UserDB[(User)]:::data
        MovieDB[(Movie)]:::data
        SubtitleDB[(Subtitle)]:::data
        TokenDB[(Token)]:::data
        CommentDB[(Comment)]:::data
        TorrentDB[(Torrent)]:::data
    end
    click UserDB "https://github.com/mnaki/pireflics/blob/master/api/models/User.js"
    click MovieDB "https://github.com/mnaki/pireflics/blob/master/api/models/Movie.js"
    click SubtitleDB "https://github.com/mnaki/pireflics/blob/master/api/models/Subtitle.js"
    click TokenDB "https://github.com/mnaki/pireflics/blob/master/api/models/Token.js"
    click CommentDB "https://github.com/mnaki/pireflics/blob/master/api/models/Comment.js"
    click TorrentDB "https://github.com/mnaki/pireflics/blob/master/api/models/Torrent.js"

    %% Connections
    WebInterface --> AuthMiddleware
    AuthMiddleware --> Controllers
    SessionMgmt --> Controllers
    
    Controllers --> ServicesLayer
    ServicesLayer --> DataLayer
    
    Player --> TorrentStream
    TorrentStream --> TorrentDB
    SubtitleSvc --> SubtitleDB
    CrawlerSvc --> MovieDB

    %% Legend
    subgraph Legend
        L1["Frontend Components"]:::frontend
        L2["Backend Components"]:::backend
        L3["Services"]:::service
        L4["Data Stores"]:::data
        L5["Security Components"]:::security
    end
```
