Skip to content

Commit

Permalink
Merge pull request #59 from DanglingDynamo/master
Browse files Browse the repository at this point in the history
Cheers Bhaisaab!!!
  • Loading branch information
aditansh authored May 12, 2024
2 parents 043f0df + 2c886f3 commit 53dee1b
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ URL=url_to_be_sent_to_mail

REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0
REDIS_DB=0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 CodeChef-VIT and All other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Define variables
include .env
DOCKER_COMPOSE = docker compose
URI = "host= port= user= password= dbname=devsoc-24-backend"

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

# Targets
.PHONY: build up down logs restart clean migrate-up migrate-down
Expand Down Expand Up @@ -41,4 +41,3 @@ help:
@echo " logs View logs of Docker containers"
@echo " restart Restart Docker containers"
@echo " clean Stop, remove containers, and also remove volumes (data)"
@echo " help Display this help message"
179 changes: 179 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<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>
</p>
<br />

# Devsoc Backend '24

The official Backend API for DEVSOC'24 Hackathon Portal

## Tech Stack

- [Golang](https://go.dev): Docker is a platform for developing, shipping, and running applications using containers.

- [Echo](https://echo.labstack.com/): A fast http router based on the go standard HTTP.
- [pgx](https://github.com/jackc/pgx): A postgresql driver for go.
- [gomail](https://github.com/go-gomail/gomail): A library to send emails using go.
- [go-redis](https://github.com/redis/go-redis): Go redis client.

- [Docker](https://www.docker.com): Docker is a platform for developing, shipping, and running applications using containers.
- [PostgreSQL](https://www.postgresql.org/): The worlds most advanced Open Source Relational Database.
- [Redis](https://redis.io): The world’s fastest in-memory database from the ones who built it.

## Features

- User Authentication
- Teams
- Project management
- Admin routes where Admins can directly score teams

# How To Run

## Prerequisites:

- [Docker](https://www.docker.com): .
- [Postman](https://www.postman.com)/[Apidog](https://apidog.com): A tool to test backend APIs without having to write frontends.
- [goose](https://github.com/pressly/goose): Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions.

## Steps

1. Clone the Repository: `git clone https://github.com/CodeChefVIT/devsoc-backend-24`
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
3. Run the migrations: `make migrate-up`
4. Use postman and test the api at the endpoint `http://localhost/api`

# Authors

<table>
<tr align="center">
<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/71623796?v=4" width="200" height="200" alt="Vedant"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Vedant Matanhelia</p>
<p align="center">
<a href="https://github.com/DanglingDynamo"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/vedant-matanhelia-aa171027b/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>

<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/86644389?v=4" width="200" height="200" alt="Aman"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Aman L</p>
<p align="center">
<a href="https://github.com/Killerrekt"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/aman-l-922819251/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>

<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/133687995?v=4" width="200" height="200" alt="Prateek"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Prateek Srivastava</p>
<p align="center">
<a href="https://github.com/prateek-srivastava001"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/prateeksrivastava-/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>

<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/84951451?v=4" width="200" height="200" alt="Akshat"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Akshat Gupta</p>
<p align="center">
<a href="https://github.com/Oik17"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/akshat-gupta-864b39235/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>

</tr>

<tr align="center">
<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/50650788?v=4" width="200" height="200" alt="Shivam"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Shivam Sharma</p>
<p align="center">
<a href="https://github.com/Mr-Emerald-Wolf"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/shivam-sharma-6a0b1b1a7/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>

<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/91564450?v=4" width="200" height="200" alt="Aaditya"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Aaditya Mahanta</p>
<p align="center">
<a href="https://github.com/aditansh"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/aadityamahanta/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>

<td>
<p align="center">
<img src="https://avatars.githubusercontent.com/u/100862487?v=4" width="200" height="200" alt="Shivam"
style="border: 2px solid grey; width: 170px; height: 170px" />
</p>
<p style="font-size: 17px; font-weight: 600">Shivam Gutgutia</p>
<p align="center">
<a href="https://github.com/shivamgutgutia"><img
src="http://www.iconninja.com/files/241/825/211/round-collaboration-social-github-code-circle-network-icon.svg"
width="36" height="36" alt="GitHub" /></a>
<a href="https://www.linkedin.com/in/shivamgutgutia/">
<img src="http://www.iconninja.com/files/863/607/751/network-linkedin-social-connection-circular-circle-media-icon.svg"
width="36" height="36" alt="LinkedIn" />
</a>
</p>
</td>
</tr>
</table>

# License

Copyright © 2024, [CodeChef-VIT](https://github.com/CodeChefVIT) and all other contributors.
Released under the [MIT License](LICENSE).

<p align="center">
Made with :heart: by <a href="https://www.codechefvit.com" target="_blank">CodeChef-VIT</a>
</p>
26 changes: 24 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version: '3'
# version: "3" -> Deprecated
services:

api:
build: .
ports:
Expand All @@ -10,3 +9,26 @@ services:
env_file:
- .env
restart: on-failure
postgres:
image: postgres:latest
ports:
- "6500:5432" # cause 5432 is generally used by other postgres servers running
volumes:
- ./postgres_data:/var/lib/postgresql/data
env_file:
- .env
redis:
image: redis:latest
container_name: redis
ports:
- "6379:6379"
env_file:
- .env
nginx:
image: nginx:latest
ports:
- "80:80" # Replace 8080 with the desired port for your application
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf # Mount your Nginx configuration file
depends_on:
- api # Nginx depends on the API service being available
114 changes: 50 additions & 64 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,71 +1,57 @@
user nginx;
# Server block for your application

# create a limit
events {
worker_connections 5000;
geo $limit {
default 1;
10.0.0.0/8 0;
192.168.0.0/24 0;
}

http {
geo $limit {
default 1;
10.0.0.0/8 0;
192.168.0.0/24 0;
}

map $limit $limit_key {
0 "";
1 $binary_remote_addr;
}

limit_req_zone $limit_key zone=api_limit:10m rate=10r/s;

server {
# Listen on the port exposed by the container (80 in this example)
listen 80;
http2 on;
server_name devsoc-24-api.codechefvit.com;
gzip on;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript;

# Access log for debugging
access_log /var/log/nginx/access.log;

# Serve static files from the application directory
location / {

if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

add_header 'Access-Control-Allow-Origin' 'https://portal.devsoc.codechefvit.com/' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;

# Adjust these settings based on your application's needs
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
proxy_buffering off;
proxy_cache off;

# Set the rate limit
limit_req zone=api_limit burst=10 nodelay;
limit_req_status 429;

map $limit $limit_key {
0 "";
1 $binary_remote_addr;
}

# Forward requests to the application container (change 127.0.0.1 to your API container name if different)
proxy_pass http://api:8080;
}
}
limit_req_zone $limit_key zone=api_limit:10m rate=5r/s;

server {
# Listen on the port exposed by the container (80 in this example)
listen 80;
http2 on;
gzip on;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript; # Access log for debugging access_log /var/log/nginx/access.log;
# Serve static files from the application directory
location /api {

# CORS
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE, PATCH';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

add_header 'Access-Control-Allow-Origin' 'http://localhost:3000' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PATCH, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;

# Adjust these settings based on your application's needs
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;

# Set the rate limit
limit_req zone=api_limit burst=20;
limit_req_status 429;

# Forward requests to the application container (change 127.0.0.1 to your API container name if different)
proxy_pass http://api:8080;
}
}

0 comments on commit 53dee1b

Please sign in to comment.