Skip to content

Latest commit

Β 

History

54 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Connecto Logo

Connecto Backend

πŸš€ A modern Node.js + TypeScript REST API for the Connecto social platform


πŸš€ Features

  1. πŸ“ Project Structure
  2. πŸ”‘ Authentication
  3. πŸ”’ Protected Endpoints
  4. πŸ§ͺ Validation
  5. βš™οΈ .env Configuration
  6. πŸ’» Technologies Used
  7. πŸš€ Deployment
  8. ©️ License
  9. ✍️ Author

πŸ“ Project Structure

Below is the modular architecture of the backend project using TypeScript, Express, Mongoose, and clean architecture principles.

πŸ“ src
βš™οΈ config

Application configuration modules

File Description
cors.config.ts Defines CORS policy to control cross-origin requests.
db.config.ts Sets up and manages the MongoDB connection using Mongoose.
index.ts Central entry point for all configuration modules for simplified imports.
logger.config.ts Configures Winston logger for structured logging and integrates with Morgan.
uploads.config.ts Defines Multer settings for secure and validated file uploads.
🧭 controllers

Business logic per feature

Directory / File Description
auth/ Register/login logic
comments/ CRUD for comments
posts/ Post operations including likes and file handling
users/ Profile & password updates
index.ts Exports grouped controllers
🚨 errors

Custom error classes and base handler

File Description
base/HttpError.ts Generic HTTP error base class
types/ClientErrors.ts 4xx client error definitions
types/ServerErrors.ts 5xx server error definitions
index.ts Central export for all error types
🧱 middlewares

Express middlewares

File Description
auth.middleware.ts JWT authentication middleware
errorHandler.middleware.ts Centralized error handling
morganLogger.middleware.ts HTTP request logging using Morgan + Winston
upload.middleware.ts Multer configuration for handling file uploads
validate.middleware.ts Zod-based request schema validation
index.ts Central export for middleware functions
πŸ—ƒοΈ models

Mongoose schemas

File Description
User.ts, Posts.ts, Comments.ts MongoDB schema definitions using Mongoose
index.ts Aggregates and re-exports models
πŸ›£οΈ routes

Express routes per module

File Description
auth.routes.ts Routes for authentication
users.routes.ts Routes for user management
posts.routes.ts Routes for post operations
index.ts Combines and mounts all route modules
πŸ› οΈ utils

General utility functions

File Description
jwt.ts, argon.ts Utilities for authentication and hashing
dbUtils.ts MongoDB-related helpers
errorHandler.ts Error transformation and forwarding helpers
serverUtils.ts Helpers for server setup, shutdown, etc.
applyProtectedRoute.ts Adds JWT protection to route groups
stackTrace.ts Parses and formats stack traces for debugging/logging
responses.ts Standardized HTTP response formatting
httpStatus.ts Central HTTP status code definitions
index.ts Central utility re-export
βœ… validations

Zod schemas for validation

File / Directory Description
auth/, comments/, posts, users Zod schema modules for request validation
schemas.ts Central export of all Zod schema types
β”œβ”€β”€ app.ts

└── server.ts

πŸ”‘ Authentication

Public routes (no token required)

  • POST /auth/signup – Create a new user
  • POST /auth/login – Log in and receive JWT token

JWT Secured

  • JWT is stored in Authorization: Bearer <token> header
  • Files access uses token in ?token=... query string (e.g., <img src="/api/v1/web-embed/proxy?proxyUrl=https%3A%2F%2Fgithub.com%2Ffiles%2Fuser%2Favatar%2Ffoo.png%3Ftoken%3D...&mode=full" />)
  • Token settings (secret, expiry) are defined in .env

πŸ”’ Protected Endpoints (require valid JWT)

πŸ‘€ Users - /users

  • GET /profile – Get current user's profile
  • PATCH /profile – Update name, family name, or avatar (with file upload)
  • PUT /password – Change password
  • DELETE / – Delete current user

