diff --git a/.gitignore b/.gitignore index 399284b..81e8cd6 100644 --- a/.gitignore +++ b/.gitignore @@ -128,6 +128,6 @@ tmtags *.sql *.sqlite *.db -/backend/node-express/hello-world/package-lock.json -/backend/node-express/hello-world/yarn.lock -/backend/node-express/hello-world/package-lock.json +/backend/node-express-js/node-express-starter-js/package-lock.json +/backend/node-express-js/node-express-starter-js/yarn.lock +/backend/node-express-js/node-express-starter-js/package-lock.json diff --git a/README.md b/README.md index 3adffc9..91f128b 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ implementing your logic. ## Technologies & Frameworks Supported -- **Web Frameworks**: React, Vue.js, Angular, etc. -- **Backend Frameworks**: Express, Django, Flask, etc. -- **Databases**: MongoDB, PostgreSQL, MySQL, Elasticsearch, etc. +- **Frontend Frameworks**: React, Vue.js, Angular, etc. +- **Backend Frameworks**: Node.js, Django, Flask, etc. +- **Data Processing**: Pandas, Apache Spark, Hadoop, Kubernetes Jobs, etc. +- **Artificial Intelligence & Machine Learning**: TensorFlow, PyTorch, SciKit-Learn, Keras, etc. - ... and many more! ## How to Use a Seed @@ -38,9 +39,10 @@ we'd love for you to contribute. Check out our [Contributing Guide](./CONTRIBUTI When creating a PR, make sure to attach appropriate labels. This helps in categorizing and reviewing PRs efficiently: -- `web-framework`: For seeds related to web frameworks. +- `frontend`: For seeds related to frontend frameworks. - `backend`: For backend-specific seeds. -- `database`: For seeds with a specific database focus. +- `data-processing`: For seeds focused on data processing techniques and tools. +- `ml/ai`: For seeds related to artificial intelligence and machine learning technologies. - ... (you can extend this list based on the categories of seeds you anticipate) ## What Makes a Good Seed? diff --git a/backend/node-express/README.md b/backend/node-express-js/README.md similarity index 58% rename from backend/node-express/README.md rename to backend/node-express-js/README.md index 46a4bd2..58d2823 100644 --- a/backend/node-express/README.md +++ b/backend/node-express-js/README.md @@ -1,12 +1,14 @@ -# Node-Express Seeds +# Node-Express Seeds (JavaScript Version) This repository contains multiple seeds (starter templates) for Node.js projects using Express.js with different configurations and additions. ## Folder Structure -- **hello-world**: This contains a basic Node-Express seed to get you started with a simple "Hello, World!" API. -- **mongoose**: This seed incorporates Mongoose, enabling you to quickly start a project with MongoDB integration. +- **node-express-starter-js**: This contains a basic Node-Express seed to get you started with a simple "Hello, World!" + API. +- **node-express-mongoose-js**: This seed incorporates Mongoose, enabling you to quickly start a project with MongoDB + integration. ## Getting Started diff --git a/backend/node-express/mongoose/.env.example b/backend/node-express-js/node-express-mongoose-js/.env.example similarity index 100% rename from backend/node-express/mongoose/.env.example rename to backend/node-express-js/node-express-mongoose-js/.env.example diff --git a/backend/node-express-js/node-express-mongoose-js/README.md b/backend/node-express-js/node-express-mongoose-js/README.md new file mode 100644 index 0000000..3cebb58 --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/README.md @@ -0,0 +1,36 @@ +# Node Express - Mongoose with Javascript Seed + +This seed helps you kickstart your Node.js projects using Express.js and **Javascript** with integrated MongoDB support +through Mongoose. + +## Getting Started + +- Navigate to the `mongoose` directory. +- Configure environment variables as described in the [local development](#local-development) section. +- Ensure you have a MongoDB instance running or use your connection string in the `.env` for an external database. +- Run `yarn install` to install the necessary dependencies. +- Use `yarn start` to start the server. +- Your API is now connected to a MongoDB instance, and you can begin creating models, routes, etc. + +## Dependencies + +This seed uses: + +- [Express.js](https://expressjs.com/): A fast, minimalist web framework for Node.js. +- [Mongoose](https://mongoosejs.com/): Elegant MongoDB object modeling for Node.js. + +## Local Development + +This seed uses environment variables for configuration: + +- Make sure to set up your `.env` file by using `.env.example` as a reference. +- Adjust the values in `.env` as necessary to match your setup. + +## Warestack Deployments + +For this Flask API to be compatible with automated deployments on Warestack, the inclusion of the `healthz` endpoint is +mandatory. Warestack uses this endpoint to ensure that the service is running correctly. + +## Questions & Contributions + +If you have any questions or wish to contribute, please open an issue or submit a pull request. diff --git a/backend/node-express/mongoose/app/app.js b/backend/node-express-js/node-express-mongoose-js/app/app.js similarity index 69% rename from backend/node-express/mongoose/app/app.js rename to backend/node-express-js/node-express-mongoose-js/app/app.js index 2587206..2785be3 100644 --- a/backend/node-express/mongoose/app/app.js +++ b/backend/node-express-js/node-express-mongoose-js/app/app.js @@ -3,8 +3,10 @@ const express = require('express'); // Load environment variables from .env file require('dotenv').config(); -const dbConfig = require('./config/database') +const dbConfig = require('./config/database'); +const RootController = require('./root/root.controller'); +const HealthController = require('./health/health.controller'); const UsersController = require('./user/user.controller'); class App { @@ -27,6 +29,8 @@ class App { dbConfig.connect(); } routes() { + this.app.use('/', new RootController().getRouter()); + this.app.use('/healthz', new HealthController().getRouter()); this.app.use(`/users`, new UsersController().getRouter()); } } diff --git a/backend/node-express/mongoose/app/config/database.js b/backend/node-express-js/node-express-mongoose-js/app/config/database.js similarity index 100% rename from backend/node-express/mongoose/app/config/database.js rename to backend/node-express-js/node-express-mongoose-js/app/config/database.js diff --git a/backend/node-express-js/node-express-mongoose-js/app/health/health.controller.js b/backend/node-express-js/node-express-mongoose-js/app/health/health.controller.js new file mode 100644 index 0000000..2f4e88c --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/health/health.controller.js @@ -0,0 +1,23 @@ +const express = require('express'); + +const HealthService = require('./health.service'); + +class HealthController { + constructor() { + this.router = express.Router(); + + // Setting the routes for the greeting endpoint group + this.router.get('/', this.health().bind(this)); // Binding is necessary for 'this' to refer to the class instance + } + + getRouter() { + return this.router; + } + + async health(request, response, next) { + const message = HealthService.health(); + response.status(200).send(message); + } +} + +module.exports = HealthController; diff --git a/backend/node-express-js/node-express-mongoose-js/app/health/health.service.js b/backend/node-express-js/node-express-mongoose-js/app/health/health.service.js new file mode 100644 index 0000000..48952c0 --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/health/health.service.js @@ -0,0 +1,7 @@ +class HealthService { + health() { + return "I am healthy!"; + } +} + +module.exports = new HealthService(); // Exporting an instance of the service diff --git a/backend/node-express-js/node-express-mongoose-js/app/root/root.controller.js b/backend/node-express-js/node-express-mongoose-js/app/root/root.controller.js new file mode 100644 index 0000000..4a2e203 --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/root/root.controller.js @@ -0,0 +1,22 @@ +const express = require('express'); +const RootService = require('./root.service'); + +class RootController { + constructor() { + this.router = express.Router(); + + // Setting the routes for the root endpoint group + this.router.get('/', this.info.bind(this)); // Binding is necessary for 'this' to refer to the class instance + } + + getRouter() { + return this.router; + } + + async info(request, response, next) { + const message = RootService.info(); + response.status(200).send(message); + } +} + +module.exports = RootController; diff --git a/backend/node-express-js/node-express-mongoose-js/app/root/root.service.js b/backend/node-express-js/node-express-mongoose-js/app/root/root.service.js new file mode 100644 index 0000000..f3516d3 --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/root/root.service.js @@ -0,0 +1,7 @@ +class RootService { + info() { + return "Hello, World!"; + } +} + +module.exports = new RootService(); // Exporting an instance of the service diff --git a/backend/node-express-js/node-express-mongoose-js/app/user/user.controller.js b/backend/node-express-js/node-express-mongoose-js/app/user/user.controller.js new file mode 100644 index 0000000..a676161 --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/user/user.controller.js @@ -0,0 +1,76 @@ +const express = require('express'); +const UserService = require('../services/users.service'); + +class UsersController { + constructor() { + this.router = express.Router(); + this.router.get('/', this.getUsers.bind(this)); + this.router.get('/:email', this.getUserByEmail.bind(this)); + this.router.post('/', this.createUser.bind(this)); + this.router.put('/:email', this.updateUser.bind(this)); + this.router.delete('/:email', this.deleteUser.bind(this)); + } + + getRouter() { + return this.router; + } + + async getUsers(request, response, next) { + try { + const users = await UserService.getUsers(); + response.status(200).send(users); + } catch (e) { + next(e); + } + } + + async getUserByEmail(request, response, next) { + try { + const user = await UserService.getUserByEmail(request.params.email); + if (!user) { + response.status(404).send({ message: 'User not found.' }); + return; + } + response.status(200).send(user); + } catch (e) { + next(e); + } + } + + async createUser(request, response, next) { + try { + const user = await UserService.createUser(request.body); + response.status(201).send(user); + } catch (e) { + next(e); + } + } + + async updateUser(request, response, next) { + try { + const updatedUser = await UserService.updateUser(request.params.email, request.body); + if (!updatedUser) { + response.status(404).send({ message: 'User not found.' }); + return; + } + response.status(200).send(updatedUser); + } catch (e) { + next(e); + } + } + + async deleteUser(request, response, next) { + try { + const deletedUser = await UserService.deleteUser(request.params.email); + if (!deletedUser) { + response.status(404).send({ message: 'User not found.' }); + return; + } + response.status(200).send(deletedUser); + } catch (e) { + next(e); + } + } +} + +module.exports = UsersController; diff --git a/backend/node-express-js/node-express-mongoose-js/app/user/user.model.js b/backend/node-express-js/node-express-mongoose-js/app/user/user.model.js new file mode 100644 index 0000000..a1c4ecc --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/user/user.model.js @@ -0,0 +1,15 @@ +const mongoose = require('mongoose'); + +const userSchema = new mongoose.Schema({ + name: { + type: String, + required: true + }, + email: { + type: String, + required: true, + unique: true + } +}); + +module.exports = mongoose.model('User', userSchema); diff --git a/backend/node-express-js/node-express-mongoose-js/app/user/user.service.js b/backend/node-express-js/node-express-mongoose-js/app/user/user.service.js new file mode 100644 index 0000000..f59b650 --- /dev/null +++ b/backend/node-express-js/node-express-mongoose-js/app/user/user.service.js @@ -0,0 +1,45 @@ +const User = require('../models/user'); + +class UserService { + async getUsers() { + try { + return await User.find(); + } catch (err) { + throw new Error('Error fetching users from the database.'); + } + } + + async getUserByEmail(email) { + try { + return await User.findOne({ email: email }); + } catch (err) { + throw new Error('Error fetching user by email.'); + } + } + + async createUser(user) { + try { + return await User.create(user); + } catch (err) { + throw new Error('Error creating user.'); + } + } + + async updateUser(email, user) { + try { + return await User.findOneAndUpdate({ email: email }, user, { new: true }); + } catch (err) { + throw new Error('Error updating user.'); + } + } + + async deleteUser(email) { + try { + return await User.findOneAndDelete({ email: email }); + } catch (err) { + throw new Error('Error deleting user.'); + } + } +} + +module.exports = new UserService(); // Exporting an instance of the service diff --git a/backend/node-express/mongoose/package.json b/backend/node-express-js/node-express-mongoose-js/package.json similarity index 59% rename from backend/node-express/mongoose/package.json rename to backend/node-express-js/node-express-mongoose-js/package.json index c443b53..4ba186b 100644 --- a/backend/node-express/mongoose/package.json +++ b/backend/node-express-js/node-express-mongoose-js/package.json @@ -1,7 +1,7 @@ { - "name": "node-express-base-seed", + "name": "node-express-mongoose-js", "version": "1.0.0", - "description": "A foundational seed for Node-Express projects.", + "description": "A foundational seed for Node-Express and Javascript with Mongoose projects.", "main": "server.js", "scripts": { "start": "node server.js" diff --git a/backend/node-express/hello-world/server.js b/backend/node-express-js/node-express-mongoose-js/server.js similarity index 100% rename from backend/node-express/hello-world/server.js rename to backend/node-express-js/node-express-mongoose-js/server.js diff --git a/backend/node-express-js/node-express-starter-js/.env.example b/backend/node-express-js/node-express-starter-js/.env.example new file mode 100644 index 0000000..c0c68b1 --- /dev/null +++ b/backend/node-express-js/node-express-starter-js/.env.example @@ -0,0 +1 @@ +PORT=3000 \ No newline at end of file diff --git a/backend/node-express-js/node-express-starter-js/README.md b/backend/node-express-js/node-express-starter-js/README.md new file mode 100644 index 0000000..0a6ea0a --- /dev/null +++ b/backend/node-express-js/node-express-starter-js/README.md @@ -0,0 +1,36 @@ +# Hello World - Node Express with Javascript Seed + +This seed is a basic starter for building an Express.js API with **JavaScript** that simply responds with "Hello, +World!". + +## Getting Started + +- Navigate to the `node-express-starter-js` directory. +- Configure environment variables as described in the [local development](#local-development) section. +- Run `yarn install` to install the necessary dependencies. +- Use `yarn start` to start the server. +- Access the API at `http://localhost:3000`. You should receive a "Hello, World!" message. +- The `healthz` endpoint at http://localhost:3000/healthz provides a health check response which is crucial for + Warestack's deployment automation. + +## Dependencies + +This seed uses: + +- [Express.js](https://expressjs.com/): A fast, minimalist web framework for Node.js. + +## Local Development + +This seed uses environment variables for configuration: + +- Make sure to set up your `.env` file by using `.env.example` as a reference. +- Adjust the values in `.env` as necessary to match your setup. + +## Warestack Deployments + +For this Flask API to be compatible with automated deployments on Warestack, the inclusion of the `healthz` endpoint is +mandatory. Warestack uses this endpoint to ensure that the service is running correctly. + +## Questions & Contributions + +If you have any questions or wish to contribute, please open an issue or submit a pull request. diff --git a/backend/node-express/hello-world/app/app.js b/backend/node-express-js/node-express-starter-js/app/app.js similarity index 54% rename from backend/node-express/hello-world/app/app.js rename to backend/node-express-js/node-express-starter-js/app/app.js index 70c6ca9..7f729bb 100644 --- a/backend/node-express/hello-world/app/app.js +++ b/backend/node-express-js/node-express-starter-js/app/app.js @@ -1,6 +1,7 @@ const express = require('express'); -const GreetingController = require('./greeting/greeting.controller'); +const RootController = require('./root/root.controller'); +const HealthController = require('./health/health.controller'); class App { constructor() { @@ -12,7 +13,8 @@ class App { } routes() { - this.app.use('/greeting', new GreetingController().getRouter()); + this.app.use('/', new RootController().getRouter()); + this.app.use('/healthz', new HealthController().getRouter()); } } diff --git a/backend/node-express-js/node-express-starter-js/app/health/health.controller.js b/backend/node-express-js/node-express-starter-js/app/health/health.controller.js new file mode 100644 index 0000000..2f4e88c --- /dev/null +++ b/backend/node-express-js/node-express-starter-js/app/health/health.controller.js @@ -0,0 +1,23 @@ +const express = require('express'); + +const HealthService = require('./health.service'); + +class HealthController { + constructor() { + this.router = express.Router(); + + // Setting the routes for the greeting endpoint group + this.router.get('/', this.health().bind(this)); // Binding is necessary for 'this' to refer to the class instance + } + + getRouter() { + return this.router; + } + + async health(request, response, next) { + const message = HealthService.health(); + response.status(200).send(message); + } +} + +module.exports = HealthController; diff --git a/backend/node-express-js/node-express-starter-js/app/health/health.service.js b/backend/node-express-js/node-express-starter-js/app/health/health.service.js new file mode 100644 index 0000000..48952c0 --- /dev/null +++ b/backend/node-express-js/node-express-starter-js/app/health/health.service.js @@ -0,0 +1,7 @@ +class HealthService { + health() { + return "I am healthy!"; + } +} + +module.exports = new HealthService(); // Exporting an instance of the service diff --git a/backend/node-express-js/node-express-starter-js/app/root/root.controller.js b/backend/node-express-js/node-express-starter-js/app/root/root.controller.js new file mode 100644 index 0000000..4a2e203 --- /dev/null +++ b/backend/node-express-js/node-express-starter-js/app/root/root.controller.js @@ -0,0 +1,22 @@ +const express = require('express'); +const RootService = require('./root.service'); + +class RootController { + constructor() { + this.router = express.Router(); + + // Setting the routes for the root endpoint group + this.router.get('/', this.info.bind(this)); // Binding is necessary for 'this' to refer to the class instance + } + + getRouter() { + return this.router; + } + + async info(request, response, next) { + const message = RootService.info(); + response.status(200).send(message); + } +} + +module.exports = RootController; diff --git a/backend/node-express-js/node-express-starter-js/app/root/root.service.js b/backend/node-express-js/node-express-starter-js/app/root/root.service.js new file mode 100644 index 0000000..f3516d3 --- /dev/null +++ b/backend/node-express-js/node-express-starter-js/app/root/root.service.js @@ -0,0 +1,7 @@ +class RootService { + info() { + return "Hello, World!"; + } +} + +module.exports = new RootService(); // Exporting an instance of the service diff --git a/backend/node-express/hello-world/package.json b/backend/node-express-js/node-express-starter-js/package.json similarity index 55% rename from backend/node-express/hello-world/package.json rename to backend/node-express-js/node-express-starter-js/package.json index 2e98857..195fcb3 100644 --- a/backend/node-express/hello-world/package.json +++ b/backend/node-express-js/node-express-starter-js/package.json @@ -1,7 +1,7 @@ { - "name": "node-express-base-seed", + "name": "node-express-started-js", "version": "1.0.0", - "description": "A foundational seed for Node-Express projects.", + "description": "A foundational seed for Node-Express and Javascript projects.", "main": "server.js", "scripts": { "start": "node server.js" diff --git a/backend/node-express/mongoose/server.js b/backend/node-express-js/node-express-starter-js/server.js similarity index 100% rename from backend/node-express/mongoose/server.js rename to backend/node-express-js/node-express-starter-js/server.js diff --git a/backend/node-express/hello-world/README.md b/backend/node-express/hello-world/README.md deleted file mode 100644 index f276d35..0000000 --- a/backend/node-express/hello-world/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Hello World - Node Express Seed - -This seed is a basic starter for building an Express.js API that simply responds with "Hello, World!". - -## Getting Started - -1. Navigate to the `hello-world` directory. -2. Run `yarn install` to install the necessary dependencies. -3. Use `yarn start` to start the server. -4. Access the API at `http://localhost:3000/greeting`. You should receive a "Hello, World!" message. - -## Dependencies - -This seed uses: - -- [Express.js](https://expressjs.com/): A fast, minimalist web framework for Node.js. - -## Questions & Contributions - -If you have any questions or wish to contribute, please open an issue or submit a pull request. diff --git a/backend/node-express/hello-world/app/greeting/greeting.controller.js b/backend/node-express/hello-world/app/greeting/greeting.controller.js deleted file mode 100644 index ef39176..0000000 --- a/backend/node-express/hello-world/app/greeting/greeting.controller.js +++ /dev/null @@ -1,22 +0,0 @@ -const express = require('express'); -const GreetingService = require('./greeting.service') - -class GreetingController { - constructor() { - this.router = express.Router(); - - // Setting the routes for the greeting endpoint group - this.router.get('/', this.hello.bind(this)); // Binding is necessary for 'this' to refer to the class instance - } - - getRouter() { - return this.router; - } - - async hello(request, response, next) { - const message = GreetingService.hello(); - response.status(200).send(message); - } -} - -module.exports = GreetingController; diff --git a/backend/node-express/hello-world/app/greeting/greeting.service.js b/backend/node-express/hello-world/app/greeting/greeting.service.js deleted file mode 100644 index 118335f..0000000 --- a/backend/node-express/hello-world/app/greeting/greeting.service.js +++ /dev/null @@ -1,7 +0,0 @@ -class GreetingService { - hello() { - return "Hello World!"; - } -} - -module.exports = new GreetingService(); // Exporting an instance of the service diff --git a/backend/node-express/mongoose/README.md b/backend/node-express/mongoose/README.md deleted file mode 100644 index 0e67546..0000000 --- a/backend/node-express/mongoose/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Mongoose - Node Express Seed - -This seed helps you kickstart your Node.js projects using Express.js with integrated MongoDB support through Mongoose. - -## Getting Started - -1. Navigate to the `mongoose` directory. -2. **Environment Configuration**: - - Copy the `.env.example` file and rename it to `.env`. - - Fill out the required environment variables in the `.env` file, especially the MongoDB connection string and other - related configurations. -3. Ensure you have a MongoDB instance running or use your connection string in the `.env` for an external database. -4. Run `yarn install` to install the necessary dependencies. -5. Use `yarn start` to start the server. -6. Your API is now connected to a MongoDB instance, and you can begin creating models, routes, etc. - -## Dependencies - -This seed uses: - -- [Express.js](https://expressjs.com/): A fast, minimalist web framework for Node.js. -- [Mongoose](https://mongoosejs.com/): Elegant MongoDB object modeling for Node.js. - -## Configuration - -This seed uses environment variables for configuration: - -- Make sure to set up your `.env` file by using `.env.example` as a reference. -- Adjust the values in `.env` as necessary to match your setup. - -## Questions & Contributions - -If you have any questions or wish to contribute, please open an issue or submit a pull request. diff --git a/backend/node-express/mongoose/app/user/user.controller.js b/backend/node-express/mongoose/app/user/user.controller.js deleted file mode 100644 index c8b9776..0000000 --- a/backend/node-express/mongoose/app/user/user.controller.js +++ /dev/null @@ -1,26 +0,0 @@ -const express = require('express'); -const UserService = require('./user.service') - -class UsersController { - constructor() { - this.router = express.Router(); - - // Setting the routes for the users endpoint group - this.router.get('/', this.getUsers.bind(this)); // Binding is necessary for 'this' to refer to the class instance - } - - getRouter() { - return this.router; - } - - async getUsers(request, response, next) { - try { - const users = UserService.getUsers(); - response.status(200).send(users); - } catch (e) { - next(new Error('No greeting found.')); - } - } -} - -module.exports = UsersController; diff --git a/backend/node-express/mongoose/app/user/user.service.js b/backend/node-express/mongoose/app/user/user.service.js deleted file mode 100644 index 6886327..0000000 --- a/backend/node-express/mongoose/app/user/user.service.js +++ /dev/null @@ -1,20 +0,0 @@ -class UserService { - getUsers() { - // Dummy greeting data in response - const users = [ - { - id: 1, - name: 'John Doe', - email: 'johndoe@example.com' - }, - { - id: 2, - name: 'Jane Smith', - email: 'janesmith@example.com' - }]; - - return users; - } -} - -module.exports = new UserService(); // Exporting an instance of the service diff --git a/backend/python-flask/README.md b/backend/python-flask/README.md new file mode 100644 index 0000000..c1c749c --- /dev/null +++ b/backend/python-flask/README.md @@ -0,0 +1,17 @@ +# Python-Flask Seeds + +This repository contains multiple seeds (starter templates) for Python projects using Flask with different +configurations and additions. + +## Folder Structure + +- **flask-starter**: This contains a basic Python-Flask seed to get you started with a simple "Hello, World!" API. +- **flask-mongoengine**: This seed sets you up with MongoEngine for those preferring a MongoDB setup with Flask. + +## Getting Started + +To use any of the seeds, navigate to the respective folder and follow the instructions in its README. + +## Contributions + +Feel free to contribute to these seeds by submitting pull requests or opening issues with suggestions/improvements. diff --git a/backend/python-flask/flask-mongoengine/.env.example b/backend/python-flask/flask-mongoengine/.env.example new file mode 100644 index 0000000..8bc8417 --- /dev/null +++ b/backend/python-flask/flask-mongoengine/.env.example @@ -0,0 +1,3 @@ +FLASK_APP=server.py +PORT=5000 +MONGO_URI=mongodb:// \ No newline at end of file diff --git a/backend/python-flask/flask-mongoengine/README.md b/backend/python-flask/flask-mongoengine/README.md new file mode 100644 index 0000000..386a84d --- /dev/null +++ b/backend/python-flask/flask-mongoengine/README.md @@ -0,0 +1,45 @@ +# flask-starter + +This seed is a foundational starter for building a Flask API integrated with MongoDB using MongoEngine. It offers the +following features: + +- A basic endpoint responding with "Hello, World!". +- A comprehensive suite of CRUD operations for the `users` resource, allowing interactions like listing, creating, + fetching, updating, and deleting users based on their email. +- A `healthz` endpoint, indispensable for automated deployments on Warestack. + +## Getting Started + +- Navigate to the `flask-starter` directory. +- Configure environment variables as described in the [local development](#local-development) section. +- Run `pip install -r requirements.txt` to install the necessary dependencies. +- Use `python3 server.py` to start the server. +- Access the API at `http://localhost:5000`. You should receive a "Hello, World!" message. +- User operations are available at http://localhost:5000/users. For specific user operations, use their email, e.g., + http://localhost:5000/users/useremail@example.com. +- The healthz endpoint at http://localhost:5000/healthz provides a health check response which is crucial for + Warestack's deployment automation. + +## Dependencies + +This seed uses: + +- [Flask](https://flask.palletsprojects.com/en/3.0.x/): Flask is a micro web framework written in Python. +- [MongoEngine](http://mongoengine.org/): MongoEngine is an Object-Document Mapper (ODM) for Python that provides a + high-level abstraction on top of PyMongo. + +## Local Development + +This seed uses environment variables for configuration: + +- Make sure to set up your `.env` file by using `.env.example` as a reference. +- Adjust the values in `.env` as necessary to match your setup. + +## Warestack Deployments + +For this Flask API to be compatible with automated deployments on Warestack, the inclusion of the `healthz` endpoint is +mandatory. Warestack uses this endpoint to ensure that the service is running correctly. + +## Questions & Contributions + +If you have any questions or wish to contribute, please open an issue or submit a pull request. diff --git a/backend/python-flask/flask-mongoengine/app/init.py b/backend/python-flask/flask-mongoengine/app/init.py new file mode 100644 index 0000000..9325e4b --- /dev/null +++ b/backend/python-flask/flask-mongoengine/app/init.py @@ -0,0 +1,29 @@ +from flask import Flask +from flask_mongoengine import MongoEngine +from dotenv import load_dotenv +import os + +load_dotenv() + +db = MongoEngine() + +def create_app(): + app = Flask(__name__) + app.config["MONGODB_SETTINGS"] = { + "host": os.getenv("MONGODB_URI") + } + db.init_app(app) + + # Import and register the root blueprint + from .routes import root as root_blueprint + app.register_blueprint(root_blueprint) + + # Import and register the health blueprint + from .routes import health as health_blueprint + app.register_blueprint(health_blueprint) + + # Import and register the users blueprint + from .routes import users as users_blueprint + app.register_blueprint(users_blueprint) + + return app diff --git a/backend/python-flask/flask-mongoengine/app/models/__init__.py b/backend/python-flask/flask-mongoengine/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/python-flask/flask-mongoengine/app/models/user_model.py b/backend/python-flask/flask-mongoengine/app/models/user_model.py new file mode 100644 index 0000000..a297521 --- /dev/null +++ b/backend/python-flask/flask-mongoengine/app/models/user_model.py @@ -0,0 +1,5 @@ +from app import db + +class User(db.Document): + name = db.StringField(required=True) + email = db.StringField(required=True) diff --git a/backend/python-flask/flask-mongoengine/app/routes/__init__.py b/backend/python-flask/flask-mongoengine/app/routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/python-flask/flask-mongoengine/app/routes/health.py b/backend/python-flask/flask-mongoengine/app/routes/health.py new file mode 100644 index 0000000..4836b43 --- /dev/null +++ b/backend/python-flask/flask-mongoengine/app/routes/health.py @@ -0,0 +1,7 @@ +from flask import Blueprint, jsonify + +health = Blueprint('health', __name__) + +@health.route('/healthz') +def health_check(): + return jsonify(status="healthy"), 200 diff --git a/backend/python-flask/flask-mongoengine/app/routes/root.py b/backend/python-flask/flask-mongoengine/app/routes/root.py new file mode 100644 index 0000000..644d89d --- /dev/null +++ b/backend/python-flask/flask-mongoengine/app/routes/root.py @@ -0,0 +1,8 @@ +from flask import Blueprint, jsonify +from app.models.example_model import Example + +root = Blueprint('root', __name__) + +@main.route('/') +def info(): + return jsonify(message="Hello, World!") diff --git a/backend/python-flask/flask-mongoengine/app/routes/users.py b/backend/python-flask/flask-mongoengine/app/routes/users.py new file mode 100644 index 0000000..7267c3e --- /dev/null +++ b/backend/python-flask/flask-mongoengine/app/routes/users.py @@ -0,0 +1,62 @@ +from flask import Blueprint, jsonify, request +from app.models import User + +users_blueprint = Blueprint('users', __name__) + +# List all users +@users_blueprint.route('/users', methods=['GET']) +def list_users(): + users = User.objects.all() + return jsonify(users=[{'name': user.name, 'email': user.email} for user in users]) + +# Create a new user +@users_blueprint.route('/users', methods=['POST']) +def create_user(): + data = request.get_json() + if not data: + return jsonify(message="No input data provided"), 400 + name = data.get('name') + email = data.get('email') + + if not name or not email: + return jsonify(message="Missing name or email"), 400 + + user = User(name=name, email=email) + user.save() + + return jsonify(message="User created successfully!", user={'name': user.name, 'email': user.email}), 201 + +# Get a specific user by email +@users_blueprint.route('/users/', methods=['GET']) +def get_user(email): + user = User.objects(email=email).first() + if not user: + return jsonify(message="User not found"), 404 + return jsonify(user={'name': user.name, 'email': user.email}) + +# Update a user's details by email +@users_blueprint.route('/users/', methods=['PUT']) +def update_user(email): + user = User.objects(email=email).first() + if not user: + return jsonify(message="User not found"), 404 + + data = request.get_json() + if not data: + return jsonify(message="No input data provided"), 400 + + user.name = data.get('name', user.name) + user.email = data.get('email', user.email) + user.save() + + return jsonify(message="User updated successfully", user={'name': user.name, 'email': user.email}) + +# Delete a user by email +@users_blueprint.route('/users/', methods=['DELETE']) +def delete_user(email): + user = User.objects(email=email).first() + if not user: + return jsonify(message="User not found"), 404 + + user.delete() + return jsonify(message="User deleted successfully") diff --git a/backend/python-flask/flask-mongoengine/requirements.txt b/backend/python-flask/flask-mongoengine/requirements.txt new file mode 100644 index 0000000..584e45e --- /dev/null +++ b/backend/python-flask/flask-mongoengine/requirements.txt @@ -0,0 +1,4 @@ +Flask +MongoEngine +Flask-MongoEngine +python-dotenv diff --git a/backend/python-flask/flask-mongoengine/server.py b/backend/python-flask/flask-mongoengine/server.py new file mode 100644 index 0000000..b90d135 --- /dev/null +++ b/backend/python-flask/flask-mongoengine/server.py @@ -0,0 +1,8 @@ +from app import create_app + +app = create_app() + +if __name__ == "__main__": + # Fetch the PORT environment variable, default to 5000 if it doesn't exist + port = int(os.environ.get('PORT', 5000)) + app.run(debug=True, port=port) diff --git a/backend/python-flask/flask-starter/.env.example b/backend/python-flask/flask-starter/.env.example new file mode 100644 index 0000000..b781f35 --- /dev/null +++ b/backend/python-flask/flask-starter/.env.example @@ -0,0 +1,2 @@ +FLASK_APP=server.py +PORT=5000 \ No newline at end of file diff --git a/backend/python-flask/flask-starter/README.md b/backend/python-flask/flask-starter/README.md new file mode 100644 index 0000000..30afd39 --- /dev/null +++ b/backend/python-flask/flask-starter/README.md @@ -0,0 +1,36 @@ +# flask-starter + +This seed is a basic starter for building a Flask API that simply responds with "Hello, World!". Additionally, it +includes a `healthz` endpoint, essential for automated deployments on Warestack. + +## Getting Started + +- Navigate to the `flask-starter` directory. +- Configure environment variables as described in the [local development](#local-development) section. +- Run `pip install -r requirements.txt` to install the necessary dependencies. +- Use `python3 server.py` to start the server. +- Access the API at `http://localhost:5000`. You should receive a "Hello, World!" message. +- The healthz endpoint at http://localhost:5000/healthz provides a health check response which is crucial for + Warestack's deployment automation. + +## Dependencies + +This seed uses: + +- [Flask](https://flask.palletsprojects.com/en/3.0.x/): Flask is a micro web framework written in Python. + +## Local Development + +This seed uses environment variables for configuration: + +- Make sure to set up your `.env` file by using `.env.example` as a reference. +- Adjust the values in `.env` as necessary to match your setup. + +## Warestack Deployments + +For this Flask API to be compatible with automated deployments on Warestack, the inclusion of the `healthz` endpoint is +mandatory. Warestack uses this endpoint to ensure that the service is running correctly. + +## Questions & Contributions + +If you have any questions or wish to contribute, please open an issue or submit a pull request. diff --git a/backend/python-flask/flask-starter/app/init.py b/backend/python-flask/flask-starter/app/init.py new file mode 100644 index 0000000..1e0c680 --- /dev/null +++ b/backend/python-flask/flask-starter/app/init.py @@ -0,0 +1,15 @@ +from flask import Flask +from dotenv import load_dotenv + +load_dotenv() + +def create_app(): + app = Flask(__name__) + + from .routes import root as root_blueprint + app.register_blueprint(root_blueprint) + + from .routes import health as health_blueprint + app.register_blueprint(health_blueprint) + + return app diff --git a/backend/python-flask/flask-starter/app/models/__init__.py b/backend/python-flask/flask-starter/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/python-flask/flask-starter/app/models/user_model.py b/backend/python-flask/flask-starter/app/models/user_model.py new file mode 100644 index 0000000..a297521 --- /dev/null +++ b/backend/python-flask/flask-starter/app/models/user_model.py @@ -0,0 +1,5 @@ +from app import db + +class User(db.Document): + name = db.StringField(required=True) + email = db.StringField(required=True) diff --git a/backend/python-flask/flask-starter/app/routes/__init__.py b/backend/python-flask/flask-starter/app/routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/python-flask/flask-starter/app/routes/health.py b/backend/python-flask/flask-starter/app/routes/health.py new file mode 100644 index 0000000..4836b43 --- /dev/null +++ b/backend/python-flask/flask-starter/app/routes/health.py @@ -0,0 +1,7 @@ +from flask import Blueprint, jsonify + +health = Blueprint('health', __name__) + +@health.route('/healthz') +def health_check(): + return jsonify(status="healthy"), 200 diff --git a/backend/python-flask/flask-starter/app/routes/root.py b/backend/python-flask/flask-starter/app/routes/root.py new file mode 100644 index 0000000..efd0874 --- /dev/null +++ b/backend/python-flask/flask-starter/app/routes/root.py @@ -0,0 +1,7 @@ +from flask import Blueprint, jsonify + +root = Blueprint('root', __name__) + +@main.route('/') +def info(): + return jsonify(message="Hello, World!") diff --git a/backend/python-flask/flask-starter/requirements.txt b/backend/python-flask/flask-starter/requirements.txt new file mode 100644 index 0000000..8156513 --- /dev/null +++ b/backend/python-flask/flask-starter/requirements.txt @@ -0,0 +1,2 @@ +Flask +python-dotenv diff --git a/backend/python-flask/flask-starter/server.py b/backend/python-flask/flask-starter/server.py new file mode 100644 index 0000000..488dae9 --- /dev/null +++ b/backend/python-flask/flask-starter/server.py @@ -0,0 +1,6 @@ +from app import create_app + +app = create_app() + +if __name__ == "__main__": + app.run(debug=True)