# redpwn/rctf architecture

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

- Interactive diagram: https://gitdiagram.com/redpwn/rctf
- Repository: https://github.com/redpwn/rctf

## Overview

##### Main Components Identification
The system has several key components that should be represented:

a. Client-Side (Frontend):
- Modules:
- Authentication (auth.js)
- Challenges management
- Scoreboard
- User/Profile management
- Admin interface

b. Server-Side (Backend):
- In the middle layer
- Core services:
- API Gateway
- Authentication Service
- Challenge Management
- Leaderboard Service
- User Management
- Admin Service

c. Providers Layer:
- At the bottom
- Provider interfaces:
- Challenge Providers
- Email Providers (Mailgun, SES, SMTP)
- Upload Providers (GCS, Local)

d. Data Layer:
- At the bottom
- Include:
- Database (PostgreSQL)
- Cache System
- File Storage

##### Component Relationships

- Double lines: Data flow

##### Specific Implementation Details

Key architectural features:
**Frontend (Preact.js)**
- ↓
**API Layer (Express.js)**
- ↓
**Service Layer**
- ↓
**Provider Interfaces**
- ↓
**Infrastructure (DB/Storage)**

##### Important Elements to Highlight

a. Security Features:
- Authentication flow
- Rate limiting
- ReCAPTCHA integration
- CTFtime integration

b. Scalability Components:
- Caching system
- Database migrations
- Load balancing considerations

**┌─ Client Layer ─────────────────┐**
- (Web Interface / Admin Panel)  │
- API Gateway Layer ────────────┤
- (REST APIs / WebSocket)        │
- Service Layer ───────────────-┤
- (Core Business Logic)          │
- Provider Layer ──────────────-┤
- (Extensible Interfaces)        │
- Data Layer ──────────────────-┘

##### Special Notes

- Modular nature of the providers
- Separation between admin and user flows
- Integration points with external services
- Caching mechanisms and their scope

Remember to:
- Use a consistent style
- Version information
- Document any assumptions

This system design should capture both the high-level architecture and the important implementation details while remaining clear and understandable.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef provider fill:#f1c40f,stroke:#f39c12,color:black
    classDef data fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        FAuth["Authentication"]:::frontend
        FChal["Challenges"]:::frontend
        FScore["Scoreboard"]:::frontend
        FProf["Profile"]:::frontend
        FAdmin["Admin Interface"]:::frontend
    end

    %% API Gateway Layer
    APIGateway["API Gateway"]:::backend

    %% Backend Services Layer
    subgraph Services
        AuthService["Authentication Service"]:::backend
        ChallService["Challenge Management"]:::backend
        LeaderService["Leaderboard Service"]:::backend
        UserService["User Management"]:::backend
        AdminService["Admin Service"]:::backend
    end

    %% Core Services Layer
    subgraph Core
        AuthCore["Auth Core"]:::backend
        ChallCore["Challenge Core"]:::backend
        EmailCore["Email Core"]:::backend
        UploadCore["Upload Core"]:::backend
    end

    %% Provider Layer
    subgraph Providers
        ChallProvider["Challenge Providers"]:::provider
        subgraph EmailProviders["Email Providers"]
            Mailgun["Mailgun"]:::provider
            SES["SES"]:::provider
            SMTP["SMTP"]:::provider
        end
        subgraph UploadProviders["Upload Providers"]
            GCS["GCS"]:::provider
            Local["Local Storage"]:::provider
        end
    end

    %% Data Layer
    subgraph Data
        DB[(PostgreSQL)]:::data
        Cache[(Cache System)]:::data
    end

    %% Frontend to API Gateway connections
    FAuth --> APIGateway
    FChal --> APIGateway
    FScore --> APIGateway
    FProf --> APIGateway
    FAdmin --> APIGateway

    %% API Gateway to Services connections
    APIGateway --> AuthService
    APIGateway --> ChallService
    APIGateway --> LeaderService
    APIGateway --> UserService
    APIGateway --> AdminService

    %% Services to Core connections
    AuthService --> AuthCore
    ChallService --> ChallCore
    UserService --> AuthCore
    AdminService --> ChallCore

    %% Core to Providers connections
    ChallCore --> ChallProvider
    EmailCore --> EmailProviders
    UploadCore --> UploadProviders

    %% Core to Data connections
    AuthCore --> DB
    ChallCore --> DB
    AuthCore --> Cache
    ChallCore --> Cache

    %% Click events for component mapping
    click FAuth "https://github.com/redpwn/rctf/blob/master/client/src/api/auth.js"
    click FChal "https://github.com/redpwn/rctf/blob/master/client/src/api/challenges.js"
    click FScore "https://github.com/redpwn/rctf/blob/master/client/src/api/scoreboard.js"
    click FProf "https://github.com/redpwn/rctf/blob/master/client/src/api/profile.js"
    click FAdmin "https://github.com/redpwn/rctf/tree/master/client/src/routes/admin/"
    click AuthService "https://github.com/redpwn/rctf/tree/master/server/api/auth/"
    click ChallService "https://github.com/redpwn/rctf/tree/master/server/api/challs/"
    click LeaderService "https://github.com/redpwn/rctf/tree/master/server/api/leaderboard/"
    click UserService "https://github.com/redpwn/rctf/tree/master/server/api/users/"
    click AdminService "https://github.com/redpwn/rctf/tree/master/server/api/admin/"
    click ChallProvider "https://github.com/redpwn/rctf/tree/master/server/providers/challenges/"
    click Mailgun "https://github.com/redpwn/rctf/tree/master/server/providers/emails/mailgun/"
    click SES "https://github.com/redpwn/rctf/tree/master/server/providers/emails/ses/"
    click SMTP "https://github.com/redpwn/rctf/tree/master/server/providers/emails/smtp/"
    click GCS "https://github.com/redpwn/rctf/tree/master/server/providers/uploads/gcs/"
    click Local "https://github.com/redpwn/rctf/tree/master/server/providers/uploads/local/"
    click DB "https://github.com/redpwn/rctf/tree/master/server/database/"
    click Cache "https://github.com/redpwn/rctf/tree/master/server/cache/"
    click AuthCore "https://github.com/redpwn/rctf/tree/master/server/auth/"
    click ChallCore "https://github.com/redpwn/rctf/tree/master/server/challenges/"
    click EmailCore "https://github.com/redpwn/rctf/tree/master/server/email/"
    click UploadCore "https://github.com/redpwn/rctf/tree/master/server/uploads/"
```
