Skip to content

Commit 53dee1b

Browse files
authored
Merge pull request #59 from DanglingDynamo/master
Cheers Bhaisaab!!!
2 parents 043f0df + 2c886f3 commit 53dee1b

File tree

6 files changed

+277
-70
lines changed

6 files changed

+277
-70
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ URL=url_to_be_sent_to_mail
2525

2626
REDIS_HOST=redis
2727
REDIS_PORT=6379
28-
REDIS_DB=0
28+
REDIS_DB=0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 CodeChef-VIT and All other contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Define variables
2+
include .env
23
DOCKER_COMPOSE = docker compose
3-
URI = "host= port= user= password= dbname=devsoc-24-backend"
44

5-
URI = "host=139.59.71.66 port=5430 user=admin password=d352F68MX2Hdh2pRFWoB3R9yg dbname=devsoc-24-backend"
5+
DB_URI = "host=localhost port=${POSTGRES_PORT} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} dbname=${POSTGRES_DB} sslmode=disable"
66

77
# Targets
88
.PHONY: build up down logs restart clean migrate-up migrate-down
@@ -41,4 +41,3 @@ help:
4141
@echo " logs View logs of Docker containers"
4242
@echo " restart Restart Docker containers"
4343
@echo " clean Stop, remove containers, and also remove volumes (data)"
44-
@echo " help Display this help message"

