A full-stack application built with Node.js, Express, React, and SQLite that allows users to manage credits and transactions. This application uses SQLite for its database, making it lightweight and easy to set up with no additional database server required.
- User Authentication (Register/Login)
- JWT Token-based Authorization
- Automatic Credit Bonus on Signup
- Credit Balance Management
- Transaction History
- Protected Routes
- Responsive Design
- RESTful API
- Real-time Balance Updates
- SQLite Database with Sequelize ORM
- Node.js
- Express.js
- SQLite3 (lightweight SQL database)
- Sequelize ORM
- JWT for Authentication
- bcryptjs for Password Hashing
- Express Validator
- Cors
- Dotenv for Environment Variables
- Morgan for Logging
- React (Create React App)
- React Router v6
- Context API for State Management
- Axios for HTTP Requests
- Custom CSS
Before you begin, ensure you have installed:
- Node.js (v14 or higher)
- npm (v6 or higher) or yarn
- Git
- Clone the repository:
git clone <repository-url>
cd finance-app- Set up the Backend:
# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Create database directory
mkdir -p database
# Create .env file
cat > .env << EOL
PORT=5000
JWT_SECRET=your_secure_jwt_secret_here
JWT_EXPIRE=1hr
SIGNUP_CREDIT_AMOUNT=1000
EOLto generate a JWT token for backend access run the following command
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
#navigate to the backend/.env file and edit the JWT_SECRET= <your-generated-jwt-secret>- Set up the Frontend:
# Navigate to frontend directory
cd ../frontend
# Install dependencies
npm install
# Create .env file
cat > .env << EOL
REACT_APP_API_URL=http://localhost:5000
EOLThe SQLite database will be automatically created when you first start the server. The database file will be located at:
/backend/database/finance.sqlite
To manually initialize the database:
cd backend
node -e "require('./config/database').sync()"- Start the Backend Server:
# From the backend directory
cd backend
npm run dev
# You should see:
# Database synced successfully
# Server running on port 5000- Start the Frontend Development Server:
# From the frontend directory
cd frontend
npm start
# The application will open in your browser at http://localhost:3000- Check Database Creation:
# From the backend directory
ls database/finance.sqlite
# Should show the SQLite database file- Test API Connection:
# Test the API health endpoint
curl http://localhost:5000/api/health
# Should return: {"status": "ok"}You can use SQLite command line tool to view the database:
# Install SQLite command line tool if needed
# Ubuntu/Debian:
sudo apt-get install sqlite3
# Access the database
sqlite3 backend/database/finance.sqlite
# Common SQLite commands:
.tables # List all tables
.schema Users # Show Users table schema
.schema Transactions # Show Transactions table schema
SELECT * FROM Users; # View all users
SELECT * FROM Transactions; # View all transactions
.quit # Exit SQLite CLI-
POST /api/auth/register - Register a new user
curl -X POST http://localhost:5000/api/auth/register \\ -H "Content-Type: application/json" \\ -d '{"name":"Test User","email":"[email protected]","password":"password123"}'
-
POST /api/auth/login - Login user
curl -X POST http://localhost:5000/api/auth/login \\ -H "Content-Type: application/json" \\ -d '{"email":"[email protected]","password":"password123"}'
-
GET /api/auth/me - Get logged in user info
curl -X GET http://localhost:5000/api/auth/me \\ -H "Authorization: Bearer YOUR_JWT_TOKEN"
- GET /api/transactions - Get all transactions
- GET /api/transactions/:id - Get specific transaction
- POST /api/transactions/spend - Create a new spending transaction
- Database Connection Issues:
# Check if database file exists
ls backend/database/finance.sqlite
# Check file permissions
ls -l backend/database/finance.sqlite
# Ensure database directory exists
mkdir -p backend/database- Server Won't Start:
# Check if port 5000 is already in use
lsof -i :5000
# Kill process if needed
kill -9 <PID>- Database Reset:
#Remove and recreate database
rm backend/database/finance.sqlite
node -e "require('./config/database').sync()"To add new features to the backend:
- Create new models in /backend/models using Sequelize syntax
- Add new controllers in /backend/controllers
- Create new routes in /backend/routes
- Update server.js if needed
To add new features to the frontend:
- Add new components in
/frontend/src/components - Create new pages in
/frontend/src/pages - Update context if needed in
/frontend/src/context - Modify App.js to include new routes
cd backend
npm testcd frontend
npm testcd backend
npm run buildcd frontend
npm run build-
Deploy Backend:
- Configure environment variables
- Ensure SQLite file permissions are correct
- Deploy to hosting service (e.g., Heroku, AWS, DigitalOcean)
-
Deploy Frontend:
- Build the React application
- Deploy static files to hosting service
- Configure environment variables correctly
For support, please open an issue in the repository or contact the development team.
This project is licensed under the MIT License - see the LICENSE file for details.
- React Documentation
- Express.js Documentation
- Node.js Documentation
- Sequelize Documentation
- SQLite Documentation
- JWT Documentation