# prp-for-your-portrait-right-protection/backend-repo architecture

> Architecture diagram of the GitHub repository prp-for-your-portrait-right-protection/backend-repo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prp-for-your-portrait-right-protection/backend-repo
- Repository: https://github.com/prp-for-your-portrait-right-protection/backend-repo

## Overview

##### Project type and purpose
- This is a standalone backend service (likely Flask or FastAPI) providing endpoints to upload/originate videos, process them (e.g. block characters, whitelist faces), and manage users.
- It uses a relational database (db/) for metadata and a bucket (bucket/) for storing raw/processed video files.

##### Main components
A. API Layer (Controllers)
- app.py: the entrypoint / WSGI app
- apis/*.py: each file defines resource routes (User, OriginVideo, ProcessedVideo, BlockCharacter, WhitelistFace)
B. Business Logic Layer (Modules)
- module/crud_module.py: generic CRUD operations
- module/user_module.py, token.py: authentication & user management
- module/file_module.py: file‑handling operations (upload/download)
- module/db_module.py: data‑access abstractions
C. Data Layer
- db/db_connection.py & db/db_config.py: connection setup to the relational database
- db/schema.py & db/enum_classes.py: ORM models or schema definitions
D. Storage Layer
- bucket/m_connection.py & bucket/m_config.py: connection setup to object storage (S3, GCS or local bucket)
E. Supporting Components
- static/status_code.py: shared HTTP/status codes
- requirements.txt & Dockerfile: runtime environment and containerization

##### Relationships & Data Flow
1. Client → HTTP(S) request → API Layer (app.py)
2. API Layer routes to appropriate controller in apis/*.py
3. Controller calls Service/Module functions
- Authentication module (token.py) validates tokens
- CRUD module orchestrates DB reads/writes via db_module
- File module interacts with bucket layer for upload/download
4. Module calls Data Layer for persistence or bucket for file storage
5. Data Layer executes queries against the relational DB or object store
6. Responses bubble back up: Module → Controller → Client

##### Architectural patterns & principles
- Layered (n‑tier) architecture separating controllers, business logic, and data access
- Single responsibility per module: auth, user‑mgmt, file‑mgmt, CRUD
- Configuration externalized (db_config, module_config, m_config)
- Containerized deployment (Dockerfile)

##### Key details not to miss
- Token flow: Login request → token module → token output → subsequent request header
- Distinguish between raw video upload (OriginVideo API) and processed output (ProcessedVideo API)
- Bucket connection separate from DB connection

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        direction TB
        A_app["app.py"]:::compute
        A_user["UserController"]:::compute
        A_origin["OriginVideoController"]:::compute
        A_processed["ProcessedVideoController"]:::compute
        A_block["BlockCharacterController"]:::compute
        A_whitelist["WhitelistFaceController"]:::compute
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        B_crud["CRUDModule"]:::compute
        B_user["UserManagementModule"]:::compute
        B_token["Auth/TokenModule"]:::compute
        B_file["FileHandlingModule"]:::compute
        B_dbmod["DBAbstractionModule"]:::compute
        B_modconf["ModuleConfig"]:::config
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        D_dbconf["DBConfig"]:::storage
        D_dbconn["DBConnection"]:::storage
        D_schema["Schemas/Models"]:::storage
        D_enum["EnumDefinitions"]:::storage
    end

    %% Storage Layer
    subgraph "Storage Layer"
        direction TB
        S_bucketconf["BucketConfig"]:::storage
        S_bucketconn["BucketConnection"]:::storage
    end

    %% Supporting Components
    subgraph "Supporting Components"
        direction TB
        SC_status["status_code.py"]:::config
        SC_req["requirements.txt"]:::config
        SC_docker["Dockerfile"]:::config
    end

    %% Relationships
    Client["Client"]:::external
    Client -->|"HTTP Request"| A_app
    A_app -->|"routes to"| A_user
    A_app -->|"routes to"| A_origin
    A_app -->|"routes to"| A_processed
    A_app -->|"routes to"| A_block
    A_app -->|"routes to"| A_whitelist

    A_user -->|"calls"| B_token
    A_user -->|"calls"| B_user
    A_origin -->|"calls"| B_file
    A_origin -->|"calls"| B_crud
    A_processed -->|"calls"| B_file
    A_processed -->|"calls"| B_crud
    A_block -->|"calls"| B_file
    A_whitelist -->|"calls"| B_file

    B_crud -->|"uses"| B_dbmod
    B_user -->|"uses"| B_dbmod
    B_token -->|"uses"| B_dbmod
    B_file -->|"uses"| S_bucketconn
    B_dbmod -->|"uses"| D_dbconn

    D_dbconn -->|"reads/writes"| D_dbconf
    D_dbconn -->|"reads/writes"| D_schema
    D_dbconn -->|"uses"| D_enum

    S_bucketconn -->|"uses"| S_bucketconf

    SC_docker -.->|"provides Environment"| A_app
    SC_req -.->|"dependencies"| A_app
    B_modconf -.->|"configures"| B_crud

    %% Click Events
    click A_app "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/app.py"
    click A_user "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/apis/User.py"
    click A_origin "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/apis/OriginVideo.py"
    click A_processed "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/apis/ProccessedVideo.py"
    click A_block "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/apis/BlockCharacter.py"
    click A_whitelist "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/apis/WhitelistFace.py"
    click B_crud "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/module/crud_module.py"
    click B_user "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/module/user_module.py"
    click B_token "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/module/token.py"
    click B_file "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/module/file_module.py"
    click B_dbmod "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/module/db_module.py"
    click B_modconf "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/module/module_config.py"
    click D_dbconf "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/db/db_config.py"
    click D_dbconn "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/db/db_connection.py"
    click D_schema "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/db/schema.py"
    click D_enum "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/db/enum_classes.py"
    click S_bucketconf "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/bucket/m_config.py"
    click S_bucketconn "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/bucket/m_connection.py"
    click SC_status "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/static/status_code.py"
    click SC_req "https://github.com/prp-for-your-portrait-right-protection/backend-repo/blob/develop/requirements.txt"
    click SC_docker "https://github.com/prp-for-your-portrait-right-protection/backend-repo/tree/develop/Dockerfile"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef storage fill:#90EE90,stroke:#000,stroke-width:1px
    classDef config fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
