# nlouis56/racingsetup architecture

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

- Interactive diagram: https://gitdiagram.com/nlouis56/racingsetup
- Repository: https://github.com/nlouis56/racingsetup

## Overview

##### Project Type and Purpose
- This is a Node.js/TypeScript monolithic backend API service (no frontend code present here).
- Purpose: power the “Setup Wizard” web/mobile client—including user auth, teams, setup sharing, and real‐time messaging/notifications.
- Exposes a GraphQL API (via resolvers under `src/*/api`) plus WebSocket endpoints (`websocket.ts`) for real‐time channels and notifications.

##### File Structure
- Top-level:
- `backend/`: contains all server code
- `docker-compose.yml`: orchestrates the API container + PostgreSQL
- `database.sql`: initial schema
- Under `backend/src`:
- `app.ts`: entry point, wires up Express, GraphQL, WebSockets, middleware
- `data-source.ts` + `entities`: TypeORM setup & entity definitions
- Feature modules:
– `auth`: user registration/login (JWT, hashing)
– `channel`: public chat channels
– `message` & `privateMessage`: posting messages, replies
– `notification`: push notifications over WebSocket
– `file`: file‐upload & retrieval
– `utils`: common helpers (hash, JWT)
- Each feature has `api/domain.ts`, `api/resolver.ts`, `repository`, `routes` subfolders.

##### README for Additional Insights
- Mentions a machine‐learning “Setup Wizard”—that likely calls out to an external ML service to suggest vehicle settings.
- Teams & community sharing suggests user‐to‐team ACLs (likely enforced in `ChannelRole`/`ChannelSubscription`).
- Real‐time updates for message/chat and possibly for ML progress.

a. Main Components
- Client Applications (Web, Mobile)
- API Server (Express + GraphQL)
- WebSocket Server (for channels & notifications)
- PostgreSQL Database (hosted in Docker)
- External Machine‐Learning Service (for the wizard)
- (Optional) Object Storage or CDN (for file uploads)
b. Relationships & Data Flow
1. Clients ←GraphQL/HTTP→ API Server
2. API Server ←→ PostgreSQL via TypeORM/Data-Source
3. Clients ←WebSocket→ API Server for real‐time channels & notifications
4. API Server ←HTTP/gRPC→ ML Service (wizard suggestions)
5. API Server ←→ Object Storage for file uploads/downloads
c. Architectural Patterns & Principles
- Modular feature-based code organization (Auth, Channel, Message, etc.)
- Repository Pattern (feature-specific PostgreSQL repo classes)
- JWT-based stateless authentication (middleware layer)
- Real-time pub/sub over WebSockets
- Containerized deployment (Docker, docker-compose)
d. Key Technologies
- Node.js, TypeScript, Express
- GraphQL (resolvers per domain)
- WebSocket (native or socket.io in `websocket.ts`)
- TypeORM + PostgreSQL
- Docker & docker-compose
- JWT & bcrypt (in utils)

