{"id":25238012,"url":"https://github.com/pungrumpy/cow-strike-kmitl-mvc","last_synced_at":"2025-10-26T12:30:53.277Z","repository":{"id":276761390,"uuid":"857053266","full_name":"PunGrumpy/cow-strike-kmitl-mvc","owner":"PunGrumpy","description":"🎓 Exit Exam for MVC (Model View and Controller)","archived":true,"fork":false,"pushed_at":"2024-09-14T09:44:19.000Z","size":320,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-11T16:02:58.677Z","etag":null,"topics":["elysiajs","kmitl","mvc"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PunGrumpy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-09-13T17:54:17.000Z","updated_at":"2025-02-11T09:02:26.000Z","dependencies_parsed_at":"2025-02-11T00:01:15.273Z","dependency_job_id":null,"html_url":"https://github.com/PunGrumpy/cow-strike-kmitl-mvc","commit_stats":null,"previous_names":["pungrumpy/kmitl-mvc-2024","pungrumpy/cow-strike-kmitl-mvc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2Fcow-strike-kmitl-mvc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2Fcow-strike-kmitl-mvc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2Fcow-strike-kmitl-mvc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2Fcow-strike-kmitl-mvc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PunGrumpy","download_url":"https://codeload.github.com/PunGrumpy/cow-strike-kmitl-mvc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238324669,"owners_count":19453140,"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","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":["elysiajs","kmitl","mvc"],"created_at":"2025-02-11T16:03:16.964Z","updated_at":"2025-10-26T12:30:52.866Z","avatar_url":"https://github.com/PunGrumpy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🦊 KMITL Exit Exam (MVC)\n\n| Preview 1                         | Preview 2                         | Preview 3                         |\n| --------------------------------- | --------------------------------- | --------------------------------- |\n| ![Preview](/public/preview-1.png) | ![Preview](/public/preview-2.png) | ![Preview](/public/preview-3.png) |\n\n## 📄 Description\n\nThis project is a robust RESTful API built with Elysia.js, following the enterprise MVC (Model-View-Controller) architecture. It leverages Prisma ORM for efficient database management and uses TypeScript to enhance type safety and developer experience.\n\n1. Create and manage cow data (code, color, age) through CowModel and CowService\n2. Simulate milking and calculate BSOD chances in CowController\n3. Generate milk production reports via MilkProductionService\n4. Display results through GUI using HTML generated from CowView\n5. Manage BSOD status and lemon feeding in CowController\n\n## 🧱 MVC Architecture\n\nThis project follows a modified Model-View-Controller (MVC) architecture pattern, adapted for a RESTful API using Elysia.js. Here's an overview of each component and its corresponding folder in the project structure:\n\n### 📁 Models (`src/models/`)\n\n- `CowModel.ts` and `MilkProductionModel.ts`\n- Define data structures, validation, and business logic\n- Handle data management, storage, and retrieval\n- Use Elysia.model for schema validation\n\n### 🖥️ Views (`Swagger UI`)\n\n- In a RESTful API, the \"View\" is the data sent back to the client\n- Managed by Elysia.js through route handlers and data serialization\n- CowView.ts creates HTML templates for displaying cow data and milk production results\n- Swagger UI is used for API documentation\n\n### 🛣️ Routes and Controllers (`src/controllers/`)\n\n- `CowController.ts`\n- Defines API endpoints and manages the request/response cycle\n- Uses models for request validation and response formatting\n- Calls appropriate service methods to process requests\n\n### 🛠️ Services (`src/services/`)\n\n- `CowService.ts` and `MilkProductionService.ts`\n- Contain business logic that doesn't belong in models or routes\n- Handle complex operations, often involving database interactions\n- Use Prisma client for database operations\n\n## 👯 How They Work Together\n\n1. **Controller** receives HTTP requests, calls **Service** to process data\n2. **Service** uses **Model** for data validation and database operations\n3. **Controller** uses **View** (in this case, sending data back) to send response\n4. `index.ts` is the application entry point, configured with Elysia.js, and invokes `CowController`\n\n## 📦 Technologies\n\n- 🦊 [Elysia.js](https://elysiajs.com/): A lightweight, flexible web framework for Node.js\n- 🛠️ [Prisma](https://www.prisma.io/): Modern database toolkit for TypeScript and Node.js\n- 🍞 [Bun](https://bun.sh/): JavaScript runtime for building web applications\n- 🦄 [TypeScript](https://www.typescriptlang.org/): Typed superset of JavaScript\n- 🦭 [MariaDB](https://mariadb.org/): Open-source relational database management system\n- 📦 [Swagger UI](https://swagger.io/tools/swagger-ui/): Open-source tool for API documentation\n\n## 🚀 Getting Started\n\n### 📋 Prerequisites\n\n- [Bun](https://bun.sh/) (v1.0.0 or later)\n- [MySQL](https://www.mysql.com/) (v5.7 or later) or [MariaDB](https://mariadb.org/) (v10.2 or later)\n\n### 🛠️ Installation Steps\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/PunGrumpy/kmitl-mvc.git\n   cd kmitl-mvc\n   ```\n\n2. Install the dependencies:\n\n   ```bash\n   bun install\n   ```\n\n3. Configure the environment variables:\n\n   - Create a `.env` file in the root of the project.\n   - Add the following environment variables:\n     ```env\n     DATABASE_URL=\"mysql://username:password@localhost:3306/your_database_name\"\n     ```\n\n4. Create Prisma client:\n\n   ```bash\n   bun db:generate\n   ```\n\n5. Run the migrations:\n   ```bash\n   bun db:migrate\n   ```\n\n### 🏃‍♂️ Running the Project\n\n1. Start the development server:\n\n   ```bash\n   bun dev\n   ```\n\n2. Access the API:\n   - Open your browser and go to `http://localhost:3000` for the Swagger documentation.\n   - The API endpoints will be available at `http://localhost:3000/users`.\n\n## 🏗️ Project Structure\n\n```\n.\n├── src/\n│   ├── models/\n│   │   └── userModel.ts\n│   ├── controllers/\n│   │   └── userControllers.ts\n│   └── services/\n│       └── userService.ts\n├── prisma/\n│   └── schema.prisma\n├── index.ts\n├── .env\n├── package.json\n└── README.md\n```\n\n## 🔑 API Endpoints\n\n- `GET /api/cows`: Retrieve all cows or find a cow by code\n- `POST /api/cows`: Create a new cow\n- `POST /api/cows/reset-bsod`: Reset BSOD status for all cows\n- `POST /api/cows/:code/add-lemon`: Add lemon to a cow\n- `POST /api/milk/:code`: Milk a cow\n- `GET /api/milk/report`: Get milk production report\n\nFor detailed API documentation, visit the Swagger UI at `http://localhost:3000` when the server is running.\n\n\u003e [!WARNING]\n\u003e This API endpoint may change in the future. Please refer to the Swagger documentation for the latest information.\n\n\u003e [!NOTE]\n\u003e In MVC architecture, API endpoints are considered as the \"View\" layer.\n\n## 🧪 Testing\n\nTo test the database connection:\n\n```bash\nbun test:connection\n```\n\n## 🛠️ Development\n\nThis project uses Bun as the JavaScript runtime. Here are some useful commands:\n\n- `bun dev`: Start the development server\n- `bun db:generate`: Generate Prisma client\n- `bun db:migrate`: Run database migrations\n- `bun test:connection`: Test database connection\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## 📝 License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n\n## 📚 References\n\n- [Elysia Documentation](https://elysiajs.com/)\n- [Prisma Documentation](https://www.prisma.io/docs/)\n- [Bun Documentation](https://bun.sh/docs)\n\n## 🙋‍♂️ Support\n\nIf you have any questions or need help, please open an issue in the GitHub repository or contact the maintainer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpungrumpy%2Fcow-strike-kmitl-mvc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpungrumpy%2Fcow-strike-kmitl-mvc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpungrumpy%2Fcow-strike-kmitl-mvc/lists"}