How sloweyyy/trustify-backend works
Project Type and Purpose
• Trustify-Backend is a monolithic backend API service built with Node.js and Express.
• Its core purpose is to handle user requests for document notarization, integrate with blockchain/NFT storage, manage payments, send emails, and store documents in Firebase.
File Structure to Extract Architectural Layers
• Entry Point & Configuration:
• src/index.js / src/app.js
• src/config/*.js (database, Firebase, blockchain, authentication, logging)
• API Layer:
• src/routes/v1/*.route.js → express routers
• src/controllers/*.controller.js → HTTP request handlers
• Swagger docs under src/docs
• Business / Service Layer:
• src/services/*.service.js → core business logic (notarization, payments, emails, chatbots, cron jobs)
• Data Access Layer:
• src/models/*.model.js → Mongoose schemas and plugins under src/models/plugins
• Middleware & Utilities:
• src/middlewares/*.js → request parsing, auth, rate limiting, error handling
• src/utils/*.js → error classes, async wrappers, picker functions
• Static Assets & Email Templates:
• src/public → static HTML/CSS/JS and email templates
• Testing & CI/CD:
• Jest tests under tests/*, GitHub Actions, Travis CI, Dockerfiles, Jenkinsfile, buildspec.yml
External Dependencies (from README and Config)
• Database: MongoDB via Mongoose
• Storage: Firebase Cloud Storage
• Blockchain: Solana devnet (and NFT/IPFS via Pinata, Bundlr)
• Authentication: JWT, Passport.js + Google OAuth
• Email: SMTP (Ethereal or real providers)
• Payments: PayOS
• QR Codes: VietQR API
• AI Documents: Gemini API
• Deployment & Containerization: Docker, PM2, Railway
Main Components & Their Relationships
a. API Gateway (Express Server)
• Accepts client requests (REST calls or webhooks)
• Passes requests through middlewares (auth, validation, rate-limit, logging)
• Routes to controllers
b. Controllers
• Orchestrate input validation → call service methods → format responses
c. Services
• Implement business rules:
• Notarization flows (upload, request, track status)
• Payment processing (PayOS integration)
• Email notifications (SMTP templates)
• AI doc generation (Gemini)
• Chatbot interactions
• Cron jobs for cleanup or retries
d. Data Layer
• Mongoose models handle persistence in MongoDB
• Pagination, toJSON, and other plugins
e. External Systems
• MongoDB (primary document store)
• Firebase (binary document storage)
• Blockchain/NFT (Solana program via web3, IPFS/Pinata, Bundlr)
• SMTP server
• OAuth provider (Google)
• Gemini API, VietQR API, PayOS API
Architectural Patterns & Principles
• Layered Architecture (MVC-style)
• Dependency Injection via configuration modules
• Plugin Pattern for Mongoose (paginate, toJSON)
• Separation of Concerns: controllers vs services vs models
• External Integration Adapters keep 3rd-party logic isolated in services
Putting It All Together
• Start your whiteboard or diagramming tool with the Client (browser, mobile) calling REST endpoints.
• Inside, split horizontally into Controllers → Services → Models.
• Mongoose connecting to MongoDB.
• Optionally, show CI/CD workflow on a side panel.