{"id":24618045,"url":"https://github.com/kculz/greycodejs","last_synced_at":"2026-04-12T13:33:48.893Z","repository":{"id":271942943,"uuid":"915013722","full_name":"kculz/greycodejs","owner":"kculz","description":"The GreyCode.js framework is designed to streamline the development of applications using Sequelize and Express.js. This document provides an overview of the folder structure, its purpose, and how to work with it effectively. While the structure is customizable, adhering to the default layout ensures smoother functionality.","archived":false,"fork":false,"pushed_at":"2025-01-11T00:17:36.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T23:49:27.344Z","etag":null,"topics":["api-rest","express-framework","expressjs","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/kculz.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}},"created_at":"2025-01-10T19:24:28.000Z","updated_at":"2025-01-11T00:17:40.000Z","dependencies_parsed_at":"2025-01-10T22:51:59.471Z","dependency_job_id":null,"html_url":"https://github.com/kculz/greycodejs","commit_stats":null,"previous_names":["kculz/greycodejs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kculz%2Fgreycodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kculz%2Fgreycodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kculz%2Fgreycodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kculz%2Fgreycodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kculz","download_url":"https://codeload.github.com/kculz/greycodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244313863,"owners_count":20433011,"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":["api-rest","express-framework","expressjs","nodejs"],"created_at":"2025-01-24T23:49:36.285Z","updated_at":"2025-10-29T00:18:23.196Z","avatar_url":"https://github.com/kculz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GreyCodeJS Documentation\n\n## Introduction\n\nGreyCodeJS is a Node.js framework that provides an elegant, structured approach to building web applications. Built on top of Express.js, it simplifies common tasks while giving developers the flexibility to customize their application architecture.\n\n## Core Concepts\n\n### MVC Architecture\n\nGreyCodeJS follows the Model-View-Controller (MVC) pattern:\n\n- **Models**: Data structure and database operations\n- **Views**: Presentation layer (templates)\n- **Controllers**: Business logic and request handling\n\n### Directory Structure\n\n- **bin**: Contains CLI tools\n- **config**: Configuration files for database, app settings\n- **controllers**: Route controllers for handling requests\n- **core**: Framework core files\n- **middlewares**: Custom middleware functions\n- **models**: Data models representing database tables\n- **public/statics**: Static assets (CSS, JS, images)\n- **routes**: Route definitions\n- **seeds**: Database seed files\n- **templates**: Templates for CLI code generation\n- **views**: View templates for rendering HTML\n\n## Getting Started\n\n### Installation\n\n```bash\nnpm install -g greycodejs-installer\n```\n\n```bash\ngreycodejs-installer new my-project\n```\n\n```bash\ncd my-project\n```\n\n### Run project\n```bash\nnpm run dev\n```\n\n### Configuration\n\n1. Database setup in `config/database.js`\n2. Environment variables in `.env` file\n3. Application settings in `config/app.js` (if present)\n\n## Database Operations\n\n### Models\n\nModels define your data structure and are stored in the `models` directory.\n\n```javascript\n// models/User.js\nmodule.exports = (sequelize, DataTypes) =\u003e {\n  const User = sequelize.define('User', {\n    name: {\n      type: DataTypes.STRING,\n      allowNull: false\n    },\n    email: {\n      type: DataTypes.STRING,\n      unique: true\n    }\n  });\n  \n  return User;\n};\n```\n\n### Migrations and Seeders\n\nUse the CLI to create and run migrations:\n\n```bash\nnpm run cli -- create-migration create_users_table\nnpm run cli -- migrate\n```\n\nCreate seed data:\n\n```bash\nnpm run cli -- create-seed users\nnpm run cli -- seed\n```\n\n## Routing\n\n### Defining Routes\n\nCreate route files in the `routes` directory:\n\n```javascript\n// routes/users.js\nconst express = require('express');\nconst router = express.Router();\nconst UserController = require('../controllers/UserController');\n\nrouter.get('/', UserController.index);\nrouter.get('/:id', UserController.show);\nrouter.post('/', UserController.store);\nrouter.put('/:id', UserController.update);\nrouter.delete('/:id', UserController.destroy);\n\nmodule.exports = router;\n```\n\n### Route Registration\n\nRegister routes in `app.js`:\n\n```javascript\nconst usersRoutes = require('./routes/users');\napp.use('/api/users', usersRoutes);\n```\n\n## Controllers\n\nCreate controller files in the `controllers` directory:\n\n```javascript\n// controllers/UserController.js\nconst { User } = require('../models');\n\nmodule.exports = {\n  async index(req, res) {\n    try {\n      const users = await User.findAll();\n      return res.json(users);\n    } catch (error) {\n      return res.status(500).json({ error: error.message });\n    }\n  },\n  \n  async store(req, res) {\n    try {\n      const user = await User.create(req.body);\n      return res.status(201).json(user);\n    } catch (error) {\n      return res.status(400).json({ error: error.message });\n    }\n  },\n  \n  // Other controller methods...\n};\n```\n\n## Middleware\n\nCreate middleware in the `middlewares` directory:\n\n```javascript\n// middlewares/auth.js\nmodule.exports = (req, res, next) =\u003e {\n  const token = req.headers.authorization;\n  \n  if (!token) {\n    return res.status(401).json({ error: 'Authentication required' });\n  }\n  \n  // Token validation logic\n  \n  next();\n};\n```\n\nApply middleware in routes:\n\n```javascript\nconst authMiddleware = require('../middlewares/auth');\nrouter.get('/protected', authMiddleware, UserController.protectedMethod);\n```\n\n## Views and Templates\n\nGreyCodeJS uses EJS by default for view rendering:\n\n```javascript\n// controllers/HomeController.js\nmodule.exports = {\n  index(req, res) {\n    res.render('home', { title: 'Welcome to GreyCodeJS' });\n  }\n};\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `npm run cli -- create-model \u003cname\u003e` | Create a new model |\n| `npm run cli -- create-controller \u003cname\u003e` | Create a new controller |\n| `npm run cli -- create-route \u003cname\u003e` | Create a new route file |\n| `npm run cli -- create-middleware \u003cname\u003e` | Create middleware |\n| `npm run cli -- create-migration \u003cname\u003e` | Create a migration |\n| `npm run cli -- migrate` | Run migrations |\n| `npm run cli -- create-seed \u003cname\u003e` | Create a seed file |\n| `npm run cli -- seed` | Run seed files |\n\n## Error Handling\n\nGreyCodeJS provides centralized error handling through middleware:\n\n```javascript\n// middlewares/errorHandler.js\nmodule.exports = (err, req, res, next) =\u003e {\n  console.error(err.stack);\n  res.status(500).json({\n    error: {\n      message: err.message,\n      stack: process.env.NODE_ENV === 'production' ? null : err.stack\n    }\n  });\n};\n```\n\n## Advanced Topics\n\n### Custom Services\n\nCreate service classes for complex business logic:\n\n```javascript\n// services/EmailService.js\nclass EmailService {\n  static async sendWelcomeEmail(user) {\n    // Email sending logic\n  }\n}\n\nmodule.exports = EmailService;\n```\n\n### Validation\n\nImplement request validation:\n\n```javascript\n// middlewares/validateUser.js\nmodule.exports = (req, res, next) =\u003e {\n  const { name, email, password } = req.body;\n  \n  if (!name || !email || !password) {\n    return res.status(400).json({ error: 'Missing required fields' });\n  }\n  \n  // More validation...\n  \n  next();\n};\n```\n\n### Authentication\n\nSet up JWT authentication:\n\n```javascript\n// services/AuthService.js\nconst jwt = require('jsonwebtoken');\n\nclass AuthService {\n  static generateToken(user) {\n    return jwt.sign({ id: user.id }, process.env.JWT_SECRET, {\n      expiresIn: '1d'\n    });\n  }\n  \n  static verifyToken(token) {\n    return jwt.verify(token, process.env.JWT_SECRET);\n  }\n}\n\nmodule.exports = AuthService;\n```\n\n## Deployment\n\n1. Set environment variables for production\n2. Build assets if needed\n3. Run migrations\n4. Start the application in production mode:\n\n```bash\nNODE_ENV=production npm start\n```\n\n## Resources\n\n- [GitHub Repository](https://github.com/kculz/greycodejs)\n- [Report Issues](https://github.com/kculz/greycodejs/issues)\n- [Express.js Documentation](https://expressjs.com/)\n- [Sequelize Documentation](https://sequelize.org/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkculz%2Fgreycodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkculz%2Fgreycodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkculz%2Fgreycodejs/lists"}