How body661/blog-app-api works
Project type and purpose
• This is a monolithic Node.js backend API (“Blog-app-api”) that exposes RESTful endpoints for a blogging platform.
• It handles user authentication, post creation/management, administrative operations, and media storage via AWS S3.
File structure
• Top-level:
• index.mjs – application entry point (express server setup)
• db.mjs – database connection module
• S3.mjs – AWS S3 client wrapper for file uploads
• Procfile – deployment script (e.g., Heroku)
• controllers/ – business logic grouped by domain:
• auth.mjs – signup, login, token handling
• post.mjs – CRUD operations on blog posts
• admin.mjs – admin-only operations (e.g., user management, moderation)
• routes/ – HTTP routing definitions that delegate to controllers
• auth.mjs, posts.mjs, admin.mjs
• package.json – dependencies (likely Express, AWS SDK, ORM or driver)
Key insights from README
• Minimal: project name “Blog-app-api.”
• We infer core features: user authentication, post management, media upload.
Main components
a. Clients
• Web & Mobile front-end apps (React, Vue, mobile)
b. API Server
• HTTP server (Express.js in index.mjs)
• Router layer (routes/*.mjs)
• Controller layer (controllers/*.mjs)
• Service/utility modules (db.mjs, S3.mjs)
c. Data stores
• Primary database (e.g., MongoDB, PostgreSQL)
• Object storage (AWS S3)
d. Authentication
• JWT or session service (inside auth controller)
e. Deployment platform
• Heroku or any PaaS referenced by Procfile
f. External services
• AWS S3 for media
• (Potentially) external email/SMS service for notifications
Relationships & interactions
1. Client → HTTP(S) → API Server (Express router)
2. Router → Controller → decides logic path
– Auth controller → issues/verifies JWT → responds
– Post controller → interacts with db.mjs for CRUD
– Admin controller → elevated privileges → db.mjs
– Any controller invoking S3.mjs for upload/download
3. db.mjs → Database cluster (reads/writes data)
4. S3.mjs → AWS S3 (uploads post images, retrieves them)
5. API Server uses environment variables (config) for DB/S3 credentials
Architectural patterns & design principles
• Layered architecture:
• Presentation (HTTP layer) → Routing
• Business logic (Controllers)
• Data access (db module, AWS SDK wrapper)
• Single responsibility: controllers only implement domain logic, not routing or DB wiring
• Externalized configuration (Procfile & env vars) for 12-factor app
• Statelessness: relies on JWT for auth, no in-memory sessions