# javierparradev/casino architecture

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

## Overview

##### Project type and purpose
- This is a full-stack web application for a “casino” or sports betting platform.
- The frontend (“casino-frontend”) is a React/Vite single-page app.
- The backend (root “src/”) is a Node.js/Express REST API that manages users, authentication, bets, transactions and football fixtures.
- It persists data in MongoDB and pulls live match data from an external Football API (via RapidAPI).

##### File structure
- Top-level separation:
- casino-frontend/ (React SPA)
- src/ (Express app)
- Frontend: standard Vite project with index.html, src/components, src/pages, a central App.jsx, and an api.js module for HTTP calls.
- Backend:
- config/ (db connection, env validation, RapidAPI config)
- controllers/ (request handlers per domain: auth, user, football, bet, transaction, dashboard)
- routes/ (Express routes mapping URLs to controllers)
- services/ (business logic: fetching fixtures, placing bets, processing transactions, user management)
- models/ (Mongoose schemas for User, Bet, Transaction)
- middlewares/ (JWT auth, validation, error handling)
- utils/ (JWT helpers)
- Deployment/config: .env, package.json, gitignore.

##### README for additional insights
- Confirms architecture: Express app with route-controller-service-model layers.
- Mentions MongoDB connection, JWT, RapidAPI integration for football data.

