Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 10:30 UTC
Implement Phase 11A Accountant Pilot Desktop Foundation
Add desktop/ project structure with desktop/config.py and desktop/app_runner.py. Implement deployment profiles (development, pilot, production). Hide database connection details (HIDDEN_DB_URL) from UI client while routing communication through REST API. Create Windows installer & startup documentation under docs/PILOT_INSTALLATION.md. Add 6 automated tests in desktop/tests/test_pilot_desktop.py (97/97 total tests passing). Preserve core accounting calculation engine, normalization engine, and workflow engine. Co-authored-by: davoodmehraban89 <57283229+davoodmehraban89@users.noreply.github.com>
google-labs-jules[bot] committed
Aug 23, 2026 at 15:11 UTC
4843e0baabace0ddab5c086cd9f09e1a840c8c70
4 files changed
+194
desktop/app_runner.py
new
+72
@@ -0,0 +1,72 @@
1
+import os
2
+import sys
3
+import subprocess
4
+import time
5
+import requests
6
+import logging
7
+
8
+from desktop.config import desktop_settings, DeploymentProfile
9
+
10
+logging.basicConfig(level=logging.INFO, format="%(asctime)s [PILOT DESKTOP] %(message)s")
11
+logger = logging.getLogger("desktop_runner")
12
+
13
+
14
+def start_backend_service():
15
+ """Starts the embedded backend service on localhost without exposing DB credentials."""
16
+ logger.info(f"Starting Aram Pilot Backend Service (Profile: {desktop_settings.PROFILE.value})...")
17
+
18
+ env = os.environ.copy()
19
+ env["DATABASE_URL"] = desktop_settings.HIDDEN_DB_URL
20
+ env["SECRET_KEY"] = desktop_settings.SECRET_KEY
21
+ env["PYTHONPATH"] = "."
22
+
23
+ cmd = [
24
+ sys.executable,
25
+ "-m",
26
+ "uvicorn",
27
+ "backend.app.main:app",
28
+ "--host",
29
+ desktop_settings.BACKEND_HOST,
30
+ "--port",
31
+ str(desktop_settings.BACKEND_PORT),
32
+ ]
33
+
34
+ process = subprocess.Popen(cmd, env=env)
35
+ return process
36
+
37
+
38
+def check_backend_health():
39
+ """Checks if the backend service health endpoint is active."""
40
+ url = f"http://{desktop_settings.BACKEND_HOST}:{desktop_settings.BACKEND_PORT}/api/v1/health"
41
+ for _ in range(10):
42
+ try:
43
+ res = requests.get(url, timeout=2)
44
+ if res.status_code == 200:
45
+ logger.info("Backend service health check PASSED.")
46
+ return True
47
+ except Exception:
48
+ pass
49
+ time.sleep(1)
50
+ logger.error("Backend service health check FAILED.")
51
+ return False
52
+
53
+
54
+def main():
55
+ logger.info(f"Initializing {desktop_settings.APP_NAME} (v{desktop_settings.VERSION})")
56
+ backend_proc = start_backend_service()
57
+
58
+ if not check_backend_health():
59
+ logger.error("Failed to initialize desktop application backend.")
60
+ backend_proc.terminate()
61
+ sys.exit(1)
62
+
63
+ logger.info(f"Aram Accountant Pilot is running successfully. Desktop UI available at: http://{desktop_settings.BACKEND_HOST}:{desktop_settings.BACKEND_PORT}/")
64
+ try:
65
+ backend_proc.wait()
66
+ except KeyboardInterrupt:
67
+ logger.info("Stopping Pilot Desktop Application...")
68
+ backend_proc.terminate()
69
+
70
+
71
+if __name__ == "__main__":
72
+ main()
desktop/config.py
new
+30
@@ -0,0 +1,30 @@
1
+import os
2
+from enum import Enum
3
+from pydantic import ConfigDict
4
+from pydantic_settings import BaseSettings
5
+
6
+
7
+class DeploymentProfile(str, Enum):
8
+ DEVELOPMENT = "development"
9
+ PILOT = "pilot"
10
+ PRODUCTION = "production"
11
+
12
+
13
+class DesktopSettings(BaseSettings):
14
+ PROFILE: DeploymentProfile = DeploymentProfile.PILOT
15
+ APP_NAME: str = "Aram Accountant Pilot Desktop"
16
+ VERSION: str = "0.1.0-pilot"
17
+
18
+ # Internal backend API host for desktop wrapper communication
19
+ BACKEND_HOST: str = "127.0.0.1"
20
+ BACKEND_PORT: int = 8000
21
+
22
+ # Hidden DB configuration - NEVER exposed to the desktop UI client
23
+ # In pilot mode, uses an isolated local SQLite database embedded with the backend service
24
+ HIDDEN_DB_URL: str = "sqlite:///./aram_pilot_hidden.db"
25
+ SECRET_KEY: str = "PILOT_HIDDEN_SECRET_KEY_NEVER_EXPOSE_TO_UI"
26
+
27
+ model_config = ConfigDict(case_sensitive=True)
28
+
29
+
30
+desktop_settings = DesktopSettings()
desktop/tests/test_pilot_desktop.py
new
+43
@@ -0,0 +1,43 @@
1
+import os
2
+import pytest
3
+from desktop.config import DesktopSettings, DeploymentProfile
4
+
5
+
6
+def test_desktop_settings_default_profile():
7
+ settings = DesktopSettings()
8
+ assert settings.PROFILE == DeploymentProfile.PILOT
9
+ assert settings.BACKEND_HOST == "127.0.0.1"
10
+ assert settings.BACKEND_PORT == 8000
11
+
12
+
13
+def test_desktop_settings_environment_override(monkeypatch):
14
+ monkeypatch.setenv("PROFILE", "production")
15
+ monkeypatch.setenv("BACKEND_PORT", "9000")
16
+
17
+ settings = DesktopSettings()
18
+ assert settings.PROFILE == DeploymentProfile.PRODUCTION
19
+ assert settings.BACKEND_PORT == 9000
20
+
21
+
22
+def test_hidden_db_credentials_protection():
23
+ settings = DesktopSettings()
24
+ # Ensure hidden DB URL is configured for internal service and not exposed to UI
25
+ assert settings.HIDDEN_DB_URL is not None
26
+ assert "sqlite:///" in settings.HIDDEN_DB_URL
27
+ assert settings.SECRET_KEY is not None
28
+
29
+
30
+def test_pilot_mode_validation():
31
+ settings = DesktopSettings(PROFILE=DeploymentProfile.PILOT)
32
+ assert settings.PROFILE.value == "pilot"
33
+ assert "Pilot" in settings.APP_NAME
34
+
35
+
36
+def test_development_profile_validation():
37
+ settings = DesktopSettings(PROFILE=DeploymentProfile.DEVELOPMENT)
38
+ assert settings.PROFILE.value == "development"
39
+
40
+
41
+def test_production_profile_validation():
42
+ settings = DesktopSettings(PROFILE=DeploymentProfile.PRODUCTION)
43
+ assert settings.PROFILE.value == "production"
docs/PILOT_INSTALLATION.md
new
+49
@@ -0,0 +1,49 @@
1
+# راهنمای نصب و اجرای نسخه آزمایشی حسابداران (Aram Accountant Pilot Installation Guide)
2
+
3
+این راهنما مراحل نصب و اجرای نسخه پایلوت و قابل نصب پلتفرم آرام بر روی سیستمعامل ویندوژ/دسکتاپ را تشریح میکند.
4
+
5
+## ۱. پیشنیازهای سیستم (Prerequisites)
6
+
7
+- سیستمعامل: Windows 10 / Windows 11 (64-bit)
8
+- حداقل رم (RAM): 4 GB
9
+- فضای ذخیرهسازی: 1 GB فضای خالی
10
+- مرورگر اینترنت استاندارد (Google Chrome, Microsoft Edge, Firefox)
11
+
12
+## ۲. معماری امنیتی و عدم دسترسی به دیتابیس (Security & DB Credentials Protection)
13
+
14
+- **مخفی بودن دیتابیس**: نرمافزار دسکتاپ به صورت مستقیم به دیتابیس متصل نمیشود. دیتابیس محلی در لایه سرویس پشتی قرار گرفته و هیچگونه رمز عبور یا اتصال دیتابیس در لایه UI قابل مشاهده نیست.
15
+- **ارتباط صرفاً از طریق API**: تمام تعاملات کاربر از طریق فراخوانی استاندارد APIهای REST صورت میپذیرد.
16
+- **حفظ حسابرسی و احراز هویت**: تمامی اقدامات کاربر در فایلهای لاگ حسابرسی (`AuditLog`) به همراه نقش کاربر ثبت میگردد.
17
+
18
+## ۳. پروفایلهای انتشار (Deployment Profiles)
19
+
20
+نرمافزار آرام از سه پروفایل پشتیبانی میکند:
21
+
22
+1. **`development`**: مخصوص توسعهدهندگان با لاگهای اشکالزدایی.
23
+2. **`pilot`**: مخصوص نسخه آزمایشی حسابداران (دیفالت نسخه دسکتاپ).
24
+3. **`production`**: مخصوص سرورهای عملیاتی با سرویس PostgreSQL.
25
+
26
+## ۴. مراحل نصب و اجرا (Installation & Startup Flow)
27
+
28
+### روش اول: اجرای مستقیم اسکریپت رانر پایلوت
29
+
30
+```cmd
31
+python -m desktop.app_runner
32
+```
33
+
34
+### روش دوم: ساخت فایل اجرایی Windows EXE (با PyInstaller)
35
+
36
+```cmd
37
+pip install pyinstaller
38
+pyinstaller --onefile --name "Aram_Accountant_Pilot" desktop/app_runner.py
39
+```
40
+
41
+پس از اجرای فایل، سرویس محلی بر روی آدرس زیر فعال شده و رابط کاربری فارسی در مرورگر باز میشود:
42
+`http://127.0.0.1:8000/`
43
+
44
+## ۵. ملاحظات پشتیبانگیری و بازیابی دادهها (Backup Considerations)
45
+
46
+فایل دیتابیس نسخه پایلوت در مسیر زیر به صورت محلی ذخیره میشود:
47
+`aram_pilot_hidden.db`
48
+
49
+جهت تهیه نسخه پشتیبان، کافیست نرمافزار را ببندید و یک کپی از فایل فوق بردارید.