{"id":34995346,"url":"https://github.com/realharis/ai-chat-node-js-ddd-clean-architecture","last_synced_at":"2026-05-19T12:34:32.308Z","repository":{"id":328255402,"uuid":"1114822131","full_name":"RealHaris/ai-chat-node-js-ddd-clean-architecture","owner":"RealHaris","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-12T10:38:46.000Z","size":252,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-13T05:53:59.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RealHaris.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-11T23:58:32.000Z","updated_at":"2025-12-12T10:38:50.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/RealHaris/ai-chat-node-js-ddd-clean-architecture","commit_stats":null,"previous_names":["realharis/ai-chat-node-js-ddd-clean-architecture"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/RealHaris/ai-chat-node-js-ddd-clean-architecture","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealHaris%2Fai-chat-node-js-ddd-clean-architecture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealHaris%2Fai-chat-node-js-ddd-clean-architecture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealHaris%2Fai-chat-node-js-ddd-clean-architecture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealHaris%2Fai-chat-node-js-ddd-clean-architecture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RealHaris","download_url":"https://codeload.github.com/RealHaris/ai-chat-node-js-ddd-clean-architecture/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealHaris%2Fai-chat-node-js-ddd-clean-architecture/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28069214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-27T02:03:46.385Z","updated_at":"2025-12-27T02:04:58.086Z","avatar_url":"https://github.com/RealHaris.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Chat Subscription System (DDD + Clean Architecture)\n\nA robust, production-ready Node.js backend service built with **Domain-Driven Design (DDD)** and **Clean Architecture** principles. This project implements a complete subscription-based AI chat system with quota management, background workers, and comprehensive testing.\n\n**Repository:** [https://github.com/RealHaris/ai-chat-node-js-ddd-clean-architecture](https://github.com/RealHaris/ai-chat-node-js-ddd-clean-architecture)\n\n---\n\n## Key Features\n\n*   **Authentication \u0026 Authorization**\n    *   Secure JWT-based auth (Access + Refresh Tokens).\n    *   Role-based access control (Admin vs. Regular User).\n    *   Redis-backed token management (Allow/Revoke).\n*   **Subscription Management**\n    *   Flexible Bundle Tiers (Basic, Pro, Enterprise/Unlimited).\n    *   Monthly \u0026 Yearly billing cycles.\n    *   Auto-renewal and Cancellation workflows.\n    *   **Background Workers** (BullMQ) for handling subscription expiry and status updates.\n*   **Quota System**\n    *   **Free Tier**: Auto-resetting monthly quota (3 messages/month).\n    *   **Paid Tiers**: Cumulative quota management.\n    *   **Cron Jobs**: Automated monthly reset for free tier users.\n*   **Chat Module**\n    *   Message persistence and history.\n    *   Strict quota enforcement (403 Forbidden when limit reached).\n*   **Advanced Architecture**\n    *   **DDD**: Rich Domain Models, Aggregates, Value Objects.\n    *   **Clean Architecture**: Strict layer separation (Domain -\u003e Application -\u003e Infrastructure).\n    *   **CQRS**: Segregated Read and Write repositories for optimized performance.\n    *   **Dependency Injection**: Managed via \tsyringe.\n\n## Tech Stack\n\n*   **Runtime**: Node.js (\u003e= 18.12.0)\n*   **Language**: TypeScript\n*   **Framework**: Express.js\n*   **Database**: PostgreSQL\n*   **ORM**: Drizzle ORM\n*   **Caching/Queues**: Redis, BullMQ\n*   **Scheduling**: Node-cron\n*   **Validation**: Zod\n*   **Bundler**: esbuild\n*   **Testing**: TSX, Native Fetch (Custom Test Runner)\n\n## Architecture Overview\n\n    ```\n    src/\n    ├── modules/                 # Domain Modules\n    │   ├── auth/                # Authentication \u0026 Token Management\n    │   ├── user/                # User Profile \u0026 Admin Management\n    │   ├── subscription/        # Bundles, Subscriptions, Quotas\n    │   └── chat/                # Chat Messages \u0026 History\n    │       ├── domain/          # Entities, Events, Interfaces\n    │       ├── application/     # Use Cases, DTOs\n    │       └── infra/           # Controllers, Repositories\n    ├── shared/                  # Shared Kernel\n    │   ├── infra/               # DB, Redis, Queue, Cron, HTTP\n    │   └── core/                # Base Classes (Entity, Result, etc.)\n    └── worker.ts                # Background Worker Entry Point\n    ``` \n\n## Getting Started\n\n### Prerequisites\n\n*   Node.js (v18+)\n*   PostgreSQL\n*   Redis (Required for Queues and Token management)\n\n### Installation\n\n1.  **Clone the repository**\n    `ash\n    git clone https://github.com/RealHaris/ai-chat-node-js-ddd-clean-architecture.git\n    cd ai-chat-node-js-ddd-clean-architecture\n    `\n\n2.  **Install dependencies**\n    `ash\n    npm install\n    `\n\n3.  **Environment Setup**\n    Copy .env.example to .env and configure your database/redis credentials.\n    `ash\n    cp .env.example .env\n    `\n\n4.  **Database Setup**\n    `ash\n    # Generate migrations\n    npm run migration:generate\n    \n    # Apply migrations\n    npm run migration:push\n    \n    # Seed initial data (Admin user, Bundle tiers)\n    npm run db:seed\n    `\n\n### Running the Application\n\n*   **Development Server**\n    `ash\n    npm run dev\n    `\n*   **Background Worker** (Required for subscription expiry)\n    `ash\n    npm run worker:dev\n    `\n*   **Production Build**\n    `ash\n    npm run build\n    npm start\n    `\n\n## Testing\n\nThe project includes a comprehensive custom test runner covering Unit, Integration, and E2E scenarios.\n\n| Command | Description |\n| :--- | :--- |\n| `npm run test` | Run **ALL** tests (Auth, User, Bundle, Sub, Chat, E2E, Advanced, Postman) |\n| `npm run test:e2e` | Run standard End-to-End user journeys |\n| `npm run test -- advanced` | Run edge cases (Quota limits, Worker simulation, Cron reset) |\n| `npm run test -- postman` | Run happy-path scenarios matching the Postman collection |\n| `npm run test:auth` | Run specific module tests (auth, user, chat, etc.) |\n\n## Development Commands\n\n| Command | Description |\n| :--- | :--- |\n| `npm run lint` | Run ESLint |\n| `npm run lint:fix` | Fix ESLint errors |\n| `npm run format` | Format code with Prettier |\n| `npm run type-check` | Run TypeScript type checking |\n## License\n\nThis project is private.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealharis%2Fai-chat-node-js-ddd-clean-architecture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealharis%2Fai-chat-node-js-ddd-clean-architecture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealharis%2Fai-chat-node-js-ddd-clean-architecture/lists"}