##### Elements
- From browser → Frontend → API client → Backend Routes
- Backend flow down through Controllers → Services → Database or external API → back up to client
- Rectangles for compute components (frontend, backend modules)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        Browser["User Browser"]:::external
        MainEntry["main.jsx"]:::frontend
        App["App.jsx"]:::frontend
        Pages["Pages (casino-frontend/src/pages/)"]:::frontend
        Components["Components (casino-frontend/src/components/)"]:::frontend
        APIClient["api.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB

        subgraph "Configuration"
            direction TB
            Env["validateEnv.js"]:::backend
            DBConn["db.js"]:::backend
            RapidCfg["rapidapi.js"]:::backend
        end

        subgraph "HTTP API Layer (Routes)"
            direction TB
            AuthRoutes["auth.routes.js"]:::backend
            UserRoutes["user.routes.js"]:::backend
            BetRoutes["bet.routes.js"]:::backend
            TransactionRoutes["transaction.routes.js"]:::backend
            FootballRoutes["football.routes.js"]:::backend
            DashboardRoutes["dashboard.routes.js"]:::backend
        end

        subgraph "Controllers"
            direction TB
            AuthController["auth.controller.js"]:::backend
            UserController["user.controller.js"]:::backend
            BetController["bet.controller.js"]:::backend
            TransactionController["transaction.controller.js"]:::backend
            FootballController["football.controller.js"]:::backend
            DashboardController["dashboard.controller.js"]:::backend
        end

        subgraph "Service Layer"
            direction TB
            APIFootball["apiFootball.Service.js"]:::service
            FixturesService["fixtures.Service.js"]:::service
            UserService["user.Service.js"]:::service
            BetService["bet.service.js"]:::service
            TransactionService["transaction.Service.js"]:::service
        end

        subgraph "Models"
            direction TB
            UserModel["user.models.js"]:::data
            BetModel["bet.models.js"]:::data
            TransactionModel["transaction.model.js"]:::data
        end

        subgraph "Middlewares"
            direction TB
            AuthMiddleware["auth.middleware.js"]:::auth
            ValidateUser["validateUser.js"]:::auth
            ValidateLeague["validateLeague.js"]:::auth
            ErrorHandler["errorHandler.js"]:::auth
        end

        subgraph "Utilities"
            direction TB
            JWTUtils["jwt.js"]:::auth
        end

        subgraph "App Entry"
            direction TB
            AppJS["app.js"]:::backend
            IndexJS["index.js"]:::backend
        end

    end

    %% External Services
    MongoDB["MongoDB"]:::database
    RapidAPI["RapidAPI (Football API)"]:::external

    %% Flow Connections
    Browser --> MainEntry
    MainEntry --> App
    App --> Pages
    App --> Components
    Pages --> APIClient
    Components --> APIClient
    APIClient -->|HTTP/REST| AuthRoutes
    APIClient -->|HTTP/REST| UserRoutes
    APIClient -->|HTTP/REST| BetRoutes
    APIClient -->|HTTP/REST| TransactionRoutes
    APIClient -->|HTTP/REST| FootballRoutes
    APIClient -->|HTTP/REST| DashboardRoutes

    %% Routes to Controllers
    AuthRoutes --> AuthController
    UserRoutes --> UserController
    BetRoutes --> BetController
    TransactionRoutes --> TransactionController
    FootballRoutes --> FootballController
    DashboardRoutes --> DashboardController

    %% Controllers to Services
    AuthController --> UserService
    AuthController --> TransactionService
    UserController --> UserService
    BetController --> BetService
    BetController --> TransactionService
    TransactionController --> TransactionService
    FootballController --> FixturesService
    DashboardController --> UserService

    %% Services interactions
    APIFootball --> RapidAPI
    FixturesService --> APIFootball
    UserService --> UserModel
    BetService --> BetModel
    TransactionService --> TransactionModel
    TransactionService --> UserModel

    %% Models to Database
    UserModel --> MongoDB
    BetModel --> MongoDB
    TransactionModel --> MongoDB

    %% Middleware and Utils
    AuthRoutes --> AuthMiddleware
    AuthMiddleware --> JWTUtils
    AuthRoutes --> ValidateUser
    FootballRoutes --> ValidateLeague
    any --> ErrorHandler

    %% App bootstrap
    AppJS --> Env
    AppJS --> DBConn
    AppJS --> RapidCfg
    IndexJS --> AppJS

    %% Click Events
    click MainEntry "https://github.com/javierparradev/casino/blob/main/casino-frontend/src/main.jsx"
    click App "https://github.com/javierparradev/casino/blob/main/casino-frontend/src/App.jsx"
    click Pages "https://github.com/javierparradev/casino/tree/main/casino-frontend/src/pages/"
    click Components "https://github.com/javierparradev/casino/tree/main/casino-frontend/src/components/"
    click APIClient "https://github.com/javierparradev/casino/blob/main/casino-frontend/src/api.js"
    click AuthRoutes "https://github.com/javierparradev/casino/blob/main/src/routes/auth.routes.js"
    click UserRoutes "https://github.com/javierparradev/casino/blob/main/src/routes/user.routes.js"
    click BetRoutes "https://github.com/javierparradev/casino/blob/main/src/routes/bet.routes.js"
    click TransactionRoutes "https://github.com/javierparradev/casino/blob/main/src/routes/transaction.routes.js"
    click FootballRoutes "https://github.com/javierparradev/casino/blob/main/src/routes/football.routes.js"
    click DashboardRoutes "https://github.com/javierparradev/casino/blob/main/src/routes/dashboard.routes.js"
    click AuthController "https://github.com/javierparradev/casino/blob/main/src/controllers/auth.controller.js"
    click UserController "https://github.com/javierparradev/casino/blob/main/src/controllers/user.controller.js"
    click BetController "https://github.com/javierparradev/casino/blob/main/src/controllers/bet.controller.js"
    click TransactionController "https://github.com/javierparradev/casino/blob/main/src/controllers/transaction.controller.js"
    click FootballController "https://github.com/javierparradev/casino/blob/main/src/controllers/football.controller.js"
    click DashboardController "https://github.com/javierparradev/casino/blob/main/src/controllers/dashboard.controller.js"
    click APIFootball "https://github.com/javierparradev/casino/blob/main/src/services/apiFootball.Service.js"
    click FixturesService "https://github.com/javierparradev/casino/blob/main/src/services/fixtures.Service.js"
    click UserService "https://github.com/javierparradev/casino/blob/main/src/services/user.Service.js"
    click BetService "https://github.com/javierparradev/casino/blob/main/src/services/bet.service.js"
    click TransactionService "https://github.com/javierparradev/casino/blob/main/src/services/transaction.Service.js"
    click UserModel "https://github.com/javierparradev/casino/blob/main/src/models/user.models.js"
    click BetModel "https://github.com/javierparradev/casino/blob/main/src/models/bet.models.js"
    click TransactionModel "https://github.com/javierparradev/casino/blob/main/src/models/transaction.model.js"
    click AuthMiddleware "https://github.com/javierparradev/casino/blob/main/src/middlewares/auth.middleware.js"
    click ValidateUser "https://github.com/javierparradev/casino/blob/main/src/middlewares/validateUser.js"
    click ValidateLeague "https://github.com/javierparradev/casino/blob/main/src/middlewares/validateLeague.js"
    click ErrorHandler "https://github.com/javierparradev/casino/blob/main/src/middlewares/errorHandler.js"
    click Env "https://github.com/javierparradev/casino/blob/main/src/config/validateEnv.js"
    click DBConn "https://github.com/javierparradev/casino/blob/main/src/config/db.js"
    click RapidCfg "https://github.com/javierparradev/casino/blob/main/src/config/rapidapi.js"
    click JWTUtils "https://github.com/javierparradev/casino/blob/main/src/utils/jwt.js"
    click AppJS "https://github.com/javierparradev/casino/blob/main/src/app.js"
    click IndexJS "https://github.com/javierparradev/casino/blob/main/src/index.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#E8FFE0,stroke:#28a745,color:#28a745
    classDef service fill:#FFF4D6,stroke:#dbab09,color:#8a6d1b
    classDef data fill:#FFE0E0,stroke:#d73a49,color:#d73a49
    classDef database fill:#FFE0E0,stroke:#6f42c1,color:#6f42c1
    classDef external fill:#F0F0F0,stroke:#6a737d,color:#6a737d
    classDef auth fill:#F5E6FF,stroke:#6f42c1,color:#6f42c1
```