πŸ“ Posts - /posts

  • POST / – Create new post (with optional file)
  • GET / – Fetch all posts
  • GET /:id – Get single post
  • PATCH /:id/like – Like/unlike a post
  • PATCH /:id – Update a post (and optionally update file)
  • DELETE /:id – Delete a post
  • POST /:id/comments – Add comment to a post
  • GET /:id/comments – List comments on a post

πŸ’¬ Comments - /comments

  • GET /:id – Get single comment
  • PUT /:id – Update comment content
  • DELETE /:id – Delete comment

πŸ“¦ Files - /files

  • GET /user/avatar/:filename?token=... – Access user avatar (with token in URL)
  • GET /post/:filename?token=... – Access post file (with token in URL)

πŸ§ͺ Validation

All inputs are validated using Zod:

  • Body (req.body)
  • Params (req.params)
  • Auth (req.auth)

If validation fails, the API responds with a 400 Bad Request and details.


βš™οΈ .env Configuration

Make sure to create a .env file based on the example in the .env.example file


πŸ’» Technologies Used

A range of modern and robust technologies was used to develop Connecto, a secure and scalable social platform. Below is a detailed breakdown:

Technology Description
NodeJS Node.js – Runtime for backend JavaScript execution.
TypeScript TypeScript – Superset of JavaScript adding type safety and better tooling.
ExpressJS Express.js – Fast, unopinionated, minimalist web framework for Node.js.
JWT JWT (jsonwebtoken) – Secure user authentication via JSON Web Tokens.
Multer Multer – Middleware for handling multipart/form-data for file uploads.
Zod Zod – Type-safe schema validation for input data (Zod + TypeScript).
Mongoose Mongoose – Elegant MongoDB object modeling for Node.js.
Winston Winston – Logging library for professional, structured logging.
ESLint ESLint – Pluggable linter for maintaining code quality and enforcing standards.
Prettier Prettier – Opinionated code formatter to ensure consistent styling.
VS Code Visual Studio Code – Primary code editor used for development.
Postman Postman – API platform used for building, testing and documenting RESTful endpoints.

πŸš€ Deployment

πŸ› οΈ Tooling & Environment

This project is equipped with a streamlined development setup to ensure high code quality and consistency across environments.

  • Nodemon – Automatically restarts the server on file changes during development.
  • TypeScript – Enables static type checking for better reliability and maintainability.
  • ESLint & Prettier – Enforces consistent code style and catches common errors.
  • Environment Variables – Supports environment-specific configuration via .env files.

πŸ“œ Available Scripts

Run the following scripts to manage development tasks efficiently:

npm run dev             # Start the development server with Nodemon
npm run lint            # Lint all source files using ESLint
npm run lint:fix        # Automatically fix lint issues
npm run format          # Format all files using Prettier
npm run format:check    # Check if files are properly formatted (without modifying)

©️ License

πŸ”’ All Rights Reserved

This project and its entire source code are proprietary.
You are permitted to view the code only for informational or educational insight.

You may not:

  • Reuse or copy any part of this codebase
  • Modify, adapt, or build upon this project
  • Distribute or make it publicly available
  • Use it for personal, academic, or commercial projects

Unauthorized use will be considered a violation of copyright law.

For special permissions, contact the author at : Email


🧠 Author

MasterCodeDevelop
MasterCodeDevelop

Passionate Full-Stack Developer.
I craft scalable web platforms, clean architectures, and intelligent backend systems.
Always aiming for production-grade quality with well-documented, testable, and modular code.

πŸ”— Connect with me on GitHub

πŸ’‘ Contributions, issues and feature requests are welcome!

Back to top

About

πŸš€ Backend API for the Connecto social platform – built with Node.js, TypeScript, Express, MongoDB, and Zod for robust validation. πŸ”’ All rights reserved – Source code is view-only and may not be reused or redistributed.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages