# phuonghoa1201/dacn1 architecture

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

- Interactive diagram: https://gitdiagram.com/phuonghoa1201/dacn1
- Repository: https://github.com/phuonghoa1201/dacn1

## Overview

##### Project type and purpose
- This is a full‑stack e‑commerce prototype built with Flutter on the client and Node.js/Express on the server.
- The Flutter app targets mobile (Android, iOS), web, Linux, macOS, and Windows, and provides user‑facing screens (home, search, product details, account, admin).
- The server implements REST endpoints for authentication, product browsing, and admin operations, backed by a data store (e.g., MongoDB).

##### File structure
- Top‑level “android”, “ios”, “web”, “linux”, “macos”, “windows”: platform‐specific Flutter hosts.
- “lib/”: Flutter application code, subdivided into common widgets, features (account, auth, home, search, product_details, admin), models, providers, and routing.
- “server/”: Node.js/Express application with subdirectories for routes, middleware (auth, admin), models (user, product), and package configuration.
- Configuration/build files: pubspec.yaml (Flutter dependencies), build.gradle.kts, CMakeLists (desktop), package.json (Node).

##### README
- No direct mention of server in README, but presence of “server/” folder indicates a separate backend service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Flutter Client" 
        direction TB
        subgraph "Platform Hosts" 
            direction TB
            Android["Android"]:::client
            iOS["iOS"]:::client
            Web["Web"]:::client
            Linux["Linux"]:::client
            macOS["macOS"]:::client
            Windows["Windows"]:::client
        end
        Main["main.dart"]:::client
        Router["router.dart"]:::client
        Providers["user_providers.dart"]:::client
        Widgets["common/widgets/"]:::client
        subgraph "Models"
            direction TB
            UserModel["user.dart"]:::client
            ProductModel["product.dart"]:::client
        end
        subgraph "Features"
            direction TB
            subgraph AuthFeature
                direction TB
                AuthScreen["auth_screen.dart"]:::client
                AuthService["auth_service.dart"]:::client
            end
            subgraph HomeFeature
                direction TB
                HomeScreen["home_screen.dart"]:::client
                HomeService["home_services.dart"]:::client
            end
            subgraph SearchFeature
                direction TB
                SearchScreen["search_screen.dart"]:::client
                SearchService["search_services.dart"]:::client
                SearchWidgets["search/widgets/"]:::client
            end
            subgraph ProductDetailsFeature
                direction TB
                ProductDetailScreen["product_detail_screen.dart"]:::client
            end
            subgraph AccountFeature
                direction TB
                AccountScreen["account_screen.dart"]:::client
                AccountWidgets["account/widgets/"]:::client
            end
            subgraph AdminFeature
                direction TB
                AdminScreen["admin_screen.dart"]:::client
                AddProductScreen["add_product_screen.dart"]:::client
                PostsScreen["posts_screen.dart"]:::client
                AdminService["admin_services.dart"]:::client
            end
        end
        Config["pubspec.yaml"]:::client
    end

    %% Server Layer
    subgraph "API Server" 
        direction TB
        ServerIndex["index.js"]:::server
        subgraph "Routes"
            direction TB
            AuthRoute["auth.js"]:::server
            ProductRoute["product.js"]:::server
            AdminRoute["admin.js"]:::server
        end
        subgraph "Middleware"
            direction TB
            AuthMiddleware["auth.js"]:::server
            AdminMiddleware["admin.js"]:::server
        end
        subgraph "Models"
            direction TB
            ServerUserModel["user.js"]:::server
            ServerProductModel["product.js"]:::server
        end
        ServerConfig["package.json"]:::server
    end

    %% Database Layer
    Database[(Database)]:::database

    %% Connections
    Android --> Main
    iOS --> Main
    Web --> Main
    Linux --> Main
    macOS --> Main
    Windows --> Main
    Main --> Router
    Router --> Providers
    Providers --> Widgets
    Providers --> UserModel
    Providers --> ProductModel
    Features --> Providers

    AuthScreen --> AuthService
    HomeScreen --> HomeService
    SearchScreen --> SearchService
    SearchWidgets --> SearchService
    ProductDetailScreen --> Router
    AccountScreen --> AccountWidgets
    AdminScreen --> AdminService
    AddProductScreen --> AdminService
    PostsScreen --> AdminService

    %% Client to Server via REST API
    AuthService -->|POST /login| AuthRoute
    HomeService -->|GET /products| ProductRoute
    SearchService -->|GET /search| ProductRoute
    AdminService -->|POST /admin/*| AdminRoute

    %% Server internal flow
    AuthRoute --> AuthMiddleware
    AuthRoute -->|calls| ServerUserModel
    ProductRoute --> AuthMiddleware
    ProductRoute -->|calls| ServerProductModel
    AdminRoute --> AuthMiddleware
    AdminRoute --> AdminMiddleware
    AdminRoute -->|calls| ServerProductModel

    %% Server to DB
    ServerUserModel --> Database
    ServerProductModel --> Database

    %% Click Events
    click Main "https://github.com/phuonghoa1201/dacn1/blob/master/lib/main.dart"
    click Router "https://github.com/phuonghoa1201/dacn1/blob/master/lib/router.dart"
    click Providers "https://github.com/phuonghoa1201/dacn1/blob/master/lib/providers/user_providers.dart"
    click Widgets "https://github.com/phuonghoa1201/dacn1/tree/master/lib/common/widgets/"
    click UserModel "https://github.com/phuonghoa1201/dacn1/blob/master/lib/models/user.dart"
    click ProductModel "https://github.com/phuonghoa1201/dacn1/blob/master/lib/models/product.dart"
    click AuthScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/auth/screens/auth_screen.dart"
    click AuthService "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/auth/services/auth_service.dart"
    click HomeScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/home/screens/home_screen.dart"
    click HomeService "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/home/services/home_services.dart"
    click SearchScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/search/screens/search_screen.dart"
    click SearchService "https://github.com/phuonghoa1201/dacn1/blob/master/lib/search/services/search_services.dart"
    click SearchWidgets "https://github.com/phuonghoa1201/dacn1/tree/master/lib/search/widgets/"
    click ProductDetailScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/product_details/screens/product_detail_screen.dart"
    click AccountScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/account/screens/account_screen.dart"
    click AccountWidgets "https://github.com/phuonghoa1201/dacn1/tree/master/lib/features/account/widgets/"
    click AdminScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/admin/screens/admin_screen.dart"
    click AddProductScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/admin/screens/add_product_screen.dart"
    click PostsScreen "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/admin/screens/posts_screen.dart"
    click AdminService "https://github.com/phuonghoa1201/dacn1/blob/master/lib/features/admin/services/admin_services.dart"
    click Config "https://github.com/phuonghoa1201/dacn1/blob/master/pubspec.yaml"
    click ServerIndex "https://github.com/phuonghoa1201/dacn1/blob/master/server/index.js"
    click AuthRoute "https://github.com/phuonghoa1201/dacn1/blob/master/server/routes/auth.js"
    click ProductRoute "https://github.com/phuonghoa1201/dacn1/blob/master/server/routes/product.js"
    click AdminRoute "https://github.com/phuonghoa1201/dacn1/blob/master/server/routes/admin.js"
    click AuthMiddleware "https://github.com/phuonghoa1201/dacn1/blob/master/server/middleware/auth.js"
    click AdminMiddleware "https://github.com/phuonghoa1201/dacn1/blob/master/server/middleware/admin.js"
    click ServerUserModel "https://github.com/phuonghoa1201/dacn1/blob/master/server/models/user.js"
    click ServerProductModel "https://github.com/phuonghoa1201/dacn1/blob/master/server/models/product.js"
    click ServerConfig "https://github.com/phuonghoa1201/dacn1/blob/master/server/package.json"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef database fill:#FFF3E0,stroke:#FB8C00,color:#E65100
```
