# goodviet/s-mart-app architecture

> Architecture diagram of the GitHub repository goodviet/s-mart-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/goodviet/s-mart-app
- Repository: https://github.com/goodviet/s-mart-app

## Overview

##### Project type and purpose
- This is a full-stack, mobile-centric e-commerce application (“S-mart-app”) built with:
- Flutter/Dart front-end (cross-platform mobile/desktop/web)
- Node.js/Express back-end
- MongoDB NoSQL database
- Cloudinary for image storage

##### File structure
- Top level:
- takehome/ → Flutter client, subdivided by platform (android, ios, macos, linux, windows, web), with core code in lib/
- service/ → Express server, organized by app.js + server.js, config/, routes/, controller/, service/, model/
- Patterns:
- Front-end: layered “UI screens → widgets → service layer (HTTP client) → model classes”
- Back-end: MVC/service pattern: “routes → controllers → business services → models → database”

##### Extract key architectural insights from the README
- Client-Server architecture: Flutter app issues CRUD HTTP calls to Express endpoints
- External dependencies: MongoDB for product data, Cloudinary for media

##### Main components
a. Front-end (Flutter client)
- Presentation layer: Screens (home, cart, create/update product, storage)
- Widget subcomponents: custom widgets (buttons, dialogs, item cards)
- Service layer: service.app.dart – HTTP client that serializes JSON to model objects
- Models: Dart classes in lib/model
- Navigation: routes.dart → defines screen routing

b. API Layer (Express server)
- Entry points: server.js → app.js → middleware
- Routes: product.route.js, controller.route.js
- Controllers: product.controller.js – handles HTTP request/response
- Services: product.service.js – business logic (e.g., validations, orchestration)
- Models: M_Product.js – Mongoose schema mapping to MongoDB
- Config: database.config.js → MongoDB URI; cloudinary.config.js → media storage

c. Data Layer
- MongoDB database instance (products collection)
- Cloudinary external service for image uploads

##### Relationships & data flows
- User taps a Flutter screen → UI widget calls service.app.dart →
HTTP request (JSON) → Express route → Controller → Service →
Database/Cloudinary → Result returned up the chain → Flutter receives JSON → UI updates

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Flutter Client
    subgraph "Flutter Client"
        direction TB
        subgraph "Presentation Layer"
            direction TB
            Screens["Flutter UI: Screens"]:::client
            Widgets["Flutter Widgets"]:::client
        end
        ServiceLayer["Flutter Service Layer (HTTP Client)"]:::client
        Models["Flutter Models"]:::client
        Navigation["Flutter Routes (Navigator)"]:::client
    end

    %% Express API Server
    subgraph "Express API Server"
        direction TB
        ServerJS["server.js"]:::server
        AppJS["app.js"]:::server
        subgraph "Config"
            direction TB
            DBConf["database.config.js"]:::server
            CloudConf["cloudinary.config.js"]:::server
        end
        subgraph "Routes"
            direction TB
            ProdRoute["product.route.js"]:::server
            CtrlRoute["controller.route.js"]:::server
        end
        subgraph "Controllers"
            direction TB
            ProdCtrl["product.controller.js"]:::server
        end
        subgraph "Services"
            direction TB
            ProdService["product.service.js"]:::server
        end
        subgraph "Models"
            direction TB
            MProd["M_Product.js"]:::server
        end
    end

    %% Data Layer
    MongoDB["MongoDB"]:::db
    Cloudinary["Cloudinary"]:::ext

    %% Relationships
    Screens --> Widgets
    Widgets --> ServiceLayer
    ServiceLayer -->|HTTP Request| ServerJS
    ServerJS --> AppJS
    AppJS --> ProdRoute
    ProdRoute --> ProdCtrl
    ProdCtrl --> ProdService
    ProdService --> MProd
    MProd --> MongoDB
    ProdService --> Cloudinary
    %% Response back
    MongoDB -->|JSON Response| ServiceLayer
    Cloudinary -->|Media URL| ServiceLayer

    %% Click Events
    click Screens "https://github.com/goodviet/s-mart-app/tree/master/takehome/lib/screen/"
    click Widgets "https://github.com/goodviet/s-mart-app/tree/master/takehome/lib/widget/"
    click ServiceLayer "https://github.com/goodviet/s-mart-app/blob/master/takehome/lib/service/service.app.dart"
    click Models "https://github.com/goodviet/s-mart-app/tree/master/takehome/lib/model/"
    click Navigation "https://github.com/goodviet/s-mart-app/blob/master/takehome/lib/routes/routes.dart"
    click ServerJS "https://github.com/goodviet/s-mart-app/blob/master/service/server.js"
    click AppJS "https://github.com/goodviet/s-mart-app/blob/master/service/app.js"
    click DBConf "https://github.com/goodviet/s-mart-app/blob/master/service/config/database.config.js"
    click CloudConf "https://github.com/goodviet/s-mart-app/blob/master/service/config/cloudinary.config.js"
    click ProdRoute "https://github.com/goodviet/s-mart-app/blob/master/service/routes/product.route.js"
    click CtrlRoute "https://github.com/goodviet/s-mart-app/blob/master/service/routes/controller.route.js"
    click ProdCtrl "https://github.com/goodviet/s-mart-app/blob/master/service/controller/product.controller.js"
    click ProdService "https://github.com/goodviet/s-mart-app/blob/master/service/service/product.service.js"
    click MProd "https://github.com/goodviet/s-mart-app/blob/master/service/model/M_Product.js"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,color:#000
    classDef server fill:#90EE90,stroke:#000,color:#000
    classDef db fill:#FFA500,stroke:#000,color:#000
    classDef ext fill:#DDA0DD,stroke:#000,color:#000
```
