Hey there! Welcome to the documentation for this LinkedIn-inspired social media app. This is a basic CRUD (Create, Read, Update, Delete) application built with TypeScript and follows Object-Oriented Programming (OOP) principles throughout.
This is a simple social networking app where users can register, log in, and create posts - kind of like LinkedIn but way simpler! The whole codebase is written in TypeScript using classes and OOP concepts to keep things organized and maintainable.
- Language: TypeScript
- Framework: Express.js
- Database: MongoDB (with Mongoose)
- Authentication: JWT (JSON Web Tokens)
- Architecture: OOP - everything is organized in classes (Controllers, Services, Routes, Models)
The app follows a clean OOP structure:
- Models: Define how data looks in the database
- Services: Handle all the business logic
- Controllers: Deal with HTTP requests and responses
- Routes: Map URLs to controller methods
- Middlewares: Check if users are logged in
http://localhost:3000
All authentication-related stuff lives under /auth. These routes help users sign up, log in, and manage their accounts.
POST /auth/register
This is where new users create their accounts. Just send an email and password!
What you need to send:
{
"email": "[email protected]",
"password": "password123"
}What you get back:
{
"message": "User registered successfully",
"userId": "some-random-user-id"
}Notes:
- Email must be unique (no duplicates allowed!)
- Password gets hashed automatically for security
- No authentication needed for this route
POST /auth/login
Already have an account? Log in here to get your access token!
What you need to send:
{
"email": "[email protected]",
"password": "password123"
}What you get back:
{
"message": "Login successful",
"token": "your-jwt-token-here",
"userId": "your-user-id"
}Notes:
- Keep that token! You'll need it for protected routes
- Add it to your requests like this:
Authorization: Bearer your-token-here
GET /auth/users
Want to see all registered users? This route shows everyone!
What you need to send: Nothing! Just hit the endpoint.
What you get back:
{
"users": [
{
"_id": "user-id-1",
"email": "[email protected]",
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z"
},
{
"_id": "user-id-2",
"email": "[email protected]",
"createdAt": "2026-01-16T11:20:00.000Z",
"updatedAt": "2026-01-16T11:20:00.000Z"
}
]
}Notes:
- Public route - no authentication needed
- Passwords are NOT included (security first!)
GET /auth/users/:userId
Need info about a specific user? Use their ID to fetch their details.
Example:
GET /auth/users/697f570862bae9bab8d93d59
What you get back:
{
"user": {
"_id": "697f570862bae9bab8d93d59",
"email": "[email protected]",
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-01-15T10:30:00.000Z"
}
}Notes:
- No authentication needed
- If user doesn't exist, you'll get a 404 error
PUT /auth/update-password
๐ Protected Route - You must be logged in!
Want to change your password? This is the place!
Headers needed:
Authorization: Bearer your-jwt-token
What you need to send:
{
"oldPassword": "password123",
"newPassword": "newpassword456"
}What you get back:
{
"message": "Password updated successfully"
}Notes:
- You must provide your current password (for security)
- New password gets hashed automatically
- Only updates YOUR password (can't change others!)
DELETE /auth/delete
๐ Protected Route - You must be logged in!
Sad to see you go! This permanently deletes your account.
Headers needed:
Authorization: Bearer your-jwt-token
What you need to send:
{
"password": "password123"
}What you get back:
{
"message": "User deleted successfully"
}Notes:
- Must confirm with your password
- This action cannot be undone!
- Deletes YOUR account only
All post-related functionality lives under /posts. Create, read, update, and delete posts here!
POST /posts
๐ Protected Route - You must be logged in!
Share your thoughts with the world! Create a new post.
Headers needed:
Authorization: Bearer your-jwt-token
What you need to send:
{
"content": "Just learned TypeScript! Loving OOP so far ๐"
}What you get back:
{
"message": "Post created successfully",
"post": {
"_id": "post-id-here",
"userId": "your-user-id",
"content": "Just learned TypeScript! Loving OOP so far ๐",
"createdAt": "2026-02-01T14:20:00.000Z",
"updatedAt": "2026-02-01T14:20:00.000Z"
}
}Notes:
- Post automatically linked to your user ID
- Content cannot be empty
GET /posts
See what everyone's posting! Fetches all posts from all users.
What you need to send: Nothing!
What you get back:
{
"posts": [
{
"_id": "post-id-1",
"userId": "user-id-1",
"content": "Hello world!",
"createdAt": "2026-02-01T10:00:00.000Z",
"updatedAt": "2026-02-01T10:00:00.000Z"
},
{
"_id": "post-id-2",
"userId": "user-id-2",
"content": "TypeScript is awesome!",
"createdAt": "2026-02-01T11:30:00.000Z",
"updatedAt": "2026-02-01T11:30:00.000Z"
}
]
}Notes:
- Public route - no login needed
- Shows posts from all users
GET /posts/user/:userId
Want to see all posts from a specific user? This is your route!
Example:
GET /posts/user/697f570862bae9bab8d93d59
What you get back:
{
"posts": [
{
"_id": "post-id-1",
"userId": "697f570862bae9bab8d93d59",
"content": "My first post!",
"createdAt": "2026-02-01T10:00:00.000Z",
"updatedAt": "2026-02-01T10:00:00.000Z"
}
]
}Notes:
- Public route
- Returns empty array if user has no posts
GET /posts/:postId
Need details about a specific post? Fetch it by its ID!
Example:
GET /posts/697f570862bae9bab8d93d59
What you get back:
{
"post": {
"_id": "697f570862bae9bab8d93d59",
"userId": "some-user-id",
"content": "This is the post content",
"createdAt": "2026-02-01T10:00:00.000Z",
"updatedAt": "2026-02-01T10:00:00.000Z"
}
}Notes:
- Public route
- Returns 404 if post doesn't exist
PUT /posts/:postId
๐ Protected Route - You must be logged in!
Made a typo? Want to edit your post? Update it here!
Headers needed:
Authorization: Bearer your-jwt-token
Example:
PUT /posts/697f570862bae9bab8d93d59
What you need to send:
{
"content": "Updated content here!"
}What you get back:
{
"message": "Post updated successfully",
"post": {
"_id": "697f570862bae9bab8d93d59",
"userId": "your-user-id",
"content": "Updated content here!",
"createdAt": "2026-02-01T10:00:00.000Z",
"updatedAt": "2026-02-01T14:30:00.000Z"
}
}Notes:
- You can only update YOUR OWN posts
- Content cannot be empty
DELETE /posts/:postId
๐ Protected Route - You must be logged in!
Regret posting something? Delete it permanently!
Headers needed:
Authorization: Bearer your-jwt-token
Example:
DELETE /posts/697f570862bae9bab8d93d59
What you get back:
{
"message": "Post deleted successfully"
}Notes:
- You can only delete YOUR OWN posts
- This action cannot be undone!
When things go wrong, you'll get helpful error messages:
{
"message": "Something went wrong",
"error": "Detailed error description"
}Common error codes:
- 400: Bad request (missing or invalid data)
- 401: Unauthorized (need to log in or token expired)
- 403: Forbidden (trying to access/modify someone else's data)
- 404: Not found (user/post doesn't exist)
- 500: Server error (something broke on our end)
This app is built with TypeScript classes throughout:
Models (Classes extending Mongoose Schema)
User.model.ts- User data structurePost.model.ts- Post data structure
Services (Business Logic Classes)
Auth.service.ts- Handles user registration, login, password updatesPost.service.ts- Manages post creation, updates, deletion
Controllers (Request Handler Classes)
Auth.controller.ts- HTTP handlers for auth routesPost.controller.ts- HTTP handlers for post routes
Routes (Route Definition Classes)
AuthRoutes- Defines all /auth endpointsPostRoutes- Defines all /posts endpoints
Middlewares (Protection Classes)
AuthMiddleware- Verifies JWT tokens
Everything is instantiated as classes and follows OOP principles like encapsulation, single responsibility, and dependency injection!
- Make sure MongoDB is running
- Create a
.envfile with your MongoDB connection string and JWT secret - Run
npm install - Run
npm run dev - Server starts on
http://localhost:3000
Happy coding! ๐