How vanh01/api-rate-limiting works
Project Type and Purpose
• This is a Go (Golang) project designed to implement two distinct problems:
– API Rate Limiting: A system that implements multiple strategies (Fixed Window, Sliding Window, Token Bucket, and even a Leaky Bucket appears to be present) to limit the number of requests per user, similar to rate limiting in major APIs.
– Graph Shortest Path: Solving the “Tìm Đường Trong Đồ Thị Lớn” problem, which involves finding the shortest path in a weighted, undirected graph with real-time updating and algorithm optimization.
File Structure
• Top-level directories and files:
• The root contains configuration files (config.yaml and config folder), Docker-related files (.dockerignore, Dockerfile, docker-compose.yml), makefile, and Prometheus configuration (prometheus.yml) for monitoring.
• cmd/main.go is the application entry point.
• The internal directory is organized into subpackages:
▪ app – likely for starting the application and bootstrapping.
▪ controller – handling routes (see internal/controller/router.go).
▪ middleware – containing implementation of rate limiting algorithms (fixedwindow.go, slidingwindow.go, tokenbucket.go, leakybucket.go).
▪ model – domain models (for example, user.go).
▪ repo – data access/repository layer (user.go for data persistence or mock repositories).
▪ usecase – contains business logic and interfaces.
• The pkg folder has a cache module with redis implementation, suggesting caching/external resource integration.
• This structure implies an architecture that could follow an MVC-like or hexagonal/Clean Architecture approach, with clear separation between controllers, application logic, data layers, and external services.