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.
- NestJS
- Prisma ORM
- PostgreSQL
- Docker & Dockerode
- Redis & BullMQ
- pnpm
Make sure you have the following installed:
- Node.js (v18 or higher)
- pnpm (v8 or higher)
- Docker (v20 or higher)
- PostgreSQL (v14 or higher)
- Clone the project
git clone https://github.com/JamJam126/Codify-Backend.git
cd EduAI-GitHub-Assistant-Backend- Install project dependencies:
pnpm install- Install additional dependencies for the code runner:
pnpm install bullmq dockerode redis uuid
pnpm install -D @types/dockerodeCreate a .env file from the example:
cp .env.example .envUpdate 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=codifydbPrisma requires DATABASE_URL to be defined.
src/
prisma/
schema.prisma
createdb codifyOr inside psql:
CREATE DATABASE codify;npx prisma generateThis step reads your schema.prisma and creates:
- DB client
- TS types (User, Post, etc.)
Verify:
node_modules/@prisma/client/If the project already contains /prisma/migrations/**, run:
npx prisma migrate devThis:
- Compares schema β DB
- Applies needed SQL
- 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!
npx prisma db seedRedis is required for BullMQ job queue management.
docker run -d --name redis -p 6379:6379 redis:latestVerify Redis is running:
docker ps | grep redisTest Redis connection:
redis-cli ping
# Should return: PONGThe 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-cExpected output:
code-runner-c latest abc123def456 2 minutes ago 200MB
pnpm start:devSwagger (OpenAPI) documentation is available once the server is running:
Docker Compose runs everything together β app, Redis, PostgreSQL, and pgAdmin β in one command. Use this instead of running services manually.
docker stop redis
docker rm redisOn Mac/Linux:
rm -rf node_modulesOn Windows (PowerShell):
Remove-Item -Recurse -Force node_modulescd code-runner
docker build -t code-runner-c .
cd ..docker compose up --buildThis will build images and start containers. Note: At this stage, your database tables exist, but they are empty.
Open another terminal while the containers are running and execute:
docker compose exec app npx prisma db seedThis 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
| Service | URL |
|---|---|
| API | http://localhost:3000 |
| Swagger | http://localhost:3000/api |
| PostgreSQL | localhost:5432 |
| Redis | localhost:6379 |
docker compose down- 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
Make sure dependencies are installed:
pnpm installRun the unit tests:
pnpm testOr run in watch mode (reruns on file change):
pnpm test:watchUnit tests use mocks β no database or Redis setup needed.
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/1Expected response:
{
"jobId": "1",
"state": "completed",
"result": {
"stdout": "Hello World!",
"status": "success"
}
}docker stop redis
docker rm redispnpm 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:devdocker stop redis && docker rm redis
cd code-runner && docker build -t code-runner-c . && cd ..
docker compose up --build| 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 |
See docs/ORGANIZATION.md for full explanation of folders and modules.
See docs/ARCHITECTURE.md for backend architecture and module flow.