Linux/MacOS
Initialize
git clone https://github.com/botprzemek/basketball ~/basketball
cd ~/basketball
Start
docker compose down -d --volumes --remove-orphans &>/dev/null
docker compose up -d --build --force-recreate &>/dev/null
Windows
git clone https://github.com/botprzemek/basketball ~/basketball
cd ~/basketball
docker-compose down -v --remove-orphans > $null 2>&1
docker-compose up -d --build --force-recreate > $null 2>&1
docker exec -it basketball-database-1 ./cockroach init --insecure --host="basketball-database-1:26357" > $null 2>&1
docker exec -it basketball-database-1 ./cockroach sql --insecure --host="basketball-database-1:26257" --execute="CREATE DATABASE basketball; CREATE USER basketball WITH PASSWORD NULL; ALTER DATABASE basketball OWNER TO basketball; CREATE TYPE basketball.position_enum AS ENUM ('PG', 'SG', 'SF', 'PF', 'C');" > $null 2>&1
docker exec -it basketball-database-1 ./cockroach node status --insecure --host="basketball-database-1:26257"
Development
npm run install
npm run dev
Building
npm run install
npm run build
npm run start
Deployment
docker compose up
Caution
Project is still work in progress
https://youtu.be/_1IKwnbscQU?si=U3HJeYzsupcBohvN https://youtu.be/GmXPwRNIrAU?si=RJVPFVS1AHvJag6- https://youtu.be/6WZ6S-qmtqY?si=eePsuPFUwczIGOVi https://youtu.be/_gQaygjm_hg?si=WGZect2sf7qOBT8O
NGINX rate limiter
middlewares accessList.ts accessToken.ts dataValidation.ts headers.ts webToken.ts utils logger.ts paginate.ts queryParameter.ts rateLimiter.ts version.ts
tests server api delete get post put
services analitics auth data
TODO
- ADD IMAGES
- Cache invalidation
With cache invalidation, whenever a value is updated in the primary database, each cached item with a corresponding key is automatically deleted from the cache or caches. Although cache invalidation could perhaps be seen as a “brute force approach,” the advantage is that it requires only one costly and often time-consuming write—to the primary database itself—instead of two or more.
- Write-through caching
In this case, rather than updating the primary database and removing the cache, with the write-through strategy, the application updates the cache, and then the cache updates the primary database synchronously. In other words, instead of relying on the primary database to initiate any updating, the cache is in charge of maintaining its own consistency and delivering word of any changes it makes back to the primary database.
- Write-behind caching
Unfortunately, there are times when two writes can actually make a wrong. One of the drawbacks of the write-through cache strategy is that updating both the cache and the primary database requires two time-consuming, processor-taxing changes, first to the cache and then to the primary database.
Another strategy, known as write-behind, avoids this problem by initially updating only the cache and then updating the primary database later. Of course, the primary database will also need to be updated, and the sooner the better, but in this case the user doesn’t have to pay the “cost” of the two writes. The second write to the primary database occurs asynchronously and behind the scenes (hence the name, write-behind) at a time when it is less likely to impair performance.
Auth
Hypermedia HATEOAS
GZIP Compression
GET, POST, PUT, DELETE
NODEJS, TYPESCRIPT, HTTP, REDIS, COCKROACH, DOCKER, MULTI-INSTANCE
statistics
parameters
database schema
api token
rate limit
ip exclude
admin ui
tests
swagger openapi
mocking
deployment
Stack of whole project including website project - CENN (CockroachDB, Express, Nuxt, NodeJS)
This documentation provides an overview of the REST API project developed for the Knury Knurów basketball team. The API is built around JavaScript (TypeScript 🌌) with Express ☕ framework (Node.js). It integrates technologies such as CockroachDB 🪳 and Socket.IO 📡, Node-Mailer 📫 and Node-Cache ✴️
- Status
- Project Overview
- Quick Start
- Features
- Usage
- Technologies used
- Endpoints
- Database Models
- Contributors
- Author
- License
Testing API instance running on this link, please refer to API's endpoints
-
Install Node
-
Clone repository git clone https://github.com/botprzemek/basketball-api.git
cd basketball-api
npm install
cp .env.example .env
setup env file
PORT=3000
ADDRESSES=["http://localhost:3001"]
SECRET=generated_secret
COCKROACH_HOST=your.database.domain.com
COCKROACH_PORT=26257
COCKROACH_NAME=api
COCKROACH_USER=your_user
COCKROACH_PASSWORD=your_database_password
MAIL_URL=your.mail.domain.com
MAIL_PORT=587
MAIL_USER=your_user
MAIL_PASSWORD=your_mail_password
TOKEN_KEY=generated_token
npm run dev
To run the project in development mode (Nodemon - Restarting after changes), execute the following command:
npm run dev
To run the seeding script to fill your database, execute the following command:
npm run seedling
To run the project in production mode (PM2 - daemonize app and logging), execute the following command:
npm run server
- JavaScript: Programming language used for the project's core functionality. 🧰
- TypeScript: Superset of mentioned above JavaScript, used for adding static typing and enhancing code maintainability. 🔗
- Node An asynchronous event-driven JavaScript runtime, designed to build scalable network applications. 🔮
- CockroachDB: Database engine used for storing and retrieving team-related data. 📁
- Express: Web application framework for building the API's routes and handling requests. 🖨️
- Node-Cache: Caching mechanisms implemented using Node-Cache package to optimize API performance. 📦
- Node-Mailer: Allows easy as cake email sending. 📫
- Socket.IO: Caching mechanisms implemented using Node-Cache package to optimize API performance. 📦
This section provides an overview of the structure, including basketball arenas, cities, players, teams, statistics, matches, and rosters, along with their respective relationships inside the CockroachDB database.
- id (INT8): Primary key, unique identifier for the player.
- team_id (INT8): Foreign key referencing the team table (not null, references team.id, on delete cascade).
- name (VARCHAR): First name of the player (not null).
- lastname (VARCHAR): Last name of the player (not null).
- number (INT8): Player number (not null, unique within a team).
- height (INT8): Height of the player (not null).
- position (position_enum): Position of the player (not null).
- birthday (DATE): Birthday of the player (not null).
- starter (BOOLEAN): Indicates if the player is a starter (default false).
Contributors
This project follows the all-contributors specification and is brought to you by these awesome contributors.
author
Github @botprzemek Discord botprzemek Email info@botprzemek.pl
license
This project is licensed under the terms of the Apache License 2.0
http2 protobuf