The Blogs API is a robust, production-ready backend service built with Node.js and TypeScript. It follows a layered architecture, separating concerns across controllers, services, and a persistent data layer. The system features a centralized response and error handling mechanism, multi-tenant organization support via Better Auth, and schema-based validation to ensure data integrity.
Key features include:
- Layered Architecture: Clear separation between HTTP logic, business services, and database schemas.
- Standardized Responses: Unified API response structure for consistency across all endpoints.
- Advanced Authentication: Integration with Better Auth supporting social OAuth (GitHub, Google) and organizational contexts.
- Type-Safe ORM: Leveraging Drizzle ORM for performant, type-safe PostgreSQL interactions.
- Runtime: Node.js
- Language: TypeScript
- Framework: Express.js (v5)
- Database: PostgreSQL
- ORM: Drizzle ORM
- Authentication: Better Auth
- Validation: Zod
- Logging: Pino
- Mailing: Resend & React Email
Ensure you have the following installed on your local machine:
- Node.js (v20 or higher)
- pnpm (Package Manager)
- Docker & Docker Compose (For local database orchestration)
- PostgreSQL (If running outside of Docker)
-
Clone the repository:
git clone https://github.com/Fidelisaboke/blog-api.git cd blog-api -
Install dependencies:
pnpm install
-
Environment Configuration: Copy the example environment file and update the values with your credentials.
cp .env.example .env
-
Database Setup: Start the PostgreSQL container using Docker Compose:
docker-compose up -d
-
Run Migrations: Push the current schema to your database instance:
pnpm db:push
Start the server with hot-reloading enabled via tsx:
pnpm devThe server will be accessible at http://localhost:3000
To compile the TypeScript source to JavaScript and run the production build:
pnpm build
pnpm startTo inspect your data locally using a GUI:
pnpm db:studioThe project follows a modular structure to ensure high maintainability and ease of testing.
.
├── drizzle/ # Generated SQL migrations and schema snapshots
├── src/
│ ├── app.ts # Application entry point and middleware assembly
│ ├── controllers/ # Request handlers (Inheriting from BaseController)
│ ├── db/ # Database connection and Drizzle schema definitions
│ ├── lib/ # Core libraries (Auth, Logger, Standardized Response)
│ ├── middleware/ # Express middlewares (Auth, Error Handling, Validation)
│ ├── routes/ # API route definitions
│ ├── schemas/ # Zod validation schemas
│ ├── services/ # Business logic layer
│ └── types/ # Global TypeScript interfaces and declarations
├── docker-compose.yaml # Local infrastructure orchestration
├── drizzle.config.ts # Drizzle ORM configuration
├── tsconfig.json # TypeScript compiler configuration
└── package.json # Project metadata and dependencies
roadmap.sh Project URL: https://roadmap.sh/projects/blogging-platform-api