# mbrizic/ratethegame architecture

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

- Interactive diagram: https://gitdiagram.com/mbrizic/ratethegame
- Repository: https://github.com/mbrizic/ratethegame

## Overview

##### Main System Components

A. Client Layer
- Server-Side Rendered UI (highlight that there's no client-side JavaScript)
- Main UI components structure (/ui directory)
- Pages (login, register, events, sports)
- Components (cards, forms, lists)
- Core UI services (CSS, HTML operators)

B. Application Layer
- Core Services
- Authentication Service
- Cache Service (emphasize in-memory caching of domain models)
- Mail Service
- Analytics Service
- File Service

- Domain Services
- Sports Service
- Events Service
- Users Service
- Notifications Service
- Ratings Service

C. Data Layer
- PostgreSQL Database
- Sequelize ORM
- Domain Models
- Sports
- Events
- Users
- Event Ratings
- User Settings
- User Sport Subscriptions

##### Key Architectural Patterns to Highlight

- MVC-like pattern:
- Controllers (/server/*/*.controller.ts)
- Models (/database/models)
- Views (/ui/component, /ui/page)

- Caching mechanism:
- Relationship between cached domain models
- Cache boundaries

##### Specific Elements

- Core Infrastructure
- Error Handling
- Middleware
- Authentication
- Input Validation
- Route Handling

- Business Logic Layer
- Sports Management
- Event Rating System
- User Management
- Notification System

Key flows:
- User request → Server → Cache/Database
- Authentication flow
- Rating submission flow
- Cache invalidation flow
- Notification dispatch flow

##### Important Notes

Callouts for:
- Cache invalidation complexity
- No client-side JavaScript
- Custom templating engine
- Future recommendation engine integration points
- Potential scaling considerations

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef domain fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#e74c3c,stroke:#c0392b,color:white
    classDef cache fill:#9b59b6,stroke:#8e44ad,color:white
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        UI_Pages["Pages"]
        UI_Components["Components"]
        UI_Core["Core UI Services"]
        UI_Styles["Styles"]
    end

    %% Core Services Layer
    subgraph CoreServices["Core Services Layer"]
        Auth["Authentication Service"]
        Cache["Cache Service"]
        Mail["Mail Service"]
        Analytics["Analytics Service"]
        File["File Service"]
    end

    %% Domain Services Layer
    subgraph DomainServices["Domain Services Layer"]
        Sports["Sports Service"]
        Events["Events Service"]
        Users["Users Service"]
        Notifications["Notifications Service"]
        Ratings["Ratings Service"]
    end

    %% Infrastructure Layer
    subgraph Infrastructure["Infrastructure Layer"]
        ErrorHandling["Error Handling"]
        Middleware["Middleware"]
        InputValidation["Input Validation"]
        RouteHandling["Route Handling"]
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        Database[(PostgreSQL)]
        subgraph Models["Domain Models"]
            SportsModel["Sports"]
            EventsModel["Events"]
            UsersModel["Users"]
            RatingsModel["Event Ratings"]
            SettingsModel["User Settings"]
            SubscriptionsModel["Sport Subscriptions"]
        end
    end

    %% Relationships
    ClientLayer --> CoreServices
    ClientLayer --> DomainServices
    CoreServices --> Infrastructure
    DomainServices --> Infrastructure
    Infrastructure --> DataLayer
    Cache -.-> Models
    
    %% Click Events
    click UI_Pages "https://github.com/mbrizic/ratethegame/tree/master//ui/page"
    click UI_Components "https://github.com/mbrizic/ratethegame/tree/master//ui/component"
    click UI_Core "https://github.com/mbrizic/ratethegame/tree/master//ui/core"
    click UI_Styles "https://github.com/mbrizic/ratethegame/tree/master//ui/style"
    click Auth "https://github.com/mbrizic/ratethegame/tree/master//server/auth"
    click Cache "https://github.com/mbrizic/ratethegame/tree/master//server/core/cache"
    click Mail "https://github.com/mbrizic/ratethegame/blob/master//server/core/mail.service.ts"
    click Analytics "https://github.com/mbrizic/ratethegame/blob/master//server/core/analytics-event.service.ts"
    click File "https://github.com/mbrizic/ratethegame/blob/master//server/core/file.service.ts"
    click Sports "https://github.com/mbrizic/ratethegame/blob/master//server/sports/sports.service.ts"
    click Events "https://github.com/mbrizic/ratethegame/blob/master//server/events/events.service.ts"
    click Users "https://github.com/mbrizic/ratethegame/blob/master//server/users/users.service.ts"
    click Notifications "https://github.com/mbrizic/ratethegame/blob/master//server/notifications/notifications.service.ts"
    click SportsModel "https://github.com/mbrizic/ratethegame/blob/master//database/models/sports.ts"
    click EventsModel "https://github.com/mbrizic/ratethegame/blob/master//database/models/events.ts"
    click UsersModel "https://github.com/mbrizic/ratethegame/blob/master//database/models/users.ts"
    click RatingsModel "https://github.com/mbrizic/ratethegame/blob/master//database/models/event_rating.ts"
    click SettingsModel "https://github.com/mbrizic/ratethegame/blob/master//database/models/user_settings.ts"
    click SubscriptionsModel "https://github.com/mbrizic/ratethegame/blob/master//database/models/user_sport_subscriptions.ts"
    click ErrorHandling "https://github.com/mbrizic/ratethegame/tree/master//server/core/exceptions"
    click Middleware "https://github.com/mbrizic/ratethegame/tree/master//server/core/middleware"
    click InputValidation "https://github.com/mbrizic/ratethegame/blob/master//server/core/validation.ts"
    click RouteHandling "https://github.com/mbrizic/ratethegame/blob/master//server/core/route.interface.ts"

    %% Style Applications
    class UI_Pages,UI_Components,UI_Core,UI_Styles ui
    class Auth,Cache,Mail,Analytics,File core
    class Sports,Events,Users,Notifications,Ratings domain
    class Database,Models,SportsModel,EventsModel,UsersModel,RatingsModel,SettingsModel,SubscriptionsModel data
    class ErrorHandling,Middleware,InputValidation,RouteHandling infra
```
