# Geek-Life v2.0 - Multi-Tenant CLI Task Manager

<p align="center">
    <img src="media/geek-life-logo.png" align="center" alt="Geek-life Logo">
</p>

## 🚀 What's New in v2.0

- **Multi-Tenant Support**: Multiple organizations can use the same instance
- **User Management**: Multiple users per tenant with secure authentication
- **PostgreSQL Backend**: Centralized database with better performance and reliability
- **Session Management**: Secure login/logout with session tokens
- **Database Migrations**: Automated schema management
- **Row-Level Security**: Data isolation between tenants

## 🏗️ Architecture

### Multi-Tenant Design
- **Tenants**: Organizations or teams
- **Users**: Individual users within a tenant
- **Projects & Tasks**: Scoped to specific users within tenants
- **Sessions**: Secure authentication tokens

### Database Schema
- PostgreSQL with Row-Level Security (RLS)
- Automated migrations
- Optimized indexes for performance
- UUID support for external integrations

## 🛠️ Installation & Setup

### Prerequisites
- Go 1.19 or later
- PostgreSQL 12 or later

### Database Setup
1. Create a PostgreSQL database:
```sql
CREATE DATABASE geeklife;
```

2. Copy the environment configuration:
```bash
cp .env.example .env
```

3. Update `.env` with your database credentials:
```env
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=geeklife
DB_SSLMODE=disable
```

### Build & Run
```bash
# Install dependencies
go mod tidy

# Run database migrations
go run app/*.go --migrate

# Start the application
go run app/*.go
```

## 🔐 Authentication

### First Time Setup
1. **Register Tenant**: Create a new organization/tenant with an admin user
2. **Register User**: Add additional users to an existing tenant
3. **Login**: Access with existing credentials

### Session Management
- Sessions are automatically saved locally
- Use `Ctrl+L` to logout
- Sessions expire after 24 hours (configurable)

## 🎮 Usage

### Keyboard Shortcuts
- `Tab` / `Shift+Tab`: Navigate between panes
- `Enter`: Select/Edit item
- `Ctrl+C`: Quit application
- `Ctrl+L`: Logout
- `Esc`: Cancel/Go back

### Multi-User Workflow
1. **Tenant Admin**: Registers the tenant and becomes the first user
2. **Team Members**: Register as users within the existing tenant
3. **Data Isolation**: Each user sees only their own projects and tasks
4. **Collaboration**: Future versions will support shared projects

## 🔧 Configuration

### Environment Variables
```env
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=geeklife
DB_SSLMODE=disable

# Authentication Configuration
JWT_SECRET=your-super-secret-jwt-key
SESSION_DURATION=24

# Application Configuration
ENVIRONMENT=development
LOG_LEVEL=info
```

### Command Line Options
```bash
# Run database migrations
./geek-life --migrate

# Help
./geek-life --help
```

## 🗄️ Database Migrations

The application includes an automated migration system:

```bash
# Run all pending migrations
go run app/*.go --migrate
```

Migrations are located in the `migrations/` directory and are automatically applied in order.

## 🔒 Security Features

- **Password Hashing**: bcrypt with salt
- **Session Tokens**: Cryptographically secure random tokens
- **Row-Level Security**: Database-level tenant isolation
- **SQL Injection Protection**: Parameterized queries
- **Session Expiration**: Configurable session timeouts

## 🏢 Multi-Tenant Benefits

- **Cost Effective**: Single instance serves multiple organizations
- **Data Isolation**: Complete separation between tenants
- **Scalable**: Supports unlimited tenants and users
- **Secure**: Row-level security ensures data privacy
- **Maintainable**: Single codebase for all tenants

## 🔄 Migration from v1.0

The new version maintains backward compatibility with the Storm database format. You can:

1. Continue using Storm (single-user mode)
2. Migrate to PostgreSQL for multi-tenant features
3. Run both versions side by side

## 🚧 Development

### Project Structure
```
├── app/                 # Main application and UI components
├── auth/               # Authentication service
├── config/             # Configuration management
├── migration/          # Database migration system
├── model/              # Data models
├── repository/         # Data access layer
│   ├── postgres/       # PostgreSQL implementations
│   └── storm/          # Storm implementations (legacy)
├── util/               # Utility functions
├── migrations/         # SQL migration files
└── docs/              # Documentation
```

### Adding New Features
1. Update models if needed
2. Add repository methods
3. Update UI components
4. Create migrations for schema changes

## 📝 License

MIT License - see LICENSE file for details.

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

## 📞 Support

- Create an issue for bug reports
- Use discussions for feature requests
- Check the wiki for detailed documentation

---

**Geek-Life v2.0** - Now with multi-tenant support for teams and organizations! 🚀