A full-stack social networking application inspired by modern social media platforms.
This project was built primarily to explore backend development, REST API design, authentication, relational databases, session management and the architecture of a complete web application.
The application allows users to create an account, authenticate securely, manage their profile, publish posts and interact with other users through social features.
This repository is a portfolio project and is intended to be run locally. It is not currently operated as a public social networking service.
- User registration
- Login and logout
- Password hashing using bcrypt
- Persistent session-based authentication
- HTTP-only session cookies
- Protected API routes
- User session validation
- Custom usernames
- Profile pictures
- Biography
- Profile editing
- Create posts
- Delete owned posts
- Text posts
- Image support
- Video support
- Chronological feed
- Likes
- Comments
- Bookmarks
- Feed search
- Node.js
- Express.js
- PostgreSQL
pgexpress-session- bcrypt
- dotenv
- CORS
- HTML5
- CSS3
- JavaScript
- Fetch API
PostgreSQL is used for persistent application data, including:
- users
- posts
- likes
- comments
- sessions
The backend follows a layered architecture:
Client
│
│ HTTP / REST
▼
Express Router
│
▼
Controllers
│
▼
Models
│
▼
PostgreSQL
The project separates HTTP routing, application logic and database access.
backend/
├── controllers/
│ ├── authController.js
│ └── postController.js
│
├── middleware/
│ └── authMiddleware.js
│
├── models/
│ ├── userModel.js
│ └── postModel.js
│
├── routes/
│ ├── authRoutes.js
│ └── postRoutes.js
│
├── db/
│ └── init.js
│
├── database.js
├── sessionStore.js
└── server.js
The application uses server-side sessions instead of storing authentication credentials in frontend JavaScript.
Login
│
▼
POST /api/auth/login
│
▼
Password verification with bcrypt
│
▼
Session created
│
▼
Session stored server-side
│
▼
HTTP-only cookie returned to browser
│
▼
Browser automatically sends cookie
│
▼
Authentication middleware
│
▼
Protected resource
Passwords are never stored in plaintext.
The browser receives only a session identifier through an HTTP-only cookie.
Several security practices are implemented in the project:
- Password hashing with bcrypt
- Parameterized PostgreSQL queries
- HTTP-only authentication cookies
- Server-side session management
- Authentication middleware
- Ownership checks for protected resources
- Environment variables for sensitive configuration
- Input validation
- Generic authentication errors
Parameterized queries are used throughout the database layer to reduce SQL injection risks.
Example:
SELECT id, username
FROM users
WHERE email = $1
LIMIT 1;User-controlled values are passed separately from the SQL query.
Create a .env file inside the backend directory.
Example:
PORT=3000
NODE_ENV=development
DATABASE_URL=postgresql://USER:PASSWORD@HOST/DATABASE
SESSION_SECRET=replace_with_a_long_random_secretNever commit the real .env file.
An .env.example file is provided to document the required configuration.
Clone the repository:
git clone <repository-url>
cd Twitter/backendInstall dependencies:
npm installConfigure the environment variables:
cp .env.example .envThen configure your PostgreSQL connection and session secret.
Start the development server:
npm run devOr run the application normally:
npm startThe application will be available at:
http://localhost:3000
Some of the main API routes include:
POST /api/auth/register
POST /api/auth/login
POST /api/auth/logout
GET /api/auth/me
PUT /api/auth/me
GET /api/posts
POST /api/posts
DELETE /api/posts/:id
Additional endpoints handle likes, comments, bookmarks and other social interactions.
Detailed API documentation can be maintained inside:
docs/API.md
The database uses relational relationships between users and social content.
users
│
├──────── posts
│ │
│ ├── likes
│ └── comments
│
├──────── follows
│
└──────── bookmarks
Foreign keys associate posts and interactions with their owners.
PostgreSQL constraints are used where appropriate to preserve data integrity.
The main objective of this project is to demonstrate practical backend engineering skills, including:
- REST API development
- Authentication
- Session management
- SQL and relational database design
- Backend architecture
- Security fundamentals
- Client/server communication
- Asynchronous JavaScript
- Error handling
The frontend provides an interface for interacting with and demonstrating the backend functionality.
Future improvements may include:
- Cursor-based feed pagination
- Automated backend tests
- Rate limiting
- Structured request validation
- Object storage for uploaded media
- Real-time notifications with WebSockets
- Docker support
- Improved logging
- API documentation
This project is intentionally provided primarily as a local development demonstration rather than a publicly operated social network.
This keeps the repository focused on its technical purpose: demonstrating the architecture and implementation of a full-stack social networking application.
Kilian
Backend / Software Development Portfolio Project