| 1 | # NotesVerb - Microservices Note-Taking Application |
| 2 | |
| 3 | A modern, scalable note-taking application built with microservices architecture using Node.js, TypeScript, and PostgreSQL. |
| 4 | |
| 5 | ## 🏗️ Architecture Overview |
| 6 | |
| 7 | NotesVerb follows a microservices architecture pattern with the following services: |
| 8 | |
| 9 | - **API Gateway** (Port 8080) - Central entry point, routing, and authentication |
| 10 | - **Auth Service** (Port 3001) - User authentication and JWT token management |
| 11 | - **User Service** (Port 3002) - User profile management |
| 12 | - **Notes Service** (Port 3003) - Note creation, retrieval, and management |
| 13 | - **Tags Service** (Port 3004) - Tag management and organization |
| 14 | |
| 15 | Each service has its own PostgreSQL database following the database-per-service pattern. |
| 16 | |
| 17 | ## 🚀 Tech Stack |
| 18 | |
| 19 | - **Runtime**: Node.js with TypeScript |
| 20 | - **Framework**: Express.js |
| 21 | - **Database**: PostgreSQL with Prisma ORM |
| 22 | - **Authentication**: JWT tokens |
| 23 | - **Containerization**: Docker & Docker Compose |
| 24 | - **Testing**: Jest |
| 25 | - **Security**: Helmet, CORS, bcrypt |
| 26 | |
| 27 | ## 📋 Prerequisites |
| 28 | |
| 29 | - Node.js (v18 or higher) |
| 30 | - Docker and Docker Compose |
| 31 | - PostgreSQL (if running without Docker) |
| 32 | - Git |
| 33 | |
| 34 | ## 🛠️ Quick Start |
| 35 | |
| 36 | ### 1. Clone the Repository |
| 37 | |
| 38 | ```bash |
| 39 | git clone https://github.com/fiston-user/notesverb-yt.git |
| 40 | cd notesverb-yt |
| 41 | ``` |
| 42 | |
| 43 | ### 2. Environment Setup |
| 44 | |
| 45 | Copy the environment example files and configure them: |
| 46 | |
| 47 | ```bash |
| 48 | # Root environment file |
| 49 | cp .env.example .env |
| 50 | |
| 51 | # API Gateway |
| 52 | cp api-gateway/.env.example api-gateway/.env |
| 53 | |
| 54 | # Services |
| 55 | cp services/auth-service/.env.example services/auth-service/.env |
| 56 | cp services/user-service/.env.example services/user-service/.env |
| 57 | cp services/notes-service/.env.example services/notes-service/.env |
| 58 | cp services/tags-service/.env.example services/tags-service/.env |
| 59 | ``` |
| 60 | |
| 61 | ### 3. Update Environment Variables |
| 62 | |
| 63 | Edit the `.env` files and update the following critical values: |
| 64 | |
| 65 | - `JWT_SECRET` - Use a strong, random secret (minimum 256 bits) |
| 66 | - `JWT_REFRESH_SECRET` - Use a different strong, random secret |
| 67 | - Database passwords (if not using default Docker setup) |
| 68 | |
| 69 | **Generate secure secrets:** |
| 70 | |
| 71 | ```bash |
| 72 | # Generate JWT secrets |
| 73 | openssl rand -base64 32 |
| 74 | ``` |
| 75 | |
| 76 | ### 4. Start the Database |
| 77 | |
| 78 | ```bash |
| 79 | docker-compose up postgres -d |
| 80 | ``` |
| 81 | |
| 82 | ### 5. Install Dependencies |
| 83 | |
| 84 | ```bash |
| 85 | # Install dependencies for all services |
| 86 | npm install |
| 87 | |
| 88 | # Or install individually |
| 89 | cd api-gateway && npm install |
| 90 | cd ../services/auth-service && npm install |
| 91 | cd ../user-service && npm install |
| 92 | cd ../notes-service && npm install |
| 93 | cd ../tags-service && npm install |
| 94 | cd ../shared && npm install |
| 95 | ``` |
| 96 | |
| 97 | ### 6. Database Setup |
| 98 | |
| 99 | Run Prisma migrations for each service: |
| 100 | |
| 101 | ```bash |
| 102 | # Auth Service |
| 103 | cd services/auth-service |
| 104 | npx prisma migrate dev |
| 105 | npx prisma generate |
| 106 | |
| 107 | # User Service |
| 108 | cd ../user-service |
| 109 | npx prisma migrate dev |
| 110 | npx prisma generate |
| 111 | |
| 112 | # Notes Service |
| 113 | cd ../notes-service |
| 114 | npx prisma migrate dev |
| 115 | npx prisma generate |
| 116 | |
| 117 | # Tags Service |
| 118 | cd ../tags-service |
| 119 | npx prisma migrate dev |
| 120 | npx prisma generate |
| 121 | ``` |
| 122 | |
| 123 | ### 7. Start the Services |
| 124 | |
| 125 | Start each service in development mode: |
| 126 | |
| 127 | ```bash |
| 128 | # Terminal 1 - Auth Service |
| 129 | cd services/auth-service |
| 130 | npm run dev |
| 131 | |
| 132 | # Terminal 2 - User Service |
| 133 | cd services/user-service |
| 134 | npm run dev |
| 135 | |
| 136 | # Terminal 3 - Notes Service |
| 137 | cd services/notes-service |
| 138 | npm run dev |
| 139 | |
| 140 | # Terminal 4 - Tags Service |
| 141 | cd services/tags-service |
| 142 | npm run dev |
| 143 | |
| 144 | # Terminal 5 - API Gateway |
| 145 | cd api-gateway |
| 146 | npm run dev |
| 147 | ``` |
| 148 | |
| 149 | ## 📡 API Endpoints |
| 150 | |
| 151 | ### Authentication |
| 152 | |
| 153 | - `POST /api/auth/register` - User registration |
| 154 | - `POST /api/auth/login` - User login |
| 155 | - `POST /api/auth/refresh` - Refresh tokens |
| 156 | - `POST /api/auth/logout` - User logout |
| 157 | |
| 158 | ### Users |
| 159 | |
| 160 | - `GET /api/users/profile` - Get user profile |
| 161 | - `PUT /api/users/profile` - Update user profile |
| 162 | |
| 163 | ### Notes |
| 164 | |
| 165 | - `POST /api/notes` - Create a note |
| 166 | - `GET /api/notes` - Get user's notes |
| 167 | - `GET /api/notes/:id` - Get specific note |
| 168 | |
| 169 | ### Tags |
| 170 | |
| 171 | - `POST /api/tags` - Create a tag |
| 172 | - `GET /api/tags` - Get user's tags |
| 173 | |
| 174 | ## 🧪 Testing |
| 175 | |
| 176 | Run tests for each service: |
| 177 | |
| 178 | ```bash |
| 179 | # Auth Service |
| 180 | cd services/auth-service |
| 181 | npm test |
| 182 | |
| 183 | # User Service |
| 184 | cd services/user-service |
| 185 | npm test |
| 186 | |
| 187 | # Notes Service |
| 188 | cd services/notes-service |
| 189 | npm test |
| 190 | ``` |
| 191 | |
| 192 | ## 🐳 Docker Deployment |
| 193 | |
| 194 | ### Full Stack with Docker Compose |
| 195 | |
| 196 | ```bash |
| 197 | # Build and start all services |
| 198 | docker-compose up --build |
| 199 | |
| 200 | # Start in detached mode |
| 201 | docker-compose up -d |
| 202 | |
| 203 | # Stop all services |
| 204 | docker-compose down |
| 205 | ``` |
| 206 | |
| 207 | ## 🔒 Security Considerations |
| 208 | |
| 209 | 1. **Environment Variables**: Never commit `.env` files to version control |
| 210 | 2. **JWT Secrets**: Use strong, unique secrets in production |
| 211 | 3. **Database Credentials**: Use secure passwords and restrict access |
| 212 | 4. **CORS**: Configure appropriate origins for your frontend |
| 213 | 5. **HTTPS**: Use HTTPS in production environments |
| 214 | |
| 215 | ## 📁 Project Structure |
| 216 | |
| 217 | ``` |
| 218 | notesverb/ |
| 219 | ├── api-gateway/ # API Gateway service |
| 220 | ├── services/ |
| 221 | │ ├── auth-service/ # Authentication service |
| 222 | │ ├── user-service/ # User management service |
| 223 | │ ├── notes-service/ # Notes management service |
| 224 | │ └── tags-service/ # Tags management service |
| 225 | ├── shared/ # Shared utilities and types |
| 226 | ├── docker-compose.yml # Docker services configuration |
| 227 | ├── init-database.sql # Database initialization |
| 228 | └── README.md |
| 229 | ``` |
| 230 | |
| 231 | ## 🤝 Contributing |
| 232 | |
| 233 | 1. Fork the repository |
| 234 | 2. Create a feature branch |
| 235 | 3. Make your changes |
| 236 | 4. Add tests for new functionality |
| 237 | 5. Ensure all tests pass |
| 238 | 6. Submit a pull request |
| 239 | |
| 240 | ## 📄 License |
| 241 | |
| 242 | This project is licensed under the MIT License. |
| 243 | |
| 244 | ## 🆘 Troubleshooting |
| 245 | |
| 246 | ### Common Issues |
| 247 | |
| 248 | 1. **Port conflicts**: Ensure ports 3001-3004 and 8080 are available |
| 249 | 2. **Database connection**: Verify PostgreSQL is running and credentials are correct |
| 250 | 3. **JWT errors**: Ensure JWT_SECRET is consistent across all services |
| 251 | 4. **CORS issues**: Check CORS_ORIGIN configuration matches your frontend URL |
| 252 | |
| 253 | ### Health Checks |
| 254 | |
| 255 | Each service provides a health check endpoint: |
| 256 | |
| 257 | - API Gateway: `http://localhost:8080/health` |
| 258 | - Auth Service: `http://localhost:3001/health` |
| 259 | - User Service: `http://localhost:3002/health` |
| 260 | - Notes Service: `http://localhost:3003/health` |
| 261 | - Tags Service: `http://localhost:3004/health` |