# moesiomarcelino/gobarber-web architecture

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

- Interactive diagram: https://gitdiagram.com/moesiomarcelino/gobarber-web
- Repository: https://github.com/moesiomarcelino/gobarber-web

## Overview

##### Project Type and Purpose
- This is a single-page, front-end React/TypeScript application (“GoBarber Web”) for managing barbershop appointments.
- It provides user authentication, profile management, password reset flows, and a dashboard to view/create appointments by integrating with a separate back-end API.

##### Main Architectural Components
a. Browser / Client
- React SPA entry point (src/index.tsx → src/App.tsx)
- Routing layer (src/routes)
- Pages (src/pages/*): SignIn, SignUp, ForgotPassword, ResetPassword, Profile, Dashboard
- Shared UI Components (src/components/*): Button, Input, Tooltip, ToastContainer, etc.
- Hooks (src/hooks/*): Auth context, Toast notifications
- Styles (src/styles/global.ts + per-component styles)
b. HTTP API Layer
- axios instance in src/services/api.ts
- Token injection via interceptors (Auth hook)
- Exposed REST calls for authentication, user profile, appointments
c. External Back-end Services (not in this repo)
- Authentication service
- Appointments service
- Users/profile service
- Database (PostgreSQL / MongoDB / etc.)
d. Build & Tooling
- Node/Yarn or npm build scripts (package.json)
- ESLint, Prettier configurations
- Static assets served via public/index.html

##### Component Interactions and Data Flow
- User interacts with UI Components on the Browser → React Page renders form/data → triggers Hook calls or dispatches service methods.
- Services/api.ts sends HTTP requests to back-end microservices (Auth, Appointments, Users).
- Responses flow back → global state/hooks update (e.g., setUser, push Toast).
- Routing guards (Auth hook) redirect unauthenticated users to SignIn.
- ToastContainer listens to toast events via Toast hook and displays notifications.

##### Key Architectural Patterns
- Component-based UI (atomic components + pages)
- Client-side routing (react-router)
- Context API / custom hooks for cross-cutting concerns (authentication, notifications)
- Service layer for API abstraction (single axios instance)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser / Client
    subgraph "Browser / Client"
        direction TB
        Entry["src/index.tsx"]:::ui
        App["src/App.tsx"]:::ui

        subgraph "Routing Layer"
            direction TB
            Routes["src/routes/index.tsx"]:::ui
            Guard["src/routes/Route.tsx"]:::ui
        end

        subgraph "Pages" 
            direction TB
            SignIn["SignIn Page"]:::ui
            SignUp["SignUp Page"]:::ui
            Forgot["ForgotPassword Page"]:::ui
            Reset["ResetPassword Page"]:::ui
            Profile["Profile Page"]:::ui
            Dashboard["Dashboard Page"]:::ui
        end

        subgraph "Shared UI Components"
            direction TB
            Button["Button"]:::ui
            Input["Input"]:::ui
            Tooltip["Tooltip"]:::ui
            ToastContainer["ToastContainer"]:::ui
            Toast["Toast"]:::ui
        end

        subgraph "Hooks / Context"
            direction TB
            AuthHook["Auth Hook"]:::ui
            ToastHook["Toast Hook"]:::ui
            HooksIndex["hooks/index.tsx"]:::ui
        end

        subgraph "Styles"
            direction TB
            GlobalStyles["global.ts"]:::util
        end

        Entry -->|"renders"| App
        App -->|"uses"| Routes
        Routes -->|"guards via"| Guard
        Guard -->|"> pages"| SignIn
        Guard -->|"> pages"| SignUp
        Guard -->|"> pages"| Forgot
        Guard -->|"> pages"| Reset
        Guard -->|"> pages"| Profile
        Guard -->|"> pages"| Dashboard

        SignIn -->|"uses components"| Button
        SignIn -->|"uses components"| Input
        SignIn -->|"uses hooks"| AuthHook
        SignUp -->|"uses hooks"| AuthHook
        Forgot -->|"uses hooks"| AuthHook
        Reset -->|"uses hooks"| AuthHook
        Profile -->|"uses hooks"| AuthHook
        Dashboard -->|"uses hooks"| AuthHook

        ToastContainer -->|"renders"| Toast
        AnyPage(Any Page):::ui -->|"uses toasts"| ToastContainer
        AnyPage -->|"subscribes"| ToastHook

        SignIn -->|"styled by"| GlobalStyles
        SignUp -->|"styled by"| GlobalStyles
        Forgot -->|"styled by"| GlobalStyles
        Reset -->|"styled by"| GlobalStyles
        Profile -->|"styled by"| GlobalStyles
        Dashboard -->|"styled by"| GlobalStyles
    end

    %% HTTP API Layer
    subgraph "HTTP API Layer"
        direction TB
        API["src/services/api.ts"]:::service
        Utils["getValidationErrors"]:::util
    end

    %% External Back-end Services
    subgraph "External Services"
        direction TB
        AuthService["Auth Service"]:::external
        AppService["Appointments Service"]:::external
        UserService["Users/Profile Service"]:::external
    end

    %% Database
    DB["Database"]:::datastore

    %% Flows
    AnyPage -->|"POST /sessions, GET /profile, etc."| API
    API -->|"POST /sessions"| AuthService
    API -->|"GET/POST /appointments"| AppService
    API -->|"GET/PUT /users"| UserService
    AuthService -->|"queries"| DB
    AppService -->|"queries"| DB
    UserService -->|"queries"| DB
    API -->|"error validation"| Utils
    ToastHook -->|"dispatch toast"| ToastContainer

    %% Click Events
    click Entry "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/index.tsx"
    click App "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/App.tsx"
    click Routes "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/routes/index.tsx"
    click Guard "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/routes/Route.tsx"
    click SignIn "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/SignIn/index.tsx"
    click SignUp "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/SignUp/index.tsx"
    click Forgot "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/ForgotPassword/index.tsx"
    click Reset "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/ResetPassword/index.tsx"
    click Profile "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/Profile/index.tsx"
    click Dashboard "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/Dashboard/index.tsx"
    click Button "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/Button/index.tsx"
    click Input "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/Input/index.tsx"
    click Tooltip "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/Tooltip/index.tsx"
    click ToastContainer "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/ToastContainer/index.tsx"
    click Toast "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/ToastContainer/Toast/index.tsx"
    click AuthHook "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/hooks/Auth.tsx"
    click ToastHook "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/hooks/Toast.tsx"
    click HooksIndex "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/hooks/index.tsx"
    click GlobalStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/styles/global.ts"
    click API "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/services/api.ts"
    click Utils "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/utils/getValidationErrors.ts"
    click AnyPage "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/Dashboard/index.tsx"

    %% Styles click events for components (optional as mapping)
    click DefaultBtnStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/Button/styles.ts"
    click DefaultInputStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/Input/styles.ts"
    click DefaultTooltipStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/Tooltip/styles.ts"
    click DefaultToastContainerStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/ToastContainer/styles.ts"
    click DefaultToastStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/components/ToastContainer/Toast/styles.ts"
    click SignInStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/SignIn/styles.ts"
    click SignUpStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/SignUp/styles.ts"
    click ForgotStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/ForgotPassword/styles.ts"
    click ResetStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/ResetPassword/styles.ts"
    click ProfileStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/Profile/styles.ts"
    click DashboardStyles "https://github.com/moesiomarcelino/gobarber-web/blob/master/src/pages/Dashboard/styles.ts"

    %% Legend
    subgraph "Legend"
        direction TB
        L1["Rectangle: Client Modules"]:::ui
        L2["Cylinder: Database"]:::datastore
        L3["Rounded: External Services"]:::external
        L4["Hexagon: Utility/Config"]:::util
        L5["Green: Services/API"]:::service
    end

    %% Classes
    classDef ui fill:#D0E8FF,stroke:#0288D1,color:#000;
    classDef service fill:#D0FFD6,stroke:#2E7D32,color:#000;
    classDef external fill:#FFE5B4,stroke:#E65100,color:#000;
    classDef datastore fill:#FFF3B0,stroke:#F9A825,color:#000;
    classDef util fill:#E5E5E5,stroke:#757575,color:#000;
```
