# 21dh113775/mockhang_app architecture

> Architecture diagram of the GitHub repository 21dh113775/mockhang_app, 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/21dh113775/mockhang_app
- Repository: https://github.com/21dh113775/mockhang_app

## Overview

##### Main Components
- Frontend (Flutter Mobile/Web/Desktop App):
- This is primarily in the “lib” directory with separation into different modules:
▪ The “admin” module (lib/admin) which includes admin screens, data sources, models, repositories, and providers.
▪ The “user” module (lib/user) for client-facing screens (home, product, account, etc.).
▪ Shared modules such as authentication (lib/auth), common API handling (lib/api), routes (lib/routes), and common widgets.
- The project is multi-platform – notice folders for android, ios, linux, macos, windows, and web – which indicates the Flutter app is designed to run on several targets.

- Backend (Products API):
- Located in the “backend/ProductsApi” directory, this service is written in C# using ASP.NET Core.
- It contains Controllers (e.g., ProductController.cs), data models (Product.cs, StockUpdate.cs), and a DB context (ApplicationDbContext.cs) which suggests usage of an ORM (likely Entity Framework).
- There are also repository interfaces and their implementations for managing product data.

- External Services & Configuration:
- Firebase integration is signified by “firebase.json” and “lib/firebase_options.dart,” suggesting use for notifications, authentication, or analytics.
- Configuration files for different environments (e.g., appsettings.json, appsettings.Development.json).

##### Relationships and Interactions
- The Flutter frontend communicates with the backend API:
- API requests are handled by the “lib/api/api_client.dart” module, which likely wraps the network calls to the backend endpoints.
- Depending on user roles, different parts of the Flutter app (admin or user) will fetch, display, and update data.

- Separation between Admin and User components:
- The “admin” module in the lib/ directory uses local data sources and repository classes to interact with either a local database or remote endpoints (via the API client) for administrative tasks.
- The “user” module communicates similarly with the backend for displaying products, managing shopping carts, etc.

- Backend and Data Persistence:
- The backend service exposes RESTful endpoints (via the Controllers) with business logic via repositories and the DBContext.
- Although the exact database isn’t shown, the presence of an ApplicationDbContext implies a relational database is in use.

##### Architectural Patterns and Technologies
- The Flutter front-end likely follows a layered (or MVVM/MVC) approach with providers managing state.
- The backend uses standard ASP.NET Core patterns:
- Controller-Service-Repository structure.
- Dependency Injection is likely used to manage these components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flutter Frontend Subgraph
    subgraph "Flutter Frontend"
        admin["Admin Module"]:::frontend
        user["User Module"]:::frontend
        apiClient["API Client"]:::frontend
        auth["Authentication"]:::frontend
        authService["Auth Service"]:::frontend
        routes["Routes"]:::frontend
    end

    %% Backend API Subgraph
    subgraph "Backend API (ASP.NET Core)"
        controller["API Controller"]:::backend
        repository1["Implement Repository"]:::backend
        repository2["Product Repository"]:::backend
        db["DB Context"]:::backend
    end

    %% External Services Subgraph
    subgraph "External Services"
        firebase["Firebase JSON"]:::external
        firebaseOptions["Firebase Options"]:::external
    end

    %% Relationships in Flutter Frontend
    admin -->|"uses"| apiClient
    user -->|"uses"| apiClient
    admin -->|"navigates"| routes
    user -->|"navigates"| routes
    auth -->|"manages"| authService
    auth -->|"integrates"| firebaseOptions

    %% Communication between Frontend and Backend
    apiClient -->|"calls"| controller

    %% Backend Internal Relationships
    controller -->|"calls"| repository1
    controller -->|"calls"| repository2
    repository1 -->|"accesses"| db
    repository2 -->|"accesses"| db

    %% Click Event Mappings
    click admin "https://github.com/21dh113775/mockhang_app/tree/master/lib/admin"
    click user "https://github.com/21dh113775/mockhang_app/tree/master/lib/user"
    click apiClient "https://github.com/21dh113775/mockhang_app/blob/master/lib/api/api_client.dart"
    click auth "https://github.com/21dh113775/mockhang_app/tree/master/lib/auth"
    click authService "https://github.com/21dh113775/mockhang_app/blob/master/lib/auth/auth_service.dart"
    click routes "https://github.com/21dh113775/mockhang_app/blob/master/lib/routes/app_routes.dart"
    click controller "https://github.com/21dh113775/mockhang_app/blob/master/backend/ProductsApi/Controller/ProductController.cs"
    click repository1 "https://github.com/21dh113775/mockhang_app/blob/master/backend/ProductsApi/Interface/ImplementRepository.cs"
    click repository2 "https://github.com/21dh113775/mockhang_app/blob/master/backend/ProductsApi/Interface/ProductRepository.cs"
    click db "https://github.com/21dh113775/mockhang_app/blob/master/backend/ProductsApi/DBContext/ApplicationDbContext.cs"
    click firebase "https://github.com/21dh113775/mockhang_app/blob/master/firebase.json"
    click firebaseOptions "https://github.com/21dh113775/mockhang_app/blob/master/lib/firebase_options.dart"

    %% Styles
    classDef frontend fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#ccccff,stroke:#333,stroke-width:2px;
```
