How sadman-mehrab/finfam-backend works
Project Type and Purpose
• This repository is the backend API service for “FinFam,” a family-oriented financial goal tracker.
• It’s a Node.js/TypeScript Express application exposing REST endpoints for users, families, goals, and contributions.
File Structure Analysis
Top-level folders:
• src/ — TypeScript source code
– config/ — environment and database configuration
– controllers/ — HTTP request handlers per resource
– routes/ — Express route definitions mapping URLs to controllers
– services/ — business logic and orchestration
– models/ — ORM/data‐access layer definitions
– middlewares/ — e.g., authentication checks
– utils/ — shared utilities (error handling, etc.)
– types/ — TypeScript type definitions
– index.ts — Express app setup and server launch
• dist/ — compiled JavaScript output (mirror of src/)
• tsconfig.json, package.json — build and dependency config
• vercel.json — deployment settings
Key Architectural Insights from the README
• Exposed routes for CRUD operations on users, families, goals, contributions.
• Authentication middleware protects private endpoints (likely JWT-based).
• Uses a relational or document datastore (configured in config/config.ts).
Components
a. External Clients
• Web or mobile frontend apps (e.g., React frontend)
• Third-party clients (CLI, mobile)
b. API Gateway / Load Balancer (optional)
• Vercel or another hosting layer
c. Express Application Layer
• Routers: userRouter, familyRouter, goalRouter, contributionRouter
• Middlewares: authMiddleware
d. Controller Layer
• contributionController, familyController, goalController, userController
e. Service Layer
• authService and resource-specific services encapsulating business rules
f. Data Access Layer (Models)
• Sequelize or chosen ORM Models (UserModel, FamilyModel, etc.)
g. Database
• e.g., PostgreSQL, MySQL, MongoDB (depicted as a single DB or as master/replica if needed)
h. Utilities & Config
• Centralized config loader (src/config/config.ts)
• Error handling utilities (src/utils/errors.ts)
Relationships and Data Flow
• The authMiddleware intercepts certain routes, verifying tokens via authService, before Controller
• Controllers invoke services and handle HTTP request/response shaping
• Services execute domain logic and interact with Models for persistence
• Models map to database tables/collections
Architectural Patterns & Principles
• Layered pattern: Presentation (HTTP), Controller, Service, Repository
• Separation of concerns: each layer only has its own responsibility
• Dependency injection (via imports and config) for swapping implementations (e.g., test DB)
• Config‐driven environment setup (development vs. production)