File size: 5,461 Bytes
3b93905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Flare Admin UI Setup

## Quick Start (HuggingFace Deployment)

Just push all files to HuggingFace Space. The Dockerfile will handle everything:
- Build Angular UI
- Install Python dependencies
- Serve both UI and API on port 7860

## Local Development

### Backend Setup
```bash

# Install Python dependencies

pip install -r requirements.txt



# Set encryption key (if needed)

export FLARE_TOKEN_KEY="your-32-byte-base64-key"



# Run backend

python app.py

```

### Frontend Setup (for development only)
```bash

# Navigate to UI directory

cd flare-ui



# Install dependencies

npm install



# Run development server (proxies to backend on port 7860)

npm start



# Build for production (creates static/ directory)

npm run build

```

## Docker Deployment

```bash

# Build and run

docker build -t flare-admin .

docker run -p 7860:7860 flare-admin

```

Access at `http://localhost:7860`

## Default Login

- Username: `admin`
- Password: `admin`

## Creating Admin User

To create a new admin user with proper password hash:

```python

import hashlib



password = "your-password"

password_hash = hashlib.sha256(password.encode()).hexdigest()

print(f"Password hash: {password_hash}")

```

Add the user to `service_config.jsonc`:
```json

{

  "config": {

    "users": [

      {

        "username": "newuser",

        "password_hash": "your-hash-here",

        "salt": "random_salt_string"

      }

    ]

  }

}

```

## Project Structure

```

/

β”œβ”€β”€ app.py                  # Main FastAPI application

β”œβ”€β”€ admin_routes.py         # Admin API endpoints

β”œβ”€β”€ chat_handler.py         # Chat functionality

β”œβ”€β”€ service_config.jsonc    # Configuration file

β”œβ”€β”€ Dockerfile             # Handles everything for deployment

β”œβ”€β”€ flare-ui/              # Angular UI source

β”‚   β”œβ”€β”€ src/

β”‚   β”‚   β”œβ”€β”€ app/

β”‚   β”‚   β”‚   β”œβ”€β”€ components/

β”‚   β”‚   β”‚   β”œβ”€β”€ services/

β”‚   β”‚   β”‚   └── guards/

β”‚   β”‚   └── index.html

β”‚   └── package.json

└── static/                # Built UI files (auto-generated by Docker)

```

## Features Implemented

- βœ… User authentication with JWT
- βœ… Environment configuration
- βœ… Project management
- βœ… Version control
- βœ… API management
- βœ… Activity logging
- βœ… Race condition handling
- βœ… Import/Export functionality

## TODO

- [ ] User Info tab (password change)
- [ ] APIs tab (CRUD operations)
- [ ] Projects tab (full CRUD)
- [ ] Test tab implementation
- [ ] Intent/Parameter dialogs
- [ ] Version comparison
- [ ] Auto-save for drafts
- [ ] Keyboard shortcuts

---

## ⚠️ Production Deployment Note

**This setup is optimized for HuggingFace Spaces and development environments.** For production on-premise deployment, a more robust architecture will be implemented.

### Planned Production Architecture:

#### 1. **Web Server Layer**
- **Nginx** as reverse proxy and static file server
- SSL/TLS termination
- Request rate limiting and security headers
- Gzip compression for static assets

#### 2. **Application Layer**
- **Gunicorn/Uvicorn** workers for Python ASGI
- Process management with **Supervisor** or **systemd**
- Horizontal scaling with multiple worker processes
- Health check endpoints for monitoring

#### 3. **Session & Cache Layer**
- **Redis** for distributed session storage
- Centralized cache for LLM responses
- Session affinity for WebSocket connections

#### 4. **Database Layer** (Optional)
- **PostgreSQL** for configuration storage (replacing JSON file)
- Backup and replication strategies
- Migration tools for schema updates

#### 5. **Monitoring & Logging**
- **Prometheus** + **Grafana** for metrics
- **ELK Stack** (Elasticsearch, Logstash, Kibana) for log aggregation
- Application Performance Monitoring (APM)
- Alert configuration for critical events

#### 6. **Deployment Options**

**Option A: Docker Compose** (Small-Medium Scale)
```yaml

services:

  nginx:

    image: nginx:alpine

    volumes:

      - ./nginx.conf:/etc/nginx/nginx.conf

      - ./static:/usr/share/nginx/html

    ports:

      - "80:80"

      - "443:443"



  app:

    image: flare-admin:production

    scale: 3  # 3 instances

    environment:

      - REDIS_URL=redis://redis:6379



  redis:

    image: redis:alpine

    volumes:

      - redis-data:/data

```

**Option B: Kubernetes** (Large Scale)
- Helm charts for easy deployment
- Horizontal Pod Autoscaler (HPA)
- Ingress controller for routing
- Persistent Volume Claims for data
- Secrets management for credentials

#### 7. **Security Considerations**
- JWT token rotation and refresh
- API rate limiting per user
- Input validation and sanitization
- Regular security audits
- Compliance with data protection regulations

#### 8. **Backup & Disaster Recovery**
- Automated daily backups
- Point-in-time recovery
- Geo-redundant storage
- Disaster recovery procedures
- RTO/RPO targets defined

### Production Deployment Timeline:
1. **Phase 1**: Current setup (HF Spaces, development)
2. **Phase 2**: Docker Compose setup for on-premise pilot
3. **Phase 3**: Full production architecture with monitoring
4. **Phase 4**: Kubernetes deployment for enterprise scale

A comprehensive `DEPLOYMENT.md` guide will be created when transitioning to production architecture.