# ntdat02092002/person-detection-system architecture

> Architecture diagram of the GitHub repository ntdat02092002/person-detection-system, 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/ntdat02092002/person-detection-system
- Repository: https://github.com/ntdat02092002/person-detection-system

## Overview

##### Project Overview
- It uses FastAPI (in Python) as the backend, Next.js for the frontend, and PostgreSQL combined with SQLAlchemy for the database. The entire setup is containerized with Docker and orchestrated via Docker Compose.

##### Main Components
a. Frontend:
- Built with Next.js (evident from files like next.config.mjs, package.json, and the layout/page components).
- Provides a web-based UI for image upload and results display.
b. Backend:
- Implemented in FastAPI (files such as api.py, database.py, and models.py in the backend/src directory indicate handling API endpoints, database interactions, and data models).
c. Database:
- PostgreSQL is used to store detection results (with SQLAlchemy managing ORM interactions).
d. Containerization & Deployment:
- Dockerfiles in both backend and frontend directories along with a central docker-compose.yaml indicate a containerized deployment setup.
- Docker Compose manages linking the separate services (frontend, backend, and implicitly the database).

##### Relationships & Interactions
- The user accesses the Frontend via a browser (http://localhost:3000).
- The Frontend sends an image upload request to the Backend’s API (http://localhost:8000/docs for API documentation).
- Docker Compose ensures that these containers (frontend, backend, and the database) are networked correctly and can communicate with each other.

##### Technical and Architectural Patterns to Highlight
- Separation of Concerns: Clear division between frontend (presentation/UI layer) and backend (business logic, image processing, API endpoints).
- Microservice-like Containerization: Although it’s a single application, the use of Docker for each component emphasizes isolation and scalability.
- API-Driven Communication: Frontend and backend interact via RESTful endpoints.
- Persistence Layer: Use of PostgreSQL via SQLAlchemy highlights a structured ORM-based interaction with the database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    U["User (Browser)"]:::user

    %% Application Layer
    subgraph "Application Layer"
        FE["Frontend (Next.js)"]:::frontend
        BE["Backend (FastAPI)"]:::backend
        DB["Database (PostgreSQL)"]:::database
    end

    %% Deployment Layer
    subgraph "Deployment Layer"
        DC["Docker Compose"]:::docker
    end

    %% Data Flow Connections
    U -->|"HTTP_Request"| FE
    FE -->|"API_Call"| BE
    BE -->|"Persist_Data"| DB

    %% Deployment Connections (Containerization)
    DC ---|"Containerizes"| FE
    DC ---|"Containerizes"| BE
    DC ---|"Containerizes"| DB

    %% Click Events
    click FE "https://github.com/ntdat02092002/person-detection-system/tree/main/frontend/"
    click BE "https://github.com/ntdat02092002/person-detection-system/tree/main/backend/src/"
    click DB "https://github.com/ntdat02092002/person-detection-system/blob/main/backend/src/database.py"
    click DC "https://github.com/ntdat02092002/person-detection-system/blob/main/docker-compose.yaml"

    %% Styles
    classDef user fill:#F9D423,stroke:#333,stroke-width:2px;
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C3F7B5,stroke:#333,stroke-width:2px;
    classDef database fill:#F7B5B5,stroke:#333,stroke-width:2px;
    classDef docker fill:#FFF6A5,stroke:#333,stroke-width:2px;
```
