Skip to content
Β 
Β 

Repository files navigation

Codify - Backend

This repository contains the full backend system for Codify. It includes user authentication and management, assignment handling, GitHub integration, code execution, AI evaluation, and all supporting modules, built with NestJS, Prisma, and PostgreSQL.

The codebase follows a modular architecture and provides documentation for structure, architecture, and development guidelines.

πŸš€ Tech Stack

  • NestJS
  • Prisma ORM
  • PostgreSQL
  • Docker & Dockerode
  • Redis & BullMQ
  • pnpm

πŸ“‹ Prerequisites

Make sure you have the following installed:

  • Node.js (v18 or higher)
  • pnpm (v8 or higher)
  • Docker (v20 or higher)
  • PostgreSQL (v14 or higher)

πŸ“¦ Installation

  1. Clone the project
git clone https://github.com/JamJam126/Codify-Backend.git
cd EduAI-GitHub-Assistant-Backend
  1. Install project dependencies:
pnpm install
  1. Install additional dependencies for the code runner:
pnpm install bullmq dockerode redis uuid
pnpm install -D @types/dockerode

πŸ” Environment Variables

Create a .env file from the example:

cp .env.example .env

Update variables as needed:

DATABASE_URL="postgresql://user:password@localhost:5432/codify"
JWT_SECRET=supersecretkey12345
JWT_EXPIRES_IN=3600

CODE_RUNNER_VOLUME_NAME=code-temp
DB_VOLUME_NAME=codifydb

Prisma requires DATABASE_URL to be defined.

πŸ—„ Database Setup

Verify schema exists, check folder structure

src/
  prisma/
    schema.prisma

If the database does not yet exist, create it manually in PostgreSQL

createdb codify

Or inside psql:

CREATE DATABASE codify;

Generate Prisma

npx prisma generate

This step reads your schema.prisma and creates:

  • DB client
  • TS types (User, Post, etc.)

Verify:

node_modules/@prisma/client/

Apply Migration

If the project already contains /prisma/migrations/**, run:

npx prisma migrate dev

This:

  1. Compares schema ↔ DB
  2. Applies needed SQL
  3. Regenerates Prisma client

If the migrations folder is empty β†’ the project creator didn't include them, so you must run:

npx prisma db push

(creates tables without migrations).

⚠ Never run db push if migrations already exist!

Seed the database with initial data (recommended)

npx prisma db seed

🐳 Docker Setup for Code Runner

1. Run Redis

Redis is required for BullMQ job queue management.

docker run -d --name redis -p 6379:6379 redis:latest

Verify Redis is running:

docker ps | grep redis

Test Redis connection:

redis-cli ping
# Should return: PONG

2. Build Docker Image for C Runner

The Dockerfile is already provided inside the code-runner folder. Navigate into it and build the image:

cd code-runner
docker build -t code-runner-c .
cd ..

Verify the image was created:

docker images | grep code-runner-c

Expected output:

code-runner-c    latest    abc123def456    2 minutes ago    200MB

πŸƒ Run Development Server

pnpm start:dev

πŸ“‘ API Documentation (Swagger)

Swagger (OpenAPI) documentation is available once the server is running:

http://localhost:3000/api

🐳 Docker Compose Setup

Docker Compose runs everything together β€” app, Redis, PostgreSQL, and pgAdmin β€” in one command. Use this instead of running services manually.

1. Stop any running Redis container to avoid port conflicts

docker stop redis
docker rm redis

2. Remove node_modules if present

On Mac/Linux:

rm -rf node_modules

On Windows (PowerShell):

Remove-Item -Recurse -Force node_modules

3. Build the code runner image

cd code-runner
docker build -t code-runner-c .
cd ..

4. Start all services

docker compose up --build

This will build images and start containers. Note: At this stage, your database tables exist, but they are empty.

5. Seed the database

Open another terminal while the containers are running and execute:

docker compose exec app npx prisma db seed

This seeds your database with initial data, including:

  • Users: Owner, Teacher, Student
  • Classrooms: CS101, JS201
  • Coding challenges and assignments

Important: Make sure the app container is running before executing this command. You only need to run this once unless you want to reset your database.

Important: Making sure Running this command inside the project file

Once running, the API is available at:

http://localhost:3000

Services

Service URL
API http://localhost:3000
Swagger http://localhost:3000/api
PostgreSQL localhost:5432
Redis localhost:6379

Stop all services

docker compose down

πŸ§ͺ Unit Tests

Test Location

  • All unit tests are co-located with the module they test:
src/
  modules/
    classrooms/
      classroom.service.ts
      classroom.service.spec.ts
      classroom.controller.ts
      classroom.controller.spec.ts
    assignments/
      assignment.service.ts
      assignment.service.spec.ts

Running Unit Tests

Make sure dependencies are installed:

pnpm install

Run the unit tests:

pnpm test

Or run in watch mode (reruns on file change):

pnpm test:watch

Unit tests use mocks β€” no database or Redis setup needed.

πŸ§ͺ Testing Code Runner

Submit a code execution job:

curl -X POST http://localhost:3000/code-runner/run \
  -H "Content-Type: application/json" \
  -d '{
    "language": "c",
    "code": "#include \nint main() {\n    printf(\"Hello World!\\n\");\n    return 0;\n}"
  }'

Expected response:

{
  "jobId": "1",
  "status": "queued"
}

Check job status:

curl http://localhost:3000/code-runner/status/1

Expected response:

{
  "jobId": "1",
  "state": "completed",
  "result": {
    "stdout": "Hello World!",
    "status": "success"
  }
}

πŸ›‘ Stop Services

docker stop redis
docker rm redis

πŸ” Flow Summary

Local Development

pnpm install
npx prisma generate
npx prisma migrate dev
cd code-runner && docker build -t code-runner-c . && cd ..
docker run -d --name redis -p 6379:6379 redis:latest
pnpm start:dev

Docker Compose

docker stop redis && docker rm redis
cd code-runner && docker build -t code-runner-c . && cd ..
docker compose up --build

πŸ“˜ Common Prisma Workflows

Situation / Action Command Notes
First-time database setup npx prisma migrate dev Applies migrations & creates DB tables
No migrations exist npx prisma db push Creates tables directly from schema without migrations
Schema (schema.prisma) changed npx prisma migrate dev Generates new migration and updates DB
Database changed manually npx prisma db pull Updates schema.prisma to match DB
Prisma client missing / types missing npx prisma generate Regenerates client without touching DB

🧱 Project Structure and Architecture Overview

See docs/ORGANIZATION.md for full explanation of folders and modules.

See docs/ARCHITECTURE.md for backend architecture and module flow.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages