@@ -18,9 +18,118 @@ Thank you for your interest in contributing to **Stellar Goal Vault**!
1818- Check the [ FAQ.md] ( ./FAQ.md ) for answers to common questions.
1919- Browse ` OPEN_SOURCE_ISSUES.md ` for curated contribution ideas.
2020
21+ ## Backend Development
22+
23+ ### Prerequisites
24+
25+ - ** Node.js** 18+ (check with ` node --version ` )
26+ - ** npm** 9+ (comes with Node.js)
27+
28+ ### Setup
29+
30+ 1 . Navigate to the backend directory:
31+ ``` bash
32+ cd backend
33+ ```
34+
35+ 2 . Install dependencies:
36+ ``` bash
37+ npm install
38+ ```
39+
40+ 3 . Copy the environment file:
41+ ``` bash
42+ cp .env.example .env
43+ ```
44+
45+ 4 . Configure environment variables in ` .env ` :
46+ - ` DB_PATH ` : Path to SQLite database file (default: ` ../../data/campaigns.db ` )
47+ - ` NODE_ENV ` : Set to ` development ` for local development
48+ - ` PORT ` : Server port (default: 3000)
49+ - ` CORS_ALLOWED_ORIGINS ` : Comma-separated list of allowed origins
50+ - ` CONTRACT_ID ` : Stellar contract ID (required for pledge operations)
51+ - ` SOROBAN_RPC_URL ` : URL to Soroban RPC endpoint
52+ - ` NETWORK_PASSPHRASE ` : Stellar network (default: ` Test SDF Network ; September 2015 ` for testnet)
53+
54+ ### Running the Backend
55+
56+ - ** Development mode** (with auto-reload):
57+ ``` bash
58+ npm run dev
59+ ```
60+ Server listens on ` http://localhost:3000 ` by default.
61+
62+ - ** Production mode** (build and run):
63+ ``` bash
64+ npm run build
65+ npm start
66+ ```
67+
68+ - ** Watch mode** (for editing and testing):
69+ ``` bash
70+ npm run dev
71+ ```
72+
73+ ### Testing
74+
75+ - ** Run all tests once** :
76+ ``` bash
77+ npm test
78+ ```
79+
80+ - ** Run tests in watch mode** (re-run on file changes):
81+ ``` bash
82+ npm run test:watch
83+ ```
84+
85+ - ** Run with coverage** :
86+ ``` bash
87+ npm test -- --coverage
88+ ```
89+
90+ ### Database
91+
92+ - ** Seeding** : The application automatically initializes the SQLite database with the schema on first run. To seed deterministic test campaigns:
93+ ``` bash
94+ npm test -- tests/services/seedDeterministic.test.ts
95+ ```
96+
97+ - ** Viewing the database** :
98+ - Use SQLite CLI: ` sqlite3 ../../data/campaigns.db `
99+ - Or use a GUI tool like [ DB Browser for SQLite] ( https://sqlitebrowser.org/ )
100+
101+ - ** Resetting the database** (for testing):
102+ - Delete the database file: ` rm ../../data/campaigns.db `
103+ - Next run will recreate it with the schema
104+
105+ ### Troubleshooting
106+
107+ #### "SQLITE_CANTOPEN" or database file not found
108+ - Ensure the directory specified in ` DB_PATH ` exists
109+ - Check file permissions on the database directory
110+ - If the directory doesn't exist, create it: ` mkdir -p data `
111+
112+ #### Tests fail with "database is locked"
113+ - This indicates concurrent access issues. Ensure only one test process is running.
114+ - Try clearing the test database: ` rm test-temp-*.db* `
115+ - Run tests serially: ` npm test -- --no-coverage `
116+
117+ #### "Cannot find module" errors
118+ - Run ` npm install ` in the ` backend ` directory
119+ - Clear node_modules and reinstall: ` rm -rf node_modules && npm install `
120+
121+ #### Port already in use
122+ - Change the ` PORT ` in ` .env ` to an available port (e.g., 3001)
123+ - Or kill the process on the current port
124+
125+ #### Environment variable not picked up
126+ - Ensure ` .env ` file is in the ` backend ` directory
127+ - Restart the development server after editing ` .env `
128+ - Check for syntax errors in ` .env ` (no spaces around ` = ` )
129+
21130## Testing
22131
23- - Backend: ` cd backend && npx vitest `
132+ - Backend: ` cd backend && npm test `
24133- Contract: ` cd contracts && cargo test `
25134- E2E: ` npm run test:e2e `
26135
0 commit comments