# dawgdevv/full_stack_uber architecture

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

- Interactive diagram: https://gitdiagram.com/dawgdevv/full_stack_uber
- Repository: https://github.com/dawgdevv/full_stack_uber

## Overview

##### Client Layer Components
- React Application Container
- User Interface Components (show main components like LocationSearchPanel, RidePopUp, LiveTracking)
- Context Providers (UserContext, CaptainContext, SocketContext)
- Authentication Wrappers (UserProtectWrapper, CaptainProtectWrapper)
- Page Components (Home, Riding, CaptainHome, etc.)

##### Server Layer Components
Create these sections:
- Express.js Server
- Routes Layer (user.routes, captain.routes)
- Controllers Layer (user.controller, captain.controller)
- Services Layer (user.services, captain.services)
- Middleware Layer (auth.middleware)
- WebSocket Server (for real-time communication)

##### Data Layer Components
Include:
- MongoDB Database
- User Collection
- Captain Collection
- BlacklistToken Collection

##### Connection Flows
- HTTP/REST API calls between frontend and backend
- WebSocket connections for real-time updates
- Database queries between server and MongoDB
- Authentication flows

Use these specific visual elements:

- Blue: Frontend components
- Green: Backend API services
- Yellow: WebSocket connections
- Purple: Database components
- Red: Authentication/Security components

- Rectangles: Main services
- Hexagons: Security components
- Rounded rectangles: UI components

Special Considerations:

##### Real-time Features
- WebSocket connections between frontend contexts and backend
- Live tracking flow between captain and user

##### Authentication Flow
- JWT token flow
- Token blacklisting process
- Demonstrate protected route mechanisms

##### Ride Management
- Flow from ride request to completion
- Captain-user matching system
- Location tracking flow

##### Security Layer
- Where password hashing occurs
- JWT verification points
- CORS and cookie handling

##### Payment Flow (if implemented)

- Abbreviations used

Remember to include version information for key technologies:
- React 18.3
- Express.js 4.21
- MongoDB with Mongoose 8.8
- WebSocket implementation

This will create a comprehensive yet clear system design that accurately represents the application's architecture while maintaining readability and usefulness for technical discussions.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef websocket fill:#f1c40f,stroke:#f39c12,color:black
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        F[Frontend - React 18.3]:::frontend
        B[Backend - Express 4.21]:::backend
        W[WebSocket]:::websocket
        D[(MongoDB 8.8)]:::database
        A[Auth - JWT]:::auth
    end

    %% Frontend Layer
    subgraph ClientLayer["Client Layer (React 18.3)"]
        App["React App Entry"]:::frontend
        
        subgraph UIComponents["UI Components"]
            LSP["Location Search Panel"]:::frontend
            RP["Ride PopUp"]:::frontend
            LT["Live Tracking"]:::frontend
            HP["Home Page"]:::frontend
            RDP["Riding Page"]:::frontend
            CHP["Captain Home"]:::frontend
            NAV["Navigation Bar"]:::frontend
            MAP["Map Component"]:::frontend
        end

        subgraph ContextProviders["Context Providers"]
            UC["User Context
            - Auth State
            - User Profile
            - Ride History"]:::frontend
            CC["Captain Context
            - Location
            - Availability
            - Current Rides"]:::frontend
            SC["Socket Context
            - Real-time Updates
            - Location Tracking"]:::websocket
        end

        subgraph AuthWrappers["Authentication Wrappers"]
            UPW["User Protect Wrapper
            - Route Guards
            - Token Validation"]:::auth
            CPW["Captain Protect Wrapper
            - Route Guards
            - Token Validation"]:::auth
        end
    end

    %% Backend Layer
    subgraph ServerLayer["Server Layer (Express 4.21)"]
        Server["Express Server
        - CORS
        - Cookie Parser
        - Body Parser"]:::backend
        WS["WebSocket Server
        - Socket.io
        - Real-time Events"]:::websocket

        subgraph Routes["API Routes"]
            UR["User Routes
            - Authentication
            - Profile
            - Rides"]:::backend
            CR["Captain Routes
            - Authentication
            - Location
            - Ride Management"]:::backend
        end

        subgraph Controllers["Controllers"]
            UC_["User Controller
            - Login/Register
            - Ride Requests
            - Payment"]:::backend
            CC_["Captain Controller
            - Status Updates
            - Route Planning
            - Earnings"]:::backend
        end

        subgraph Services["Business Logic"]
            US["User Services
            - Profile Management
            - Ride History
            - Payment Processing"]:::backend
            CS["Captain Services
            - Location Updates
            - Availability Management
            - Route Optimization"]:::backend
        end

        AM["Auth Middleware
        - JWT Verification
        - Role Checking
        - Token Blacklist"]:::auth
    end

    %% Data Layer
    subgraph DataLayer["Data Layer (MongoDB 8.8)"]
        DB[(MongoDB)]:::database
        UM["User Collection
        - Profile
        - Ride History
        - Payment Info"]:::database
        CM["Captain Collection
        - Vehicle Info
        - Location History
        - Ratings"]:::database
        BT["Blacklist Tokens
        - Expired
        - Revoked"]:::database
        RH["Ride History
        - Routes
        - Payments
        - Ratings"]:::database
    end

    %% Connections
    App --> UIComponents
    App --> ContextProviders
    App --> AuthWrappers
    
    SC -.-> WS
    UR --> UC_
    CR --> CC_
    UC_ --> US
    CC_ --> CS
    
    US --> DB
    CS --> DB
    DB --> UM
    DB --> CM
    DB --> BT
    DB --> RH
    
    AM --> UR
    AM --> CR

    %% Click Events
    click App "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/App.jsx"
    click LSP "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/components/LocationSearchPanel.jsx"
    click RP "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/components/RidePopUp.jsx"
    click LT "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/components/LiveTracking.jsx"
    click UC "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/context/UserContext.jsx"
    click CC "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/context/CapatainContext.jsx"
    click SC "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/context/SocketContext.jsx"
    click UPW "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/pages/UserProtectWrapper.jsx"
    click CPW "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_frontend/src/pages/CaptainProtectWrapper.jsx"
    click Server "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/server.js"
    click UR "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/routes/user.routes.js"
    click CR "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/routes/captain.routes.js"
    click UC_ "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/controllers/user.controller.js"
    click CC_ "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/controllers/captain.controller.js"
    click US "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/services/user.services.js"
    click CS "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/services/captain.services.js"
    click AM "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/middleware/auth.middleware.js"
    click DB "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/db/db.js"
    click UM "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/models/user.model.js"
    click CM "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/models/captain.model.js"
    click BT "https://github.com/dawgdevv/Full_stack_uber/blob/main/uber_backend/models/blacklisttoken.model.js"
```
