|
| 1 | +# Mark Project Setup Guide |
| 2 | + |
| 3 | +This guide will help you set up the Mark project for local development. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js >= 20.9.0 |
| 8 | +- Yarn 1.22.22 |
| 9 | +- Docker Desktop (for PostgreSQL database) |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +To start the entire project in one command: |
| 14 | + |
| 15 | +```bash |
| 16 | +yarn start |
| 17 | +``` |
| 18 | + |
| 19 | +This will automatically: |
| 20 | +1. Install dependencies |
| 21 | +2. Start the database |
| 22 | +3. Run migrations |
| 23 | +4. Seed the database |
| 24 | +5. Start development servers |
| 25 | + |
| 26 | +## Step-by-Step Setup |
| 27 | + |
| 28 | +If you prefer to run each step individually, **follow this exact order**: |
| 29 | + |
| 30 | +### 1. Install Dependencies |
| 31 | + |
| 32 | +```bash |
| 33 | +yarn |
| 34 | +``` |
| 35 | + |
| 36 | +**Troubleshooting:** |
| 37 | +- Make sure you have Node.js >= 20.9.0 installed |
| 38 | +- Ensure you're using Yarn 1.22.22 |
| 39 | + |
| 40 | +### 2. Start Database |
| 41 | + |
| 42 | +```bash |
| 43 | +yarn db |
| 44 | +``` |
| 45 | + |
| 46 | +This will: |
| 47 | +- Check if Docker and Docker Compose are installed and running |
| 48 | +- Start a PostgreSQL container using docker-compose |
| 49 | +- Wait for the database to be ready |
| 50 | +- Persist data in a Docker volume (survives container restarts) |
| 51 | + |
| 52 | +**Database Management:** |
| 53 | +```bash |
| 54 | +# Stop database (keeps data) |
| 55 | +docker-compose stop |
| 56 | + |
| 57 | +# Stop and remove container (keeps data) |
| 58 | +docker-compose down |
| 59 | + |
| 60 | +# Stop and remove all data (fresh start) |
| 61 | +docker-compose down -v |
| 62 | + |
| 63 | +# View database logs |
| 64 | +docker-compose logs -f postgres |
| 65 | + |
| 66 | +# Restart database |
| 67 | +docker-compose restart postgres |
| 68 | +``` |
| 69 | + |
| 70 | +**Troubleshooting:** |
| 71 | +- If you get "Docker is not installed", install Docker Desktop from https://www.docker.com/products/docker-desktop |
| 72 | +- If you get "Docker daemon is not running", start Docker Desktop and wait for it to fully start |
| 73 | +- If you get "docker-compose is not installed", Docker Compose comes with Docker Desktop (or install docker-compose-plugin on Linux) |
| 74 | + |
| 75 | +### 3. Run Migrations |
| 76 | + |
| 77 | +```bash |
| 78 | +yarn setup |
| 79 | +``` |
| 80 | + |
| 81 | +This will: |
| 82 | +- Validate critical environment variables |
| 83 | +- Run Prisma migrations |
| 84 | +- Generate Prisma client |
| 85 | + |
| 86 | +**Troubleshooting:** |
| 87 | +- If you get "Dependencies not installed", run `yarn` first |
| 88 | +- If you get "Database container is not running", run `yarn db` first |
| 89 | +- If you get "Missing critical environment variables", check the error message for which variables are missing and add them to `dev.env` |
| 90 | + |
| 91 | +### 4. Seed Database |
| 92 | + |
| 93 | +```bash |
| 94 | +yarn seed |
| 95 | +``` |
| 96 | + |
| 97 | +This will seed the database with initial data. The script intelligently handles two scenarios: |
| 98 | + |
| 99 | +- **If `seed.sql` exists in root**: Uses `pg_restore` to restore from the SQL dump |
| 100 | +- **If no `seed.sql` found**: Uses TypeScript seed file to create sample data |
| 101 | + |
| 102 | +**Important:** You must run `yarn setup` before `yarn seed` to ensure Prisma client is generated and migrations are applied. |
| 103 | + |
| 104 | +**Troubleshooting:** |
| 105 | +- If you get "Prisma client not generated", run `yarn setup` first |
| 106 | +- If you get "Database container is not running", run `yarn db` first |
| 107 | +- If you get "node_modules not found", run `yarn` first |
| 108 | + |
| 109 | +### 5. Start Development Servers |
| 110 | + |
| 111 | +```bash |
| 112 | +yarn dev |
| 113 | +``` |
| 114 | + |
| 115 | +This will: |
| 116 | +- Validate all requirements are met |
| 117 | +- Start all development servers in parallel |
| 118 | + |
| 119 | +**Troubleshooting:** |
| 120 | +- Follow the error messages which will guide you through the required setup steps |
| 121 | + |
| 122 | +## Environment Variables |
| 123 | + |
| 124 | +### Critical Environment Variables |
| 125 | + |
| 126 | +The following environment variables are required and validated before starting the application: |
| 127 | + |
| 128 | +- `POSTGRES_PASSWORD` - Database password |
| 129 | +- `POSTGRES_USER` - Database user |
| 130 | +- `POSTGRES_DB` - Database name |
| 131 | +- `POSTGRES_HOST` - Database host |
| 132 | +- `POSTGRES_PORT` - Database port (internal, 5432) |
| 133 | +- `POSTGRES_EXTERNAL_PORT` - External port for Docker (6001) |
| 134 | +- `API_PORT` - API server port |
| 135 | +- `API_GATEWAY_PORT` - API Gateway port |
| 136 | +- `API_GATEWAY_HOST` - API Gateway host |
| 137 | +- `PORT` - Frontend port |
| 138 | + |
| 139 | +These are defined in `dev.env` in the project root. |
| 140 | + |
| 141 | +**Note**: `DATABASE_URL` and `DATABASE_URL_DIRECT` are automatically constructed from the Postgres variables if not explicitly set. |
| 142 | + |
| 143 | +### Validation |
| 144 | + |
| 145 | +To manually validate your environment variables: |
| 146 | + |
| 147 | +```bash |
| 148 | +./scripts/validate-env.sh |
| 149 | +``` |
| 150 | + |
| 151 | +## Development Workflow |
| 152 | + |
| 153 | +### Normal Development |
| 154 | + |
| 155 | +```bash |
| 156 | +yarn dev |
| 157 | +``` |
| 158 | + |
| 159 | +### Resetting Database |
| 160 | + |
| 161 | +To reset the database with fresh data: |
| 162 | + |
| 163 | +```bash |
| 164 | +# Option 1: Keep container, re-run migrations and seed |
| 165 | +yarn setup |
| 166 | +yarn seed |
| 167 | + |
| 168 | +# Option 2: Complete fresh start (removes all data) |
| 169 | +docker-compose down -v |
| 170 | +yarn db |
| 171 | +yarn setup |
| 172 | +yarn seed |
| 173 | +``` |
| 174 | + |
| 175 | +### Viewing Database |
| 176 | + |
| 177 | +```bash |
| 178 | +yarn studio |
| 179 | +``` |
| 180 | + |
| 181 | +This opens Prisma Studio to view and edit database records. |
| 182 | + |
| 183 | +## Troubleshooting Common Issues |
| 184 | + |
| 185 | +### "Docker is not installed or not in PATH" |
| 186 | + |
| 187 | +**Solution:** Install Docker Desktop from https://www.docker.com/products/docker-desktop |
| 188 | + |
| 189 | +### "Docker daemon is not running" |
| 190 | + |
| 191 | +**Solution:** Start Docker Desktop and wait for it to fully start |
| 192 | + |
| 193 | +### "Dependencies not installed" |
| 194 | + |
| 195 | +**Solution:** Run `yarn` to install dependencies |
| 196 | + |
| 197 | +### "Database container is not running" |
| 198 | + |
| 199 | +**Solution:** Run `yarn db` to start the database |
| 200 | + |
| 201 | +### "Prisma client not generated" |
| 202 | + |
| 203 | +**Solution:** Run `yarn setup` to generate the Prisma client |
| 204 | + |
| 205 | +### "Missing critical environment variables" |
| 206 | + |
| 207 | +**Solution:** |
| 208 | +1. Check the error message for which variables are missing |
| 209 | +2. Open `dev.env` in your editor |
| 210 | +3. Add the missing variables (refer to the error message for required variables) |
| 211 | + |
| 212 | +### "Port is already in use" |
| 213 | + |
| 214 | +**Problem:** Development or database port is occupied by another process |
| 215 | + |
| 216 | +**Solution:** |
| 217 | +1. Check which process is using the port (shown in the error message) |
| 218 | +2. Stop that process |
| 219 | +3. Or change the port in `dev.env`: |
| 220 | + - `POSTGRES_EXTERNAL_PORT` for database (default: 6001) |
| 221 | + - `PORT` for frontend (default: 3010) |
| 222 | + - `API_PORT` for API (default: 4222) |
| 223 | + - `API_GATEWAY_PORT` for API Gateway (default: 8000) |
| 224 | + |
| 225 | +To kill a process using a specific port: |
| 226 | +```bash |
| 227 | +# Replace PORT_NUMBER with the actual port |
| 228 | +kill -9 $(lsof -ti:PORT_NUMBER) |
| 229 | +``` |
| 230 | + |
| 231 | +## Additional Scripts |
| 232 | + |
| 233 | +### Database Management |
| 234 | +- `yarn db` - Start database |
| 235 | +- `yarn db:stop` - Stop database (keeps data) |
| 236 | +- `yarn db:down` - Stop and remove container (keeps data) |
| 237 | +- `yarn db:reset` - Stop, remove all data, and start fresh |
| 238 | +- `yarn db:logs` - View database logs |
| 239 | + |
| 240 | +### Development |
| 241 | +- `yarn build` - Build all packages |
| 242 | +- `yarn lint` - Lint all packages |
| 243 | +- `yarn test` - Run all tests |
| 244 | +- `yarn format` - Format all files |
| 245 | + |
| 246 | +### Database Tools |
| 247 | +- `yarn studio` - Open Prisma Studio |
| 248 | +- `yarn prisma:studio` - Open Prisma Studio (alternative) |
| 249 | +- `yarn prisma:migrate` - Create and run a new migration |
| 250 | +- `yarn prisma:generate` - Generate Prisma client |
| 251 | +- `yarn prisma:reset` - Reset database and re-run all migrations |
| 252 | + |
| 253 | +## Project Structure |
| 254 | + |
| 255 | +- `apps/api` - NestJS API server |
| 256 | +- `apps/api-gateway` - API Gateway |
| 257 | +- `apps/web` - Next.js frontend |
| 258 | +- `packages/*` - Shared packages |
| 259 | +- `scripts/*` - Build and development scripts |
| 260 | +- `dev.env` - Development environment variables |
| 261 | + |
| 262 | +## Getting Help |
| 263 | + |
| 264 | +If you encounter issues not covered in this guide: |
| 265 | + |
| 266 | +1. Check the error message - they're designed to be helpful and guide you to the solution |
| 267 | +2. Ensure all prerequisites are installed |
| 268 | +3. Ensure Docker Desktop is running |
| 269 | +4. Try running the steps individually to isolate the issue |
0 commit comments