README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<p align="center"><a href="https://www.codechefvit.com" target="_blank"><img src="https://i.ibb.co/4J9LXxS/cclogo.png" width=160 title="CodeChef-VIT" alt="Codechef-VIT"></a>
2+
</p>
3+
<br />
4+
5+
# Devsoc Backend '24
6+
7+
The official Backend API for DEVSOC'24 Hackathon Portal
8+
9+
## Tech Stack
10+
11+
- [Golang](https://go.dev): Docker is a platform for developing, shipping, and running applications using containers.
12+
13+
- [Echo](https://echo.labstack.com/): A fast http router based on the go standard HTTP.
14+
- [pgx](https://github.com/jackc/pgx): A postgresql driver for go.
15+
- [gomail](https://github.com/go-gomail/gomail): A library to send emails using go.
16+
- [go-redis](https://github.com/redis/go-redis): Go redis client.
17+
18+
- [Docker](https://www.docker.com): Docker is a platform for developing, shipping, and running applications using containers.
19+
- [PostgreSQL](https://www.postgresql.org/): The worlds most advanced Open Source Relational Database.
20+
- [Redis](https://redis.io): The world’s fastest in-memory database from the ones who built it.
21+
22+
## Features
23+
24+
- User Authentication
25+
- Teams
26+
- Project management
27+
- Admin routes where Admins can directly score teams
28+
29+
# How To Run
30+
31+
## Prerequisites:
32+
33+
- [Docker](https://www.docker.com): .
34+
- [Postman](https://www.postman.com)/[Apidog](https://apidog.com): A tool to test backend APIs without having to write frontends.
35+
- [goose](https://github.com/pressly/goose): Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions.
36+
37+
## Steps
38+
39+
1. Clone the Repository: `git clone https://github.com/CodeChefVIT/devsoc-backend-24`
40+
2. Start the containers: `cd devsoc-backend-24 && cp .env.example .env && make build`. Please ensure that you put the correct SMTP credentials to get email services
41+
3. Run the migrations: `make migrate-up`
42+
4. Use postman and test the api at the endpoint `http://localhost/api`
43+
44+
# Authors
45+
46+
<table>
47+
<tr align="center">
48+
<td>
49+
<p align="center">
50+
<img src="https://avatars.githubusercontent.com/u/71623796?v=4" width="200" height="200" alt="Vedant"
51+
style="border: 2px solid grey; width: 170px; height: 170px" />
52+
</p>
53+
<p style="font-size: 17px; font-weight: 600">Vedant Matanhelia</p>
54+
<p align="center">
55+
<a href="https://github.com/DanglingDynamo"><img
56+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
57+
width="36" height="36" alt="GitHub" /></a>
58+
<a href="https://www.linkedin.com/in/vedant-matanhelia-aa171027b/">
59+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
60+
width="36" height="36" alt="LinkedIn" />
61+
</a>
62+
</p>
63+
</td>
64+
65+
<td>
66+
<p align="center">
67+
<img src="https://avatars.githubusercontent.com/u/86644389?v=4" width="200" height="200" alt="Aman"
68+
style="border: 2px solid grey; width: 170px; height: 170px" />
69+
</p>
70+
<p style="font-size: 17px; font-weight: 600">Aman L</p>
71+
<p align="center">
72+
<a href="https://github.com/Killerrekt"><img
73+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
74+
width="36" height="36" alt="GitHub" /></a>
75+
<a href="https://www.linkedin.com/in/aman-l-922819251/">
76+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
77+
width="36" height="36" alt="LinkedIn" />
78+
</a>
79+
</p>
80+
</td>
81+
82+
<td>
83+
<p align="center">
84+
<img src="https://avatars.githubusercontent.com/u/133687995?v=4" width="200" height="200" alt="Prateek"
85+
style="border: 2px solid grey; width: 170px; height: 170px" />
86+
</p>
87+
<p style="font-size: 17px; font-weight: 600">Prateek Srivastava</p>
88+
<p align="center">
89+
<a href="https://github.com/prateek-srivastava001"><img
90+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
91+
width="36" height="36" alt="GitHub" /></a>
92+
<a href="https://www.linkedin.com/in/prateeksrivastava-/">
93+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
94+
width="36" height="36" alt="LinkedIn" />
95+
</a>
96+
</p>
97+
</td>
98+
99+
<td>
100+
<p align="center">
101+
<img src="https://avatars.githubusercontent.com/u/84951451?v=4" width="200" height="200" alt="Akshat"
102+
style="border: 2px solid grey; width: 170px; height: 170px" />
103+
</p>
104+
<p style="font-size: 17px; font-weight: 600">Akshat Gupta</p>
105+
<p align="center">
106+
<a href="https://github.com/Oik17"><img
107+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
108+
width="36" height="36" alt="GitHub" /></a>
109+
<a href="https://www.linkedin.com/in/akshat-gupta-864b39235/">
110+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
111+
width="36" height="36" alt="LinkedIn" />
112+
</a>
113+
</p>
114+
</td>
115+
116+
</tr>
117+
118+
<tr align="center">
119+
<td>
120+
<p align="center">
121+
<img src="https://avatars.githubusercontent.com/u/50650788?v=4" width="200" height="200" alt="Shivam"
122+
style="border: 2px solid grey; width: 170px; height: 170px" />
123+
</p>
124+
<p style="font-size: 17px; font-weight: 600">Shivam Sharma</p>
125+
<p align="center">
126+
<a href="https://github.com/Mr-Emerald-Wolf"><img
127+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
128+
width="36" height="36" alt="GitHub" /></a>
129+
<a href="https://www.linkedin.com/in/shivam-sharma-6a0b1b1a7/">
130+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
131+
width="36" height="36" alt="LinkedIn" />
132+
</a>
133+
</p>
134+
</td>
135+
136+
<td>
137+
<p align="center">
138+
<img src="https://avatars.githubusercontent.com/u/91564450?v=4" width="200" height="200" alt="Aaditya"
139+
style="border: 2px solid grey; width: 170px; height: 170px" />
140+
</p>
141+
<p style="font-size: 17px; font-weight: 600">Aaditya Mahanta</p>
142+
<p align="center">
143+
<a href="https://github.com/aditansh"><img
144+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
145+
width="36" height="36" alt="GitHub" /></a>
146+
<a href="https://www.linkedin.com/in/aadityamahanta/">
147+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
148+
width="36" height="36" alt="LinkedIn" />
149+
</a>
150+
</p>
151+
</td>
152+
153+
<td>
154+
<p align="center">
155+
<img src="https://avatars.githubusercontent.com/u/100862487?v=4" width="200" height="200" alt="Shivam"
156+
style="border: 2px solid grey; width: 170px; height: 170px" />
157+
</p>
158+
<p style="font-size: 17px; font-weight: 600">Shivam Gutgutia</p>
159+
<p align="center">
160+
<a href="https://github.com/shivamgutgutia"><img
161+
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
162+
width="36" height="36" alt="GitHub" /></a>
163+
<a href="https://www.linkedin.com/in/shivamgutgutia/">
164+
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
165+
width="36" height="36" alt="LinkedIn" />
166+
</a>
167+
</p>
168+
</td>
169+
</tr>
170+
</table>
171+
172+
# License
173+
174+
Copyright © 2024, [CodeChef-VIT](https://github.com/CodeChefVIT) and all other contributors.
175+
Released under the [MIT License](LICENSE).
176+
177+
<p align="center">
178+
Made with :heart: by <a href="https://www.codechefvit.com" target="_blank">CodeChef-VIT</a>
179+
</p>

docker-compose.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
version: '3'
1+
# version: "3" -> Deprecated
22
services:
3-
43
api:
54
build: .
65
ports:
@@ -10,3 +9,26 @@ services:
109
env_file:
1110
- .env
1211
restart: on-failure
12+
postgres:
13+
image: postgres:latest
14+
ports:
15+
- "6500:5432" # cause 5432 is generally used by other postgres servers running
16+
volumes:
17+
- ./postgres_data:/var/lib/postgresql/data
18+
env_file:
19+
- .env
20+
redis:
21+
image: redis:latest
22+
container_name: redis
23+
ports:
24+
- "6379:6379"
25+
env_file:
26+
- .env
27+
nginx:
28+
image: nginx:latest
29+
ports:
30+
- "80:80" # Replace 8080 with the desired port for your application
31+
volumes:
32+
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf # Mount your Nginx configuration file
33+
depends_on:
34+
- api # Nginx depends on the API service being available

nginx/nginx.conf

Lines changed: 50 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,57 @@
1-
user nginx;
21
# Server block for your application
32

43
# create a limit
5-
events {
6-
worker_connections 5000;
4+
geo $limit {
5+
default 1;
6+
10.0.0.0/8 0;
7+
192.168.0.0/24 0;
78
}
89

9-
http {
10-
geo $limit {
11-
default 1;
12-
10.0.0.0/8 0;
13-
192.168.0.0/24 0;
14-
}
15-
16-
map $limit $limit_key {
17-
0 "";
18-
1 $binary_remote_addr;
19-
}
20-
21-
limit_req_zone $limit_key zone=api_limit:10m rate=10r/s;
22-
23-
server {
24-
# Listen on the port exposed by the container (80 in this example)
25-
listen 80;
26-
http2 on;
27-
server_name devsoc-24-api.codechefvit.com;
28-
gzip on;
29-
gzip_proxied any;
30-
gzip_types text/plain text/css application/json application/javascript;
31-
32-
# Access log for debugging
33-
access_log /var/log/nginx/access.log;
34-
35-
# Serve static files from the application directory
36-
location / {
37-
38-
if ($request_method = 'OPTIONS') {
39-
add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/';
40-
add_header 'Access-Control-Allow-Credentials' 'true';
41-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
42-
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
43-
add_header 'Access-Control-Max-Age' 1728000;
44-
add_header 'Content-Type' 'text/plain charset=UTF-8';
45-
add_header 'Content-Length' 0;
46-
return 204;
47-
}
48-
49-
add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/' always;
50-
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always;
51-
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
52-
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
53-
add_header 'Access-Control-Allow-Credentials' 'true' always;
54-
55-
# Adjust these settings based on your application's needs
56-
proxy_set_header Host $host;
57-
proxy_set_header X-Real-IP $remote_addr;
58-
proxy_cache_bypass $http_upgrade;
59-
proxy_buffering off;
60-
proxy_cache off;
61-
62-
# Set the rate limit
63-
limit_req zone=api_limit burst=10 nodelay;
64-
limit_req_status 429;
65-
10+
map $limit $limit_key {
11+
0 "";
12+
1 $binary_remote_addr;
13+
}
6614

67-
# Forward requests to the application container (change 127.0.0.1 to your API container name if different)
68-
proxy_pass http://api:8080;
69-
}
70-
}
15+
limit_req_zone $limit_key zone=api_limit:10m rate=5r/s;
16+
17+
server {
18+
# Listen on the port exposed by the container (80 in this example)
19+
listen 80;
20+
http2 on;
21+
gzip on;
22+
gzip_proxied any;
23+
gzip_types text/plain text/css application/json application/javascript; # Access log for debugging access_log /var/log/nginx/access.log;
24+
# Serve static files from the application directory
25+
location /api {
26+
27+
# CORS
28+
if ($request_method = 'OPTIONS') {
29+
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000';
30+
add_header 'Access-Control-Allow-Credentials' 'true';
31+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
32+
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
33+
add_header 'Access-Control-Max-Age' 1728000;
34+
add_header 'Content-Type' 'text/plain charset=UTF-8';
35+
add_header 'Content-Length' 0;
36+
return 204;
37+
}
38+
39+
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always;
40+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always;
41+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
42+
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
43+
add_header 'Access-Control-Allow-Credentials' 'true' always;
44+
45+
# Adjust these settings based on your application's needs
46+
proxy_set_header Host $host;
47+
proxy_set_header X-Real-IP $remote_addr;
48+
proxy_cache_bypass $http_upgrade;
49+
50+
# Set the rate limit
51+
limit_req zone=api_limit burst=20;
52+
limit_req_status 429;
53+
54+
# Forward requests to the application container (change 127.0.0.1 to your API container name if different)
55+
proxy_pass http://api:8080;
56+
}
7157
}

0 commit comments

Comments
 (0)