# jyboy/subject-rankings architecture

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

- Interactive diagram: https://gitdiagram.com/jyboy/subject-rankings
- Repository: https://github.com/jyboy/subject-rankings

## Overview

##### Main Components
a. Frontend (Client):
- Located in the “client” folder.
- Built with React and Redux. It includes UI layout, styling (SCSS), assets (fonts and images), and pages (e.g., subject and university pages).
- Handles user interactions, internationalization, and responsive design for both PC and mobile.

b. Backend (Server):
- Located in the “server” folder.
- Developed with TypeScript and provides API endpoints for subjects and universities.
- Manages data access (e.g., interacting with an SQLite3 database found in “server/data/db.sqlite3”) and includes modules for models, routes, and types.
- Incorporates CI/CD and testing (includes Vitest configurations, tests for models and routes, and linting/formatting settings).
- Configuration and deployment settings are further supported by files such as tsconfig.json, wrangler.toml (hinting at Cloudflare services), and environment/type definition files.

c. Database:
- The backend includes an SQLite3 database used for storing and retrieving subject ranking data.

d. External and Supporting Services:
- Cloudflare: As indicated by the “wrangler.toml” and the provided Cloudflare badge, the application leverages Cloudflare’s deployment/CDN services.
- CI/CD and Testing: GitHub Actions (workflows in .github/workflows) are used for automated testing and deployment. Cypress tests in the client verify end-to-end functionality.

##### Relationships and Interactions
- The client sends API calls to the backend server to retrieve or update ranking data.
- The server interacts with the SQLite database for persistent storage.
- Users’ actions on the UI flow through the React components (with Redux managing state) and eventually hit the backend API, forming a clear separation between frontend presentation and backend business logic/data handling.
- Testing pipelines (unit tests, integration tests, and E2E tests) help ensure that both components interact correctly.
- CI/CD workflows tie together development, testing, and deployment.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly divides the project into a client (presentation/UI) and server (API/data) layer.
- MVC-like or API-Driven Architecture (for the backend): Routes and models are separated, suggesting that the server adheres to a modular design for handling data operations and HTTP endpoints.
- Responsive and Internationalized UI: The client is built with entry points and configuration for languages and device responsiveness.
- Emphasis on automated Quality Assurance (using ESLint, Prettier, testing scripts, and GitHub workflows).

##### Including Relevant Technologies, Frameworks, and Libraries
- Client: React, Redux, Cypress (for E2E testing), SCSS, and related front-end tooling.
- Server: Node.js, TypeScript, SQLite (as a lightweight DB), and Cloudflare services (suggested by wrangler configuration).
- CI/CD: GitHub workflows, possibly integrated with Cloudflare Pages for deployment.
- Testing: Vitest and Cypress for establishing strong testing coverage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend (React Client)"
        RC["React Client"]:::frontend
        SP["Subject Page"]:::frontend
        UP["University Page"]:::frontend
        RM["State Management (Redux)"]:::frontend
        RU["Client Utilities & Config"]:::frontend
        RA["Assets (Media)"]:::frontend
        RS["Styles (SCSS)"]:::frontend
        CT["Cypress E2E Tests"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend (API Server)"
        BS["API Server"]:::backend
        AI["API & Initialization"]:::backend
        SM["Server Models"]:::backend
        SR["Server Routes"]:::backend
        ST["Server Types & Utils"]:::backend
        BT["Backend Tests (Vitest & Others)"]:::backend
    end

    %% Other Components
    DB(("SQLite Database")):::database
    CF["Cloudflare Deployment"]:::external
    CI["CI/CD Pipelines"]:::ci

    %% Relationships
    RC -->|"HTTP_API_calls"| BS
    BS -->|"Data_queries"| DB
    CI -->|"Deploy_Test"| RC
    CI -->|"Deploy_Test"| BS
    CF -->|"Deploy/CDN"| BS
    CF -->|"Deploy/CDN"| RC

    %% Additional internal frontend links
    RC --> SP
    RC --> UP
    RC --> RM
    RC --> RU
    RC --> RA
    RC --> RS
    RC --> CT

    %% Additional internal backend links
    BS --> AI
    BS --> SM
    BS --> SR
    BS --> ST
    BS --> BT

    %% Click Events for Frontend
    click RC "https://github.com/jyboy/subject-rankings/tree/master/client/"
    click SP "https://github.com/jyboy/subject-rankings/tree/master/client/src/pages/subject"
    click UP "https://github.com/jyboy/subject-rankings/tree/master/client/src/pages/university"
    click RM "https://github.com/jyboy/subject-rankings/tree/master/client/src/states/"
    click RU "https://github.com/jyboy/subject-rankings/tree/master/client/src/utils/"
    click RA "https://github.com/jyboy/subject-rankings/tree/master/client/src/assets/"
    click RS "https://github.com/jyboy/subject-rankings/tree/master/client/src/styles/"
    click CT "https://github.com/jyboy/subject-rankings/tree/master/client/cypress/"

    %% Click Events for Backend
    click BS "https://github.com/jyboy/subject-rankings/tree/master/server/"
    click AI "https://github.com/jyboy/subject-rankings/blob/master/server/src/index.ts"
    click SM "https://github.com/jyboy/subject-rankings/tree/master/server/src/models/"
    click SR "https://github.com/jyboy/subject-rankings/tree/master/server/src/routes/"
    click ST "https://github.com/jyboy/subject-rankings/tree/master/server/src/types/"
    click BT "https://github.com/jyboy/subject-rankings/blob/master/server/vitest.config.ts"

    %% Click Events for Database, Cloudflare and CI/CD
    click DB "https://github.com/jyboy/subject-rankings/blob/master/server/data/db.sqlite3"
    click CF "https://github.com/jyboy/subject-rankings/blob/master/server/wrangler.toml"
    click CI "https://github.com/jyboy/subject-rankings/tree/master/.github/workflows/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef ci fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
