How adarsh0727/typeflow-finance-backend works
Project Type and Purpose
• This is a Node.js/Express RESTful backend ("typeFlow-finance-backend") for managing financial data: users, categories, transactions, reports, and OCR extraction. It exposes HTTP endpoints, applies authentication, orchestrates business logic in controllers, interacts with a database, and calls out to an OCR utility.
File Structure Analysis
• server.js: bootstraps the Express app, applies global middleware, mounts route handlers, and starts the HTTP listener.
• routes/*.js: define URL endpoints under /category, /transaction, /report, /ocr, etc., and delegate to controllers.
• controllers/*.controller.js: implement request handling, call model/database APIs or OCR utilities, and return responses.
• models/*.model.js: define the schema and data-access layer (e.g., Mongoose models or ORM entities) for User, Category, Transaction.
• db/connect.js: configures and establishes the database connection pool.
• middleware/auth.middleware.js + errorHandler.middleware.js: cross-cutting concerns for JWT auth, permission checks, and centralized error handling.
• utils/ocrHelper.js + parser.js: encapsulate OCR invocation (e.g., Tesseract or third-party API) and parsing logic for extracting structured data from images.
• package.json: lists dependencies (express, mongoose/knex, jsonwebtoken, etc.) and scripts.
Key Architectural Patterns
• Layered MVC-style separation: Routes → Controllers → Models (Data Layer).
• Middleware pipeline for authentication and error handling.
• Single Node.js process as HTTP API gateway.
• Utility modules for external integration (OCR).
Main Components
a. External Clients (Web or Mobile App)
b. API Gateway (Express.js Server)
• Global Middleware (Auth, Error Handler)
• Router Layer (category.routes, transaction.routes, etc.)
• Controller Layer (category.controller, ocr.controller, …)
c. Business Logic / Utilities (OCR Helper, Parser)
d. Persistence Layer
• Database Connection (db/connect.js)
• Data Models (User, Category, Transaction)
e. External Service Integration
• OCR Engine (Tesseract or Cloud OCR API)
Relationships and Data Flows
• Within Server: Request → Auth Middleware → Route → Controller.
• Controller → Model/DB or Controller → OCR Utility → External OCR Service → Parser → Controller.
• Controller → Response → Client.
• Model methods use the db connection to perform CRUD on the database.