# aclab-hcmut/thesis_mdt260_application_motion_detection architecture

> Architecture diagram of the GitHub repository aclab-hcmut/thesis_mdt260_application_motion_detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aclab-hcmut/thesis_mdt260_application_motion_detection
- Repository: https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection

## Overview

This project is a full-stack application that combines a Flutter frontend with a Node.js–based backend. The purpose is to serve as a starting point for a Flutter application (as indicated by the README) with an accompanying backend API server that supports various functions like user management, activities, real-time communications through sockets, and more.

##### Main components
- Frontend: A Flutter application intended to run on multiple platforms (Android, iOS, web, Linux, macOS, and Windows). The Flutter codebase is structured under the “frontend” directory, featuring components, screens, models, services, and localization support.
- Backend: A Node.js–based server located in the “backend” directory. It follows an MVC-inspired structure with directories for controllers, routes (in different API versions v1 and v2), models, middlewares, validations, sockets (for real-time features), configuration files, utility functions, and providers.
- Database/External Services: Although not explicitly detailed, the “backend/src/config/mongodb.js” file suggests that MongoDB is used as the datastore.
- (Optional) Socket Server: Under “backend/src/sockets”, the inclusion of a sample socket file indicates support for real-time communications which can be diagrammed as an additional component interacting with the backend.

##### Component relationships and interactions
- The Backend handles requests via route files, passes them to controllers, and interacts with the database to process data. This flow should be shown in a step-wise or layered manner. For example:
- API Request → Route → Middleware (authentication, error handling, etc.) → Controller → Database/Model interaction → Response back to Frontend.

##### Architectural patterns and design principles
- The backend design seems to follow the Modular/Layered architecture with clear separations for configurations, routes, controllers, models, middlewares, and validations.
- The frontend leverages Flutter’s standard project architecture with separation of UI components, screens, services, and models.
- Separation of concerns between client-side UI handling and server-side business logic.

##### Relevant technologies/frameworks
- For the frontend, note Flutter and Dart as the programming language/environment along with support for multi-platform deployment (Android, iOS, web, etc.).
- For the backend, note Node.js alongside configuration files for Babel, ESLint, and environment configurations, as well as MongoDB for database operations.
- Mention additional functionalities like WebSocket support for real-time communications.

##### Final checklist
- Components are clearly labeled.
- Be as detailed as possible by separating the components into their submodules (routes, controllers, middlewares, etc.) to capture the maximum granularity of the system’s architecture.
- Notes on any potential extensibility points, such as the WebSocket service and the provider modules, to give a clear picture of how the system can evolve.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend
    A["Flutter Frontend"]:::frontend

    %% Backend Container
    B["Node.js Backend API"]:::backend

    %% Backend Components inside the backend container
    subgraph "Backend Components"
        R1["Routes (v1)"]:::route
        R2["Routes (v2)"]:::route
        M["Middlewares"]:::middleware
        C["Controllers"]:::controller
        MO["Models"]:::model
        VA["Validations"]:::validation
        PR["Providers"]:::provider
        UT["Utils"]:::util
        MC["MongoDB Config"]:::config
        SC["Socket Server"]:::socket
    end

    %% Database Component
    N["MongoDB"]:::database

    %% Connections from Frontend to Backend
    A -->|"HTTP_Request"| B

    %% Connections from Backend API container to its components
    B --> R1
    B --> R2
    B --> SC

    %% Routing flow: Routes -> Middlewares -> Controllers
    R1 --> M
    R2 --> M
    M --> C

    %% Controllers interacting with Models and configuration
    C --> MO
    C --> VA
    C --> PR
    C --> UT
    C --> MC

    %% Database interactions
    MO -->|"CRUD"| N
    MC -->|"Configures"| N

    %% WebSocket communication between Frontend and Socket Server
    A ---|"WebSocket"| SC
    SC ---|"Real-time"| A

    %% Click Events
    click A "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/frontend/lib"
    click B "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src"
    click R1 "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/routes/v1"
    click R2 "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/routes/v2"
    click M "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/middlewares"
    click C "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/controllers"
    click MO "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/models"
    click VA "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/validations"
    click PR "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/providers"
    click UT "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/utils"
    click MC "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/blob/main/backend/src/config/mongodb.js"
    click SC "https://github.com/aclab-hcmut/thesis_mdt260_application_motion_detection/tree/main/backend/src/sockets"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef route fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef middleware fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef controller fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef model fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef validation fill:#fefefe,stroke:#343a40,stroke-width:2px;
    classDef provider fill:#e9ecef,stroke:#adb5bd,stroke-width:2px;
    classDef util fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef config fill:#d6d8db,stroke:#343a40,stroke-width:2px;
    classDef socket fill:#d1ffd1,stroke:#2d862d,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
