Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ COPY . .

EXPOSE 3000

CMD ["node", "src/server.js"]
CMD ["node", "src/server.ts"]
40 changes: 32 additions & 8 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,30 @@ To run tests with coverage:
npm test -- --coverage
```

## PG-Admin

1. make sure the docker is running
2. open:
```
http://localhost:5151
```
3. login using pgadmin email and password
4. right click on 'Servers"
5. navigate to Register > Server
6. in the 'General' tab
```
Name: postgres
```
7. in the 'Connection' tab
```
Host: db
Maintenance database: postgres db (from env)
Username: postgres user (from env)
Password: postgres password (from env)
```
8. 'Save'


## Project Structure

```
Expand All @@ -130,14 +154,14 @@ All API endpoints are prefixed with `/api`. A full list of service contracts is

## Tech Stack

| Concern | Technology |
|---|---|
| Runtime | Node.js v18 |
| Framework | Express |
| Database | PostgreSQL 15 |
| Code Execution | Judge0 |
| Testing | Jest |
| Containerisation | Docker |
| Concern | Technology |
| ---------------- | ------------- |
| Runtime | Node.js v18 |
| Framework | Express |
| Database | PostgreSQL 15 |
| Code Execution | Judge0 |
| Testing | Jest |
| Containerisation | Docker |

## Common Issues

Expand Down
44 changes: 20 additions & 24 deletions database/init.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
--very generic tables that can be changed later, just trying not to keep the file empty

CREATE TYPE problem_category AS ENUM ('math', 'programming');
CREATE TYPE difficulty_level AS ENUM('Easy','Medium','Difficult');
CREATE TYPE supported_languages AS ENUM('java','c++');

CREATE TABLE IF NOT EXISTS users (
user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
username VARCHAR(50) UNIQUE NOT NULL,
Expand All @@ -7,8 +12,17 @@ CREATE TABLE IF NOT EXISTS users (
created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS problems (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
type problem_category NOT NULL,
difficulty_level difficulty_level NOT NULL,
title VARCHAR(20) NOT NULL,
description VARCHAR(40) NOT NULL,
time_limit TIME(2) NOT NULL
);

CREATE TABLE IF NOT EXISTS match_problems(
match_problems_id PRIMARY KEY DEFAULT gen_random_uuid(),
match_problems_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
question1 UUID REFERENCES problems(id) NOT NULL,
question2 UUID REFERENCES problems(id) NOT NULL,
question3 UUID REFERENCES problems(id) NOT NULL, --every match has a minimum of 3 questions, i.e. difficult mode
Expand Down Expand Up @@ -36,44 +50,26 @@ CREATE TABLE IF NOT EXISTS match_log(
elo_lost INTEGER
);

CREATE TYPE problem_category AS ENUM ('math', 'programming');

CREATE TABLE IF NOT EXISTS problems (
id SERIAL PRIMARY KEY,
type problem_category NOT NULL,
difficulty_level ENUM('Easy', 'Medium', 'Difficult') NOT NULL,
title VARCHAR(20) NOT NULL,
description VARCHAR(40) NOT NULL,
time_limit TIME(2) NOT NULL
);

CREATE TABLE IF NOT EXISTS elo_ratings (
elo_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES users(user_id),
rating INTEGER DEFAULT 600,
updated_at TIMESTAMP DEFAULT NOW(),

updated_at TIMESTAMP DEFAULT NOW()
);


CREATE TABLE IF NOT EXISTS math_problems (
id SERIAL PRIMARY KEY,
problem_id INT NOT NULL REFERENCES problems(id) ON DELETE CASCADE,
problem_id UUID NOT NULL REFERENCES problems(id) ON DELETE CASCADE,
--equation VARCHAR(20) NOT NULL,
solution_formula VARCHAR(20) NOT NULL,
CONSTRAINT math_category_check CHECK (
(SELECT type FROM problems WHERE id = problem_id) = 'math'
)
solution_formula VARCHAR(20) NOT NULL
);

CREATE TABLE IF NOT EXISTS programming_problems (
id SERIAL PRIMARY KEY,
problem_id INT NOT NULL REFERENCES problems(id) ON DELETE CASCADE,
problem_id UUID NOT NULL REFERENCES problems(id) ON DELETE CASCADE,
--function_signature VARCHAR(25) NOT NULL,
supported_languages ENUM('java', 'c++') NOT NULL,
CONSTRAINT programming_category_check CHECK (
(SELECT type FROM problems WHERE id = problem_id) = 'programming'
)
supported_languages supported_languages NOT NULL
);

CREATE TABLE IF NOT EXISTS elo_history (
Expand Down
34 changes: 28 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
backend:
build: ./backend
Expand All @@ -12,6 +10,8 @@ services:
volumes:
- ./backend:/app
- /app/node_modules
networks:
- pgnetwork

# frontend:
# build: ./frontend
Expand All @@ -24,16 +24,34 @@ services:

db:
image: postgres:15-alpine
container_name: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: codeclash
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASS}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- pgnetwork

pgadmin:
image: dpage/pgadmin4:9.15
container_name: pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASS}
PGADMIN_LISTEN_PORT: ${PGADMIN_PORT}
ports:
- "${PGADMIN_PORT}:5151"
volumes:
- pgadmin_data:/var/lib/pgadmin
depends_on:
- db
networks:
- pgnetwork
# judge0:
# image: judge0/judge0:latest
# ports:
Expand All @@ -42,4 +60,8 @@ services:
#TODO IMPORTANT return this when we want to start implementing code execution

volumes:
postgres_data:
postgres_data:
pgadmin_data:

networks:
pgnetwork:
Loading