A robust backend API for Village Savings and Loan Association (VSLA) management system built with Node.js, Express.js, and MySQL.
- User Management: Registration, authentication, and profile management
- Group Management: Create and manage VSLA groups
- Contributions: Track member savings and contributions
- Loan Management: Loan applications, approvals, and repayments
- Reports: Financial summaries and group analytics
- Security: JWT authentication, input validation, and secure password handling
- Node.js (v16 or higher)
- MySQL (v8 or higher)
- npm or yarn
-
Clone the repository
git clone https://github.com/mugabe-rob/cooperative-savings.git cd vsla-backend
-
Install dependencies
npm install
-
Environment setup
cp .env.example .env
Update the
.env
file with your database credentials and JWT secret. -
Database setup
- Create MySQL database using the SQL file in
database/workbench_compatible.sql
- Import the file into MySQL Workbench or run via command line
- Create MySQL database using the SQL file in
-
Start the server
npm run dev # Development mode npm start # Production mode
POST /api/auth/register
- User registrationPOST /api/auth/login
- User login
GET /api/users
- Get all usersGET /api/users/:id
- Get user by IDPUT /api/users/:id
- Update userDELETE /api/users/:id
- Delete user
GET /api/groups
- Get all groupsPOST /api/groups
- Create new groupGET /api/groups/:id
- Get group detailsPUT /api/groups/:id
- Update groupDELETE /api/groups/:id
- Delete group
GET /api/contributions
- Get all contributionsPOST /api/contributions
- Record new contributionGET /api/contributions/group/:groupId
- Get group contributions
GET /api/loans
- Get all loansPOST /api/loans
- Apply for loanPOST /api/loans/:id/repay
- Record loan repayment
GET /api/reports/summary
- Get financial summaryGET /api/reports/group/:groupId
- Get group report
vsla-backend/
├── src/
│ ├── app.js # Main application file
│ ├── config/
│ │ ├── database.js # Database configuration
│ │ └── dotenv.js # Environment configuration
│ ├── controllers/ # Request handlers
│ ├── middlewares/ # Custom middleware
│ ├── models/ # Database models
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ └── utils/ # Utility functions
├── database/
│ └── workbench_compatible.sql # Database schema
├── .env.example # Environment variables template
├── package.json # Project dependencies
└── README.md # Project documentation
PORT=5000
NODE_ENV=development
DB_NAME=savings_app
DB_USER=root
DB_PASSWORD=your_password
DB_HOST=localhost
JWT_SECRET=your_jwt_secret
The database includes the following main tables:
- Users - User accounts and authentication
- Groups - VSLA group information
- UserGroups - Many-to-many relationship between users and groups
- Contributions - Member savings records
- Loans - Loan applications and tracking
- Repayments - Loan repayment records
- JWT token-based authentication
- Password hashing with bcrypt
- Input validation and sanitization
- CORS configuration
- Security headers with Helmet.js
- Environment-based configuration
npm run dev
npm start
- Set
NODE_ENV=production
- Configure production database
- Set secure JWT secret
- Configure CORS for your domain
All API responses follow this standard format:
{
"success": true/false,
"message": "Response message",
"data": {
// Response data
}
}
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Robert Mugabe
- GitHub: @mugabe-rob
- Email: [email protected]
- Built for Rwanda's VSLA community
- Inspired by cooperative financial systems
- Thanks to all contributors and testers
Golden Nest VSLA - Empowering communities through cooperative savings 🏦✨