File size: 6,373 Bytes
24e6f5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
213
214
215
216
217
218
219
220
@echo off
setlocal enabledelayedexpansion

echo ==========================================
echo   FinMK - Full Setup Script
echo ==========================================
echo.
echo This script will:
echo   1. Check Prerequisites
echo   2. Create .env file with MongoDB configuration
echo   3. Install all Python dependencies
echo   4. Install frontend dependencies
echo   5. Build frontend with Vite
echo   6. Sync static files and Run Migrations
echo   7. Verify MongoDB connection
echo   8. Run Django system checks
echo   9. Start both development servers
echo.
echo ==========================================
echo.

:: Check Prerequisites
echo [Step 1/9] Checking Prerequisites...
where python >nul 2>nul
if %errorlevel% neq 0 (
    echo [ERROR] Python is not installed or not in PATH.
    echo Please install Python 3.8+ and add it to PATH.
    pause
    exit /b 1
)

where npm >nul 2>nul
if %errorlevel% neq 0 (
    echo [ERROR] Node.js/npm is not installed or not in PATH.
    echo Please install Node.js and add it to PATH.
    pause
    exit /b 1
)

echo [OK] Python and Node.js detected.
echo.

:: Create .env file
echo [Step 2/9] Creating .env file...
cd /d "%~dp0backend"

if exist .env (
    echo [INFO] .env file already exists. Skipping creation.
) else (
    echo Creating .env file with MongoDB Atlas configuration...
    (
        echo # MongoDB Configuration
        echo MONGODB_URI=mongodb+srv://kumar:KumarDB7@mkcluster.hkk76.mongodb.net/finance
        echo.
        echo # Django Configuration
        echo SECRET_KEY=django-insecure-ereyyk0#@t#lc$@hpx^&9h@60-=-e+#=-3w^w+91w^&ol-^(6c^(fv
        echo DEBUG=True
        echo ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
        echo.
        echo # Database Name
        echo DB_NAME=finance
        echo.
        echo # Gemini AI Configuration
        echo # Get your free API key from: https://aistudio.google.com/app/apikey
        echo # Replace 'your_gemini_api_key_here' with your actual API key
        echo GEMINI_API_KEY=your_gemini_api_key_here
    ) > .env
    echo [OK] .env file created successfully.
    echo.
    echo [IMPORTANT] Please add your Gemini API key to backend\.env file
    echo            to enable AI chatbot features.
    echo            Get your free key from: https://aistudio.google.com/app/apikey
)
echo.

:: Install Python Dependencies
echo [Step 3/9] Installing Python Dependencies...
echo This may take several minutes...
echo.
python -m pip install --upgrade pip
if %errorlevel% neq 0 (
    echo [WARNING] Failed to upgrade pip. Continuing...
)

echo Installing requirements.txt...
pip install -r requirements.txt
if %errorlevel% neq 0 (
    echo [ERROR] Failed to install Python dependencies.
    pause
    exit /b 1
)
echo [OK] Python dependencies installed successfully.
echo.

:: Install Frontend Dependencies
echo [Step 4/9] Installing Frontend Dependencies...
cd /d "%~dp0frontend"
echo Installing npm packages...
call npm install
if %errorlevel% neq 0 (
    echo [ERROR] Failed to install npm packages.
    pause
    exit /b 1
)
echo [OK] Frontend dependencies installed.
echo.

:: Build Frontend
echo [Step 5/9] Building Frontend with Vite...
echo This may take a minute...
call npm run build
if %errorlevel% neq 0 (
    echo [ERROR] Frontend build failed.
    pause
    exit /b 1
)
echo [OK] Frontend built successfully.
echo.

:: Sync Static Files and Migrations
echo [Step 6/9] Syncing Static Files and Running Migrations...
cd /d "%~dp0"

if not exist backend\staticfiles mkdir backend\staticfiles

echo Copying frontend build to staticfiles...
xcopy /E /I /Y "frontend\dist\*" "backend\staticfiles\"
if %errorlevel% neq 0 (
    echo [WARNING] Failed to copy some files.
)

cd backend
echo Running database migrations (SQLite)...
python manage.py migrate
if %errorlevel% neq 0 (
    echo [ERROR] Database migration failed.
    pause
    exit /b 1
)

echo Running Django collectstatic...
python manage.py collectstatic --no-input
if %errorlevel% neq 0 (
    echo [WARNING] collectstatic completed with warnings.
) else (
    echo [OK] Static files collected and migrations applied.
)
echo.

:: Verify MongoDB Connection
echo [Step 7/9] Verifying MongoDB Connection...
python -c "from pymongo import MongoClient; import os; from dotenv import load_dotenv; load_dotenv(); uri = os.getenv('MONGODB_URI'); client = MongoClient(uri, serverSelectionTimeoutMS=5000); client.server_info(); print('[OK] MongoDB connected successfully!')"
if %errorlevel% neq 0 (
    echo [WARNING] MongoDB connection failed. Please check your MONGODB_URI in .env file.
    echo The application may not work properly without MongoDB.
) else (
    echo [OK] MongoDB connection verified.
)
echo.

:: Run Django System Check
echo [Step 8/9] Running Django System Check...
python manage.py check
if %errorlevel% neq 0 (
    echo [WARNING] Django system check found issues.
) else (
    echo [OK] Django system check passed.
)
echo.

:: Final Summary
echo ==========================================
echo   Setup Complete!
echo ==========================================
echo.
echo All components have been initialized:
echo   [x] Python dependencies installed
echo   [x] AI models downloaded
echo   [x] Database migrations applied
echo   [x] Frontend built
echo   [x] Static files synced
echo   [x] MongoDB connection verified
echo   [x] Django system check passed
echo.


echo ==========================================
echo   Starting Development Servers
echo ==========================================
echo.

:: Start Backend Server
cd /d "%~dp0backend"
echo Starting Backend (Django) on http://localhost:8000...
start "FinMK Backend" powershell -NoExit -Command "cd '%~dp0backend'; python manage.py runserver 0.0.0.0:8000"

:: Wait a moment before starting frontend
timeout /t 2 /nobreak >nul

:: Start Frontend Server
cd /d "%~dp0frontend"
echo Starting Frontend (Vite) on http://localhost:5173...
start "FinMK Frontend" powershell -NoExit -Command "cd '%~dp0frontend'; npm run dev"

echo.
echo ==========================================
echo   Servers Started!
echo ==========================================
echo.
echo Backend:  http://localhost:8000
echo Frontend: http://localhost:5173
echo.
echo Both servers are running in separate windows.
echo Close the PowerShell windows to stop the servers.
echo.
echo Press any key to exit this setup window...
pause >nul

endlocal