Skip to content

Commit 99abb63

Browse files
committed
docs: update readme and rswag infos
update readme update rswag to avoid deprecated warning add get token script
1 parent fbf0482 commit 99abb63

4 files changed

Lines changed: 356 additions & 17 deletions

File tree

README.md

Lines changed: 286 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,114 @@
55
[![Rails Version](https://img.shields.io/badge/rails-7.2-CC342D?logo=rubyonrails)](https://rubyonrails.org/)
66
[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-14+-blue.svg?logo=postgresql)](https://www.postgresql.org/)
77
[![Redis](https://img.shields.io/badge/Redis-6+-red.svg?logo=redis)](https://redis.io/)
8+
[![Swagger](https://img.shields.io/badge/API-Swagger-85EA2D?logo=swagger)](http://localhost:3333/api-docs)
89
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](http://creativecommons.org/licenses/by-nc-sa/4.0/)
910

1011
# ProStaff API
1112

12-
Ruby on Rails API for the ProStaff.gg esports team management platform.
13-
14-
## Quick Start
13+
> Ruby on Rails API for the ProStaff.gg esports team management platform.
14+
15+
<details>
16+
<summary>Key Features (Click to show details) </summary>
17+
18+
- **JWT Authentication** with refresh tokens and token blacklisting
19+
- **Interactive Swagger Documentation** (107 endpoints documented)
20+
- **Riot Games API Integration** for automatic match import and player sync
21+
- **Advanced Analytics** (KDA trends, champion pools, vision control, etc.)
22+
- **Scouting System** with talent discovery and watchlist management
23+
- **VOD Review System** with timestamp annotations
24+
-**Schedule Management** for matches, scrims, and team events
25+
- **Goal Tracking** for team and player performance objectives
26+
- **Background Jobs** with Sidekiq for async processing
27+
-**Security Hardened** (OWASP Top 10, Brakeman, ZAP tested)
28+
- **High Performance** (p95: ~500ms, with cache: ~50ms)
29+
-**Modular Monolith** architecture for scalability
30+
</details>
31+
32+
## Table of Contents
33+
34+
- [Quick Start](#quick-start)
35+
- [Technology Stack](#technology-stack)
36+
- [Architecture](#architecture)
37+
- [Setup](#setup)
38+
- [Development Tools](#️-development-tools)
39+
- [API Documentation](#-api-documentation)
40+
- [Testing](#-testing)
41+
- [Performance & Load Testing](#-performance--testing)
42+
- [Security](#security-testing-owasp)
43+
- [Deployment](#deployment)
44+
- [Contributing](#contributing)
45+
- [License](#license)
46+
47+
<details>
48+
<summary> Quick Start (Click to show details) </summary>
49+
50+
### Option 1: With Docker (Recommended)
1551

1652
```bash
53+
# Start all services (API, PostgreSQL, Redis, Sidekiq)
1754
docker compose up -d
1855

56+
# Create test user
1957
docker exec prostaff-api-api-1 rails runner scripts/create_test_user.rb
2058

59+
# Get JWT token for testing
60+
./scripts/get-token.sh
61+
62+
# Access API docs
63+
open http://localhost:3333/api-docs
64+
65+
# Run smoke tests
2166
./load_tests/run-tests.sh smoke local
67+
68+
# Run security scan
2269
./security_tests/scripts/brakeman-scan.sh
2370
```
2471

72+
### Option 2: Without Docker (Local Development)
73+
74+
```bash
75+
# Install dependencies
76+
bundle install
77+
78+
# Generate secrets
79+
./scripts/generate_secrets.sh # Copy output to .env
80+
81+
# Setup database
82+
rails db:create db:migrate db:seed
83+
84+
# Start Redis (in separate terminal)
85+
redis-server
86+
87+
# Start Sidekiq (in separate terminal)
88+
bundle exec sidekiq
89+
90+
# Start Rails server
91+
rails server -p 3333
92+
93+
# Get JWT token for testing
94+
./scripts/get-token.sh
95+
96+
# Access API docs
97+
open http://localhost:3333/api-docs
98+
```
99+
100+
**API will be available at:** `http://localhost:3333`
101+
**Swagger Docs:** `http://localhost:3333/api-docs`
102+
</details>
103+
25104
## Technology Stack
26105

27106
- **Ruby**: 3.4.5
28-
- **Rails**: 7.1+ (API-only mode)
107+
- **Rails**: 7.2.0 (API-only mode)
29108
- **Database**: PostgreSQL 14+
30-
- **Authentication**: JWT
109+
- **Authentication**: JWT (with refresh tokens)
31110
- **Background Jobs**: Sidekiq
32111
- **Caching**: Redis (port 6380)
33-
- **Testing**: RSpec, k6, OWASP ZAP
112+
- **API Documentation**: Swagger/OpenAPI 3.0 (rswag)
113+
- **Testing**: RSpec, Integration Specs, k6, OWASP ZAP
114+
- **Authorization**: Pundit
115+
- **Serialization**: Blueprinter
34116

35117
## Architecture
36118

@@ -291,7 +373,78 @@ rails server
291373

292374
The API will be available at `http://localhost:3333`
293375

294-
## API Documentation
376+
## Development Tools
377+
378+
### Generate Secrets
379+
380+
Generate secure secrets for your `.env` file:
381+
382+
```bash
383+
./scripts/generate_secrets.sh
384+
```
385+
386+
This will generate:
387+
- `SECRET_KEY_BASE` - Rails secret key
388+
- `JWT_SECRET_KEY` - JWT signing key
389+
390+
### Get JWT Token (for API testing)
391+
392+
Generate a JWT token for testing the API:
393+
394+
```bash
395+
./scripts/get-token.sh
396+
```
397+
398+
This will:
399+
1. Create or find a test user (`test@prostaff.gg`)
400+
2. Generate a valid JWT token
401+
3. Show instructions on how to use it
402+
403+
**Quick usage:**
404+
```bash
405+
# Export to environment variable
406+
export BEARER_TOKEN=$(./scripts/get-token.sh | grep -oP 'eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*')
407+
408+
# Use in curl
409+
curl -H "Authorization: Bearer $BEARER_TOKEN" http://localhost:3333/api/v1/players
410+
```
411+
412+
**Custom credentials:**
413+
```bash
414+
TEST_EMAIL="admin@example.com" TEST_PASSWORD="MyPass123!" ./scripts/get-token.sh
415+
```
416+
<details>
417+
<summary> 📚 API Documentation (Click to show details) </summary>
418+
419+
### Interactive Documentation (Swagger UI)
420+
421+
The API provides interactive documentation powered by Swagger/OpenAPI 3.0:
422+
423+
**Access the docs:**
424+
```
425+
http://localhost:3333/api-docs
426+
```
427+
428+
**Features:**
429+
- ✅ Try out endpoints directly from the browser
430+
- ✅ See request/response schemas
431+
- ✅ Authentication support (Bearer token)
432+
- ✅ Complete parameter documentation
433+
- ✅ Example requests and responses
434+
435+
### Generating/Updating Documentation
436+
437+
The Swagger documentation is automatically generated from RSpec integration tests:
438+
439+
```bash
440+
# Run integration specs and generate Swagger docs
441+
bundle exec rake rswag:specs:swaggerize
442+
443+
# Or run specs individually
444+
bundle exec rspec spec/integration/
445+
```
446+
447+
The generated documentation file is located at `swagger/v1/swagger.yaml`.
295448

296449
### Base URL
297450
```
@@ -306,6 +459,29 @@ All endpoints (except auth endpoints) require a Bearer token in the Authorizatio
306459
Authorization: Bearer <your-jwt-token>
307460
```
308461

462+
**Token Details:**
463+
- **Access Token**: Expires in 24 hours (configurable via `JWT_EXPIRATION_HOURS`)
464+
- **Refresh Token**: Expires in 7 days
465+
- **Token Type**: Bearer (JWT)
466+
467+
**Getting a token:**
468+
```bash
469+
# Option 1: Use the script
470+
./scripts/get-token.sh
471+
472+
# Option 2: Login via API
473+
curl -X POST http://localhost:3333/api/v1/auth/login \
474+
-H "Content-Type: application/json" \
475+
-d '{"email":"test@prostaff.gg","password":"Test123!@#"}'
476+
```
477+
478+
**Refreshing a token:**
479+
```bash
480+
curl -X POST http://localhost:3333/api/v1/auth/refresh \
481+
-H "Content-Type: application/json" \
482+
-d '{"refresh_token":"your-refresh-token"}'
483+
```
484+
309485
### Authentication Endpoints
310486

311487
- `POST /auth/register` - Register new organization and admin user
@@ -345,16 +521,113 @@ Authorization: Bearer <your-jwt-token>
345521
- `POST /scouting/players` - Add scouting target
346522

347523
#### Analytics
348-
- `GET /analytics/performance` - Player performance data
349-
- `GET /analytics/champions/:player_id` - Champion statistics
350-
- `GET /analytics/kda-trend/:player_id` - KDA trend analysis
524+
- `GET /analytics/performance` - Team performance analytics
525+
- `GET /analytics/team-comparison` - Compare all players
526+
- `GET /analytics/champions/:player_id` - Champion pool statistics
527+
- `GET /analytics/kda-trend/:player_id` - KDA trend over time
528+
- `GET /analytics/laning/:player_id` - Laning phase performance
529+
- `GET /analytics/teamfights/:player_id` - Teamfight performance
530+
- `GET /analytics/vision/:player_id` - Vision control statistics
531+
532+
#### Schedules
533+
- `GET /schedules` - List all scheduled events
534+
- `GET /schedules/:id` - Get schedule details
535+
- `POST /schedules` - Create new event
536+
- `PATCH /schedules/:id` - Update event
537+
- `DELETE /schedules/:id` - Delete event
538+
539+
#### Team Goals
540+
- `GET /team-goals` - List all goals
541+
- `GET /team-goals/:id` - Get goal details
542+
- `POST /team-goals` - Create new goal
543+
- `PATCH /team-goals/:id` - Update goal progress
544+
- `DELETE /team-goals/:id` - Delete goal
545+
546+
#### VOD Reviews
547+
- `GET /vod-reviews` - List VOD reviews
548+
- `GET /vod-reviews/:id` - Get review details
549+
- `POST /vod-reviews` - Create new review
550+
- `PATCH /vod-reviews/:id` - Update review
551+
- `DELETE /vod-reviews/:id` - Delete review
552+
- `GET /vod-reviews/:id/timestamps` - List timestamps
553+
- `POST /vod-reviews/:id/timestamps` - Create timestamp
554+
- `PATCH /vod-timestamps/:id` - Update timestamp
555+
- `DELETE /vod-timestamps/:id` - Delete timestamp
556+
557+
#### Riot Data
558+
- `GET /riot-data/champions` - Get champions ID map
559+
- `GET /riot-data/champions/:key` - Get champion details
560+
- `GET /riot-data/all-champions` - Get all champions data
561+
- `GET /riot-data/items` - Get all items
562+
- `GET /riot-data/summoner-spells` - Get summoner spells
563+
- `GET /riot-data/version` - Get current Data Dragon version
564+
- `POST /riot-data/clear-cache` - Clear Data Dragon cache (owner only)
565+
- `POST /riot-data/update-cache` - Update Data Dragon cache (owner only)
566+
567+
#### Riot Integration
568+
- `GET /riot-integration/sync-status` - Get sync status for all players
569+
570+
**For complete endpoint documentation with request/response examples, visit `/api-docs`**
571+
572+
</details>
573+
574+
## 🧪 Testing
575+
576+
### Unit & Request Tests
577+
578+
Run the complete test suite:
579+
580+
```bash
581+
bundle exec rspec
582+
```
583+
584+
Run specific test types:
585+
```bash
586+
# Unit tests (models, services)
587+
bundle exec rspec spec/models
588+
bundle exec rspec spec/services
351589

352-
## Testing
590+
# Request tests (controllers)
591+
bundle exec rspec spec/requests
592+
593+
# Integration tests (Swagger documentation)
594+
bundle exec rspec spec/integration
595+
```
353596

354-
Run the test suite:
597+
### Integration Tests (Swagger Documentation)
598+
599+
Integration tests serve dual purpose:
600+
1. **Test API endpoints** with real HTTP requests
601+
2. **Generate Swagger documentation** automatically
355602

356603
```bash
357-
bundle exec rspec
604+
# Run integration tests and generate Swagger docs
605+
bundle exec rake rswag:specs:swaggerize
606+
607+
# Run specific integration spec
608+
bundle exec rspec spec/integration/players_spec.rb
609+
```
610+
611+
**Current coverage:**
612+
- ✅ Authentication (8 endpoints)
613+
- ✅ Players (9 endpoints)
614+
- ✅ Matches (11 endpoints)
615+
- ✅ Scouting (10 endpoints)
616+
- ✅ Schedules (8 endpoints)
617+
- ✅ Team Goals (8 endpoints)
618+
- ✅ VOD Reviews (11 endpoints)
619+
- ✅ Analytics (7 endpoints)
620+
- ✅ Riot Data (14 endpoints)
621+
- ✅ Riot Integration (1 endpoint)
622+
- ✅ Dashboard (4 endpoints)
623+
624+
**Total:** 107 endpoints documented
625+
626+
### Code Coverage
627+
628+
View coverage report after running tests:
629+
```bash
630+
open coverage/index.html
358631
```
359632

360633
## Deployment

config/initializers/rswag_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Rswag::Api.configure do |c|
2-
# Specify a root folder where Swagger JSON files are located
3-
c.swagger_root = Rails.root.join('swagger').to_s
2+
# Specify a root folder where OpenAPI JSON files are located
3+
c.openapi_root = Rails.root.join('swagger').to_s
44

55
# Inject a lambda function to alter the returned Swagger prior to serialization
66
# c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }

config/initializers/rswag_ui.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Rswag::Ui.configure do |c|
2-
# List the Swagger endpoints that you want to be documented through the
2+
# List the OpenAPI endpoints that you want to be documented through the
33
# swagger-ui. The first parameter is the path (absolute or relative to the UI
44
# host) to the corresponding endpoint and the second is a title that will be
55
# displayed in the document selector.
6-
c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'ProStaff API V1 Docs'
6+
c.openapi_endpoint '/api-docs/v1/swagger.yaml', 'ProStaff API V1 Docs'
77

88
# Add Basic Auth in case your API is private
99
# c.basic_auth_enabled = true

0 commit comments

Comments
 (0)