# hitusss/cs-grenade architecture

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

- Interactive diagram: https://gitdiagram.com/hitusss/cs-grenade
- Repository: https://github.com/hitusss/cs-grenade

## Overview

##### Project type and purpose
- This is a full‐stack, server‐rendered React web application built on a Remix-style framework.
- Purpose: allow Counter-Strike 2 players to browse interactive maps, view and submit grenade guides, manage content via an admin dashboard, and handle user authentication/authorization.

##### File structure
- app/components, app/hooks, app/utils, app/models: React UI, custom hooks, utilities, and data-access logic.
- app/routes & routes.ts: file-based routing (loaders/actions serve data, React components render pages).
- server/index.ts + server/dev-server.js: custom Node server entry points for production and development.
- prisma/: database schema, migrations, and seed scripts using Prisma ORM.
- other/: Docker and LiteFS configuration for Fly.io deployment.
- Vite, Tailwind CSS, and TypeScript config files.
- .github/workflows/deploy.yml: CI/CD pipeline.

##### README
- Confirms core features: interactive map navigation, guides, user submissions, and an admin dashboard.
- Instructs local development with pnpm, environment variables, and dev server.

##### Main components & interactions
a. Frontend (Browser + React/Remix)
- entry.client.tsx hydrates on the client.
- React components under app/components drive the UI.
- Tailwind CSS handles styling.
b. Server (Node/Remix runtime)
- entry.server.tsx + server/index.ts run all route loaders/actions.
- app/routes/* define URL endpoints, server logic, and rendering.
c. Database (Prisma + SQLite or Postgres + LiteFS)
- prisma/schema.prisma defines all models (maps, grenades, users, sessions, permissions, reports, etc.).
- LiteFS (in other/litefs.yml) ensures SQLite durability on Fly.io.
d. Authentication & Authorization
- OAuth providers (Discord, GitHub) via app/utils/providers.
- Session management in app/utils/session.server.ts.
- Role/permission checks in app/utils/permissions.server.ts.
e. File & Media Storage
- Static assets served from public/.
- Dynamic images and other resources via routes/resources/*.tsx endpoints.
f. External Services
- Email server (via app/utils/email.server.ts).
- Monitoring/analytics (app/utils/monitoring.client.ts, server/utils/monitoring.ts).
- CI/CD: GitHub Actions → Docker build → Fly.io deployment.
g. Testing
- Playwright E2E (tests/e2e) and unit tests (tests).

##### Architectural patterns & design principles
- File-based routing (Remix convention).
- SSR with client hydration for interactivity.
- MVC-like separation: routes (controllers), models (Prisma ORM), views (React components).
- Feature modularization: group by domain (maps, grenades, admin, auth).
- Use of middleware utilities (auth.server, cache.server, honeypot.server).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Browser (Client)" 
        direction TB
        EntryClient["entry.client.tsx\n(Client Hydration)"]:::frontend
        Components["React UI Components\n(app/components)"]:::frontend
        Styles["Tailwind CSS\n(app/styles/tailwind.css\n& tailwind.config.js)"]:::frontend
        MonClient["Monitoring (client)\n(app/utils/monitoring.client.tsx)"]:::frontend
    end

    %% CDN / Static Assets
    StaticAssets["Static Assets CDN\n(public/)"]:::external

    %% Backend Layer
    subgraph "Remix Server (Node.js)" 
        direction TB
        EntryServer["entry.server.tsx\n(Server Rendering)"]:::backend
        Routes["File-based Routing & Pages\n(app/routes & routes.ts)"]:::backend
        AuthRoutes["Authentication Routes\n(app/routes/_auth+/)"]:::backend
        AdminRoutes["Admin Dashboard Routes\n(app/routes/admin+/)"]:::backend
        FeatureRoutes["Map & Grenade Features\n(app/routes/map+/)"]:::backend
        UtilityRoutes["User & Support Routes\n(app/routes/settings+/\napp/routes/support+/\napp/routes/users+/)"]:::backend
        Providers["OAuth Providers\n(app/utils/providers)"]:::backend
        Session["Session Management\n(app/utils/session.server.ts)"]:::backend
        Permissions["Authorization & Permissions\n(app/utils/permissions.server.ts)"]:::backend
        EmailService["Email Service\n(app/utils/email.server.ts)"]:::external
        MonServer["Monitoring (server)\n(server/utils/monitoring.ts)"]:::backend
    end

    %% Database
    DB["Prisma Database\n(schema.prisma + migrations)"]:::db

    %% External Services
    OAuthExt["OAuth Providers\n(Discord, GitHub)"]:::external
    CI["CI/CD Pipeline\n(.github/workflows/deploy.yml)"]:::external
    DeployConfig["Docker & Fly.io Config\n(other/Dockerfile,\nother/litefs.yml,\nfly.toml)"]:::external

    %% Connections
    EntryClient -->|"hydrates"| Components
    EntryClient -->|"loads styles"| Styles
    Components -->|"monitors"| MonClient
    EntryClient -->|"requests assets"| StaticAssets

    Components -->|"HTTP Requests"| EntryServer
    EntryServer -->|"renders pages via Routes"| Routes
    Routes -->|"loads Auth endpoints"| AuthRoutes
    Routes -->|"loads Admin"| AdminRoutes
    Routes -->|"loads Features"| FeatureRoutes
    Routes -->|"loads User/Support"| UtilityRoutes
    EntryServer -->|"calls ORM"| DB
    EntryServer -->|"OAuth flow"| OAuthExt
    EntryServer -->|"uses Providers"| Providers
    EntryServer -->|"manages sessions"| Session
    EntryServer -->|"checks permissions"| Permissions
    EntryServer -->|"sends emails"| EmailService
    EntryServer -->|"server analytics"| MonServer

    CI -->|"build & deploy"| DeployConfig
    DeployConfig -->|"deploys container"| EntryServer

    %% Click Events
    click EntryClient "https://github.com/hitusss/cs-grenade/blob/main/app/entry.client.tsx"
    click EntryServer "https://github.com/hitusss/cs-grenade/blob/main/app/entry.server.tsx"
    click Components "https://github.com/hitusss/cs-grenade/tree/main/app/components"
    click Styles "https://github.com/hitusss/cs-grenade/blob/main/app/styles/tailwind.css"
    click Styles "https://github.com/hitusss/cs-grenade/blob/main/tailwind.config.js"
    click Routes "https://github.com/hitusss/cs-grenade/tree/main/app/routes"
    click Routes "https://github.com/hitusss/cs-grenade/blob/main/app/routes.ts"
    click AuthRoutes "https://github.com/hitusss/cs-grenade/tree/main/app/routes/_auth+/"
    click AdminRoutes "https://github.com/hitusss/cs-grenade/tree/main/app/routes/admin+/"
    click FeatureRoutes "https://github.com/hitusss/cs-grenade/tree/main/app/routes/map+/"
    click UtilityRoutes "https://github.com/hitusss/cs-grenade/tree/main/app/routes/settings+/"
    click UtilityRoutes "https://github.com/hitusss/cs-grenade/tree/main/app/routes/support+/"
    click UtilityRoutes "https://github.com/hitusss/cs-grenade/tree/main/app/routes/users+/"
    click Providers "https://github.com/hitusss/cs-grenade/blob/main/app/utils/providers/provider.ts"
    click Session "https://github.com/hitusss/cs-grenade/blob/main/app/utils/session.server.ts"
    click Permissions "https://github.com/hitusss/cs-grenade/blob/main/app/utils/permissions.server.ts"
    click EmailService "https://github.com/hitusss/cs-grenade/blob/main/app/utils/email.server.ts"
    click MonClient "https://github.com/hitusss/cs-grenade/blob/main/app/utils/monitoring.client.tsx"
    click MonServer "https://github.com/hitusss/cs-grenade/blob/main/server/utils/monitoring.ts"
    click DB "https://github.com/hitusss/cs-grenade/blob/main/prisma/schema.prisma"
    click DB "https://github.com/hitusss/cs-grenade/tree/main/prisma/migrations/"
    click CI "https://github.com/hitusss/cs-grenade/blob/main/.github/workflows/deploy.yml"
    click DeployConfig "https://github.com/hitusss/cs-grenade/tree/main/other/Dockerfile"
    click DeployConfig "https://github.com/hitusss/cs-grenade/blob/main/other/litefs.yml"
    click DeployConfig "https://github.com/hitusss/cs-grenade/blob/main/fly.toml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#4a90e2,color:#000
    classDef backend fill:#d4edda,stroke:#28a745,color:#000
    classDef db fill:#fff3cd,stroke:#ffc107,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
```
