Skip to content

Commit 28cb2c4

Browse files
MihracMihrac
authored andcommitted
first auth_service commit
0 parents  commit 28cb2c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2183
-0
lines changed

.cursorrules

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
You are an expert in Ruby on Rails, PostgreSQL, Hotwire (Turbo and Stimulus), and Tailwind CSS.
3+
4+
Code Style and Structure
5+
- Write concise, idiomatic Ruby code with accurate examples.
6+
- Follow Rails conventions and best practices.
7+
- Use object-oriented and functional programming patterns as appropriate.
8+
- Prefer iteration and modularization over code duplication.
9+
- Use descriptive variable and method names (e.g., user_signed_in?, calculate_total).
10+
- Structure files according to Rails conventions (MVC, concerns, helpers, etc.).
11+
12+
Naming Conventions
13+
- Use snake_case for file names, method names, and variables.
14+
- Use CamelCase for class and module names.
15+
- Follow Rails naming conventions for models, controllers, and views.
16+
17+
Ruby and Rails Usage
18+
- Use Ruby 3.x features when appropriate (e.g., pattern matching, endless methods).
19+
- Leverage Rails' built-in helpers and methods.
20+
- Use ActiveRecord effectively for database operations.
21+
22+
Syntax and Formatting
23+
- Follow the Ruby Style Guide (https://rubystyle.guide/)
24+
- Use Ruby's expressive syntax (e.g., unless, ||=, &.)
25+
- Prefer single quotes for strings unless interpolation is needed.
26+
27+
Error Handling and Validation
28+
- Use exceptions for exceptional cases, not for control flow.
29+
- Implement proper error logging and user-friendly messages.
30+
- Use ActiveModel validations in models.
31+
- Handle errors gracefully in controllers and display appropriate flash messages.
32+
33+
UI and Styling
34+
- Use Hotwire (Turbo and Stimulus) for dynamic, SPA-like interactions.
35+
- Implement responsive design with Tailwind CSS.
36+
- Use Rails view helpers and partials to keep views DRY.
37+
38+
Performance Optimization
39+
- Use database indexing effectively.
40+
- Implement caching strategies (fragment caching, Russian Doll caching).
41+
- Use eager loading to avoid N+1 queries.
42+
- Optimize database queries using includes, joins, or select.
43+
44+
Key Conventions
45+
- Follow RESTful routing conventions.
46+
- Use concerns for shared behavior across models or controllers.
47+
- Implement service objects for complex business logic.
48+
- Use background jobs (e.g., Sidekiq) for time-consuming tasks.
49+
50+
Testing
51+
- Write comprehensive tests using RSpec or Minitest.
52+
- Follow TDD/BDD practices.
53+
- Use factories (FactoryBot) for test data generation.
54+
55+
Security
56+
- Implement proper authentication and authorization (e.g., Devise, Pundit).
57+
- Use strong parameters in controllers.
58+
- Protect against common web vulnerabilities (XSS, CSRF, SQL injection).
59+
60+
Follow the official Ruby on Rails guides for best practices in routing, controllers, models, views, and other Rails components.
61+

.dockerignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2+
3+
# Ignore git directory.
4+
/.git/
5+
/.gitignore
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all environment files (except templates).
11+
/.env*
12+
!/.env*.erb
13+
14+
# Ignore all default key files.
15+
/config/master.key
16+
/config/credentials/*.key
17+
18+
# Ignore all logfiles and tempfiles.
19+
/log/*
20+
/tmp/*
21+
!/log/.keep
22+
!/tmp/.keep
23+
24+
# Ignore pidfiles, but keep the directory.
25+
/tmp/pids/*
26+
!/tmp/pids/.keep
27+
28+
# Ignore storage (uploaded files in development and any SQLite databases).
29+
/storage/*
30+
!/storage/.keep
31+
/tmp/storage/*
32+
!/tmp/storage/.keep
33+
34+
# Ignore CI service files.
35+
/.github
36+
37+
# Ignore development files
38+
/.devcontainer
39+
40+
# Ignore Docker-related files
41+
/.dockerignore
42+
/Dockerfile*

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
2+
3+
# Mark the database schema as having been generated.
4+
db/schema.rb linguist-generated
5+
6+
# Mark any vendored files as having been vendored.
7+
vendor/* linguist-vendored
8+
config/credentials/*.yml.enc diff=rails_credentials
9+
config/credentials.yml.enc diff=rails_credentials

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: bundler
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
- package-ecosystem: github-actions
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
scan_ruby:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Ruby
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: .ruby-version
20+
bundler-cache: true
21+
22+
- name: Scan for common Rails security vulnerabilities using static analysis
23+
run: bin/brakeman --no-pager
24+
25+
lint:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Ruby
32+
uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: .ruby-version
35+
bundler-cache: true
36+
37+
- name: Lint code for consistent style
38+
run: bin/rubocop -f github
39+

.gitignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# Temporary files generated by your text editor or operating system
4+
# belong in git's global ignore instead:
5+
# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all logfiles and tempfiles.
11+
/log/*
12+
/tmp/*
13+
!/log/.keep
14+
!/tmp/.keep
15+
16+
# Ignore pidfiles, but keep the directory.
17+
/tmp/pids/*
18+
!/tmp/pids/
19+
!/tmp/pids/.keep
20+
21+
# Ignore uploaded files in development
22+
/storage/*
23+
!/storage/.keep
24+
25+
# Ignore master key for decrypting credentials
26+
/config/master.key
27+
28+
# Ignore environment variables
29+
.env
30+
.env.*
31+
32+
# Ignore database configuration
33+
/config/database.yml
34+
35+
# Ignore Redis dump file
36+
dump.rdb
37+
38+
# Ignore system files
39+
.DS_Store
40+
.idea/
41+
.vscode/
42+
43+
# Ignore node modules
44+
/node_modules
45+
46+
# Ignore yarn files
47+
/yarn-error.log
48+
yarn-debug.log*
49+
.yarn-integrity
50+
51+
# Ignore coverage files
52+
/coverage/

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Omakase Ruby styling for Rails
2+
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3+
4+
# Overwrite or add rules to create your own house style
5+
#
6+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7+
# Layout/SpaceInsideArrayLiteralBrackets:
8+
# Enabled: false

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.3.6

Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
4+
# docker build -t my-app .
5+
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
6+
7+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
8+
ARG RUBY_VERSION=3.3.6
9+
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
10+
11+
# Rails app lives here
12+
WORKDIR /rails
13+
14+
# Install base packages
15+
RUN apt-get update -qq && \
16+
apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
17+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
18+
19+
# Set production environment
20+
ENV RAILS_ENV="production" \
21+
BUNDLE_DEPLOYMENT="1" \
22+
BUNDLE_PATH="/usr/local/bundle" \
23+
BUNDLE_WITHOUT="development"
24+
25+
# Throw-away build stage to reduce size of final image
26+
FROM base AS build
27+
28+
# Install packages needed to build gems
29+
RUN apt-get update -qq && \
30+
apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config && \
31+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
32+
33+
# Install application gems
34+
COPY Gemfile Gemfile.lock ./
35+
RUN bundle install && \
36+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
37+
bundle exec bootsnap precompile --gemfile
38+
39+
# Copy application code
40+
COPY . .
41+
42+
# Precompile bootsnap code for faster boot times
43+
RUN bundle exec bootsnap precompile app/ lib/
44+
45+
46+
47+
48+
# Final stage for app image
49+
FROM base
50+
51+
# Copy built artifacts: gems, application
52+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
53+
COPY --from=build /rails /rails
54+
55+
# Run and own only the runtime files as a non-root user for security
56+
RUN groupadd --system --gid 1000 rails && \
57+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
58+
chown -R rails:rails db log storage tmp
59+
USER 1000:1000
60+
61+
# Entrypoint prepares the database.
62+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
63+
64+
# Start the server by default, this can be overwritten at runtime
65+
EXPOSE 3000
66+
CMD ["./bin/rails", "server"]

0 commit comments

Comments
 (0)