Skip to content

togisoft/t-force

Repository files navigation

πŸ” T-Force - Modern Authentication & Chat Platform

T-Force Logo

Rust Next.js TypeScript PostgreSQL Docker License

πŸ“Έ Screenshots

T-Force Dashboard
T-Force Dashboard
T-Force Dashboard
## πŸ“‹ Table of Contents

🎯 About the Project

T-Force is a comprehensive authentication and real-time chat platform developed for modern web applications. It provides a high-performance, secure, and scalable solution using Rust backend and Next.js frontend.

🎯 Goals

  • Security: Modern encryption and authentication standards
  • Performance: Rust's speed and Next.js optimizations
  • Scalability: Microservice architecture and Docker support
  • User Experience: Modern UI/UX design

✨ Features

πŸ” Authentication

  • βœ… Email/Password Login: Secure user registration and login
  • βœ… OAuth Integration: Social login with Google and GitHub
  • βœ… Two-Factor Authentication (2FA): TOTP-based security
  • βœ… Password Reset: Secure password reset via email
  • βœ… Session Management: Multi-session control and termination
  • βœ… JWT Token System: Secure token-based authentication

πŸ’¬ Real-Time Chat

  • βœ… WebSocket Connection: Instant messaging
  • βœ… Room System: Private and public chat rooms
  • βœ… Media Sharing: Image, video, and voice messages
  • βœ… Message History: Persistent message storage
  • βœ… Room Passwords: Secure private rooms
  • βœ… Auto Reconnection: Automatic recovery on connection loss

πŸ‘₯ User Management

  • βœ… Profile Management: User information and profile pictures
  • βœ… Role-Based Authorization: Admin and user roles
  • βœ… User Status: Active/inactive user control
  • βœ… Admin Panel: User management and system control

πŸ›‘οΈ Security Features

  • βœ… Rate Limiting: API request rate limiting
  • βœ… CORS Protection: Cross-origin request security
  • βœ… SQL Injection Protection: ORM-based secure database operations
  • βœ… XSS Protection: Frontend security measures
  • βœ… Password Hashing: Secure password storage with Argon2

πŸ› οΈ Technology Stack

πŸ¦€ Backend (Rust)

# Core Framework
actix-web = "4.4.0"          # Web framework
actix-cors = "0.7.1"         # CORS middleware
actix-web-actors = "4.2.0"   # WebSocket support

# Database
sea-orm = "1.1.14"           # ORM
postgres = "16-alpine"       # Database

# Authentication
jsonwebtoken = "9.3.1"       # JWT token
argon2 = "0.5.2"             # Password hashing
oauth2 = "4.4.2"             # OAuth integration

# Other
serde = "1.0.188"            # Serialization
tokio = "1.32.0"             # Async runtime
lettre = "0.11.18"           # Email sending

βš›οΈ Frontend (Next.js)

{
  "next": "15.5.0",              // React framework
  "react": "19.0.0",            // UI library
  "typescript": "5.0+",         // Type safety
  "tailwindcss": "3.4.0",       // CSS framework
  "shadcn/ui": "latest",        // UI components
  "react-hook-form": "7.62.0",  // Form management
  "jwt-decode": "4.0.0",        // JWT parsing
  "lucide-react": "0.541.0"     // Icons
}

πŸ—„οΈ Database & Infrastructure

  • PostgreSQL 16: Primary database
  • Docker & Docker Compose: Containerization
  • Traefik: Reverse proxy and load balancer
  • Nginx (production): Static file serving
  • Let's Encrypt: Automatic SSL certificates

πŸ”„ DevOps & Monitoring

  • GitHub Actions: CI/CD pipeline
  • Prometheus: Metrics collection
  • Grafana: Monitoring dashboard
  • Docker Health Checks: Service monitoring
  • Automated Backups: Database backup scripts
  • Log Aggregation: Structured logging

πŸ› οΈ Development Tools

  • Cargo: Rust package manager
  • npm/yarn: Node.js package manager
  • ESLint & Prettier: Code formatting
  • TypeScript: Type checking
  • Sea-ORM: Database ORM
  • Actix-Web: Web framework
  • Tailwind CSS: Utility-first CSS
  • Shadcn/UI: Component library

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚    Traefik      β”‚    β”‚    Backend      β”‚
β”‚   (Next.js)     │◄──►│  (Reverse Proxy)│◄──►│    (Rust)       β”‚
β”‚   Port: 3000    β”‚    β”‚   Port: 80      β”‚    β”‚   Port: 8080    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Static Files  β”‚    β”‚   Load Balancer β”‚    β”‚   PostgreSQL    β”‚
β”‚   & Assets      β”‚    β”‚   & SSL/TLS     β”‚    β”‚   Database      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‘ API Endpoints

πŸ” Authentication

POST   /api/auth/register     # User registration
POST   /api/auth/login        # Login
POST   /api/auth/logout       # Logout
GET    /api/auth/validate     # Token validation
POST   /api/auth/forgot       # Password reset request
POST   /api/auth/reset        # Password reset

πŸ‘€ User Management

GET    /api/user/me           # Get user information
PUT    /api/user/profile      # Update profile
POST   /api/user/avatar       # Upload profile picture
GET    /api/user/sessions     # Active sessions
DELETE /api/user/session/:id  # Terminate session

πŸ’¬ Chat System

GET    /api/chat/rooms        # Get chat rooms
POST   /api/chat/rooms        # Create a new room
GET    /api/chat/rooms/:id    # Get room details
DELETE /api/chat/rooms/:id    # Delete room
GET    /api/chat/messages     # Get message history
POST   /api/chat/upload       # Upload media
WS     /ws                    # WebSocket connection

πŸš€ Installation

πŸ“‹ Requirements

  • Docker & Docker Compose: Container management
  • Git: Version control
  • Node.js 18+: Frontend development (optional)
  • Rust 1.70+: Backend development (optional)

πŸ”§ Quick Start

  1. Clone the project
git clone https://github.com/togisoft/t-force.git
cd t-force
  1. Create environment file
cp env.prod.example .env.prod
# Edit the .env.prod file
  1. Start development environment
# For development
cp env.prod.example .env.dev
./scripts/dev.sh

# For production
./scripts/prod-deploy.sh
  1. Access the application

🐳 Production Deployment

# Create production environment file
cp env.prod.example .env.prod

# Start in production mode
./scripts/prod-deploy.sh

πŸ“± Usage

πŸ‘€ User Registration and Login

  1. Click on "Sign Up" tab on the main page
  2. Enter email, name and a strong password
  3. Complete email verification
  4. Sign in or use OAuth for quick login

πŸ’¬ Chat Usage

  1. Access the dashboard
  2. Click on "New Room" button
  3. Set room name and password (optional)
  4. Invite friends by sharing the room code
  5. Start sending messages, images, videos and audio

πŸ”’ Security Settings

  1. Go to profile settings
  2. Open "Two-Factor Authentication" section
  3. Scan QR code and enter verification code
  4. Store your backup codes in a safe place

πŸ”§ Development

πŸ”§ Development Environment Setup

# Backend development
cd backend
cargo run

# Frontend development
cd frontend
npm install
npm run dev

# Database migration (handled automatically by prod-deploy.sh)

πŸ§ͺ Running Tests

# Backend tests
cd backend
cargo test

# Frontend tests
cd frontend
npm test

# E2E tests
npm run test:e2e

πŸ“œ Available Scripts

All scripts should be run from the project root directory:

# Start development environment
./scripts/dev.sh

# Start production environment
./scripts/prod-deploy.sh

# Create backup
./scripts/backup.sh

# View logs
./scripts/logs.sh

# Stop services
./scripts/stop.sh

# Reset environment
./scripts/reset.sh

πŸ“ Code Standards

Rust (Backend)

# Format check
cargo fmt --check

# Linting
cargo clippy -- -D warnings

# Run tests
cargo test

TypeScript (Frontend)

# Format check
npm run lint

# Type checking
npm run type-check

# Build test
npm run build

πŸ“Š API Documentation

πŸ” Authentication Endpoints

POST /api/auth/register

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "securePassword123"
}

POST /api/auth/login

{
  "email": "john@example.com",
  "password": "securePassword123"
}

Response:

{
  "user": {
    "id": "uuid",
    "email": "john@example.com",
    "name": "John Doe",
    "role": "user"
  },
  "token": "jwt_token_here"
}

πŸ’¬ Chat WebSocket Events

Client β†’ Server

{
  "type": "join_room",
  "room_id": "room_uuid",
  "password": "optional_password"
}

{
  "type": "send_message",
  "room_id": "room_uuid",
  "content": "Hello, world!",
  "message_type": "text"
}

Server β†’ Client

{
  "type": "message",
  "data": {
    "id": "message_uuid",
    "user": {
      "id": "user_uuid",
      "name": "John Doe"
    },
    "content": "Hello, world!",
    "timestamp": "2024-01-01T12:00:00Z"
  }
}

πŸ”’ Security

πŸ›‘οΈ Security Measures

  • Password Hashing: Argon2 algorithm
  • JWT Token: Secure token-based authentication
  • Rate Limiting: API request rate limiting
  • CORS: Cross-origin request security
  • SQL Injection: Protection via ORM usage
  • XSS: Frontend sanitization

πŸ” Environment Variables

# Critical security settings
NEXTAUTH_SECRET=your-super-secret-key
JWT_SECRET=your-jwt-secret
DATABASE_URL=postgres://user:pass@localhost/db

# OAuth settings
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret

🚨 Security Recommendations

  1. Use strong passwords
  2. Enable 2FA
  3. Keep environment variables secure
  4. Use HTTPS (in production)
  5. Perform regular updates

🀝 Contributing

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“‹ Contribution Guidelines

  • Follow code standards
  • Write tests
  • Update documentation
  • Write descriptive commit messages

πŸ“„ License

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


Developed with ❀️

πŸ› Bug Report | πŸ’¬ Discussions | πŸ“– Wiki