# adrianhajdin/uber architecture

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

- Interactive diagram: https://gitdiagram.com/adrianhajdin/uber
- Repository: https://github.com/adrianhajdin/uber

## Overview

##### Project’s Main Layers and Components
- Frontend Mobile Client:
- Built with React Native (Expo framework) with screens under directories such as app/(auth) and app/(root)/(tabs).
- Contains UI components (e.g., CustomButton, DriverCard, InputField) and layout components for ride booking, profiles, chat, etc.
- Integrates mapping features (Google Maps) for location and navigation display.

- Backend API Layer:
- Serverless API endpoints are found under app/(api) with several endpoints such as:
▪ Stripe endpoints (app/(api)/(stripe)) for payment processing
▪ Driver, ride creation, ride details, and user management endpoints
- These endpoints use Neon (Serverless PostgreSQL) to interact with the database.

- Database:
- PostgreSQL database (managed via NeonDB) stores data for rides, drivers, and users.
- The SQL queries and table creation scripts (e.g., CREATE TABLE drivers, CREATE TABLE rides, CREATE TABLE users) in the repository illustrate the data model.

- External Services & Integrations:
- Authentication using Clerk (with OAuth and email/password support).
- Payment processing via Stripe.
- Location and directions using Google Maps and Geoapify.

- State Management Layer:
- Client-side state management with Zustand (see store/index.ts) used to manage user location, destination, driver selection, etc.

##### Organizing and Diagramming the Architecture

A. Frontend:
- Inside that, include sub-components for:
- Authentication Screens (sign-in, sign-up, welcome; under app/(auth))
- Main Application Screens (book ride, confirm ride, chat, home, profile, rides tab; found under app/(root)/(tabs) and other root-level files like book-ride.tsx)
- UI Components (group or annotate “Reusable UI Components” such as CustomButton, InputField, Map, DriverCard).
- State Management (Zustand store) that coordinates user location, selected driver, etc.

B. Backend API:
- Ride Endpoints (e.g., app/(api)/ride/create+api.ts, [id]+api.ts) for ride booking and fetching ride details.
- Payment Endpoints within the Stripe folder (app/(api)/(stripe)) for creating and processing payments.
- Additional endpoints for user data and driver information.

C. Database:
- With tables such as:
▪ Drivers (with fields like id, first_name, car_image_url, etc.)
▪ Rides (with fields such as ride_id, origin/destination addresses, payment_status, etc.)
▪ Users (registration details, Clerk id, email, etc.)

D. External Services:
- Separate external service components:
- Clerk for Authentication (show connection from mobile client to external auth service)
- Stripe for payments (from mobile client and/or through API endpoints)
- Google Maps/Geoapify for location data and directions (used in both frontend for mapping and backend calculations).

##### Relationships and Data Flow
- The Mobile Client calls API endpoints (GET, POST) to create rides or fetch driver details.
- The API layer interacts with the PostgreSQL database (data insertion, queries, joins).
- Payment processing flows from the mobile app through the Stripe endpoints.
- External services such as Clerk and Google Maps are integrated both at the UI (for login and map rendering) and backend (for computing travel times).

##### Architectural Patterns and Principles
- The project uses a clear separation of concerns (presentation layer, API layer, and data persistence).
- It adopts a serverless approach for API endpoints facilitating easy scalability.
- The state management using Zustand is a key design principle for decoupled client-side logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#9A6400,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;

    %% Frontend Mobile Client
    subgraph "Frontend Mobile Client"
        A1["React Native Mobile App"]:::frontend
        subgraph "Screens & Components"
            A2["Authentication Screens"]:::frontend
            A3["Main App Screens"]:::frontend
            A4["Reusable UI Components"]:::frontend
            A5["State Management (Zustand)"]:::frontend
            A6["Payment UI"]:::frontend
        end
    end

    %% Backend API Layer
    subgraph "Backend API Layer"
        B1["General API Endpoints"]:::backend
        subgraph "Endpoints"
            B2["Ride Endpoints"]:::backend
            B3["Stripe Payment Endpoints"]:::backend
        end
    end

    %% Database
    subgraph "Database & Storage"
        C1["PostgreSQL Database"]:::database
    end

    %% External Services
    subgraph "External Services"
        D1["Authentication (Clerk)"]:::external
        subgraph "Mapping Integration"
            D2a["Map Component"]:::external
            D2b["Google Text Input"]:::external
            D2c["Map Logic"]:::external
        end
        D3["Stripe Payment Gateway"]:::external
    end

    %% Connections between layers
    A1 -->|"HTTPCalls"| B1
    A1 -->|"AuthCall"| D1
    A1 -->|"MapRendering"| D2a
    A1 -->|"PaymentRequest"| A6

    B1 -->|"DataQueries"| C1
    B2 -->|"RideDataOps"| C1
    B3 -->|"PaymentDataOps"| C1

    %% Internal Frontend Flow
    A2 -->|"NavigatesTo"| A3
    A3 -->|"Uses"| A4
    A4 -->|"InteractsWith"| A5

    %% Payment Flow from Frontend to External Payment
    A6 -->|"InitiatesPayment"| D3
    %% Backend Stripe validation
    B3 -->|"ValidatesPayment"| D3

    %% Click Events for Frontend Components
    click A1 "https://github.com/adrianhajdin/uber/tree/main/app/"
    click A2 "https://github.com/adrianhajdin/uber/tree/main/app/(auth)/"
    click A3 "https://github.com/adrianhajdin/uber/tree/main/app/(root)/"
    click A4 "https://github.com/adrianhajdin/uber/tree/main/components/"
    click A5 "https://github.com/adrianhajdin/uber/blob/main/store/index.ts"
    click A6 "https://github.com/adrianhajdin/uber/blob/main/components/Payment.tsx"

    %% Click Events for Backend API Layer
    click B1 "https://github.com/adrianhajdin/uber/tree/main/app/(api)/"
    click B2 "https://github.com/adrianhajdin/uber/tree/main/app/(api)/ride/"
    click B3 "https://github.com/adrianhajdin/uber/tree/main/app/(api)/(stripe)/"

    %% Click Events for External Services
    click D1 "https://github.com/adrianhajdin/uber/blob/main/lib/auth.ts"
    click D2a "https://github.com/adrianhajdin/uber/blob/main/components/Map.tsx"
    click D2b "https://github.com/adrianhajdin/uber/blob/main/components/GoogleTextInput.tsx"
    click D2c "https://github.com/adrianhajdin/uber/blob/main/lib/map.ts"
```
