Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=uvarsity
DB_USER=uvarsity_user
DB_PASSWORD=uvarsity_password

# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT Configuration
JWT_SECRET=dev-secret-key
JWT_EXPIRES_IN=1h

# Node Environment
NODE_ENV=development
PORT=3000
41 changes: 41 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=uvarsity
DB_USER=uvarsity_user
DB_PASSWORD=uvarsity_password

# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=1h

# Node Environment
NODE_ENV=development
PORT=3000

# Email Configuration (for future implementation)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password

# Mobile Money API Configuration (for future implementation)
MPESA_CONSUMER_KEY=your-mpesa-consumer-key
MPESA_CONSUMER_SECRET=your-mpesa-consumer-secret
MPESA_SHORTCODE=your-shortcode
MPESA_PASSKEY=your-passkey

# File Upload Configuration
MAX_FILE_SIZE=10485760
ALLOWED_FILE_TYPES=jpg,jpeg,png,pdf,mp4,mov

# AWS S3 Configuration (optional)
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
AWS_REGION=us-east-1
AWS_S3_BUCKET=uvarsity-uploads
59 changes: 59 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build output
dist/
build/

# Environment variables
.env.local
.env.production

# Logs
*.log
logs/

# Runtime data
pids/
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage/

# nyc test coverage
.nyc_output

# IDEs and editors
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Docker
docker-compose.override.yml

# Temporary files
tmp/
temp/

# Database
*.sqlite
*.db

# Redis dump
dump.rdb
235 changes: 235 additions & 0 deletions README_BACKEND.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# Uvarsity Platform Backend

## Overview
This is the backend microservices architecture for the Uvarsity Learning Platform - an ed-tech platform focused on equipping African youth with employable skills in design and technology.

## Quick Start

### Prerequisites
- Node.js 18+
- PostgreSQL 15+
- Redis 7+
- Docker & Docker Compose (optional)

### Installation

1. Clone the repository
```bash
git clone https://github.com/Uvarsity-Learning-Platform/uvarsity-platform.git
cd uvarsity-platform
```

2. Install dependencies
```bash
npm install
```

3. Setup environment variables
```bash
cp .env.example .env
# Edit .env with your configuration
```

4. Start the database (using Docker)
```bash
docker-compose up -d postgres redis
```

5. Run database migrations
```bash
# Database schema is auto-created from init.sql
```

6. Start the development server
```bash
npm run dev
```

The API will be available at `http://localhost:3000`

### Using Docker

To run the entire stack with Docker:
```bash
docker-compose up -d
```

## API Documentation

Once the server is running, visit:
- **Swagger UI**: http://localhost:3000/api/docs
- **Health Check**: http://localhost:3000/api/v1/health

## Project Structure

```
src/
β”œβ”€β”€ auth/ # Authentication service
β”‚ β”œβ”€β”€ controllers/ # Auth controllers
β”‚ β”œβ”€β”€ services/ # Auth business logic
β”‚ β”œβ”€β”€ entities/ # User entity
β”‚ β”œβ”€β”€ dto/ # Data transfer objects
β”‚ β”œβ”€β”€ guards/ # JWT guards
β”‚ └── strategies/ # Passport strategies
β”œβ”€β”€ user/ # User management service
β”œβ”€β”€ course/ # Course management service
β”œβ”€β”€ payment/ # Payment processing service
β”œβ”€β”€ mentorship/ # Mentorship service
β”œβ”€β”€ community/ # Community/forums service
β”œβ”€β”€ job/ # Job matching service
β”œβ”€β”€ notification/ # Notification service
β”œβ”€β”€ health/ # Health check endpoints
└── shared/ # Shared interfaces and utilities
```

## Features Implemented

### βœ… Phase 1 (MVP)
- [x] Authentication Service (JWT with refresh tokens)
- [x] User Management Service (profiles with African-specific fields)
- [x] Database schema with PostgreSQL
- [x] API documentation with Swagger
- [x] Docker configuration
- [x] Health check endpoints
- [x] Basic security (helmet, rate limiting, CORS)

### 🚧 Phase 2 (In Progress)
- [ ] Course Management Service
- [ ] Payment Service (Mobile Money integration)
- [ ] Content Delivery Service
- [ ] Basic tests

### πŸ“‹ Phase 3 (Planned)
- [ ] Mentorship Service
- [ ] Community Service
- [ ] Job Matching Service
- [ ] Analytics Service
- [ ] Notification Service
- [ ] Advanced features (real-time, AI recommendations)

## African-Focused Features

- **Multi-country support**: Kenya, Nigeria, Ghana, Tanzania, Uganda, Rwanda, South Africa, Egypt, Morocco, Ethiopia
- **Mobile Money integration**: M-Pesa, MTN Mobile Money, Airtel Money
- **Multi-language support**: English, Swahili, French, Hausa, Arabic, Amharic
- **Timezone awareness**: Automatic timezone detection based on country
- **Low-bandwidth optimization**: Compressed responses, offline-first architecture
- **Local currency support**: KES, NGN, GHS, TZS, UGX, RWF, ZAR, EGP, MAD, ETB

## API Endpoints

### Authentication
- `POST /api/v1/auth/register` - Register new user
- `POST /api/v1/auth/login` - User login
- `POST /api/v1/auth/forgot-password` - Request password reset
- `POST /api/v1/auth/reset-password` - Reset password with token
- `POST /api/v1/auth/change-password` - Change password (authenticated)
- `GET /api/v1/auth/verify-email/:token` - Verify email address
- `POST /api/v1/auth/refresh-token` - Refresh access token
- `GET /api/v1/auth/profile` - Get current user profile

### Users
- `GET /api/v1/users/profile` - Get user profile

### Health
- `GET /api/v1/health` - General health check
- `GET /api/v1/health/database` - Database health check
- `GET /api/v1/health/redis` - Redis health check

## Environment Variables

Key environment variables (see `.env.example` for complete list):

```bash
# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=uvarsity
DB_USER=uvarsity_user
DB_PASSWORD=uvarsity_password

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=1h

# Server
NODE_ENV=development
PORT=3000
```

## Testing

```bash
# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run specific test file
npm test auth.controller.spec.ts
```

## Database Schema

The database includes tables for:
- Users and user profiles
- Courses and enrollments
- Payments and installment plans
- Mentorship sessions
- Community forums
- Job postings and applications
- Notifications
- User settings

## Security Features

- JWT authentication with refresh tokens
- Password hashing with bcrypt
- Rate limiting (100 requests per 15 minutes)
- CORS configuration for African regions
- Input validation and sanitization
- Helmet for security headers
- Environment-based configuration

## Mobile Money Integration (Planned)

Support for major African mobile money providers:
- **Kenya**: M-Pesa
- **Nigeria**: MTN Mobile Money, Airtel Money
- **Ghana**: MTN Mobile Money, Airtel Money, Vodafone Cash
- **Tanzania**: M-Pesa, Airtel Money, Tigo Pesa
- **Uganda**: MTN Mobile Money, Airtel Money
- **Rwanda**: MTN Mobile Money, Airtel Money

## Deployment

### Production Deployment
1. Set production environment variables
2. Build the application: `npm run build`
3. Start with PM2: `pm2 start ecosystem.config.js`

### Using Docker
```bash
docker-compose -f docker-compose.prod.yml up -d
```

## Contributing

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/your-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin feature/your-feature`
5. Submit a pull request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

**Uvarsity** - Learning designed for Africa, powered by community, and driven by opportunity.
Loading