The FinTech App is a full-stack financial application built using Node.js, Express, MySQL, and Sequelize ORM. It features secure user authentication and allows users to manage financial transactions like deposits and withdrawals.
The project uses dotenv to manage environment variables. Make sure to set up a .env file at the root directory with the following configuration:
DB_HOST=localhost # MySQL Server Host
DB_PORT=3306 # MySQL Port
DB_NAME=db # Database Name
DB_USER=root # MySQL Username
DB_PASSWORD=MySQL_Passwd # MySQL Password
DB_DIALECT=mysql # Database Dialect (Sequelize)
PORT=3000 # Application Port
JWT_SECRET=super_secret # JWT Secret for Token Generation
JWT_EXPIRES_IN=1h # JWT Expiry TimeReplace placeholders like
Password$123andsuper_secretwith your own secure values.
The authentication system relies on:
- Session Management using
express-session - Password Hashing with
bcryptjs - JWT Support for future extensions (optional)
Defined in user.js:
- Fields:
id,email,username,password_hash, andbalance - Password Hashing: Passwords are hashed using
bcryptjsbefore being stored.
Example Snippet:
import bcrypt from 'bcryptjs';
const passwordHash = await bcrypt.hash(password, 10); // Hash passwordRoutes are defined in auth.js:
- Login (
/login): Allows users to authenticate with email and password. - Register (
/register): Enables new user registration. - Logout (
/logout): Clears user session.
Example Snippet:
router.post('/login', async (req, res) => {
const { email, password } = req.body;
// Check user credentials and start session
});A middleware requireAuth ensures that only authenticated users can access secure pages like /dashboard and /transactions:
const requireAuth = (req, res, next) => {
if (!req.session.user) {
return res.redirect('/login');
}
next();
};The User and Transaction models are linked via foreignKey:
- User: Holds user information like email, password, and balance.
- Transaction: Tracks deposits and withdrawals.
Database tables:
CREATE TABLE user (
id INT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(255) UNIQUE NOT NULL,
username VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
balance DECIMAL(10, 2) DEFAULT 0.00
);
CREATE TABLE transaction (
id INT PRIMARY KEY AUTO_INCREMENT,
amount DECIMAL(10, 2) NOT NULL,
type VARCHAR(255) NOT NULL,
description VARCHAR(255),
user_id INT,
FOREIGN KEY (user_id) REFERENCES user(id)
);- Node.js installed
- MySQL server running
- Clone the repository.
- Install dependencies:
npm install
- Setup
.envas described. - Start the server:
npm start
- Access the app at
http://localhost:3000.
Key dependencies include:
- express: Web framework
- sequelize: ORM for MySQL
- bcryptjs: Password hashing
- express-session: Session management
- dotenv: Environment variable management.
Full list of dependencies can be found in the package.json file.
- Add JWT-based authentication for API security.
- Enable deployment to cloud platforms like Heroku or AWS.
- Enhance UI with more dynamic components.