Skip to content

Проект для работы с заметками с jwt авторизацией

kolelan/js-jwt-notes

Repository files navigation

JWT Notes Application

A full-stack notes application built with React, Node.js, Express, MongoDB, and Docker. Features JWT authentication, OAuth integration (Google & VK), folder organization, and real-time note management.

screen.png

🚀 Features

  • Authentication: JWT-based authentication with optional OAuth (Google & VK)
  • Note Management: Create, edit, delete, and organize notes
  • Folder Organization: Hierarchical folder structure for note organization
  • Search & Tags: Tag-based categorization and search functionality
  • Favorites: Mark notes as favorites for quick access
  • Responsive Design: Modern, mobile-friendly interface
  • Docker Support: Full containerization with Docker Compose
  • Development Mode: Hot reload for both frontend and backend

🏗️ Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Frontend      │    │   Nginx         │    │   Backend       │
│   (React)       │◄───┤   (Reverse     │◄───┤   (Node.js)     │
│   Port: 3000    │    │    Proxy)      │    │   Port: 5000    │
│                 │    │   Port: 80     │    │                 │
└─────────────────┘    └─────────────────┘    └─────────────────┘
                                                       │
                                              ┌─────────────────┐
                                              │   MongoDB       │
                                              │   Port: 27017   │
                                              └─────────────────┘

🛠️ Tech Stack

Frontend

  • React 18 with Vite
  • React Router for navigation
  • Axios for API calls
  • CSS3 with modern styling

Backend

  • Node.js with Express
  • MongoDB with Mongoose
  • JWT for authentication
  • Passport.js for OAuth strategies
  • bcryptjs for password hashing

Infrastructure

  • Docker & Docker Compose
  • Nginx reverse proxy
  • MongoDB database

📋 Prerequisites

  • Docker and Docker Compose
  • Git

🚀 Quick Start

1. Clone the Repository

git clone <repository-url>
cd js-jwt-notes

2. Environment Setup

Create a .env file in the root directory (optional for OAuth):

GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
VK_CLIENT_ID=your_vk_client_id
VK_CLIENT_SECRET=your_vk_client_secret

3. Start the Application

# Using Makefile (recommended)
make up

# Or using Docker Compose directly
docker compose up -d

4. Access the Application

🛠️ Development

Development Mode

# Start development environment with hot reload
make dev

# Or
docker compose -f docker-compose.dev.yml up

Available Make Commands

make up          # Start production containers
make down        # Stop all containers
make build       # Build all images
make dev         # Start development environment
make logs        # View all logs
make clean       # Clean up containers and volumes
make mongo-shell # Access MongoDB shell
make backend-logs # View backend logs only
make frontend-logs # View frontend logs only

📁 Project Structure

js-jwt-notes/
├── backend/
│   ├── src/
│   │   ├── config/
│   │   │   └── passport.js      # Authentication strategies
│   │   ├── models/
│   │   │   ├── User.js         # User model
│   │   │   ├── Note.js         # Note model
│   │   │   └── Folder.js       # Folder model
│   │   ├── routes/
│   │   │   ├── auth.js         # Authentication routes
│   │   │   ├── notes.js        # Notes CRUD routes
│   │   │   └── folders.js      # Folders CRUD routes
│   │   └── server.js           # Express server setup
│   ├── Dockerfile              # Production backend image
│   ├── Dockerfile.dev          # Development backend image
│   └── package.json
├── frontend/
│   ├── src/
│   │   ├── components/         # React components
│   │   ├── pages/             # Page components
│   │   ├── contexts/          # React contexts
│   │   └── main.jsx           # App entry point
│   ├── Dockerfile              # Production frontend image
│   ├── Dockerfile.dev          # Development frontend image
│   └── package.json
├── nginx/
│   └── nginx.conf              # Nginx configuration
├── docker-compose.yml          # Production setup
├── docker-compose.dev.yml      # Development setup
├── Makefile                    # Convenient commands
└── README.md

🔧 API Endpoints

Authentication

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • GET /api/auth/verify - Verify JWT token
  • GET /api/auth/google - Google OAuth
  • GET /api/auth/vkontakte - VK OAuth

Notes

  • GET /api/notes - Get all user notes
  • POST /api/notes - Create new note
  • PUT /api/notes/:id - Update note
  • DELETE /api/notes/:id - Delete note
  • GET /api/notes/folder/:folderId - Get notes by folder

Folders

  • GET /api/folders - Get all user folders
  • POST /api/folders - Create new folder
  • PUT /api/folders/:id - Update folder
  • DELETE /api/folders/:id - Delete folder
  • GET /api/folders/tree - Get folder tree structure

🔐 Authentication

The application supports multiple authentication methods:

  1. JWT Authentication: Standard email/password login
  2. Google OAuth: Social login with Google (optional)
  3. VK OAuth: Social login with VKontakte (optional)

JWT Token Usage

// Include token in API requests
fetch('/api/notes', {
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
})

🐳 Docker Configuration

Production Setup

  • Frontend: Nginx serving React build
  • Backend: Node.js with PM2 (if needed)
  • Database: MongoDB with persistent volumes
  • Proxy: Nginx reverse proxy

Development Setup

  • Frontend: Vite dev server with hot reload
  • Backend: Node.js with nodemon for auto-restart
  • Database: MongoDB with development volumes

🔧 Configuration

Environment Variables

Backend (.env)

NODE_ENV=production
PORT=5000
MONGODB_URI=mongodb://admin:password123@mongodb:27017/notes-app?authSource=admin
JWT_SECRET=your-super-secret-jwt-key-change-in-production
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
VK_CLIENT_ID=your_vk_client_id
VK_CLIENT_SECRET=your_vk_client_secret
CLIENT_URL=http://localhost:3000

Frontend (Vite)

VITE_API_URL=http://localhost:5000

🚀 Deployment

Production Deployment

  1. Set up environment variables
  2. Configure OAuth credentials (optional)
  3. Run docker compose up -d
  4. Access via http://localhost

Development Deployment

  1. Run make dev or docker compose -f docker-compose.dev.yml up
  2. Access frontend at http://localhost:3000
  3. API available at http://localhost:5000

🐛 Troubleshooting

Common Issues

  1. Port conflicts: Ensure ports 80, 3000, 5000, and 27017 are available
  2. OAuth errors: Set up OAuth credentials or the app will work without them
  3. Database connection: Check MongoDB container status
  4. Build failures: Ensure all dependencies are installed

Useful Commands

# Check container status
docker compose ps

# View logs
make logs

# Restart specific service
docker compose restart backend

# Clean up everything
make clean

📝 License

This project is licensed under the MIT License.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

📞 Support

For support and questions, please open an issue in the repository.


Happy Note-Taking! 📝✨

About

Проект для работы с заметками с jwt авторизацией

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published