The FinTech API is a robust and secure backend solution designed for financial technology applications. It provides a comprehensive set of features for user management, account handling, and transaction processing. Built with NestJS and leveraging modern web technologies, this API ensures high performance, scalability, and maintainability.
- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Authentication: Passport.js, JWT
- Validation: Class Validator
- API Documentation: Swagger
- Testing: Jest
- Containerization: Docker
- CI/CD: GitHub Actions
The project follows a modular architecture based on NestJS best practices:
- Modules: Each feature (Users, Accounts, Transactions, Auth) is encapsulated in its own module, promoting separation of concerns and maintainability.
- Controllers: Handle incoming HTTP requests and define API endpoints.
- Services: Contain business logic and interact with repositories.
- Repositories: Abstract database operations and interact directly with the Prisma ORM.
- DTOs (Data Transfer Objects): Define the structure of data for requests and responses.
- Guards: Implement authentication and authorization checks.
- Interceptors: Handle cross-cutting concerns like serialization.
- Decorators: Custom decorators for things like current user extraction.
src/
├── auth/
├── users/
│ └── contacts/
├── accounts/
├── transactions/
├── database/
├── core/
│ └── serialize/
├── utils/
└── main.ts
This structure allows for easy navigation, scalability, and maintenance of the codebase. Each module (auth, users, accounts, transactions) contains its own controllers, services, and DTOs, keeping related functionality together.
- User registration and authentication
- Profile management (update details, change password, change email)
- Contact information management
- Create and manage multiple accounts per user
- View account details and balance
- Close accounts
- Deposit funds
- Withdraw funds
- Transfer funds between accounts
- Transaction history and details
- JWT-based authentication
- Role-based access control
- Password hashing and validation
sequenceDiagram
participant Client
participant AuthController
participant UsersService
participant Database
Client->>AuthController: POST /auth/register
AuthController->>UsersService: create(userData)
UsersService->>Database: Insert user data
Database-->>UsersService: Confirm insertion
UsersService-->>AuthController: Return user object
AuthController-->>Client: Return success message
sequenceDiagram
participant Client
participant AuthController
participant AuthService
participant UsersService
participant JwtService
Client->>AuthController: POST /auth/login
AuthController->>AuthService: validateUser(credentials)
AuthService->>UsersService: getOneBy(username/email)
UsersService-->>AuthService: Return user
AuthService->>AuthService: Validate password
AuthService-->>AuthController: Return validated user
AuthController->>AuthService: makeToken(userId)
AuthService->>JwtService: sign(payload)
JwtService-->>AuthService: Return JWT
AuthService-->>AuthController: Return token
AuthController-->>Client: Return access token
sequenceDiagram
participant Client
participant AccountsController
participant AccountsService
participant Database
Client->>AccountsController: POST /accounts
AccountsController->>AccountsService: create(userId)
AccountsService->>Database: Insert account data
Database-->>AccountsService: Confirm insertion
AccountsService-->>AccountsController: Return account object
AccountsController-->>Client: Return created account
sequenceDiagram
participant Client
participant TransactionsController
participant AccountsService
participant TransactionsService
participant Database
Client->>TransactionsController: POST /transactions/deposit
TransactionsController->>AccountsService: getOneById(accountId)
AccountsService-->>TransactionsController: Return account
TransactionsController->>AccountsService: validate(user, account)
TransactionsController->>TransactionsService: calcTax(amount)
TransactionsController->>TransactionsService: createDeposit(accountId, netAmount)
TransactionsService->>Database: Insert transaction & Update balance
Database-->>TransactionsService: Confirm transaction
TransactionsService-->>TransactionsController: Return transaction object
TransactionsController-->>Client: Return transaction details
Before you begin, ensure you have the following installed:
- Node.js (v21.0.0 recommended)
- Yarn package manager
- Docker and docker-compose
-
Clone the repository:
git clone https://github.com/ahmdhusam/fintech.git cd fintech
-
Install dependencies:
yarn install
-
Set up environment variables:
- Create a
.env
file in the project root - Copy the contents from
.env.example
to.env
- Modify the values as needed for your local setup
- Create a
-
Start the Docker containers:
docker-compose up -d
This will start the PostgreSQL database container.
-
Run database migrations:
yarn prisma migrate dev
-
Start the application in development mode:
yarn start:dev
The API will be available at
http://localhost:3000
by default. -
For production builds:
yarn build yarn start:prod
API documentation is available at /api/docs
when the server is running, powered by Swagger.
The project includes unit tests and e2e tests. Run tests using:
yarn test
yarn test:e2e
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.