Skip to content

authyx/exchange-13

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exchange 1337

A peer-to-peer money exchange web app for 1337 students. The idea is simple: if you have physical cash but need a CIH bank transfer (or vice versa), this platform matches you with a student on your campus who needs the exact opposite.

Why this exists

Finding someone to do a quick cash-to-bank exchange on campus usually means asking around or posting in Discord server. This app automates the process with a matching engine so you don't have to look for people manually.

Features

  • OAuth Authentication: Secure login using the 42 Intra API. Users are restricted to their primary campus automatically.
  • Smart Matching Engine: A transaction-backed matching engine that automatically pairs complementary orders (e.g., matching a "Need Cash/Have CIH" order with a "Need CIH/Have Cash" order).
  • Partial Fulfillment: Large orders can automatically be fulfilled by multiple smaller orders.
  • Live Dashboard: A clean HTML/JS dashboard with real-time browser notifications for new matches.
  • Discord Integration: One-click copy tool for sending Discord DMs to your matched counterpart to arrange the physical exchange.

Requirements

  • Node.js (v16+ recommended)
  • PostgreSQL (v12+)
  • 42 Intra API Credentials

Environment Variables

Create a .env file in the root directory and configure the following variables:

PORT=3000
DATABASE_URL=postgres://user:password@localhost:5432/exchange_db

# 42 Intra API Credentials
UID=your_42_app_client_id
SECRET=your_42_app_client_secret
BASE_URL=http://localhost:3000

# Auth
JWT_SECRET=your_secure_random_string

# Environment ('dev' enables the /auth/dev-login route for testing)
NODE_ENV=dev

Setup & Installation

  1. Install Dependencies:

    npm install
  2. Initialize Database: Run the SQL script located in src/config/init.sql against your PostgreSQL database to create the necessary tables, types, and constraints.

    psql -U postgres -d exchange_db -f src/config/init.sql

    or use it to create tables in your preferred database client.

  3. Run the Application:

    npm run start
    # or for development with auto-restart:
    node --watch src/server.js

    The app will be running at http://localhost:3000.

Testing

When NODE_ENV is set to dev, you can use the /auth/dev-login endpoint to bypass the 42 OAuth flow and log in as test users.

curl -X POST http://localhost:3000/auth/dev-login -H "Content-Type: application/json" -d '{"username": "alice", "campus": 16}'

Contributing

Contributions are always welcome! Whether it's fixing bugs, adding new payment methods (like Attijari or PayPal), or improving the UI, feel free to jump in.

If you are modifying the backend:

  • The matching engine (src/services/matchService.js) handles concurrency using PostgreSQL transactions and FOR UPDATE SKIP LOCKED.
  • Make sure to test your code for race conditions, especially in the /confirm and /cancel routes, as this handles financial states.

How to contribute

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/cool-new-feature)
  3. Commit your changes
  4. Push to the branch (git push origin feature/cool-new-feature)
  5. Open a Pull Request

License

This project is intended for the internal use of 1337 students.

About

A small system to exchange money between students in 1337 campus

Topics

Resources

Stars

Watchers

Forks

Contributors