# IMK Platform Documentation

## Table of Contents
1. [Introduction](#introduction)
2. [Features](#features)
3. [Technical Stack](#technical-stack)
4. [Architecture](#architecture)
5. [User Flows](#user-flows)
6. [API Documentation](#api-documentation)
7. [Security](#security)
8. [Deployment](#deployment)

## Introduction

IMK Platform is a modern web application built to manage and share documents securely. The platform provides robust user management, document handling, and secure sharing capabilities.

## Features

### User Management
- User registration and authentication
- Role-based access control (Admin, User)
- Password reset functionality
- Email notifications for account activities
- Profile management

### Document Management
- Document upload and storage
- Document sharing between users
- Document version control
- Document metadata management
- Secure document access control

### Email Notifications
- Welcome emails for new users
- Password reset notifications
- Document sharing notifications
- Password change confirmations

### Administrative Features
- User management dashboard
- Document oversight
- System monitoring
- Access control management

## Technical Stack

### Frontend
- React.js with Vite
- TypeScript for type safety
- TailwindCSS for styling
- Shadcn UI components
- React Query for state management
- React Router for navigation

### Backend
- NestJS framework
- TypeScript
- Prisma ORM
- PostgreSQL database
- Node.js runtime
- JWT authentication
- Nodemailer for email services

## Architecture

### Frontend Architecture
- Component-based architecture
- Responsive design
- State management using React Query
- Protected routes with authentication
- Form validation and error handling

### Backend Architecture
- RESTful API design
- Modular architecture with NestJS
- Database abstraction with Prisma
- Email service integration
- JWT-based authentication
- Role-based authorization

## User Flows

### Authentication Flow
1. User Registration
   - User fills registration form
   - System validates input
   - Welcome email sent
   - User redirected to login

2. Login Flow
   - User enters credentials
   - System validates credentials
   - JWT token issued
   - User redirected to dashboard

3. Password Reset Flow
   - User requests password reset
   - System sends reset email
   - User clicks reset link
   - User sets new password
   - Confirmation email sent

### Document Management Flow
1. Document Upload
   - User selects document
   - System validates document
   - Document metadata captured
   - Document stored securely

2. Document Sharing
   - User selects document to share
   - User selects recipient(s)
   - System sends notification
   - Access granted to recipient

## API Documentation

### Authentication Endpoints
- POST /auth/register - User registration
- POST /auth/login - User login
- POST /auth/reset-password - Password reset request
- POST /auth/change-password - Password change

### User Endpoints
- GET /users/profile - Get user profile
- PUT /users/profile - Update user profile
- GET /users - List users (admin only)
- PUT /users/:id - Update user (admin only)

### Document Endpoints
- POST /documents - Upload document
- GET /documents - List documents
- GET /documents/:id - Get document details
- PUT /documents/:id - Update document
- DELETE /documents/:id - Delete document
- POST /documents/:id/share - Share document

## Security

### Authentication Security
- JWT token-based authentication
- Password hashing with bcrypt
- Rate limiting on auth endpoints
- Session management
- CSRF protection

### Data Security
- HTTPS encryption
- Input validation
- XSS protection
- SQL injection prevention
- File type validation

### Access Control
- Role-based access control
- Document-level permissions
- API endpoint protection
- Resource isolation

## Deployment

### Frontend Deployment
- Static site hosting
- CDN integration
- Environment configuration
- Build optimization

### Backend Deployment
- Node.js runtime environment
- Process management with PM2
- Nginx reverse proxy
- SSL/TLS configuration
- Database backup system

### Environment Variables
Frontend:
```env
VITE_API_URL=https://api.example.com
```

Backend:
```env
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=user@example.com
SMTP_PASS=password
EMAIL_FROM=noreply@example.com
JWT_SECRET=your-secret-key
```

## Getting Started

### Development Setup
1. Clone the repository
2. Install dependencies:
   ```bash
   # Frontend
   cd frontend
   npm install

   # Backend
   cd backend
   npm install
   ```
3. Set up environment variables
4. Start development servers:
   ```bash
   # Frontend
   npm run dev

   # Backend
   npm run start:dev
   ```

### Production Deployment
1. Build applications:
   ```bash
   # Frontend
   npm run build

   # Backend
   npm run build
   ```
2. Configure environment variables
3. Start production servers:
   ```bash
   # Frontend
   serve -s dist

   # Backend
   npm run start:prod
   ```

## Support and Maintenance

### Monitoring
- Application performance monitoring
- Error tracking and logging
- Database monitoring
- Email service monitoring

### Backup and Recovery
- Database backup strategy
- Document backup system
- System configuration backup
- Recovery procedures

### Updates and Maintenance
- Regular security updates
- Dependency updates
- Performance optimization
- Feature updates 