Skip to content

Repository files navigation

Uni-Chance Backend

A production-ready REST API that estimates a student's chance of admission to universities. Built with NestJS, MongoDB (Mongoose), and OpenAI, it handles user accounts, multi-provider authentication, AI-driven admission predictions, and Stripe-based subscription billing.

Features

  • Authentication — email/password with email verification, JWT access & refresh tokens (httpOnly cookies), password reset, plus Google, Microsoft, and Facebook OAuth.
  • Predictions — students submit their academic profile (exams, GPA, activities, honors) and receive an AI-generated admission chance via OpenAI.
  • Universities — CRUD catalog of universities used as prediction targets.
  • Plans & Subscriptions — configurable subscription plans and per-user subscription tracking.
  • Payments — Stripe Checkout sessions and webhook handling for subscription lifecycle.
  • Users — user management and profiles.
  • Global request throttling, class-validator DTO validation, and CORS with credentials.

Tech Stack

Concern Technology
Framework NestJS 11
Database MongoDB via Mongoose
Auth Passport (JWT, Google, Microsoft, Facebook)
AI OpenAI
Payments Stripe
Email Nodemailer / Brevo (SendinBlue) / SendGrid
Language TypeScript
Testing Jest

Getting Started

Prerequisites

  • Node.js 20+
  • MongoDB (local or Atlas)
  • Accounts/keys for OpenAI, Stripe, and any OAuth providers you enable

Installation

npm install

Configuration

Create a .env file in the project root:

NODE_ENV=development
PORT=5505
ALLOWED_ORIGINS=http://localhost:5173

# Database
MONGODB_URI=mongodb://localhost:27017/lets-cook

# JWT
ACCESS_TOKEN_SECRET=your-access-secret
ACCESS_TOKEN_EXPIRE_TIME=7d
REFRESH_TOKEN_SECRET=your-refresh-secret
REFRESH_TOKEN_EXPIRE_TIME=7d

# Email
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=you@example.com
EMAIL_PASSWORD=your-email-password
EMAIL_FROM=you@example.com
BREVO_API_KEY=your-brevo-key

# Google OAuth
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=http://localhost:5500/v1/auth/google/callback

# Microsoft OAuth
MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
MICROSOFT_CALLBACK_URL=http://localhost:5500/v1/auth/microsoft/callback

# Facebook OAuth
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
FACEBOOK_CALLBACK_URL=http://localhost:5500/v1/auth/facebook/callback

# OpenAI
OPENAI_API_KEY=

# Stripe
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=

Running

# development (watch mode)
npm run start:dev

# production build
npm run build
npm run start:prod

The API listens on PORT (default 5505) and is served under the global prefix /v1.

API Overview

All routes are prefixed with /v1.

Auth — /v1/auth

Method Path Description
POST /register Register a new user
POST /login Log in, issue tokens
POST /verify-email Verify email address
POST /refresh Refresh access token
POST /logout Log out
GET /profile Current user profile
POST /forgot-password Request password reset
POST /reset-password Reset password
GET /google, /google/callback Google OAuth
GET /microsoft, /microsoft/callback Microsoft OAuth
GET /facebook, /facebook/callback Facebook OAuth

Predictions — /v1/predictions

Method Path Description
POST / Create a prediction profile
POST /:id/predict Run the AI prediction
GET /me Current user's predictions
GET /user/:userId Predictions for a user
GET /:id Get a prediction
DELETE /:id Delete a prediction

Universities — /v1/university

Full CRUD: POST /, GET /, GET /:id, PUT /:id, DELETE /:id.

Users — /v1/users

POST /, GET /, GET /:id, PATCH /:id.

Plans — /v1/plans

POST /, GET /, GET /:id, PATCH /:id, POST /:id/inactivate, DELETE /:id.

Subscriptions — /v1/subscribtions

GET /my — current user's subscription.

Payments — /v1/payment

Method Path Description
POST /create-checkout-session Create a Stripe Checkout session
POST /webhook Stripe webhook receiver
GET /my Current user's payments

Project Structure

src/
├── auth/           # Authentication, OAuth strategies, guards, JWT
├── users/          # User accounts
├── university/     # University catalog
├── predictions/    # Admission-chance predictions (OpenAI)
├── plans/          # Subscription plans
├── subscribtions/  # User subscriptions
├── payments/       # Stripe payments & webhooks
├── common/         # Shared base repository, decorators, guards, services
├── config/         # Environment validation (envalid)
└── main.ts         # Bootstrap

Additional module-level documentation lives in the docs/ directory.

Testing

npm test          # unit tests
npm run test:e2e  # end-to-end tests
npm run test:cov  # coverage

Docker

Build and run with the production compose file (API + MongoDB):

docker compose -f docker-compose-prod.yml up --build

See docs/DOCKER_DEPLOY.md for deployment details.

License

UNLICENSED — private project.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages