A scalable, production-ready backend built with NestJS, TypeScript, PostgreSQL, Docker, and TypeORM. This backend powers the Code Stream Blog application, handling authentication, user management, and blog post operations.
Checkout the API Documentation deployed at - https://api.code-stream.avinash-kumar.com/api/docs
- Framework: NestJS (TypeScript)
- Database: PostgreSQL (TypeORM for ORM)
- Authentication: Passport.js (JWT Strategy)
- Containerization: Docker
- Validation: Zod (Runtime environment variable validation)
- Documentation: Swagger (Accessible at
/api/docs)
src/
├── main.ts # Entry point of the application
├── app.module.ts # Root module
├── orm.config.ts # TypeORM database configuration
├── config/ # Configuration files
├── entities/ # TypeORM entity files
├── filters/ # Exception and other filters
├── guards/ # HTTP guards (e.g., Auth Guard)
├── middlewares/ # Middlewares (e.g., Logger)
├── migrations/ # TypeORM migration files
├── modules/ # Feature modules
│ ├── user/ # User module
│ ├── auth/ # Authentication module
│ ├── post/ # Post module
│ ├── healthcheck/ # Healthcheck module
├── strategies/ # Authentication strategies (e.g., JWT Strategy)
├── types/ # TypeScript types
- User Authentication: Google/Facebook login with JWT token generation
- User & Post Management: Full CRUD operations on
usersandposts - Swagger API Documentation: Available at
/api/docs - Database Migration Support: Using TypeORM migrations
- Security & Validation: JWT authentication and Zod runtime validation
- Developer-Friendly Makefile: Simplifies running commands
- Future Roadmap: AWS SDK integration for direct S3 uploads
| Column | Type | Constraints |
|---|---|---|
| id | Autogenerated Number (PK) | Primary Key |
| name | VARCHAR(255) | Not Null |
| VARCHAR(255) | Unique, Not Null | |
| thumbnail | TEXT | Nullable (S3 URL) |
| created_at | TIMESTAMP (without timezone) | Default: now() |
| updated_at | TIMESTAMP (without timezone) | Default: now() |
| Column | Type | Constraints |
|---|---|---|
| id | Autogenerated Number (PK) | Primary Key |
| user_id | Number (FK to users.id) | Foreign Key, Not Null |
| title | VARCHAR(255) | Not Null |
| description | VARCHAR(255) | Not Null |
| body | TEXT | Not Null |
| thumbnail | TEXT | Nullable (S3 URL) |
| created_at | TIMESTAMP (without timezone) | Default: now() |
| updated_at | TIMESTAMP (without timezone) | Default: now() |
Relations:
- One-to-Many:
users→posts(Foreign Key:user_id)
- User sends a login request with a provider (Google/Facebook) and an OAuth access token.
- Backend validates the token with the respective provider.
- If successful, fetches user data and creates or retrieves the user in the database.
- Returns a signed JWT token for subsequent authenticated requests.
git clone https://github.com/your-repo/code-stream-backend.git
cd code-stream-backendCreate a .env file in the root directory:
NODE_ENV=development
SERVER_PORT=3000
JWT_SECRET=codestream_secret_32_chars_long_string_for_making_jwt_token
DATABASE_URL=postgres://codestream_user:codestream_password@db:5432/codestream_dbmake start # Starts the app using Docker Composenvm use
npm install
npm run start:devThe project includes a Makefile for easier command execution:
make help # List all available commandsSwagger documentation is available at: http://localhost:3000/api/docs
- AWS SDK Integration: Generate pre-signed URLs for direct S3 uploads.
- Rate Limiting & Caching: Improve API performance and security.
- NestJS Docs → https://docs.nestjs.com/
- TypeORM Docs → https://typeorm.io/
- Passport.js JWT Strategy → https://docs.nestjs.com/security/authentication
- Swagger Docs → https://docs.nestjs.com/openapi/introduction
- Zod Validation → https://zod.dev/