spy4x / seed Goto Github PK
View Code? Open in Web Editor NEWFull-stack startup monorepo template. Build your next startup idea with best practices from day 1!
Full-stack startup monorepo template. Build your next startup idea with best practices from day 1!
Right now it only deletes the user's row in DB.
Problem:
If an exception is raised in an event handler - it kills the execution pipe for all other event handlers.
But the application survives that and keeps running, just without any event handlers execution.
A solution might be to add a try-catch block in a proper place (to EventBusExt? or implement a BaseEventHandler class?).
try {
this.handle(fn)
} catch (error: unknown) {
logSegment.error({ error: error as Error });
}
How to do it: https://youtu.be/-qJv4ks6YAE?t=6312
After it's done - remove usage of @prisma/client
in frontend apps
Right now application just "trusts" the environment that all required variables are presented. Which leads to exceptions being raised later on if some of them are missing.
We need a functions that checks if environment is presented and throws an error if it's not.
Before:
export const API_CONFIG = {
redisHost: process.env['REDIS_HOST'] as string,
// ... other vars
};
After:
export const API_CONFIG = {
redisHost: getEnv('REDIS_HOST'),
// ... other vars
};
function getEnv(name: string): string {
const value = process.env[name];
if(!value) {
throw new Error(`Environment variable ${name} is misssing`);
}
return value;
}
"compilerOptions": {
"plugins": ["@nestjs/swagger/plugin"]
}
Links:
it's rarely used by SaaS startups, mostly by social networks.
$ yarn prisma migrate dev --name users_add_email
$ yarn format && yarn precommit && yarn nx affected:build
succeedsfront-web
(http://localhost:4200)Related to #109 - field "email" replaces field "userName".
Client app:
Admin app:
Rephrase text using Amazon "backwards" approach:
It is UI component responsibility to validate inputs.
Right now CacheManager stores values in-memory.
We should move it to Redis.
This is where it is configured.
This is how it should be configured:
import * as redisStore from 'cache-manager-redis-store'; // TODO: yarn add cache-manager-redis-store
const cacheModule = CacheModule.register({
store: redisStore as unknown as CacheStoreFactory,
port: 6379,
host: API_CONFIG.redisHost,
ttl: CacheTTL.week,
});
Right now LogService usage is a nasty overwhelming boilerplate.
Every controller's endpoint and command/query/event handler function look like this:
async methodName(...params): ReturnType {
return this.logger.trackSegment(this.methodName.name, async () => {
... actual code ...
}, {params});
}
It would be neat to simplify this to just:
@Logger()
async methodName(...params): ReturnType {
... actual code ...
}
webpack-bundle-analyzer
to figure out what's inside the bundleimport type
instead of just import
. Example: import type {Prisma} from '@prisma/client';
Field properties:
Related to #108 - field "email" replaces field "userName".
Parts are similar to "userName" (check related issue) - frontend, backend, prisma field definition, prisma migration.
libs/front/shared/auth/ui/src/lib/profile/profile.component.html
.Look at libs/front/web/auth/src/lib/create-profile/create-profile.component.html
as an example.
Note: you'll need to define a form = new FormGroup({...});
in TS file to make HTML form fields work.
Define @Output() update = new EventEmitter<User>();
and @Input() isSaving = false
for delegating a parent component (libs/front/web/profile/src/lib/profile/profile.component.html
) to handle the logic and provide a loading state back to this component.
Implement necessary NGRX actions, effects, and selectors to handle the REST API interaction. Folder: libs/front/shared/auth/state/src/lib/+state
Use implemented action and selector in libs/front/web/profile/src/lib/profile/profile.component.ts
to initiate an update and watch the loading state. Check if it works. Repeat in libs/front/admin/profile/src/lib/profile/profile.component.html
The final result will look similar to the "Create Profile" component, just with photoURL
field instead of email
:
Next command should run before a deployment: $ yarn prisma migrate deploy
Main Flow:
1. Ask email
2. Get providers for the email (fetchSignInMethodsForEmail)
3. If no providers - show "Sign up flow" (see below)
4. If one provider - initiate it straight away
5. If multiple providers - show icons for each of them
6. User initiates some provider flow
Sign up flow:
1. Show all possible providers
2. User initiates some provider flow
Places:
$ yarn remove @fortawesome/fontawesome-free
libs/front/shared/styles/src/shared/imports.sass
Frontend:
Backend:
{
"hosting": {
"rewrites": [{
"source": "/api",
"run": {
"serviceId": "api",
"region": "us-central1"
}
}]
"headers": [{
"source": "/api",
"headers": [{
"key": "Cache-Control",
"value": "no-store"
}]
}]
}
}
This document is WIP. It will be used to create a script that initializes the whole Google Cloud structure for you automatically.
Project initialization (for new users)
MANUALLY:
# Install Google Cloud CLI https://cloud.google.com/sdk/docs/install
# Create Firebase Hosting Sites for Admin Panel & Web Client
firebase hosting:sites:create SITE_ID
SCRIPT:
# Environment variables:
PROJECT_ID=FILL_WITH_YOUR_VALUE
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)')
CLOUD_RUN_API_APP_NAME=api
REGION=us-central1
FRONT_WEB_CLIENT_HOSTING_TARGET=seed-web-client
FRONT_ADMIN_PANEL_HOSTING_TARGET=seed-admin-panel
# Create SQL instance and get connection name
TODO
INSTANCE_CONNECTION_NAME=TODO
DB_CONNECTION_STRING=TODO
gcloud sql instances create $CLOUD_SQL_INSTANCE_NAME \
--database-version=POSTGRES_13 \
--region=$REGION \
--tier=db-f1-micro \
--authorized-networks=<AUTHORIZED_IP> \
--root-password=DB_PASSWORD
# outputs DB IP address
# Enable APIs
gcloud services enable --project "${PROJECT_ID}" \
containerregistry.googleapis.com \
run.googleapis.com \
secretmanager.googleapis.com \
firebase.googleapis.com
gcloud config set run/platform managed
gcloud config set run/region $REGION
API_URL=gcloud run services describe $CLOUD_RUN_API_APP_NAME --format='value(status.url)'
# Configure Docker to have access to Google Cloud Container Registry
gcloud auth configure-docker
# Grant Cloud Build permission to manage Cloud Run
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:[email protected] \
--role=roles/run.admin
gcloud iam service-accounts add-iam-policy-binding \
[email protected] \
--member=serviceAccount:[email protected] \
--role=roles/iam.serviceAccountUser
# Grant Cloud Build permission to deploy Firebase
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:[email protected] \
--role=roles/firebase.admin
# Grant Cloud Build permission to access Secret Manager
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member=serviceAccount:[email protected] \
--role=roles/secretmanager.secretAccessor
# Install builders for caching
gcloud builds submit --config cloud-build/init-builders.yaml --no-source
gsutil mb gs://${PROJECT_ID}_cloudbuild_cache
# TODO: add bucket lifecycle rule
# Deploy custom builder
docker build . -t gcr.io/$PROJECT_ID/builder -f cloud-build/builder.dockerfile
docker push gcr.io/$PROJECT_ID/builder
# Fill Secrets
echo -n $REGION | \
gcloud secrets create REGION --data-file=-
echo -n $CLOUD_RUN_API_APP_NAME | \
gcloud secrets create CLOUD_RUN_API_APP_NAME --data-file=-
echo -n $API_URL | \
gcloud secrets create API_URL --data-file=-
echo -n "postgresql://postgres:uL9xjQk6VzWnd4vVNXwiHVe6rv4ALJ@localhost/postgres?host=/cloudsql/seed-anton:us-central1:seed-db" | \
gcloud secrets create DB_CONNECTION_STRING --data-file=-
echo -n "seed-anton:us-central1:seed-db" | \
gcloud secrets create INSTANCE_CONNECTION_NAME --data-file=-
echo -n $FRONT_WEB_CLIENT_HOSTING_TARGET | \
gcloud secrets create FRONT_WEB_CLIENT_HOSTING_TARGET --data-file=-
echo -n $FRONT_ADMIN_PANEL_HOSTING_TARGET | \
gcloud secrets create FRONT_ADMIN_PANEL_HOSTING_TARGET --data-file=-
# TODO: generate .envs/* files
OPTIONAL:
- How to init Nx Cloud accessToken private key
A Seed user (developer) should be able to clone Seed and run a script/command that would setup the whole infrastructure for it in the cloud.
$ yarn nx run-many --target=deploy --all=true
) - should be defined if it is convenient.User executes $ yarn setup:cloud
that runs one of:
docs/how-to-init-cloud-infrastructure.md
$ npx seed-startup
Wizard that: 1. clones repo 2. installs deps 3. asks for ProjectID and if it should setup infrastructure nowFile: libs/front/shared/styles/src/shared/imports.sass
It's vertical and viewer has to scroll a lot to see it all.
It would be good to change it to something like a table with horizontal cells, maybe multiple rows.
Ideas? Suggestions?
Can be generated using tools like https://github.com/mingrammer/diagrams
Responsibilities of "event bus":
"Queue"
A node posts an event, then a free node can grab and process it.
Example: Delivery order statuses change: Order created -> Cooking -> Delivery in progress -> Delivered.
"Bus"
A node posts an event, then all nodes are notified.
Example: WebSocket notifications to all participants in a chat app.
Candidates:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.