Skip to content

imshubham07/Draw-app

Repository files navigation

🎨 Excalidraw Clone - Collaborative Drawing App

A modern full-stack web application for real-time collaborative drawing. Built with Next.js, TypeScript, WebSockets, and PostgreSQL.

Node TypeScript Next.js Docker License

πŸ“Œ Table of Contents

✨ Features

  • 🎯 Real-time Collaborative Drawing - Multiple users can draw simultaneously with WebSocket synchronization
  • πŸ” User Authentication - Secure JWT-based authentication with password hashing
  • πŸ’Ύ Persistent Storage - Save drawings to PostgreSQL database
  • πŸ“± Responsive UI - Modern Next.js 15 frontend with Tailwind CSS
  • πŸš€ Monorepo Architecture - Organized with pnpm workspaces and Turbo
  • 🐳 Docker Ready - Containerized services with docker-compose
  • πŸ“ Type Safe - 100% TypeScript codebase
  • ⚑ Fast Builds - Optimized with Turbo caching

πŸ› οΈ Tech Stack

Frontend

  • Next.js 15.5 - React framework with SSR
  • React 19 - UI library
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Socket.io Client - WebSocket communication

Backend

  • Node.js 20 - Runtime
  • Express.js - REST API framework
  • WebSocket (ws) - Real-time communication
  • JWT - Authentication
  • bcrypt - Password hashing

Database

  • PostgreSQL 16 - Primary database
  • Prisma - ORM and migrations

DevOps

  • Docker & Docker Compose - Containerization
  • pnpm - Package manager
  • Turbo - Monorepo build system
  • TypeScript - Static typing

πŸ“ Project Structure

Excalidraw/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ excelidraw-frontend/     # Next.js 15 React app
β”‚   β”‚   β”œβ”€β”€ app/                 # App directory structure
β”‚   β”‚   β”œβ”€β”€ Components/          # React components
β”‚   β”‚   β”œβ”€β”€ public/              # Static assets
β”‚   β”‚   └── package.json
β”‚   β”œβ”€β”€ http-backend/            # Express REST API
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts         # Server entry point
β”‚   β”‚   β”‚   └── middleware.ts    # Custom middleware
β”‚   β”‚   └── package.json
β”‚   └── ws-backend/              # WebSocket server
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   └── index.ts         # WS server entry
β”‚       └── package.json
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ db/                      # Prisma ORM & migrations
β”‚   β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”‚   β”œβ”€β”€ schema.prisma    # Database schema
β”‚   β”‚   β”‚   └── migrations/      # DB migrations
β”‚   β”‚   └── package.json
β”‚   β”œβ”€β”€ common/                  # Shared TypeScript types
β”‚   β”œβ”€β”€ backend-common/          # Backend utilities
β”‚   β”œβ”€β”€ ui/                      # Shared React components
β”‚   β”œβ”€β”€ typescript-config/       # Shared tsconfig
β”‚   └── eslint-config/           # Shared ESLint config
β”œβ”€β”€ docker-compose.yml           # Service orchestration
β”œβ”€β”€ pnpm-workspace.yaml          # Workspace config
β”œβ”€β”€ turbo.json                   # Build configuration
β”œβ”€β”€ package.json                 # Root package
└── README.md                    # This file

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ (Download)
  • pnpm 9.0+
    npm install -g pnpm@9.0.0
  • PostgreSQL 16+ (for local development)
  • Docker & Docker Compose (for containerized setup)

Option 1: Local Development

  1. Clone and setup

    git clone <repo-url>
    cd Excalidraw
    pnpm install
  2. Configure environment

    # Create .env in root
    echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/excalidraw" > .env
    echo "JWT_SECRET=your-secret-key" >> .env
  3. Setup database

    cd packages/db
    npx prisma migrate dev
    npx prisma generate
    cd ../..
  4. Start development

    pnpm dev

    Services will start:

Option 2: Docker (Recommended)

git clone <repo-url>
cd Excalidraw
docker compose up -d --build

Access at http://localhost:3000

See README.docker.md for detailed Docker guide.

πŸ’» Development

Install Dependencies

pnpm install

Start Dev Server

pnpm dev

Build for Production

pnpm build

Type Checking

pnpm check-types

Linting & Formatting

pnpm lint          # Run ESLint
pnpm format        # Format with Prettier

Run Specific App

pnpm dev --filter=excelidraw-frontend
pnpm dev --filter=http-backend
pnpm dev --filter=ws-backend

πŸ“‹ Scripts

All scripts run via pnpm in the root directory:

Script Purpose
pnpm dev Start all services in dev mode
pnpm build Build all apps & packages for production
pnpm lint Run ESLint on all code
pnpm format Format code with Prettier
pnpm check-types TypeScript type checking

Database scripts (from packages/db):

npx prisma migrate dev     # Create & apply migrations
npx prisma generate        # Generate Prisma client
npx prisma studio         # Open database GUI

🐳 Docker Deployment

Quick start with Docker:

docker compose up -d --build

Services:

Useful Docker Commands:

# View logs
docker compose logs -f http-backend
docker compose logs -f ws-backend

# Stop services
docker compose down

# Rebuild specific service
docker compose up -d --build http-backend

See README.docker.md for complete Docker documentation.

πŸ—„οΈ Database

Schema Overview

The database includes tables for:

  • Users - User accounts with hashed passwords
  • Drawings - Persisted drawing data
  • Sessions - User session management

Migrations

Migrations are in packages/db/prisma/migrations/. To create a new migration:

cd packages/db
npx prisma migrate dev --name your_migration_name

Access Database

Local PostgreSQL:

psql postgresql://postgres:postgres@localhost:5432/excalidraw

Docker:

docker compose exec db psql -U postgres -d excalidraw

πŸ—οΈ Architecture

Monorepo Structure

  • Uses pnpm workspaces for dependency management
  • Uses Turbo for intelligent build caching
  • Shared packages reduce code duplication

Service Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Next.js Frontend (3000)         β”‚
β”‚  - User Interface                    β”‚
β”‚  - Drawing Canvas                    β”‚
β”‚  - Real-time Sync via WebSocket      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚                   β”‚
β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ HTTP API    β”‚    β”‚  WebSocket   β”‚
β”‚ (3001)      β”‚    β”‚  (8080)      β”‚
β”‚ - Auth      β”‚    β”‚ - Real-time  β”‚
β”‚ - CRUD      β”‚    β”‚ - Drawing    β”‚
β”‚ - JWT       β”‚    β”‚ - Sync       β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚                   β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
        β”‚ PostgreSQL   β”‚
        β”‚ (5432)       β”‚
        β”‚ - Users      β”‚
        β”‚ - Drawings   β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🀝 Contributing

  1. Create a feature branch

    git checkout -b feature/amazing-feature
  2. Make your changes and commit

    git add .
    git commit -m "Add amazing feature"
  3. Run checks before pushing

    pnpm lint
    pnpm format
    pnpm check-types
    pnpm build
  4. Push and create pull request

    git push origin feature/amazing-feature

πŸ“„ License

MIT License - feel free to use this project for personal or commercial purposes.

πŸ†˜ Troubleshooting

Port Already in Use?

# Kill process on port 3000
lsof -i :3000 | grep LISTEN | awk '{print $2}' | xargs kill -9

Database Connection Issues?

# Verify PostgreSQL is running
psql --version
psql postgresql://postgres:postgres@localhost:5432/excalidraw

Node Modules Issues?

# Clean install
pnpm store prune
rm -rf node_modules packages/*/node_modules
pnpm install

For more help, see README.docker.md for Docker-specific issues.


Happy Drawing! 🎨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published