# guiller2211/riders architecture

> Architecture diagram of the GitHub repository guiller2211/riders, 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/guiller2211/riders
- Repository: https://github.com/guiller2211/riders

## Overview

##### Project type and purpose
- This is an NX-managed monorepo combining:
– A Remix-based “riders” storefront application (apps/riders)
– A reusable UI design system and toolkit (libs/ui)
– Shared domain types (libs/types)
– Core services & handlers (libs/core)
– A Firebase provider implementation (libs/providers/firebase)
- The README calls it “Rider’s Realm UI Toolkit,” an open-source React component & utility library, integrated into a demo Remix app.

##### High-level file structure & architectural patterns
- Top-level “apps” directory
– apps/riders: a full Remix project
· app/routes: URL-driven React pages and nested routes
· app/server: CSRF, Firebase session handling
· app/service: data-access services (cart, product, user, etc.)
· app/ui: page-level compositions and an API endpoint (MercadoPago)
· public: static assets
· server: shipping targets (Express for local, Netlify for deployment)
- Top-level “libs” directory
– libs/types: domain-level TypeScript types/enums
– libs/core: framework-agnostic services (config, localization, session handlers, request decorators)
– libs/providers/firebase: plugs in Firebase APIs as a slice/provider for state management
– libs/ui: the design system (46 atomic + composite components, hooks, utilities, context providers, theming)
- Monorepo orchestration by NX
– Shared tsconfig, build scripts (Vite configs per library, Remix config), testing (Vitest), linting, formatting, and deployment tooling.

##### Key insights from README
- It’s both a UI toolkit and a demo integration (“riders” Remix app).
- Uses React + TypeScript, built with NX, tested with Vitest, deployed via Netlify, with optional Express server target.
- The UI library is framework-agnostic (can be consumed by any React app) and separated into its own build pipeline (`nx build ui` → dist/ui).

a. Main Components
1. NX Monorepo Core (workspace, Nx CLI, shared tooling)
2. “riders” Remix Application
– UI Layer (app/routes + app/ui)
– Service Layer (app/service)
– Server Layer (app/server + server/*.ts)
– Static Assets (public/)
3. UI Toolkit Library (libs/ui)
4. Shared Domain Types (libs/types)
5. Core Services & Handlers (libs/core)
6. Firebase Provider (libs/providers/firebase)
7. External Services
– Firebase Auth/Firestore
– MercadoPago (API)
– Netlify/Express hosting
b. Relationships & Data Flows
– riders app → imports UI components from libs/ui
– riders app → uses data services in app/service, which call into libs/providers/firebase (or a local datasource)
– service layer → maps domain types from libs/types
– libs/ui → consumes types from libs/types for prop typings
– libs/providers/firebase → depends on Firebase SDK and maps raw JSON to domain models via libs/types
– libs/core → provides underlying cross-cutting services (configuration, session handling) used by both app/server and libs/providers
– Hosting layer (Netlify/Express) serves the SSR entrypoints of riders
c. Architectural Patterns & Principles
– Monorepo modularization (apps vs. libs)
– Layered architecture: Presentation → Application Services → Domain Types → Infrastructure
– Dependency inversion: high-level modules (app & UI) depend on abstractions (libs/core, libs/types), not on concrete Firebase SDK
– Reusability: UI component library separated from business logic
– SSR with Remix, with client hydration for interactive UI
d. Technologies & Frameworks
– React + Remix for the storefront
– TypeScript across all modules
– NX for workspace management
– Vite for building libs and apps
– Vitest for unit/integration tests
– Firebase SDK for data persistence/auth
– Netlify & Express for deployment targets

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% NX Workspace
    subgraph "NX Monorepo Core"
        direction TB
        NXConfig["nx.json, tsconfig.base.json, package.json"]:::build
        Tools["tools/"]:::build
    end

    %% Apps
    subgraph "apps/riders (Remix App)" 
        direction TB
        subgraph "Presentation / UI Layer"
            direction TB
            Routes["app/routes"]:::app
            UIPages["app/ui/pages"]:::app
        end
        subgraph "Service Layer"
            direction TB
            Service["app/service"]:::app
        end
        subgraph "Server Layer"
            direction TB
            AppServer["app/server"]:::app
            Servers["server/ (express.server.ts, netlify.server.ts)"]:::app
        end
        Static["public/"]:::app
    end

    %% Libraries
    subgraph "libs/types (Domain Types)"
        direction TB
        Types["src/lib/* domain models"]:::lib
    end

    subgraph "libs/core (Core Services & Handlers)"
        direction TB
        CoreServices["src/lib/services"]:::lib
        SessionHandler["src/lib/handlers/session.handler.ts"]:::lib
        DataSources["src/lib/data"]:::lib
        RequestDecorator["src/lib/server/request-decorator.ts"]:::lib
    end

    subgraph "libs/providers/firebase (Firebase Provider)"
        direction TB
        FirebaseService["src/lib/services/firebase.service.tsx"]:::lib
        Mappers["src/lib/mappers"]:::lib
        OrderProvider["src/lib/provider/OrderProvider"]:::lib
        UserProvider["src/lib/provider/UserProvider"]:::lib
        FirebaseIndex["src/index.ts"]:::lib
    end

    subgraph "libs/ui (UI Toolkit Library)"
        direction TB
        Components["src/lib/components"]:::lib
        Context["src/lib/context"]:::lib
        Hooks["src/lib/hooks"]:::lib
        Layout["src/lib/layout"]:::lib
        Themes["src/lib/themes"]:::lib
        Utils["src/lib/utils"]:::lib
    end

    %% External Services
    subgraph "External Services"
        direction TB
        FirebaseSDK["Firebase Auth / Firestore"]:::external
        Mercado["MercadoPago API"]:::external
        Hosting["Netlify / Express"]:::external
    end

    %% Build & Deployment
    subgraph "Build & Deployment Tools"
        direction TB
        NxCLI["Nx CLI, Vite, Vitest"]:::build
        Deploy["Netlify Plugin"]:::build
    end

    %% Relationships
    NXConfig -->|workspace config| Routes
    Tools -->|build scripts| NxCLI
    Routes -->|"imports UI components"| Components
    UIPages -->|"imports UI components"| Components
    Service -->|"uses providers"| FirebaseService
    Service -->|"uses types"| Types
    Service -->|"calls core services"| CoreServices
    AppServer -->|"uses session handlers"| SessionHandler
    AppServer -->|"uses request decorator"| RequestDecorator
    Servers -->|"hosts SSR"| Hosting
    FirebaseService -->|"calls Firebase SDK"| FirebaseSDK
    FirebaseService -->|"maps JSON to domain models"| Types
    Components -->|"use types for props"| Types
    Components -->|"use core services"| CoreServices
    Components -->|"expose context/hooks"| Context
    Components -->|"theme support"| Themes
    NxCLI -->|build ui| Components
    NxCLI -->|run riders:dev| Routes
    Deploy -->|deploy app| Hosting

    %% Click Events
    click NXConfig "https://github.com/guiller2211/riders/blob/main/nx.json"
    click NXConfig "https://github.com/guiller2211/riders/blob/main/tsconfig.base.json"
    click NXConfig "https://github.com/guiller2211/riders/blob/main/package.json"
    click Tools "https://github.com/guiller2211/riders/tree/main/tools/"
    click Routes "https://github.com/guiller2211/riders/tree/main/apps/riders/app/routes/"
    click UIPages "https://github.com/guiller2211/riders/tree/main/apps/riders/app/ui/pages/"
    click Service "https://github.com/guiller2211/riders/tree/main/apps/riders/app/service/"
    click AppServer "https://github.com/guiller2211/riders/tree/main/apps/riders/app/server/"
    click Servers "https://github.com/guiller2211/riders/tree/main/apps/riders/server/"
    click Static "https://github.com/guiller2211/riders/tree/main/apps/riders/public/"
    click Components "https://github.com/guiller2211/riders/tree/main/libs/ui/src/lib/components/"
    click Context "https://github.com/guiller2211/riders/tree/main/libs/ui/src/lib/context/"
    click Hooks "https://github.com/guiller2211/riders/tree/main/libs/ui/src/lib/hooks/"
    click Layout "https://github.com/guiller2211/riders/tree/main/libs/ui/src/lib/layout/"
    click Themes "https://github.com/guiller2211/riders/tree/main/libs/ui/src/lib/themes/"
    click Utils "https://github.com/guiller2211/riders/tree/main/libs/ui/src/lib/utils/"
    click Types "https://github.com/guiller2211/riders/tree/main/libs/types/src/lib/"
    click CoreServices "https://github.com/guiller2211/riders/tree/main/libs/core/src/lib/services/"
    click SessionHandler "https://github.com/guiller2211/riders/blob/main/libs/core/src/lib/handlers/session.handler.ts"
    click DataSources "https://github.com/guiller2211/riders/tree/main/libs/core/src/lib/data/"
    click RequestDecorator "https://github.com/guiller2211/riders/blob/main/libs/core/src/lib/server/request-decorator.ts"
    click FirebaseService "https://github.com/guiller2211/riders/blob/main/libs/providers/firebase/src/lib/services/firebase.service.tsx"
    click Mappers "https://github.com/guiller2211/riders/tree/main/libs/providers/firebase/src/lib/mappers/"
    click OrderProvider "https://github.com/guiller2211/riders/tree/main/libs/providers/firebase/src/lib/provider/OrderProvider/"
    click UserProvider "https://github.com/guiller2211/riders/tree/main/libs/providers/firebase/src/lib/provider/UserProvider/"
    click FirebaseIndex "https://github.com/guiller2211/riders/blob/main/libs/providers/firebase/src/index.ts"

    %% Styles
    classDef app fill:#D0E8FF,stroke:#0066CC,color:#000
    classDef lib fill:#E6F4EA,stroke:#2E7D32,color:#000
    classDef external fill:#FFE8CC,stroke:#E65100,color:#000
    classDef build fill:#F0F0F0,stroke:#757575,color:#000
```
