Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoApp committed Nov 5, 2024
1 parent 1bb2b9d commit d7065e1
Show file tree
Hide file tree
Showing 128 changed files with 5,629 additions and 6,618 deletions.
8 changes: 7 additions & 1 deletion .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ echo "export CODESPACE_WDS_SOCKET_PORT=443" >> ~/.bashrc
echo "printf \"\n\n☁️☁️☁️️ Anythink: Develop in the Cloud ☁️☁️☁️\n\"" >> ~/.bashrc
echo "printf \"\n\x1b[31m \x1b[1m👉 Type: \\\`docker compose up\\\` to run the project. 👈\n\n\"" >> ~/.bashrc

nohup bash -c "cd /wilco-agent && node agent.js &" >> /tmp/agent.log 2>&1
nohup bash -c "cd /wilco-agent && node agent.js &" >> /tmp/agent.log 2>&1

# Check if docker is installed
if command -v docker &> /dev/null
then
docker compose pull
fi
30 changes: 22 additions & 8 deletions .github/workflows/wilco-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,38 @@ jobs:
timeout-minutes: 10
name: Pr checks

services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
SECRET_KEY: secret
POSTGRES_DB: anythink-market
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out project
uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Start MongoDB
uses: supercharge/[email protected]
- name: Use Python
uses: actions/setup-python@v4
with:
mongodb-version: "4.4"
python-version: "3.9.13"

- uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}

- name: Setup Node for Wilco Checks
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Wilco checks
id: Wilco
uses: trywilco/actions@main
Expand Down
20 changes: 20 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
.env*
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git*
scripts
postman
./postgres-data
123 changes: 98 additions & 25 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,110 @@
# Logs
logs
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.DS_Store
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

npm-debug.log*
# Jupyter Notebook
.ipynb_checkpoints

# Runtime data
pids
*.pid
*.seed
# pyenv
.python-version

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# celery beat schedule file
celerybeat-schedule

# Coverage directory used by tools like istanbul
coverage
# SageMath parsed files
*.sage.py

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# node-waf configuration
.lock-wscript
# Spyder project settings
.spyderproject
.spyproject

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Rope project settings
.ropeproject

# Dependency directory
node_modules
# mkdocs documentation
/site

# Optional npm cache directory
.npm
# mypy
.mypy_cache/

# Optional REPL history
.node_repl_history
.idea/
.vscode/

.idea
# Project
postgres-data
1 change: 0 additions & 1 deletion backend/Dockerfile

This file was deleted.

15 changes: 10 additions & 5 deletions backend/Dockerfile.aws
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM node:16
FROM python:3.9.13

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN pip install poetry==1.2.0

# Pre-install poetry packages
WORKDIR /usr/src
COPY backend ./backend
COPY .wilco ./.wilco

# Pre-install npm packages
WORKDIR /usr/src/backend
RUN yarn install

RUN poetry install
RUN poetry export -f "requirements.txt" --without-hashes --with-credentials > "requirements.txt"
21 changes: 21 additions & 0 deletions backend/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Nik Sidnev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
SELLERS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 24 additions & 16 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
# Anythink Market Backend
Web routes
==========

The Anythink Market backend is Node web app written with [Express](https://expressjs.com/)
All routes are available on `/docs` or `/redoc` paths with Swagger or ReDoc.

## Dependencies
Project structure
=================

- [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) - For generating JWTs used by authentication
- [mongoose](https://github.com/Automattic/mongoose) - For modeling and mapping MongoDB data to javascript
- [mongoose-unique-validator](https://github.com/blakehaswell/mongoose-unique-validator) - For handling unique validation errors in Mongoose. Mongoose only handles validation at the document level, so a unique index across a collection will throw an exception at the driver level. The `mongoose-unique-validator` plugin helps us by formatting the error like a normal mongoose `ValidationError`.
- [passport](https://github.com/jaredhanson/passport) - For handling user authentication
- [slug](https://github.com/dodo/node-slug) - For encoding titles into a URL-friendly format
Files related to application are in the `app` or `tests` directories. Application parts are:

## Application Structure
app
├── api - web related stuff.
│   ├── dependencies - dependencies for routes definition.
│   ├── errors - definition of error handlers.
│   └── routes - web routes.
├── core - application configuration, startup events, logging.
├── db - db related stuff.
│   ├── migrations - manually written alembic migrations.
│   └── repositories - all crud stuff.
├── models - pydantic models for this application.
│   ├── domain - main models that are used almost everywhere.
│   └── schemas - schemas for using in web routes.
├── resources - strings that are used in web responses.
├── services - logic that is not just crud related.
└── main.py - FastAPI application creation and configuration.

- `app.js` - The entry point to our application. This file defines our express server and connects it to MongoDB using mongoose. It also requires the routes and models we'll be using in the application.
- `config/` - This folder contains configuration for passport as well as a central location for configuration/environment variables.
- `routes/` - This folder contains the route definitions for our API.
- `models/` - This folder contains the schema definitions for our Mongoose models.
Project structure
=================

## Error Handling

In `routes/api/index.js`, we define a error-handling middleware for handling Mongoose's `ValidationError`. This middleware will respond with a 422 status code and format the response to have [error messages the clients can understand](https://github.com/gothinkster/realworld/blob/master/API.md#errors-and-status-codes)
Project dependencies are managed by poetry (https://python-poetry.org), using venv (https://docs.python.org/3/library/venv.html).
36 changes: 36 additions & 0 deletions backend/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[alembic]
script_location = ./app/db/migrations

[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
Loading

0 comments on commit d7065e1

Please sign in to comment.