214 lines
3.8 KiB
Markdown
214 lines
3.8 KiB
Markdown
# Setup Instructions
|
|
|
|
## Prerequisites
|
|
|
|
1. **Node.js 18+** - [Download](https://nodejs.org/)
|
|
2. **pnpm 8+** - Install with: `npm install -g pnpm`
|
|
3. **PostgreSQL 14+** - Either:
|
|
- Install locally: [PostgreSQL Downloads](https://www.postgresql.org/download/)
|
|
- Use Docker: `docker-compose up -d postgres`
|
|
4. **Redis** - Either:
|
|
- Install locally: [Redis Downloads](https://redis.io/download)
|
|
- Use Docker: `docker-compose up -d redis`
|
|
|
|
## Quick Start
|
|
|
|
### Option 1: Using Docker (Recommended)
|
|
|
|
If you have Docker and Docker Compose installed:
|
|
|
|
```bash
|
|
# 1. Start all services (PostgreSQL + Redis)
|
|
docker-compose up -d
|
|
|
|
# 2. Install dependencies
|
|
pnpm install
|
|
|
|
# 3. Generate Prisma client
|
|
pnpm db:generate
|
|
|
|
# 4. Run database migrations
|
|
pnpm db:migrate
|
|
|
|
# 5. (Optional) Seed the database
|
|
pnpm db:seed
|
|
|
|
# 6. Start development servers
|
|
pnpm dev
|
|
```
|
|
|
|
### Option 2: Local Services
|
|
|
|
If you prefer to run PostgreSQL and Redis locally:
|
|
|
|
1. **Install and start PostgreSQL:**
|
|
```bash
|
|
# Ubuntu/Debian
|
|
sudo apt-get install postgresql postgresql-contrib
|
|
sudo systemctl start postgresql
|
|
|
|
# Create database
|
|
sudo -u postgres psql
|
|
CREATE DATABASE aseret_bank;
|
|
CREATE USER aseret_user WITH PASSWORD 'aseret_password';
|
|
GRANT ALL PRIVILEGES ON DATABASE aseret_bank TO aseret_user;
|
|
\q
|
|
```
|
|
|
|
2. **Install and start Redis:**
|
|
```bash
|
|
# Ubuntu/Debian
|
|
sudo apt-get install redis-server
|
|
sudo systemctl start redis-server
|
|
```
|
|
|
|
3. **Configure environment:**
|
|
```bash
|
|
cp .env.example .env
|
|
# Edit .env with your database credentials
|
|
```
|
|
|
|
4. **Install dependencies and setup:**
|
|
```bash
|
|
pnpm install
|
|
pnpm db:generate
|
|
pnpm db:migrate
|
|
pnpm db:seed
|
|
pnpm dev
|
|
```
|
|
|
|
## Environment Variables
|
|
|
|
Copy `.env.example` to `.env` and configure:
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
Key variables to set:
|
|
- `DATABASE_URL` - PostgreSQL connection string
|
|
- `REDIS_URL` - Redis connection string
|
|
- `JWT_SECRET` - Secret for JWT tokens (generate a strong random string)
|
|
- `JWT_REFRESH_SECRET` - Secret for refresh tokens
|
|
- `FRONTEND_URL` - Frontend URL (default: http://localhost:3000)
|
|
- `PORT` - Backend port (default: 3001)
|
|
|
|
## Database Setup
|
|
|
|
### Initial Migration
|
|
|
|
```bash
|
|
pnpm db:migrate
|
|
```
|
|
|
|
This will:
|
|
- Create all database tables
|
|
- Set up relationships
|
|
- Create indexes
|
|
|
|
### Seed Data
|
|
|
|
```bash
|
|
pnpm db:seed
|
|
```
|
|
|
|
This creates:
|
|
- Admin user: `admin@aseret.com` / `admin123`
|
|
- Loan Officer: `officer@aseret.com` / `officer123`
|
|
- Sample Customer: `customer@example.com` / `customer123`
|
|
|
|
### Prisma Studio
|
|
|
|
View and edit database data:
|
|
|
|
```bash
|
|
pnpm db:studio
|
|
```
|
|
|
|
Opens at: http://localhost:5555
|
|
|
|
## Development
|
|
|
|
### Start Both Servers
|
|
|
|
```bash
|
|
pnpm dev
|
|
```
|
|
|
|
- Backend: http://localhost:3001
|
|
- Frontend: http://localhost:3000
|
|
- API Docs: http://localhost:3001/api-docs
|
|
|
|
### Start Separately
|
|
|
|
```bash
|
|
# Backend only
|
|
pnpm dev:backend
|
|
|
|
# Frontend only
|
|
pnpm dev:frontend
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Database Connection Issues
|
|
|
|
1. Verify PostgreSQL is running:
|
|
```bash
|
|
sudo systemctl status postgresql
|
|
# or
|
|
docker-compose ps
|
|
```
|
|
|
|
2. Test connection:
|
|
```bash
|
|
psql -h localhost -U aseret_user -d aseret_bank
|
|
```
|
|
|
|
3. Check DATABASE_URL in `.env` matches your setup
|
|
|
|
### Redis Connection Issues
|
|
|
|
1. Verify Redis is running:
|
|
```bash
|
|
redis-cli ping
|
|
# Should return: PONG
|
|
```
|
|
|
|
2. Check REDIS_URL in `.env`
|
|
|
|
### Port Already in Use
|
|
|
|
If ports 3000 or 3001 are already in use:
|
|
|
|
1. Find the process:
|
|
```bash
|
|
lsof -i :3001
|
|
```
|
|
|
|
2. Kill the process or change PORT in `.env`
|
|
|
|
### Prisma Client Not Generated
|
|
|
|
```bash
|
|
cd backend
|
|
pnpm prisma:generate
|
|
```
|
|
|
|
## Production Build
|
|
|
|
```bash
|
|
# Build
|
|
pnpm build
|
|
|
|
# Start
|
|
pnpm start
|
|
```
|
|
|
|
## Additional Resources
|
|
|
|
- [Prisma Documentation](https://www.prisma.io/docs)
|
|
- [Next.js Documentation](https://nextjs.org/docs)
|
|
- [Express Documentation](https://expressjs.com/)
|
|
- [pnpm Documentation](https://pnpm.io/)
|