Skip to content

ARRNAV26/backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TWINCODE - Real-Time Pair Programming Platform

Overview

TwinCode is a modern, real-time collaborative code editor that enables multiple developers to work together on the same codebase simultaneously. Built with cutting-edge web technologies, it provides instant synchronization of code changes, intelligent autocomplete suggestions, and a polished user experience.

✨ Features

  • ** Room-Based Collaboration**: Create unique collaborative sessions with shareable URLs
  • ** Real-Time Synchronization**: See code changes instantly across all connected users (WebSocket-powered)
  • ** AI-Powered Autocomplete**: Intelligent code completion triggered after brief typing pauses
  • ** Persistent Sessions**: Code is automatically saved and survives browser refreshes
  • ** Professional UI**: Material-UI design with responsive mobile support
  • ** CORS Security**: Configured for production deployment safety

How to Run Both Services

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm

Backend Setup

cd pair-programming-app/backend

# Install Python dependencies
pip install -r requirements.txt

# Set environment variables (optional)
export DATABASE_URL="sqlite:///./test.db"  # Or PostgreSQL URL

# Start the FastAPI server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd pair-programming-app/frontend

# Install Node dependencies
npm install

# Configure environment (optional - defaults to production)
echo "REACT_APP_API_ENV=development" > .env.local  # For localhost backend
# Or REACT_APP_API_ENV=production for deployed backend

# Start the React development server
npm start

Alternative: Docker Deployment

# From project root
docker-compose up --build

Architecture and Design Choices

Backend Architecture (FastAPI)

  • Layered Architecture: Separated routers, services, models, and configuration
  • WebSocket Manager: Extracted connection logic for maintainability
  • Database Abstraction: SQLAlchemy ORM with async support ready
  • Environment Configuration: Pydantic-based config with environment variables

Frontend Architecture (React TypeScript)

  • Component Structure: Modular, reusable React components with TypeScript
  • API Abstraction: Centralized service layer with Axios
  • Configuration Management: Environment-aware API URLs (dev/prod)
  • Responsive Design: Material-UI breakpoints for cross-device support
  • Code Editor: Monaco Editor integration with TypeScript support

Real-Time Synchronization Design

  • Conflict Resolution: Last-write-wins approach (simple, reliable for pair programming)
  • Database Persistence: SQLite with room-based isolation
  • WebSocket Protocol: JSON messages for type safety and easy extension
  • Connection Management: Automatic cleanup and reconnection handling

Security Considerations

  • CORS Policy: Specific origin whitelisting (production-ready)
  • Input Validation: Pydantic models for API data validation
  • UUID Rooms: Unpredictable room IDs prevent enumeration
  • Rate Limiting: Configurable per-endpoint throttling ready

Deployed Demo Link

🌐 Live Demo: twinco.netlify.app

The frontend is deployed on Netlify with the backend running on Koyeb. The application automatically uses production API endpoints when deployed.

🔧 What You Would Improve with More Time

High Priority

  • Authentication System: User login/registration with JWT tokens
  • Operational Transform: Advanced conflict resolution for concurrent editing
  • User Presence: Show online users, cursors, and collaborators
  • File Management: Support multiple files and project structure

Medium Priority

  • Code Version History: Git-like versioning within sessions
  • Language Support: Syntax highlighting and autocomplete for multiple languages
  • Collaborative Cursors: Real-time cursor positions from all users
  • Voice/Text Chat: Built-in communication within rooms
  • Performance Monitoring: Real-time metrics and optimization

Low Priority

  • Unit/Integration Tests: Comprehensive test coverage
  • API Documentation: Swagger/OpenAPI specification
  • Docker Optimization: Multi-stage builds and security scanning
  • Offline Mode: Service worker for basic offline functionality

⚠️ Limitations

Current Implementation Limits

  • Concurrent Editing: Simple last-write-wins may overwrite simultaneous changes
  • Browser Compatibility: WebSocket support required (modern browsers only)
  • Room Size: No explicit limit on users per room (performance degrades with >10)
  • Language Support: Currently Python-only for autocomplete
  • Authentication: No user management or room ownership

Performance Considerations

  • Database Load: Frequent updates may strain SQLite in high-traffic scenarios
  • Memory Usage: Large codebases consume WebSocket memory buffers
  • Network Latency: Geographic distribution affects real-time responsiveness
  • Scalability: Single-server architecture limits horizontal scaling

Technical Achievements

  • Zero-Configuration Development: Hot-reloaded frontend/backend with environment switching
  • Type Safety: Full TypeScript coverage with Pydantic validation
  • Responsive Design: Mobile-first Material-UI implementation
  • Production Deployment: CORS, environment configs, and deployment-ready builds
  • Code Quality: ESLint compliance, cognitive complexity optimization
  • Developer Experience: Clear architecture, comprehensive documentation, and modular code

Contributing

  1. Fork the repository
  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

📄 License

This project is open source and available under the MIT License.


Built with ❤️ using React, FastAPI, WebSockets, and creative coding passion!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors