# riyoneri/brewtopia-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/riyoneri/brewtopia-frontend
- Repository: https://github.com/riyoneri/brewtopia-frontend

## Overview

Based on our analysis, Brewtopia is a full-stack Next.js application that appears to serve two primary roles: a customer-facing storefront (located under the app/(user) routes) and an administration/dashboard section (located under app/obsidian). Even though the README is minimal (“Under development”) the file tree clearly reveals a rich structure with routes for account management, authentication flows, checkout processes, order management, and product administration. There’s also a clear separation of concerns through the use of specialized directories (such as components, hooks, data, and utils) and Next.js’s App Directory conventions.

##### Main components
- “User Interface Layer”: This comprises the Next.js pages/components under app/(user) which include the public pages, user authentication (login, register, forgot/new password, verify), checkout flow, cart, orders, events, news and various “home” sections.
- “Admin/Obsidian Dashboard”: The admin interface under app/obsidian handles customers, orders, products (and product categories), promotions, settings, and admin-specific authentication flows.
- “API Endpoints & Authentication”: The API routes (for example, api.ts at the root and app/api/* related to NextAuth) are centralized components handling user authentication and potentially other business logic.
- “Shared Components & Libraries”: This includes the reusable components, hooks (for both admin and user operations), helper functions, and static data. They support the UI and encapsulate business logic (e.g., fetching data, managing state, and handling socket connections).
- “Configuration & Styling”: The root-level configuration files (like next.config.mjs, tailwind.config.ts, tsconfig.json, etc.) that define build, linting, formatting, and styling protocols.

##### Out relationships and interactions
- The Client Browser accesses the Next.js frontend where navigation between pages handles the user journey (for both general users and admin users).
- User actions trigger interactions via custom hooks (in the hooks directories) that call the API endpoints (including NextAuth endpoints) using helper functions (as found in helpers/fetcher.ts and friends).
- The Admin dashboard (Obsidan) is structurally similar but contains specialized pages and components for managing products, promotions, and customers; while it also uses a similar authentication mechanism, it likely applies more privileges.
- Data flows: The static “data” folder indicates sample/seed data, which is used by components and hooks. Additionally, state updates (e.g., in checkout and cart flows) are represented in component interactions.
- External integrations: Though not visible explicitly, aspects like authentication (with NextAuth) may integrate with external providers and services.

##### Architectural patterns and design principles
- Next.js App Directory structure: This pattern is evident here with route grouping (e.g., (user), (protected), (obsidian)) which helps separate concerns.
- Separation between UI and business logic: Clear-cut directories for components, hooks, and helpers signal a modular design.
- Use of modern React patterns with reusable, self-contained components.
- Integration of code quality tools as indicated by ESLint, Prettier, and husky hooks.

##### Technologies and frameworks
- Next.js (with the new App Router)
- React (with server and client components)
- Tailwind CSS (for styling)
- NextAuth.js (for authentication)
- Modern JavaScript/TypeScript practices (as evidenced by tsconfig.json, .ts/.tsx files)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["User Browser"]:::browser

    subgraph "User Interface Layer"
        UI["Next.js User Pages (app/(user))"]:::ui
    end

    subgraph "Admin/Obsidian Dashboard"
        Admin["Admin Interface (app/obsidian)"]:::admin
    end

    subgraph "API Endpoints & Authentication"
        API["API Routes (api.ts, app/api)"]:::api
    end

    subgraph "Shared Components & Libraries"
        Shared["Components, Hooks, Data, Helpers & Utils"]:::shared
    end

    subgraph "Configuration & Styling"
        CFG1["next.config.mjs"]:::config
        CFG2["tailwind.config.ts"]:::config
        CFG3["tsconfig.json"]:::config
        CFG4[".eslintrc.json"]:::config
        CFG5[".prettierrc"]:::config
    end

    %% Connections
    Browser -->|"accesses"| UI
    Browser -->|"accesses admin"| Admin

    UI -->|"calls via hooks"| API
    Admin -->|"calls via hooks"| API

    UI -->|"uses"| Shared
    Admin -->|"uses"| Shared

    Shared -->|"fetches data"| API
    API -->|"returns data"| Shared

    API -->|"services"| UI
    API -->|"services"| Admin

    UI -->|"configured by"| CFG1
    UI -->|"configured by"| CFG2
    UI -->|"configured by"| CFG3
    UI -->|"configured by"| CFG4
    UI -->|"configured by"| CFG5

    Admin -->|"configured by"| CFG1
    Admin -->|"configured by"| CFG2
    Admin -->|"configured by"| CFG3
    Admin -->|"configured by"| CFG4
    Admin -->|"configured by"| CFG5

    %% Click Events
    click UI "https://github.com/riyoneri/brewtopia-frontend/tree/main/app/(user)"
    click Admin "https://github.com/riyoneri/brewtopia-frontend/tree/main/app/obsidian"
    click API "https://github.com/riyoneri/brewtopia-frontend/blob/main/api.ts"
    click API "https://github.com/riyoneri/brewtopia-frontend/blob/main/app/api/auth/[...nextauth]/route.ts"
    click Shared "https://github.com/riyoneri/brewtopia-frontend/tree/main/components"
    click Shared "https://github.com/riyoneri/brewtopia-frontend/tree/main/hooks"
    click Shared "https://github.com/riyoneri/brewtopia-frontend/tree/main/data"
    click Shared "https://github.com/riyoneri/brewtopia-frontend/tree/main/helpers"
    click Shared "https://github.com/riyoneri/brewtopia-frontend/tree/main/utils"
    click CFG1 "https://github.com/riyoneri/brewtopia-frontend/blob/main/next.config.mjs"
    click CFG2 "https://github.com/riyoneri/brewtopia-frontend/blob/main/tailwind.config.ts"
    click CFG3 "https://github.com/riyoneri/brewtopia-frontend/blob/main/tsconfig.json"
    click CFG4 "https://github.com/riyoneri/brewtopia-frontend/blob/main/.eslintrc.json"
    click CFG5 "https://github.com/riyoneri/brewtopia-frontend/blob/main/.prettierrc"

    %% Styling
    classDef browser fill:#a6cee3,stroke:#333,stroke-width:2px;
    classDef ui fill:#b2df8a,stroke:#333,stroke-width:2px;
    classDef admin fill:#fb9a99,stroke:#333,stroke-width:2px;
    classDef api fill:#fdbf6f,stroke:#333,stroke-width:2px;
    classDef shared fill:#cab2d6,stroke:#333,stroke-width:2px;
    classDef config fill:#ffff99,stroke:#333,stroke-width:2px;
```
