Skip to content

azizbekdevuz/trainium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

112 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Trainium E-Commerce Platform

A modern, full-stack e-commerce platform built for selling high-tech fitness equipment. Trainium features a comprehensive product catalog, shopping cart, checkout system, real-time notifications, and an admin panel for managing all aspects of the business.

πŸ—οΈ Architecture

For a comprehensive overview of the system architecture, design patterns, and implementation details, see the Architecture Documentation.

✨ Features

  • E-Commerce Core

    • Product catalog with variants, categories, and inventory management
    • Shopping cart with guest and authenticated user support
    • Multi-provider payment processing (Stripe, Toss Payments)
    • Order management and tracking
    • Product recommendations engine
  • User Management

    • Multi-provider authentication (Google, Kakao, Email/Password)
    • Role-based access control (Admin, Staff, Customer)
    • User profiles and account management
  • Real-Time Features

    • Socket.IO-based notification system
    • Real-time order updates
    • Product alerts and system notifications
  • Admin Panel

    • Dashboard with analytics and statistics
    • Product, order, and customer management
    • Category and FAQ management
    • Low stock alerts and inventory tracking
  • Social Features

    • Product reviews and ratings
    • Favorites and likes
    • Review replies and interactions
  • Internationalization

    • Multi-language support (English, Korean, Uzbek)
    • URL-based locale routing
    • Translated email notifications

πŸ› οΈ Tech Stack

  • Frontend: Next.js 15.5, React 19, TypeScript, Tailwind CSS
  • Backend: Next.js API Routes, Express.js
  • Database: PostgreSQL with Prisma ORM
  • Authentication: NextAuth.js 5.0
  • Real-Time: Socket.IO
  • Payments: Stripe, Toss Payments
  • Email: Resend
  • Build System: Turbo (Monorepo)
  • Package Manager: pnpm

πŸ“ Project Structure

trainium/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ web/              # Next.js web application
β”‚   └── socket/            # Socket.IO server
β”œβ”€β”€ prisma/                # Database schema
β”œβ”€β”€ scripts/               # Build and utility scripts
└── architecture.md        # Architecture documentation

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • pnpm 9.0.6+
  • PostgreSQL database
  • Docker (optional, for containerized deployment)

Installation

  1. Clone the repository:
git clone <repository-url>
cd trainium
  1. Install dependencies:
pnpm install
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configuration

Required environment variables:

  • DATABASE_URL: PostgreSQL connection string
  • AUTH_SECRET: NextAuth secret key
  • GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET: Google OAuth credentials
  • KAKAO_CLIENT_ID / KAKAO_CLIENT_SECRET: Kakao OAuth credentials
  • STRIPE_SECRET_KEY / NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: Stripe credentials
  • TOSS_CLIENT_KEY / TOSS_SECRET_KEY: Toss Payments credentials
  • RESEND_API_KEY: Resend email service key
  • NEXTAUTH_URL: Application URL
  • SOCKET_SERVER_URL: Socket server URL for server-side HTTP calls (required in production)
  • NEXT_PUBLIC_SOCKET_URL: Socket server URL for client WebSocket connections
  • SOCKET_ADMIN_SECRET: Socket server admin secret (X-Admin-Secret header)

Docker Deployment

Important Security Note: Environment variables are handled securely:

  • .env files are NOT copied into Docker images
  • Build-time variables (NEXT_PUBLIC_*) are passed via build args
  • Runtime variables are loaded via env_file in docker-compose

Building with Docker Compose:

  1. Ensure your .env file exists in the project root with all required variables

  2. Build and start services:

    docker-compose up -d --build
  3. Set up the database:

# Generate Prisma client
pnpm --filter @apps/web prisma:generate

# Push schema (or run migrations)
pnpm --filter @apps/web prisma:push

# Optional: seed database
pnpm --filter @apps/web seed
  1. Start development servers:
# Start both web and socket servers
pnpm dev

# Or start individually
pnpm dev:web      # Web app on http://localhost:3000
pnpm dev:socket   # Socket server on http://localhost:4000

πŸ“ Available Scripts

Root Level

  • pnpm dev - Start all services in development mode
  • pnpm build - Build all applications
  • pnpm start - Start all services in production mode
  • pnpm lint - Lint all code
  • pnpm typecheck - Type check all TypeScript code

Web Application

  • pnpm dev:web - Start Next.js dev server (port 3000)
  • pnpm start:web - Start Next.js production server
  • pnpm --filter @apps/web prisma:studio - Open Prisma Studio
  • pnpm --filter @apps/web test - Run Vitest tests

Socket Server

  • pnpm dev:socket - Start Socket.IO server (port 4000)
  • pnpm start:socket - Start Socket.IO server in production

🐳 Docker Deployment

The project includes Docker configuration for containerized deployment:

# Build and start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

πŸ“š Documentation

πŸ” Authentication

The platform supports multiple authentication methods:

  • Google OAuth: Social login via Google
  • Kakao OAuth: Korean social login
  • Email/Password: Traditional credentials authentication

All authentication is handled via NextAuth.js with JWT session strategy. Admin routes and API endpoints are protected via requireAdminSession(); the first admin account is created via /admin/auth/signup when no admin exists (bootstrap).

πŸ’³ Payment Processing

The platform integrates with two payment providers:

  • Stripe: International payment processing
  • Toss Payments: Korean payment gateway

Both providers support multiple currencies and handle zero-decimal currencies (KRW, JPY, VND) correctly.

🌐 Internationalization

The platform supports three languages:

  • English (en) - Default
  • Korean (ko)
  • Uzbek (uz)

Locale routing is URL-based (/en/..., /ko/..., /uz/...) with cookie-based preference storage.

πŸ“§ Email Notifications

Email notifications are sent via Resend for:

  • Order confirmations
  • Order status updates
  • Shipping notifications

πŸ”” Real-Time Notifications

The platform includes a real-time notification system powered by Socket.IO:

  • User-specific notifications
  • Order update notifications
  • Product alerts
  • System-wide announcements
  • Deduplication and read sync between DB and socket events

πŸ§ͺ Development

Code Structure

  • Components: Reusable React components in apps/web/src/components/
  • API Routes: Next.js API routes in apps/web/src/app/api/
  • Business Logic: Core logic in apps/web/src/lib/
  • Types: TypeScript definitions in apps/web/src/types/

Database Management

# Open Prisma Studio
pnpm --filter @apps/web prisma:studio

# Generate ERD diagram (requires Mermaid CLI; use WSL on Windows)
node scripts/generate-erd.js

CI (GitHub Actions)

On push/PR to main, the workflow runs: lint (web + socket), typecheck (web), and tests (web). No build step (sitemap generation requires a live DB).

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct before submitting a pull request. Use our issue templates and pull request template when opening issues and PRs.

πŸ“ž Support

For questions and discussions, use GitHub Discussions. For security issues, see SECURITY.md.

About

TRAINIUM - This a NextJS turborepo app including web app and socket server offering the client pages and admin pages offering the modern and user friendly design.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors