GhostOf0days/Tradelingo

Duolingo for Trading (Class Project)

โ˜… 1Forks 0TypeScriptGitHub โ†—Compare

Project website โ†—

README

Tradelingo

A Duolingo-style financial education platform that teaches users about trading, investing, and financial literacy through interactive lessons and quizzes.

Features

  • 4 Comprehensive Modules with 52+ lessons covering:

    • Module 1: Trading (15 lessons) - Stock market fundamentals, technical analysis, risk management
    • Module 2: Retirement Planning (12 lessons) - 401(k), IRAs, Social Security, tax strategies
    • Module 3: Cryptocurrencies (15 lessons) - Blockchain, Bitcoin, Ethereum, DeFi, trading strategies
    • Module 4: Brokers & Trading Platforms (10 lessons) - Broker types, order execution, margin trading
  • Interactive Learning

    • Module pretests to assess knowledge
    • Detailed lessons with practical examples
    • Quiz questions after each lesson
    • Progress tracking and streak system
    • Experience points (XP) and level progression
  • User Features

    • Account registration and authentication
    • Daily activity streaks with reset logic
    • Module completion tracking
    • Automatic module unlocking on completion
    • Experience points system

Tech Stack ๐Ÿ› ๏ธ

Frontend:

  • React 18.3.1
  • TypeScript 5.6.3
  • Vite 6.4.1
  • React Router for navigation
  • Lucide React for icons

Backend:

  • Express 5.2.1
  • MongoDB 7.1.0 for data persistence
  • Bcryptjs for password hashing
  • CORS enabled for frontend communication

Getting Started

Prerequisites

  • Bun runtime (https://bun.sh)
  • MongoDB Atlas account or local MongoDB instance
  • Node.js 20+

Installation

  1. Clone the repository

    git clone https://github.com/GhostOf0days/Tradelingo.git
    cd Tradelingo
  2. Install dependencies

    bun install
  3. Set up environment variables Create a .env file in the root directory with your MongoDB connection string:

    MONGODB_URI=your_mongodb_connection_string_here
    

    โš ๏ธ Important: Keep your .env file private and never commit it to version control. Add it to .gitignore.

  4. Start the backend server

    bun server/index.ts

    Server runs on http://localhost:3000

  5. Start the frontend dev server (in another terminal)

    bun run dev

    Frontend runs on http://localhost:5173 or http://localhost:5174

Database ๐Ÿ—„๏ธ

MongoDB with automatic schema migrations:

  • Users collection with authentication, progress tracking, and module completion data
  • Automatic field addition for legacy users (lastUnlockedModuleId, progressByModuleId, completedModules)
  • Secure password hashing with bcrypt

User Schema

{
  email: string,
  password: string (hashed),
  displayName: string,
  experiencePoints: number,
  lastUnlockedModuleId: number,
  progressByModuleId: { [moduleId]: { lessonCurrent: number } },
  streakDays: number,
  lastActivityDate: string (ISO date),
  completedModules: array,
  createdAt: Date
}

API Endpoints

Authentication

  • POST /api/register - Register new user
  • POST /api/login - Login user

Progress & Learning

  • GET /api/progress/:email - Get user's module progress
  • POST /api/complete-lesson - Mark lesson as complete
  • POST /api/pass-module - Pass module pretest and unlock next module
  • POST /api/complete-module - Mark entire module as completed
  • POST /api/update-xp - Update user's experience points

User Data

  • GET /api/user/:email - Get user's full profile
  • GET /api/completed-modules/:email - Get list of completed modules
  • POST /api/update-streak - Update daily streak

Development

  • bun run lint โ€” ESLint (src, server, tests)
  • bun run lint:fix
  • bun run format โ€” Prettier
  • bun run test / bun run test:run โ€” Vitest (mocked DB in tests/mockDb.ts)
  • bun run test:coverage

Project Structure

Tradelingo/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/       # React components (Header, ModulesPage, etc.)
โ”‚   โ”œโ”€โ”€ pages/           # Page components (Lesson, Login, Register)
โ”‚   โ”œโ”€โ”€ contexts/        # React contexts (UserContext for auth)
โ”‚   โ”œโ”€โ”€ data/            # Module lesson content (module1.ts, module2.ts, etc.)
โ”‚   โ”œโ”€โ”€ App.tsx
โ”‚   โ””โ”€โ”€ index.tsx
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ index.ts         # Express server & API endpoints
โ”‚   โ””โ”€โ”€ db.ts            # Database utilities
โ”œโ”€โ”€ tests/               # Unit tests and mock data (api.test.ts, mockDb.ts)
โ”œโ”€โ”€ vite.config.ts       # Vite configuration
โ”œโ”€โ”€ vitest.config.ts     # Vitest configuration
โ”œโ”€โ”€ eslint.config.js     # ESLint flat config
โ”œโ”€โ”€ tsconfig.json        # TypeScript configuration
โ””โ”€โ”€ package.json

Features Implemented

  • User authentication with password hashing
  • 4 complete modules with comprehensive lessons
  • Module unlocking system (unlock next module on completion)
  • Pretest & post-lesson quizzes
  • Progress tracking per module
  • Daily streak system
  • Experience points system
  • Schema migration for legacy users
  • Responsive UI with CSS styling

Database Migrations

The backend automatically runs migrations on startup to ensure all users have required fields:

  • Adds lastUnlockedModuleId: 1 for legacy users
  • Adds progressByModuleId: {} for legacy users
  • Adds completedModules: [] for legacy users

License

Class project for educational purposes.

Contributors

kaden-kkGhostOf0daysJ1m4Marcuschan2004

Issues