# fyp-hyz-mjj-2024/posture-face-compare architecture

> Architecture diagram of the GitHub repository fyp-hyz-mjj-2024/posture-face-compare, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fyp-hyz-mjj-2024/posture-face-compare
- Repository: https://github.com/fyp-hyz-mjj-2024/posture-face-compare

## Overview

##### Main Components
- API Server: Represented mainly by the entry point (main.py) and auxiliary scripts such as auth.py and query.py.
- CRUD Modules: Two major submodules under the CRUD package—one for “face” and one for “user”—each implemented with models, schemas, and service layers that encapsulate business logic.
- Face Comparison Service: Found in the face_compare package, which suggests additional functionality for comparing or validating face images.
- Database: PostgreSQL is clearly the dedicated datastore with setup instructions in the README.
- External Deployment Infrastructure: A depiction of the DigitalOcean Ubuntu server equipped with Nginx as a reverse proxy, SSL via Certbot, and terminal tools like “screen” for session management.
- External Dependencies: For building and running computer vision tasks (e.g., using dlib, OpenCV, cmake, and build-essential).

##### Relationships and Interactions
- Client requests (from a mobile app or a web frontend) hit the Nginx reverse proxy (depicted as an edge component) which forwards the requests to the API Server running main.py.
- The API Server exposes endpoints that trigger CRUD operations for both user and face data. These endpoints are mapped to service layers in the CRUD folder.
- The “user” module handles user-related operations including authentication (hinted by auth.py) and uses schemas to validate data.
- The face_compare package likely serves as a specialized component to perform advanced image matching or comparisons by consuming models provided in the “face” component.
- The API Server interfaces with the PostgreSQL database via database.py for all persistent storage operations.
- Additional environment and deployment management details (Conda virtual environments, .env configuration) should be noted as part of the infrastructure setup.

##### Important Architectural Patterns and Design Principles
- The project follows a modular design approach. Each major domain (user and face) is separated into its own submodule with clearly segregated responsibilities (models, schemas, services).
- There is an explicit separation of concerns: business logic (services) is kept separate from data representation (models and schemas) and from deployment/infrastructure concerns.
- External dependencies are “plugged” into the project via package requirements and manual installations (e.g., cmake, opencv-python-headerless) which enhance the backend’s computer vision capabilities.
- The overall architecture looks like a typical 3-tier backend service (API layer, Service/Business Logic layer, and Data Layer) with added support for dedicated face recognition functionalities.

##### Relevant Technologies and Frameworks
- Programming Language: Python.
- Libraries/Frameworks: dlib and OpenCV (for face detection/recognition), possibly FastAPI (or a similar Python web framework, inferred by the modular package structure and deployment via Python command).
- Database: PostgreSQL.
- Deployment Tools: Nginx, Certbot (for SSL), DigitalOcean Ubuntu server.
- Build Tools: cmake and build-essential for compiling computer vision libraries.
- Environment Management: Conda for virtual environments.

- Clear labels for each component (e.g., “API Server (main.py)”, “Auth & Query Module”, “Face CRUD”, “User CRUD”, “Face Comparison Service”, “PostgreSQL Database”, “DigitalOcean / Nginx Reverse Proxy”).
- Optionally, include notes on external dependencies like “dlib models loaded here” under the Face CRUD module.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Edge/Deployment Layer
    subgraph "Edge/Deployment"
        A["Client (Mobile/Web)"]:::edge
        B["DigitalOcean / Nginx Reverse Proxy (SSL, Certbot)"]:::infra
        A -->|"sends request"| B
    end

    %% API Layer
    subgraph "API Layer"
        C["API Server (main.py)"]:::api
        D["Auth Module (auth.py)"]:::api
        E["Query Module (query.py)"]:::api
        B -->|"forwards request"| C
        C -->|"invokes"| D
        C -->|"invokes"| E
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        F["Face CRUD Module<br/>(Uses dlib/OpenCV models)"]:::crud
        G["User CRUD Module"]:::crud
        H["Face Comparison Service"]:::crud
        C -->|"triggers"| F
        C -->|"triggers"| G
        C -->|"triggers"| H
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        I["Database Interface (database.py)"]:::db
        J["PostgreSQL Database"]:::db
        C -->|"queries via"| I
        I -->|"reads/writes to"| J
    end

    %% Click Events
    click C "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/blob/master/main.py"
    click D "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/blob/master/auth.py"
    click E "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/blob/master/query.py"
    click F "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/tree/master/CRUD/face"
    click G "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/tree/master/CRUD/user"
    click H "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/tree/master/face_compare"
    click I "https://github.com/fyp-hyz-mjj-2024/posture-face-compare/blob/master/database.py"

    %% Styles
    classDef edge fill:#fceabb,stroke:#d79b00,stroke-width:2px;
    classDef infra fill:#d0e6a5,stroke:#82a658,stroke-width:2px;
    classDef api fill:#a8d0e6,stroke:#335d92,stroke-width:2px;
    classDef crud fill:#f9d5e5,stroke:#d65a7a,stroke-width:2px;
    classDef db fill:#c2e7da,stroke:#2f7d7a,stroke-width:2px;
```
