# matteobira/jss architecture

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

- Interactive diagram: https://gitdiagram.com/matteobira/jss
- Repository: https://github.com/matteobira/jss

## Overview

##### Project type and purpose
- This is a full-stack JavaScript application implementing the Italian card game “Scopa” as a web app.
- The frontend is a static web client (HTML/CSS/JS) served from the public folder; the backend is a Node.js/Express monolith exposing RESTful game APIs; there’s also a simple database initialization script.

##### File structure
Top-level
- .env.example / .gitignore – environment and ignore rules
- package.json / package-lock.json – Node.js dependencies and scripts
- project_structure.md – (likely docs on logical layout)
- scripts/create-db.js – DB schema/setup script
- README.md – project overview

public/ (frontend)
- index.html, style.css, script.js – main UI and styling
- assets/, img/, music/, soundEffects/ – static media resources
- pdf/guide.pdf – game guide

server/ (backend)
- server.js – entry point, Express app setup
- API/ – route handlers (addAdmin.js, index.js)
- Card/, Mazzo/, Partita/, Player/ – domain logic modules, each with its own index.js

##### Key insights from README
- Pure-JavaScript implementation of Scopa
- No mention of external services beyond user’s browser and your Node.js server
- Game rules and flow but no extra microservices or message brokers

##### Main components
a. Client (Browser)
– Static files: index.html, script.js, style.css, media assets
– UI logic: rendering the table, cards, user interactions, sound playback
b. Web Server (Node.js/Express)
– HTTP(S) server (server.js)
– API Layer (server/API) handling requests (e.g., startGame, playCard, addAdmin)
– Domain Modules (server/Card, server/Mazzo, server/Partita, server/Player) encapsulating game rules and state transitions
c. Database (SQL or NoSQL)
– Initialized by scripts/create-db.js
– Persists users, admin flags, game sessions, scores, etc.
d. (Optional) CI/CD
– GitHub Actions workflow in .github/workflows/test.yml for automated tests

##### Relationships and interactions
- Browser → HTTP → Express API endpoints
- Express endpoints → domain modules → database
- Database → Express (read/write game state) → Browser (updated UI)
- All static-asset requests → Express static middleware → public/

##### Architectural patterns and design principles
- Monolithic, modularized by domain (Card, Mazzo, Partita, Player)
- Clear separation of concerns:
– Static assets vs. dynamic API
– Route handling vs. business logic
- Single origin for frontend and backend (no separate CDN or microservices)

##### Technologies and frameworks
- Node.js & Express for server
- Vanilla JavaScript for frontend (no framework)
- Relational or document database accessed via create-db.js (custom setup)
- GitHub Actions for CI tests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser (UI)"]:::frontend
        S1["index.html"]:::frontend
        S2["style.css"]:::frontend
        S3["script.js"]:::frontend
        S4["assets/"]:::frontend
        S5["img/"]:::frontend
        S6["music/"]:::frontend
        S7["soundEffects/"]:::frontend
        S8["guide.pdf"]:::frontend
    end

    %% Server Layer
    subgraph "Server Layer"
        Srv["server.js"]:::backend
        subgraph "API Layer"
            API1["index.js"]:::backend
            API2["addAdmin.js"]:::backend
        end
        subgraph "Domain Modules"
            D1["Card"]:::backend
            D2["Mazzo"]:::backend
            D3["Partita"]:::backend
            D4["Player"]:::backend
        end
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        db[(Database)]:::database
        script["create-db.js"]:::backend
    end

    %% CI/CD
    subgraph "CI/CD"
        CI["test.yml"]:::ci
    end

    %% Relationships
    Browser -->|"loads"| S1
    Browser -->|"loads"| S2
    Browser -->|"loads"| S3
    Browser -->|"loads"| S4
    Browser -->|"loads"| S5
    Browser -->|"loads"| S6
    Browser -->|"loads"| S7
    Browser -->|"loads"| S8
    Browser -->|"HTTP JSON"| Srv

    Srv -->|"serves static"| S1
    Srv -->|"serves static"| S2
    Srv -->|"serves static"| S3
    Srv -->|"serves static"| S4
    Srv -->|"serves static"| S5
    Srv -->|"serves static"| S6
    Srv -->|"serves static"| S7
    Srv -->|"serves static"| S8

    Srv --> API1
    Srv --> API2

    API1 --> D1
    API1 --> D2
    API1 --> D3
    API1 --> D4

    API2 --> D4

    D1 --> db
    D2 --> db
    D3 --> db
    D4 --> db

    script --> db

    CI --- Srv

    %% Click Events
    click S1 "https://github.com/matteobira/jss/blob/main/public/index.html"
    click S2 "https://github.com/matteobira/jss/blob/main/public/style.css"
    click S3 "https://github.com/matteobira/jss/blob/main/public/script.js"
    click S4 "https://github.com/matteobira/jss/tree/main/public/assets/"
    click S5 "https://github.com/matteobira/jss/tree/main/public/img/"
    click S6 "https://github.com/matteobira/jss/tree/main/public/music/"
    click S7 "https://github.com/matteobira/jss/tree/main/public/soundEffects/"
    click S8 "https://github.com/matteobira/jss/blob/main/public/pdf/guide.pdf"
    click Srv "https://github.com/matteobira/jss/blob/main/server/server.js"
    click API1 "https://github.com/matteobira/jss/blob/main/server/API/index.js"
    click API2 "https://github.com/matteobira/jss/blob/main/server/API/addAdmin.js"
    click D1 "https://github.com/matteobira/jss/blob/main/server/Card/index.js"
    click D2 "https://github.com/matteobira/jss/blob/main/server/Mazzo/index.js"
    click D3 "https://github.com/matteobira/jss/blob/main/server/Partita/index.js"
    click D4 "https://github.com/matteobira/jss/blob/main/server/Player/index.js"
    click script "https://github.com/matteobira/jss/blob/main/scripts/create-db.js"
    click CI "https://github.com/matteobira/jss/blob/main/.github/workflows/test.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef database fill:#FFD700,stroke:#333,stroke-width:1px
    classDef ci fill:#D3D3D3,stroke:#333,stroke-width:1px
```
