Skip to content

Commit adc3e36

Browse files
Merge pull request #1 from Harshvardhan2164/frontend
Frontend
2 parents 83b0f6c + 9198b4a commit adc3e36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6361
-26
lines changed

.gitignore

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
11
test
2-
.env
2+
.env
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
pnpm-debug.log*
11+
lerna-debug.log*
12+
13+
node_modules
14+
dist
15+
dist-ssr
16+
*.local
17+
18+
# Editor directories and files
19+
.vscode/*
20+
!.vscode/extensions.json
21+
.idea
22+
.DS_Store
23+
*.suo
24+
*.ntvs*
25+
*.njsproj
26+
*.sln
27+
*.sw?

README.md

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,141 @@
1-
# Custom-API-Gateway
1+
# RouteX - Custom API Gateway with Rate Limiting & JWT Authentication
2+
3+
**RouteX** is a **custom-built API Gateway** built from scratch using **Go (backend)** and **React + Vite + TypeScript (frontend)**. It provides:
4+
5+
* **Dynamic Route Mapping** (to upstream services)
6+
* **JWT & API Key Authentication**
7+
* **Per-user Rate Limiting (token bucket)**
8+
* **Admin Panel** to manage API Keys, Routes, and Test APIs
9+
* **MongoDB Integration** for persistence
10+
* **Dockerized setup** for easy deployment
11+
12+
## Features
13+
14+
### Backend (Go API Gateway)
15+
16+
1. **Dynamic Route Mapping** → Map `/service-a``http://upstream-service-a.local`
17+
18+
2. **Authentication**
19+
20+
* Supports **JWT** (`Authorization: Bearer <token>`)
21+
* Supports **API Key** (`X-API-Key` header)
22+
23+
3. **Rate Limiting**
24+
25+
* Token bucket per API key/user
26+
* Configurable request rate (`N requests/minute`)
27+
28+
4. **MongoDB Integration**
29+
30+
* `api_keys` collection → stores key + rate limit
31+
* `routes` collection → stores path + upstream target
32+
33+
5. **Admin APIs**
34+
35+
* `/admin/api-keys` → Create/Delete API Keys
36+
* `/admin/routes` → Create/Delete Routes
37+
* `/admin/generate-token` → Generate JWT for an API Key
38+
39+
### Frontend (React + Vite + TypeScript)
40+
41+
1. **Admin Dashboard** with pages:
42+
43+
* **API Keys**: Create & manage API keys & rate limits
44+
* **Routes**: Create & manage route mappings
45+
* **JWT Generator**: Generate a JWT for any API Key
46+
* **API Tester**: Test requests through the Gateway with JWT or API Key
47+
48+
2. **Axios API Client**: Communicates with backend
49+
3. **CORS enabled** for dev (`localhost:5173``localhost:8080`)
50+
51+
### Web Client
52+
53+
![](https://github.com/Harshvardhan2164/Custom-API-Gateway/blob/main/assets/home.png)
54+
55+
![](https://github.com/Harshvardhan2164/Custom-API-Gateway/blob/main/assets/api.png)
56+
57+
![](https://github.com/Harshvardhan2164/Custom-API-Gateway/blob/main/assets/test.png)
58+
59+
![](https://github.com/Harshvardhan2164/Custom-API-Gateway/blob/main/assets/jwt.png)
60+
61+
### Authentication Flow
62+
63+
1. **Admin** creates an API Key via admin panel
64+
2. **JWT Generator** can issue a short-lived JWT for that API Key
65+
3. Clients call Gateway using **either**:
66+
67+
* `Authorization: Bearer <jwt>`
68+
* `X-API-Key: <raw-api-key>`
69+
70+
Backend validates token → checks MongoDB → enforces rate limit → forwards to upstream service.
71+
72+
### Rate Limiting
73+
74+
Implemented using **Token Bucket Algorithm** per API Key:
75+
76+
* Each API key has a **max tokens** (rate limit)
77+
* Tokens refill every **minute**
78+
* Requests consume 1 token → If no tokens left → **429 Too Many Requests**
79+
80+
## Backend API Endpoints
81+
82+
| Method | Path | Description |
83+
| ------ | ----------------------- | ------------------------------------ |
84+
| GET | `/admin/api-keys` | List API keys |
85+
| POST | `/admin/api-keys` | Create API key `{key, rate_limit}` |
86+
| DELETE | `/admin/api-keys/:id` | Delete API key |
87+
| GET | `/admin/routes` | List routes |
88+
| POST | `/admin/routes` | Create route `{path, target_url}` |
89+
| DELETE | `/admin/routes/:id` | Delete route |
90+
| POST | `/admin/generate-token` | Generate JWT for an API Key |
91+
| ANY | `/your-service-path` | Forwards request to upstream service |
92+
93+
## Frontend Pages
94+
95+
1. **API Keys Manager**: CRUD for API keys
96+
2. **Routes Manager**: CRUD for route mappings
97+
3. **JWT Generator**: Input an API key → Get a signed JWT
98+
4. **API Tester**: Input path, select auth method (JWT/API Key), test request
99+
100+
## Installation and Setup
101+
102+
1. Clone the repository:
103+
104+
```bash
105+
git clone https://github.com/Harshvardhan2164/Custom-API-Gateway.git
106+
cd Custom-API-Gateway/
107+
```
108+
109+
2. **Start MongoDB, Backend & Frontend**
110+
111+
```bash
112+
docker compose build
113+
docker compose up -d
114+
```
115+
116+
3. **Open Admin Panel**`http://localhost:5173`
117+
118+
4. **Create an API Key** with a rate limit
119+
120+
5. **Create Routes** mapping `/service``http://httpbin.org/get` (or any upstream)
121+
122+
6. **Generate JWT** for that API Key
123+
124+
7. **Use API Tester** → send request with JWT or API Key
125+
126+
8. If you exceed the rate limit → **429 Too Many Requests**
127+
128+
## Future Enhancements
129+
130+
* Redis-based distributed rate limiting
131+
* Multi-route custom rate limits
132+
* OAuth2 support
133+
* TLS termination with Nginx
134+
135+
## Contributing
136+
137+
Feel free to fork the repository, open issues, or submit pull requests.
138+
139+
## License
140+
141+
This project is licensed under the MIT License - see the LICENSE file for details.

assets/api.png

86.2 KB
Loading

assets/home.png

110 KB
Loading

assets/jwt.png

96.5 KB
Loading

assets/keys.png

76.1 KB
Loading

assets/routes.png

76.8 KB
Loading

assets/test.png

75.9 KB
Loading

assets/tester.png

27.8 KB
Loading

backend/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.21 AS builder
2+
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
10+
RUN go build -o gateway ./cmd/main.go
11+
12+
FROM gcr.io/distroless/base-debian12
13+
14+
WORKDIR /app
15+
16+
COPY --from=builder /app/gateway .
17+
18+
EXPOSE 8080
19+
20+
CMD ["./gateway"]

0 commit comments

Comments
 (0)