##### Detailed Steps
- HTTP/GraphQL layer (app.ts, resolvers)
- Auth middleware (JWT)
- Feature modules: Auth, Channel, Message, File, Notification, PrivateMessage
- WebSocket gateway (websocket.ts)
- Data-Source/ORM layer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        direction TB
        Web["Web Client"]:::client
        Mobile["Mobile Client"]:::client
    end

    %% Docker & Deployment
    subgraph "Docker & docker-compose"
        direction TB
        %% API Server Core
        subgraph "API Server"
            direction TB
            App["app.ts\n(Express, GraphQL, WebSocket)"]:::server
            Config["config.ts"]:::server
            DNS["data-source.ts"]:::server
            Docs["documentation.ts"]:::server

            subgraph "Auth Module"
                direction TB
                AuthDomain["domain.ts"]:::server
                AuthResolver["resolver.ts"]:::server
                AuthRepo["repositoryPostgreSQL.ts"]:::server
                AuthRoutes["routesPost.ts"]:::server
            end

            subgraph "Channel Module"
                direction TB
                ChannelDomain["domain.ts"]:::server
                ChannelResolver["resolver.ts"]:::server
                ChannelRepo["repositoryPostgresql.ts"]:::server
                ChannelRoutes["routesPost.ts"]:::server
            end

            subgraph "Message Module"
                direction TB
                MessageDomain["domain.ts"]:::server
                MessageResolver["resolver.ts"]:::server
                MessageRepo["repositoryPostgresql.ts"]:::server
                MessageRoutes["routes.ts"]:::server
                WSMsg["websocket.ts"]:::server
            end

            subgraph "PrivateMessage Module"
                direction TB
                PMDomain["domain.ts"]:::server
                PMResolver["resolver.ts"]:::server
                PMRepo["repositoryPostgresql.ts"]:::server
                PMRoutes["routes.ts"]:::server
            end

            subgraph "Notification Module"
                direction TB
                NotifDomain["domain.ts"]:::server
                NotifResolver["resolver.ts"]:::server
                WSNotif["websocket.ts"]:::server
            end

            subgraph "File Module"
                direction TB
                FileDomain["domain.ts"]:::server
                FileResolver["resolver.ts"]:::server
                FileRoutes["routes.ts"]:::server
            end

            subgraph "Utils"
                direction TB
                Hash["hash.ts"]:::server
                JWT["jwt.ts"]:::server
            end
        end

        %% Database
        DB["PostgreSQL"]:::db
    end

    %% External Services
    ML["External ML Service"]:::external
    Storage["Object Storage / CDN"]:::external

    %% Relationships
    Web -->|"HTTP/GraphQL"| App
    Mobile -->|"HTTP/GraphQL"| App
    Web -->|"WebSocket (WS)"| WSMsg
    Mobile -->|"WebSocket (WS)"| WSMsg
    App -->|"TypeORM ORM"| DNS
    DNS -->|"SQL Queries"| DB
    App -->|"gRPC/HTTP"| ML
    App -->|"REST API"| Storage

    %% Click Events
    click App "https://github.com/nlouis56/racingsetup/blob/main/backend/src/app.ts"
    click Config "https://github.com/nlouis56/racingsetup/blob/main/backend/src/config.ts"
    click DNS "https://github.com/nlouis56/racingsetup/blob/main/backend/src/data-source.ts"
    click Docs "https://github.com/nlouis56/racingsetup/blob/main/backend/src/documentation.ts"
    click AuthDomain "https://github.com/nlouis56/racingsetup/blob/main/backend/src/auth/api/domain.ts"
    click AuthResolver "https://github.com/nlouis56/racingsetup/blob/main/backend/src/auth/api/resolver.ts"
    click AuthRepo "https://github.com/nlouis56/racingsetup/blob/main/backend/src/auth/repository/repositoryPostgreSQL.ts"
    click AuthRoutes "https://github.com/nlouis56/racingsetup/blob/main/backend/src/auth/routes/routesPost.ts"
    click ChannelDomain "https://github.com/nlouis56/racingsetup/blob/main/backend/src/channel/api/domain.ts"
    click ChannelResolver "https://github.com/nlouis56/racingsetup/blob/main/backend/src/channel/api/resolver.ts"
    click ChannelRepo "https://github.com/nlouis56/racingsetup/blob/main/backend/src/channel/repository/repositoryPostgresql.ts"
    click ChannelRoutes "https://github.com/nlouis56/racingsetup/blob/main/backend/src/channel/routes/routesPost.ts"
    click MessageDomain "https://github.com/nlouis56/racingsetup/blob/main/backend/src/message/api/domain.ts"
    click MessageResolver "https://github.com/nlouis56/racingsetup/blob/main/backend/src/message/api/resolver.ts"
    click MessageRepo "https://github.com/nlouis56/racingsetup/blob/main/backend/src/message/repository/repositoryPostgresql.ts"
    click MessageRoutes "https://github.com/nlouis56/racingsetup/blob/main/backend/src/message/routes/routes.ts"
    click WSMsg "https://github.com/nlouis56/racingsetup/blob/main/backend/src/message/websocket.ts"
    click PMDomain "https://github.com/nlouis56/racingsetup/blob/main/backend/src/privateMessage/api/domain.ts"
    click PMResolver "https://github.com/nlouis56/racingsetup/blob/main/backend/src/privateMessage/api/resolver.ts"
    click PMRepo "https://github.com/nlouis56/racingsetup/blob/main/backend/src/privateMessage/repository/repositoryPostgresql.ts"
    click PMRoutes "https://github.com/nlouis56/racingsetup/blob/main/backend/src/privateMessage/routes/routes.ts"
    click NotifDomain "https://github.com/nlouis56/racingsetup/blob/main/backend/src/notification/api/domain.ts"
    click NotifResolver "https://github.com/nlouis56/racingsetup/blob/main/backend/src/notification/api/resolver.ts"
    click WSNotif "https://github.com/nlouis56/racingsetup/blob/main/backend/src/notification/websocket.ts"
    click FileDomain "https://github.com/nlouis56/racingsetup/blob/main/backend/src/file/api/domain.ts"
    click FileResolver "https://github.com/nlouis56/racingsetup/blob/main/backend/src/file/api/resolver.ts"
    click FileRoutes "https://github.com/nlouis56/racingsetup/blob/main/backend/src/file/routes/routes.ts"
    click Hash "https://github.com/nlouis56/racingsetup/blob/main/backend/src/utils/hash.ts"
    click JWT "https://github.com/nlouis56/racingsetup/blob/main/backend/src/utils/jwt.ts"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef server fill:#E0FFE0,stroke:#28a745,color:#28a745
    classDef db fill:#FFE0B3,stroke:#d97706,color:#d97706
    classDef external fill:#E0E0E0,stroke:#6c757d,color:#6c757d
```
