# utimur/online-store-full-course architecture

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

- Interactive diagram: https://gitdiagram.com/utimur/online-store-full-course
- Repository: https://github.com/utimur/online-store-full-course

## Overview

##### Main Components
- Client (Frontend):
– It uses React with routing and state management.
– Subdivide it into key segments such as:
○ Views/Pages (e.g., Admin, Auth, Basket, DevicePage, Shop)
○ Components (for the UI, e.g., NavBar, BrandBar, modals like CreateDevice, CreateType, etc.)
○ HTTP Service Layer (files under client/src/http, like deviceAPI.js, userAPI.js)
○ State Management (e.g., DeviceStore, UserStore)
○ A configuration/environment layer (represented by the .env file).

- Server (Backend):
– Built on Express, with an entry point (server/index.js).
– Divided into several layers:
○ Routes (organized in the server/routes folder, including brandRouter, deviceRouter, etc.)
○ Controllers (server/controllers handling business logic such as brandController, deviceController, etc.)
○ Models (in server/models - likely representing database entities, bundled in models.js)
○ Middleware (authentication, error handling, role-checking in server/middleware)
○ Error handling module (custom ApiError in server/error)

##### Relationships and Data Flows
- The Server should forward requests to the proper Controller based on the Route mappings.
- Controllers interact with Models and the Database to perform CRUD operations.
- Middleware is applied in the request flow: from the incoming API call, pass through authentication checks, role validations, and error handling.
- On the client, the state management (stores) receives data from HTTP responses and updates UI components accordingly.

##### Key Architectural Patterns & Design Principles
- The project is structured following a clear separation of concerns (MVC-like on the server side and component-based design on the client side).
- Use of RESTful API design: Different routers and controllers for brands, devices, types, and users.
- Modularity is present; for example, the separation into custom modals, utility functions, and isolated API service modules.
- Environment-specific configuration via .env files for both client and server.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client (Frontend) Subgraph
    subgraph "Client (Frontend)"
        direction TB
        CE1["React Entry"]:::frontend
        CE2["React App"]:::frontend
        PGS["Pages"]:::frontend
        UIC["UI Components"]:::frontend
        MOD["Modals"]:::frontend
        HTTP["HTTP Service"]:::frontend
        SM["State Management"]:::frontend
        ENV_C["Env Config (Client)"]:::frontend
    end

    %% Server (Backend) Subgraph
    subgraph "Server (Backend)"
        direction TB
        SE["Server Entry"]:::backend
        MR["API Routes"]:::backend
        MW["Middleware"]:::backend
        CTL["Controllers"]:::backend
        MODL["Models"]:::backend
        DB["Database"]:::external
        ERR["Error Module"]:::backend
        ENV_S["Env Config (Server)"]:::backend
    end

    %% Client Internal Flow (logical grouping, not strict execution order)
    CE1 --> CE2
    CE2 --> PGS
    PGS --> UIC
    UIC --> MOD
    MOD --> HTTP
    HTTP --> SM
    SM --> ENV_C

    %% API call from Client to Server
    HTTP -->|"API_call"| MR

    %% Server Internal Flow
    SE --> MR
    MR --> MW
    MW --> CTL
    CTL --> MODL
    MODL --> DB
    DB --> CTL
    CTL --> ERR
    ERR --> ENV_S

    %% Click Events for Client components
    click CE1 "https://github.com/utimur/online-store-full-course/blob/master/client/src/index.js"
    click CE2 "https://github.com/utimur/online-store-full-course/blob/master/client/src/App.js"
    click PGS "https://github.com/utimur/online-store-full-course/tree/master/client/src/pages"
    click UIC "https://github.com/utimur/online-store-full-course/tree/master/client/src/components"
    click MOD "https://github.com/utimur/online-store-full-course/tree/master/client/src/components/modals"
    click HTTP "https://github.com/utimur/online-store-full-course/tree/master/client/src/http"
    click SM "https://github.com/utimur/online-store-full-course/tree/master/client/src/store"
    click ENV_C "https://github.com/utimur/online-store-full-course/blob/master/client/.env"

    %% Click Events for Server components
    click SE "https://github.com/utimur/online-store-full-course/blob/master/server/index.js"
    click MR "https://github.com/utimur/online-store-full-course/tree/master/server/routes"
    click MW "https://github.com/utimur/online-store-full-course/tree/master/server/middleware"
    click CTL "https://github.com/utimur/online-store-full-course/tree/master/server/controllers"
    click MODL "https://github.com/utimur/online-store-full-course/tree/master/server/models"
    click ERR "https://github.com/utimur/online-store-full-course/tree/master/server/error"
    click DB "https://github.com/utimur/online-store-full-course/blob/master/server/db.js"
    click ENV_S "https://github.com/utimur/online-store-full-course/blob/master/server/.env"

    %% Class Definitions for colors and styles
    classDef frontend fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef backend fill:#FFE0B2,stroke:#FB8C00,stroke-width:2px;
    classDef external fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
```
